我正在尝试用Python创建一个情绪分析器,它可以下载文本,并对照一系列负面和正面的单词进行分析。对于文本中与poswords.txt文件应该有一个+1
分数,对于中文本中的每个匹配项negwords.txt文件应该有一个-1
分数,文本的总分数将是情感分数。这是我一直试图做到的,但我一直只得到0分。你知道吗
下面的答案似乎不起作用,我的情绪得分一直是0。你知道吗
split = text.split()
poswords = open('poswords.txt','r')
for word in split:
if word in poswords:
sentimentScore +=1
poswords.close()
negwords = open('negwords.txt','r')
for word in split:
if word in negwords:
sentimentScore -=1
negwords.close()
代码中的
poswords
和negwords
只是文件句柄,而不是读取这些文件中的单词。你知道吗此处:
如果文件很大,上述方法就不是最佳解决方案。为肯定词和否定词创建词典:
相关问题 更多 >
编程相关推荐