Modularized the tool.

This commit is contained in:
2025-07-21 15:49:15 +02:00
parent 03e6e56a35
commit 71890d1a57
8 changed files with 426 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
# sentiment_analyzer.py
from nltk.sentiment.vader import SentimentIntensityAnalyzer
# Initialize the VADER sentiment intensity analyzer
# We only need to create one instance of this.
_analyzer = SentimentIntensityAnalyzer()
def get_sentiment_score(text):
"""
Analyzes a piece of text and returns its sentiment score.
The 'compound' score is a single metric that summarizes the sentiment.
It ranges from -1 (most negative) to +1 (most positive).
"""
# The polarity_scores() method returns a dictionary with 'neg', 'neu', 'pos', and 'compound' scores.
# We are most interested in the 'compound' score.
scores = _analyzer.polarity_scores(text)
return scores['compound']