首页 > 解决方案 > NLTK 可用于停用词的语言

问题描述

我想知道在哪里可以找到 NLTK 停用词支持的语言(及其键)的完整列表。

我在https://pypi.org/project/stop-words/中找到了一个列表,但它不包含每个国家/地区的密钥。因此,尚不清楚您是否可以通过简单地检索列表stopwords.words("Bulgarian")。事实上,这会引发错误。

我查看了 NLTK 站点,有 4 个文档与“停用词”匹配,但没有一个文档描述了这一点。 https://www.nltk.org/search.html?q=stopwords&check_keywords=yes&area=default

他们的书中什么也没说: http ://www.nltk.org/book/ch02.html#stopwords_index_term

那么,你知道我在哪里可以找到钥匙列表吗?

标签: pythonnlpnltkstop-words

解决方案


当您使用以下方法导入停用词时:

from nltk.corpus import stopwords
english_stopwords = stopwords.words(language)

您正在根据 fileid(语言)检索停用词。为了查看所有可用的停用词语言,您可以使用以下命令检索文件 ID 列表:

from nltk.corpus import stopwords
print(stopwords.fileids())

对于 nltk v3.4.5,这将返回 23 种语言:

['arabic', 
 'azerbaijani', 
 'danish', 
 'dutch', 
 'english', 
 'finnish', 
 'french', 
 'german', 
 'greek',
 'hungarian', 
 'indonesian', 
 'italian', 
 'kazakh', 
 'nepali', 
 'norwegian', 
 'portuguese', 
 'romanian', 
 'russian', 
 'slovene', 
 'spanish', 
 'swedish', 
 'tajik', 
 'turkish']

推荐阅读