-
Notifications
You must be signed in to change notification settings - Fork 0
/
nlp.py
58 lines (48 loc) · 1.88 KB
/
nlp.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# -*- coding: utf-8 -*-
"""
Created on Sat Aug 31 23:16:48 2019
@author: Dominick
"""
#rautken api
import requests
import argparse
import unirest
#amazon api
import boto3
import json
#requires from prior downloading for the amazon NLP
def nlp_call():
#text processing NLP call
response = unirest.post("https://japerk-text-processing.p.rapidapi.com/sentiment/",
headers={
"X-RapidAPI-Host": "japerk-text-processing.p.rapidapi.com",
"X-RapidAPI-Key": "1cb24d07fdmsh0a4062c072f1dbdp164f8cjsn1c8a66bfc2fd",
"Content-Type": "application/x-www-form-urlencoded"
},
params={
"language": "english",
"text": "How much damage does heroin do to the brain and how addictive is it?"
}
)
for i in response.body['probability']:
print (response.body['probability'][i])
#microsoft NLP call
response2 = unirest.post("https://microsoft-azure-text-analytics-v1.p.rapidapi.com/sentiment",
headers={
"X-RapidAPI-Host": "microsoft-azure-text-analytics-v1.p.rapidapi.com",
"X-RapidAPI-Key": "1cb24d07fdmsh0a4062c072f1dbdp164f8cjsn1c8a66bfc2fd",
"Content-Type": "application/json"
},
params=("{\"documents\":[{\"language\":\"en\",\"id\":\"string\",\"text\":\"How much damage does heroin do to the brain and how addictive is it? \"}]}")
)
print("microsoft: ", response2.body['documents'][0]['score'])
if (response2.body['documents'][0]['score'] < 1):
print("hello")
#Amazon NLP call
comprehend = boto3.client(service_name='comprehend', region_name='us-east-2')
text = "It is raining today in Seattle"
print('Calling DetectSentiment')
print(json.dumps(comprehend.detect_sentiment(Text=text, LanguageCode='en'), sort_keys=True, indent=4))
print('End of DetectSentiment\n')
if __name__ == "__main__":
nlp_call()