我剛剛運行我的數據集維德情感分析: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
謝謝你的建議! –