【发布时间】:2018-02-06 10:45:29
【问题描述】:
我在两台不同的机器(Mac 和 Linux)上运行相同的代码,尽管两台机器都运行相同版本的 nltk,但它们提供了不同数量语言的停用词列表(Mac 为 14 个,Linux 为 17 个) .
import nltk
nltk.__version__
from nltk.corpus import stopwords
stopwords.ensure_loaded
stopwords_dict = {lang:stopwords.words(lang) for lang in stopwords.__dict__.get('_fileids')}
stopwords_dict.keys()
len(stopwords_dict.keys())
两台机器上的nltk 版本相同'3.2.5',但语言数量不同:
苹果机:
dict_keys(['danish', 'dutch', 'english', 'finnish', 'french', 'german', 'hungarian', 'italian', 'norwegian', 'portuguese', 'russian', 'spanish', 'swedish', 'turkish'])
14
Linux:
dict_keys(['kazakh', 'swedish', 'spanish', 'danish', 'english', 'italian', 'portuguese', 'dutch', 'turkish', 'arabic', 'romanian', 'russian', 'french', 'hungarian', 'german', 'finnish', 'norwegian'])
17
我试图在nltk 文档中找到答案,但没有成功。
【问题讨论】:
-
在 Mac 上更新您的
nltk_data? -
哎哟!漂亮,你完全正确
nltk.download("stopwords")在我的情况下解决了它。我忘了 nltk 数据是分开处理的。 @alvas,您能否将其作为答案进行回复,以免我们将其作为未回答的问题?我知道解决方案是微不足道的,但它可能对其他人有帮助,这样我们就可以保持 SO questions-answers 的主要思想。 -
尝试回答并为下一个用户提供信息=)
标签: python-3.x nlp nltk