-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvader_analyzer.py
28 lines (26 loc) · 1.15 KB
/
vader_analyzer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
class VaderAnalyzer():
def analyze(self, sentence):
# Create a SentimentIntensityAnalyzer object.
sid_obj = SentimentIntensityAnalyzer()
# polarity_scores method of SentimentIntensityAnalyzer
# object gives a sentiment dictionary.
# which contains pos, neg, neu, and compound scores.
sentiment_dict = sid_obj.polarity_scores(sentence)
# print("Overall sentiment dictionary is : ", sentiment_dict)
# print("sentence was rated as ", sentiment_dict['neg'] * 100, "% Negative")
# print("sentence was rated as ", sentiment_dict['neu'] * 100, "% Neutral")
# print("sentence was rated as ", sentiment_dict['pos'] * 100, "% Positive")
#
# print("Sentence Overall Rated As", end=" ")
#
# # decide sentiment as positive, negative and neutral
# if sentiment_dict['compound'] >= 0.05:
# print("Positive")
#
# elif sentiment_dict['compound'] <= - 0.05:
# print("Negative")
#
# else:
# print("Neutral")
return sentiment_dict