Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions utils/sentiment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from textblob import TextBlob

Check warning on line 1 in utils/sentiment.py

View check run for this annotation

Codecov Notifications / codecov/patch

utils/sentiment.py#L1

Added line #L1 was not covered by tests

def detect_sentiment(text):
sentences = text.split('. ')
sentiment_analysis = []

Check warning on line 5 in utils/sentiment.py

View check run for this annotation

Codecov Notifications / codecov/patch

utils/sentiment.py#L3-L5

Added lines #L3 - L5 were not covered by tests

for sentence in sentences:
blob = TextBlob(sentence)
polarity = blob.sentiment.polarity
if polarity > 0:
sentiment = 'Positive'
elif polarity < 0:
sentiment = 'Negative'

Check warning on line 13 in utils/sentiment.py

View check run for this annotation

Codecov Notifications / codecov/patch

utils/sentiment.py#L7-L13

Added lines #L7 - L13 were not covered by tests
else:
sentiment = 'Neutral'
sentiment_analysis.append((sentence, sentiment))

Check warning on line 16 in utils/sentiment.py

View check run for this annotation

Codecov Notifications / codecov/patch

utils/sentiment.py#L15-L16

Added lines #L15 - L16 were not covered by tests

return sentiment_analysis

Check warning on line 18 in utils/sentiment.py

View check run for this annotation

Codecov Notifications / codecov/patch

utils/sentiment.py#L18

Added line #L18 was not covered by tests
Loading