-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalysis.py
37 lines (33 loc) · 1.36 KB
/
analysis.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
37
# Add functionality to get sentiments
from watson_developer_cloud import AlchemyLanguageV1
from termcolor import colored as color
# from main import get_user_input
def alchemy(words):
alchemy_language = AlchemyLanguageV1(api_key='a7f5da4c25eeea912cee000a9fbe17860c24e819')
# sentiment dictionry
if words is not None:
sentiment = alchemy_language.sentiment(text=words)
sentiment_type = sentiment['docSentiment']['type']
emotion = alchemy_language.emotion(text=words)
anger = emotion['docEmotions']['anger']
fear = emotion['docEmotions']['fear']
joy = emotion['docEmotions']['joy']
sadness = emotion['docEmotions']['sadness']
disgust = emotion['docEmotions']['disgust']
from prettytable import PrettyTable
print("")
print("")
sentiment_table = PrettyTable(["SENTIMENT"])
sentiment_table.add_row([sentiment_type])
print(color(sentiment_table, 'green'))
print("")
print("")
print("")
alchemy_table = PrettyTable(["EMOTION", "VALUE"])
alchemy_table.add_row(["Anger", anger])
alchemy_table.add_row(["Fear", fear])
alchemy_table.add_row(["Joy", joy])
alchemy_table.add_row(["sadness", sadness])
alchemy_table.add_row(["disgust", disgust])
print(color(alchemy_table, 'green'))
return ' '