-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSentiment_analysis.py
More file actions
38 lines (24 loc) · 1013 Bytes
/
Copy pathSentiment_analysis.py
File metadata and controls
38 lines (24 loc) · 1013 Bytes
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
29
30
31
32
33
34
35
36
37
38
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
def sentiment_scores(sentence):
sid_obj = SentimentIntensityAnalyzer()
sentiment_dict = sid_obj.polarity_scores(sentence)
print("\nSentiment Scores:")
print(sentiment_dict)
print(f"Negative: {sentiment_dict['neg'] * 100:.2f}%")
print(f"Neutral: {sentiment_dict['neu'] * 100:.2f}%")
print(f"Positive: {sentiment_dict['pos'] * 100:.2f}%")
if sentiment_dict['compound'] >= 0.05:
print("Overall Sentiment: Positive 😊")
elif sentiment_dict['compound'] <= -0.05:
print("Overall Sentiment: Negative 😞")
else:
print("Overall Sentiment: Neutral 😐")
if __name__ == "__main__":
print("💬 Sentiment Analysis using VADER")
print("Type 'quit' to exit.")
while True:
sentence = input("\nEnter a sentence: ")
if sentence.lower() == "quit":
print("Exiting Sentiment Analyzer...")
break
sentiment_scores(sentence)