2016-09-13 4 views
0

작동하지 않습니다, 그러나 그것은 나에게 오류를 제공합니다NLTK 심리 베이더 : polarity_scores (텍스트) 내가 NLTK에서 베이더 심리 분석에서 <code>polarity_scores()</code>를 사용하는 것을 시도하고있다

polarity_scores() missing 1 required positional argument: 'text'

내가 파이썬에서 완전히 초보자입니다. 당신의 도움을 주셔서 감사합니다!

from nltk.sentiment.vader import SentimentIntensityAnalyzer as sid 
sentences=["hello","why is it not working?!"] 
for sentence in sentences: 
    ss = sid.polarity_scores(sentence) 

답변

3

SentimentIntensityAnalyzer은 클래스입니다. SentimentIntensityAnalyzer의 객체를 초기화하고 그에 대한 polarity_scores() 메소드를 호출해야합니다. 이미

>>> import nltk 
>>> nltk.download() 
--------------------------------------------------------------------------- 
d) Download l) List u) Update c) Config h) Help q) Quit 
--------------------------------------------------------------------------- 
Downloader> d vader_lexicon 
Downloader> q 
+0

감사합니다 톤을하지 않은 경우

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) 

당신은 사전 파일을 다운로드 할 수 있습니다! 그냥 내가 어휘 파일을 놓친 것 같아서. 이제 작동 중입니다. – alicecongcong