我正在检查字典中是否存在词干为词干的单词。这是我正在做的一些情绪分析工作。我要回来的只是这个错误:
Traceback (most recent call last):
File "sentiment.py", line 369, in <module>
score += int(senti_word_dict.get(get_stem(word)))
TypeError: int() argument must be a string or a number, not 'NoneType'
下面是通过NLTK查找词干词的方法的代码:
^{pr2}$下面是根据字典检查该单词的代码:
for comment in all_comments:
score = 0
tokens = tokenize(comment)
for word in tokens:
if word in senti_word_dict:
score += int(senti_word_dict.get(get_stem(word)))
print(str(score)+" "+comment)
print('\n')
现在我只是得到分数。有没有一种方法可以让我把这个词干作为一个字符串来传递,看看字典里的分数是多少?如果有什么我做错了或可以做得更好的,让我知道!谢谢!在
检查
word
是否在senti_word_dict
中。也许是的。但你却阻止了它(它变成了另一个词!)并尝试使用senti_word_dict.get
从字典中检索词干。如果词干不在字典里(为什么要在字典里?),get()
返回None
。因此,错误。解决方法:先把这个词词干,然后再查。在相关问题 更多 >
编程相关推荐