我刚刚运行我的数据集维德情感分析:NLTK情绪维达:排序
from nltk.sentiment.vader import SentimentIntensityAnalyzer
from nltk import tokenize
sid = SentimentIntensityAnalyzer()
for sentence in filtered_lines2:
print(sentence)
ss = sid.polarity_scores(sentence)
for k in sorted(ss):
print('{0}: {1}, '.format(k, ss[k]),)
print()
这里我的结果的一个样本:我想
Are these guests on Samsung and Google event mostly Chinese Wow Theyre
boring
Google Samsung
('compound: 0.3612, ',)
()
('neg: 0.12, ',)
()
('neu: 0.681, ',)
()
('pos: 0.199, ',)
()
Adobe lose 135bn to piracy Report
('compound: -0.4019, ',)
()
('neg: 0.31, ',)
()
('neu: 0.69, ',)
()
('pos: 0.0, ',)
()
Samsung Galaxy Nexus announced
('compound: 0.0, ',)
()
('neg: 0.0, ',)
()
('neu: 1.0, ',)
()
('pos: 0.0, ',)
()
知道有多少次“化合物”等于,大于或小于零。
我知道这可能很简单,但我对Python和编码一般都很陌生。 我尝试了很多不同的方式来创建我需要的东西,但我找不到任何解决方案。
(请编辑我的问题,如果“成绩的样品”是不正确的,因为我不知道写的正确方法)
看起来你正在编写Python 3的代码,但与Python 2运行(这无关你的问题,但可能让你最终陷入困境)。 – lenz
谢谢你的建议! –