我有很多英语文本,我正在寻找一种方法来提取具有情感内容的词语,例如“愤怒”,“讨厌”,“偏执狂”,“退出”等等。有没有办法用NLTK或WordNet做到这一点?
答案 0 :(得分:2)
您可以在NLTK中使用SentiWordNet接口来检查英语单词的情感内容。来自NLTK的用法。
>>> from nltk.corpus import sentiwordnet as swn
>>> list(swn.senti_synsets('breakdown'))
[SentiSynset('dislocation.n.02'),
SentiSynset('breakdown.n.02'),
SentiSynset('breakdown.n.03'),
SentiSynset('breakdown.n.04')]
>>> breakdown = swn.senti_synset('breakdown.n.03')
>>> print(breakdown)
<breakdown.n.03: PosScore=0.0 NegScore=0.25>
>>> breakdown.pos_score()
0.0
>>> breakdown.neg_score()
0.25
>>> breakdown.obj_score()
0.75