-
Notifications
You must be signed in to change notification settings - Fork 5
/
watson_test.py
37 lines (25 loc) · 1.1 KB
/
watson_test.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
import json
from ibm_watson import NaturalLanguageUnderstandingV1
from ibm_watson.natural_language_understanding_v1 \
import Features, EntitiesOptions, KeywordsOptions, EmotionOptions
natural_language_understanding = NaturalLanguageUnderstandingV1(
version='2019-07-12',
iam_apikey='oRW-WiI73HQMQxq0mVZnPJzN3UFwX4-9oD-XpjLjqUNi',
url='https://gateway-wdc.watsonplatform.net/natural-language-understanding/api')
response = natural_language_understanding.analyze(
text="Trump is a stupid fucker",
features=Features(
EmotionOptions(document=True))
).get_result()
print(json.dumps(response, indent=2))
"""
response = natural_language_understanding.analyze(
text='IBM is an American multinational technology company '
'headquartered in Armonk, New York, United States, '
'with operations in over 170 countries.',
features=Features(
entities=EntitiesOptions(emotion=True, sentiment=True, limit=2),
keywords=KeywordsOptions(emotion=True, sentiment=True,
limit=2))).get_result()
print(json.dumps(response, indent=2))
"""