我正在尝试使用NLTK中的Vader情绪分析中的polarity_scores()
,但它给了我错误:
polarity_scores()缺少1个必需的位置参数:'text'
我完全是Python的初学者。感谢您的帮助!
from nltk.sentiment.vader import SentimentIntensityAnalyzer as sid
sentences=["hello","why is it not working?!"]
for sentence in sentences:
ss = sid.polarity_scores(sentence)
答案 0 :(得分:6)
SentimentIntensityAnalyzer
是一个班级。您需要初始化SentimentIntensityAnalyzer
的对象并在其上调用polarity_scores()
方法。
from nltk.sentiment.vader import SentimentIntensityAnalyzer as SIA
sentences=["hello","why is it not working?!"]
sid = SIA()
for sentence in sentences:
ss = sid.polarity_scores(sentence)
如果您还没有
,则可能需要下载词典文件>>> import nltk
>>> nltk.download()
---------------------------------------------------------------------------
d) Download l) List u) Update c) Config h) Help q) Quit
---------------------------------------------------------------------------
Downloader> d vader_lexicon
Downloader> q
答案 1 :(得分:0)
您需要首先初始化SentimentIntensityAnalyzer对象,然后在该对象上调用polarity_scores方法。
尝试此代码:
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
sid = SentimentIntensityAnalyzer()
sentences=["hello","why is it not working?!"]
for sentence in sentences:
ss = sid.polarity_scores(sentence)
print (ss)