forked from Explore-AI/cloud-computing-predict
-
Notifications
You must be signed in to change notification settings - Fork 0
/
find_maximum_sentiment.py
36 lines (24 loc) · 1.32 KB
/
find_maximum_sentiment.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""
Function used to extract the overwhelming sentiment of a message.
Author: Explore Data Science Academy.
Note:
---------------------------------------------------------------------
The contents of this file should be added to a AWS Lambda function
created as part of the EDSA Cloud-Computing Predict.
For further guidance around this process, see the README instruction
file which sits at the root of this repo.
---------------------------------------------------------------------
"""
# Find overwhelming sentiment in article
def find_max_sentiment(Comprehend_Sentiment_Output):
sentiment_score = 0
if Comprehend_Sentiment_Output['Sentiment'] == 'POSITIVE':
sentiment_score = Comprehend_Sentiment_Output['SentimentScore']['Positive']
elif Comprehend_Sentiment_Output['Sentiment'] == 'NEGATIVE':
sentiment_score = Comprehend_Sentiment_Output['SentimentScore']['Negative']
elif Comprehend_Sentiment_Output['Sentiment'] == 'NEUTRAL':
sentiment_score = Comprehend_Sentiment_Output['SentimentScore']['Neutral']
else:
sentiment_score = Comprehend_Sentiment_Output['SentimentScore']['Mixed']
print(sentiment_score, Comprehend_Sentiment_Output['Sentiment'])
return Comprehend_Sentiment_Output['Sentiment'], sentiment_score