ali*_*ong 2 python nltk sentiment-analysis
我试图使用polarity_scores()NLTK中的Vader情绪分析,但它给了我错误:
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)
Run Code Online (Sandbox Code Playgroud)
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)
Run Code Online (Sandbox Code Playgroud)
您可能必须下载词典文件(如果尚未下载)
>>> import nltk
>>> nltk.download()
---------------------------------------------------------------------------
d) Download l) List u) Update c) Config h) Help q) Quit
---------------------------------------------------------------------------
Downloader> d vader_lexicon
Downloader> q
Run Code Online (Sandbox Code Playgroud)