Update.
This commit is contained in:
parent
061d71ac1e
commit
7ae80ab600
35
sentiment.py
Normal file
35
sentiment.py
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
import json
|
||||||
|
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
|
||||||
|
|
||||||
|
def analyze_sentiment_vader(text, analyzer):
|
||||||
|
"""
|
||||||
|
Analyzes text using VADER and returns a dictionary with the results.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
text (str): The text content to analyze.
|
||||||
|
analyzer (SentimentIntensityAnalyzer): An instantiated VADER analyzer.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
dict: A dictionary containing the sentiment classification, compound score,
|
||||||
|
and detailed scores (positive, neutral, negative).
|
||||||
|
"""
|
||||||
|
scores = analyzer.polarity_scores(text)
|
||||||
|
compound_score = scores['compound']
|
||||||
|
|
||||||
|
if compound_score >= 0.05:
|
||||||
|
sentiment = 'Positive'
|
||||||
|
elif compound_score <= -0.05:
|
||||||
|
sentiment = 'Negative'
|
||||||
|
else:
|
||||||
|
sentiment = 'Neutral'
|
||||||
|
|
||||||
|
return {
|
||||||
|
'sentiment': sentiment,
|
||||||
|
'score': compound_score,
|
||||||
|
'details': scores
|
||||||
|
}
|
||||||
|
|
||||||
|
vader_analyzer = SentimentIntensityAnalyzer()
|
||||||
|
|
||||||
|
def analyze(content):
|
||||||
|
return analyze_sentiment_vader(content, vader_analyzer)
|
||||||
Loading…
Reference in New Issue
Block a user