如何使用sentiwordnet获取synet的得分名称

时间:2017-02-06 19:56:09

标签: python-3.x

我有一个字符串,我希望使用sentiword网得到每个单词的pos / neg分数。这是我的代码:

from nltk.corpus import sentiwordnet as swn
from nltk.tokenize import word_tokenize

text = "good bad. work hard"
word_tokens = word_tokenize(text)
for i in word_tokens:
     synsets=list(swn.senti_synsets(i))
     print(synsets[0])

我的输出有错误:

<good.n.01: PosScore=0.5 NegScore=0.0>
<bad.n.01: PosScore=0.0 NegScore=0.875>
Traceback (most recent call last):
  File "C:\Python34\test2.py", line 20, in <module>
    print(synsets[0])
IndexError: list index out of range

任何想法为什么? 提前致谢

0 个答案:

没有答案