sentiment.py 431 B

123456789101112131415161718
  1. import nltk
  2. #nltk.download('punkt')
  3. #nltk.download('vader_lexicon')
  4. from nltk.sentiment.vader import SentimentIntensityAnalyzer
  5. sia = SentimentIntensityAnalyzer()
  6. def calc_score(text:str):
  7. score = sia.polarity_scores(text)
  8. if(score['compound']>=0.05):
  9. return "Positive"
  10. elif(score['compound']<0.05 and score['compound']>-0.05):
  11. return "Neutral"
  12. else:
  13. return "Negative"