forked from x4nth055/pythoncode-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sentiment_analysis.py
25 lines (21 loc) · 951 Bytes
/
sentiment_analysis.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
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
# init the sentiment analyzer
sia = SentimentIntensityAnalyzer()
sentences = [
"This food is amazing and tasty !",
"Exoplanets are planets outside the solar system",
"This is sad to see such bad behavior"
]
for sentence in sentences:
score = sia.polarity_scores(sentence)["compound"]
print(f'The sentiment value of the sentence :"{sentence}" is : {score}')
for sentence in sentences:
print(f'For the sentence "{sentence}"')
polarity = sia.polarity_scores(sentence)
pos = polarity["pos"]
neu = polarity["neu"]
neg = polarity["neg"]
print(f'The percententage of positive sentiment in :"{sentence}" is : {round(pos*100,2)} %')
print(f'The percententage of neutral sentiment in :"{sentence}" is : {round(neu*100,2)} %')
print(f'The percententage of negative sentiment in :"{sentence}" is : {round(neg*100,2)} %')
print("="*50)