【发布时间】:2011-07-29 08:15:07
【问题描述】:
我正在为 NLTK 停用词而苦苦挣扎。
这是我的一段代码.. 有人能告诉我有什么问题吗?
from nltk.corpus import stopwords
def removeStopwords( palabras ):
return [ word for word in palabras if word not in stopwords.words('spanish') ]
palabras = ''' my text is here '''
【问题讨论】:
-
你只是错过了对函数的调用吗?尝试在最后一行之后添加
print removeStopwords(palabras)。 -
对!!!我错过了!
-
确保接受一个答案并点赞
-
我不知道您是否遇到过 stopwords.words('spanish') 返回一个列表,其中并非每个单词都使用 Unicode 编码的问题。因此,检查一个单词是否存在于用 Unicode (u'word') 编码的单词中,并使用 'in' 运算符,可能会导致错误的比较。我收到这条消息:UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - 将它们解释为不相等有什么线索吗?我猜 NLTK.CORPUS.STOPWORDS 应该返回 unicode 列表 gracias!
标签: python nltk stop-words