我知道几种方法:维德将分数作为分级返回(介于0和1之间)
Stanford NLP返回一个分类(即0、1、2、3)。在
NLTK方法:from nltk.sentiment.vader import SentimentIntensityAnalyzer as sia
sentences = ['This is the worst lunch I ever had!',
'This is the best lunch I have ever had!!',
'I don\'t like this lunch.',
'I eat food for lunch.',
'Red is a color.',
'A really bad, horrible book, the plot was .']
hal = sia()
for sentence in sentences:
print(sentence)
ps = hal.polarity_scores(sentence)
for k in sorted(ps):
print('\t{}: {:>1.4}'.format(k, ps[k]), end=' ')
print()
输出示例:
^{pr2}$
斯坦福NLP,Python方法:
(请注意,这种方式需要启动CoreNLP服务器的一个实例来运行,例如:java -mx1g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNL