Skip to main content
 首页 » 编程设计

python之NLTK 停用词可用语言

2025年05月04日26lidabo

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

我在 https://pypi.org/project/stop-words/ 中找到了一个列表但它不包含每个国家/地区的 key 。因此,不清楚是否可以通过简单地 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

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

请您参考如下方法:

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

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

您正在根据文件 ID(语言)检索停用词。为了查看所有可用的停用词语言,您可以使用以下方法检索文件 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']