Spaces:
Runtime error
Runtime error
File size: 633 Bytes
135f6a8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
from textblob import TextBlob
class SentimentAnalysisAgent:
def __init__(self):
self.analyzer = SentimentIntensityAnalyzer()
def analyze(self, news_item):
text = news_item.get("headline","") + " " + news_item.get("summary","")
vs = self.analyzer.polarity_scores(text)
blob = TextBlob(text)
final_score = 0.7*vs['compound'] + 0.3*blob.sentiment.polarity
news_item['sentiment'] = final_score
return news_item
def batch_analyze(self, articles):
return [self.analyze(a) for a in articles]
|