用NLTK分析python中的句子情感

时间:2017-08-17 12:56:12

标签: python nltk sentiment-analysis

我有这个python代码,其中我打算做的是为三个不同极性的分析仪提供一些输入。但问题是哪一个更可靠和广泛使用。

import nltk
from nltk.tokenize import word_tokenize
from nltk.sentiment.util import *
from nltk.sentiment.vader import SentimentIntensityAnalyzer as sia



text=["i have a good feeling about this."]
text1='she has the worse character in the class'

sid=sia()
for word in text:
    ss = sid.polarity_scores(word)
    print ss



nltk.sentiment.util.demo_vader_instance(text1)
nltk.sentiment.util.demo_liu_hu_lexicon(text1, plot=False)

输出如下:

Python 2.7.8 (default, Jun 30 2014, 16:08:48) [MSC v.1500 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
>>> 
{'neg': 0.0, 'neu': 0.405, 'pos': 0.595, 'compound': 0.5267}
{'neg': 0.307, 'neu': 0.693, 'pos': 0.0, 'compound': -0.4767}
Negative
>>> 

如果有任何其他方式来分析句子并查明用户是否幸福,悲伤或中立......那么请随时提出想法。

如果用户感到高兴,悲伤或中立,我如何根据极性值来决定?

0 个答案:

没有答案