使用NLTK提供的SentiWordNet工具计算一个句子的情感倾向性,计算方法为每个词所处词性下的每个词义情感倾向性之和。
import string
from nltk.tokenize import word_tokenize
from nltk import pos_tag
from nltk.corpus import stopwords
from nltk.corpus import sentiwordnet
from nltk.corpus import wordnet
# 停用词
stpw = stopwords.words('english')
# 标点符号
punc = list(string.punctuation)
# 不需要分析的词和标点
stop = punc + stpw
# 要分析的句子
sentence = "His performance is so great that he got the price. "
# 1.标记解析
words = word_tokenize(sentence)
for word