Optimized text cleanup and function parameters
This commit is contained in:
parent
a20f7331bb
commit
c6b16b9ccf
3 changed files with 21 additions and 21 deletions
|
|
@ -28,14 +28,14 @@ class SentiTooter:
|
|||
self.labels = ['negative', 'neutral', 'positive']
|
||||
self.sia = SentimentIntensityAnalyzer()
|
||||
|
||||
def analyze(self, toot):
|
||||
match toot.language:
|
||||
def analyze(self, language, content):
|
||||
match language:
|
||||
case 'de':
|
||||
sentiment = self.deModel.predict_sentiment([toot.content])
|
||||
sentiment = self.deModel.predict_sentiment([content])
|
||||
sentiment.append('germanSentiment')
|
||||
return sentiment
|
||||
case 'en':
|
||||
text = preprocess(toot.content)
|
||||
text = preprocess(content)
|
||||
encoded_input = self.enTokenizer(text, return_tensors='pt')
|
||||
output = self.enModel(**encoded_input)
|
||||
scores = output[0][0].detach().numpy()
|
||||
|
|
@ -45,7 +45,7 @@ class SentiTooter:
|
|||
sentiment = [sentimentLabel, 'twitter-roberta-base-sentiment']
|
||||
return sentiment
|
||||
case _:
|
||||
compound = self.sia.polarity_scores(toot.content)['compound']
|
||||
compound = self.sia.polarity_scores(content)['compound']
|
||||
if compound > (1 / 3):
|
||||
return ['positive', 'vaderSentiment']
|
||||
elif compound < (-1 / 3):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue