generated from akshatvg/template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
senti.py
28 lines (22 loc) · 1014 Bytes
/
senti.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
from ibm_watson import NaturalLanguageUnderstandingV1
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
import json
import os
from watson_developer_cloud.natural_language_understanding_v1 import Features, SentimentOptions
def get_senti(text):
authenticator = IAMAuthenticator(os.environ.get('apikey'))
# authenticator = IAMAuthenticator('sW2bItawdCipA-xqY3hc5SIC5WrW6QFq-VaBvRTnQfNL')
natural_language_understanding = NaturalLanguageUnderstandingV1(
version='2019-07-12',
authenticator=authenticator
)
natural_language_understanding.set_service_url('https://gateway-lon.watsonplatform.net/natural-language-understanding/api')
response = natural_language_understanding.analyze(
text=text,
features=Features(sentiment=SentimentOptions())).get_result()
b=response['sentiment']['document']
return b
#print(json.dumps(response, indent=2))
if __name__ == "__main__":
senti = get_senti('this product is amazing')
print(senti)