-
Notifications
You must be signed in to change notification settings - Fork 0
/
LUIS.py
49 lines (29 loc) · 1.4 KB
/
LUIS.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
import requests
class LUIS:
def __init__(self, key):
self.intent=""
self.input=""
self.APIkey=key
self.link="https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/7f58c0cb-8b08-4c85-9074-56e4c7b6c946?subscription-key="+self.APIkey+"&timezoneOffset=-360&q="
#access the API
def GetJson(self, response):
#do the initialization of Luis with the API key
query=self.link+response
try:
#r = requests.get('https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/7f58c0cb-8b08-4c85-9074-56e4c7b6c946?subscription-key=9d556518bc2b49489a61ddbdc98884a3&timezoneOffset=-360&q=weather in tallahassee')
r= requests.get(query)
except Exception as e:
print("[Errno {0}] {1}".format(e.errno, e.strerror))
return r.json()
def GetIntent(self, response):
#use response to get the intent
x = self.GetJson(response)
return x['topScoringIntent']
def GetEntities(self, response):
x = self.GetJson(response)
return x['entities']
if __name__ == "__main__":
y=LUIS("9d556518bc2b49489a61ddbdc98884a3")
x=y.GetIntent("weather in 8 hour")
#x=y.GetEntities("weather in tallhassee tomorrow")
print(x['intent'])