Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.

Commit c74cf2f

Browse files
Add sentiment class
1 parent 8945e37 commit c74cf2f

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

utils/sentiment.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from textblob import TextBlob
2+
3+
def detect_sentiment(text):
4+
sentences = text.split('. ')
5+
sentiment_analysis = []
6+
7+
for sentence in sentences:
8+
blob = TextBlob(sentence)
9+
polarity = blob.sentiment.polarity
10+
if polarity > 0:
11+
sentiment = 'Positive'
12+
elif polarity < 0:
13+
sentiment = 'Negative'
14+
else:
15+
sentiment = 'Neutral'
16+
sentiment_analysis.append((sentence, sentiment))
17+
18+
return sentiment_analysis

0 commit comments

Comments
 (0)