-
Notifications
You must be signed in to change notification settings - Fork 1
/
get_wit.py
102 lines (88 loc) · 2.32 KB
/
get_wit.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
from wit import Wit
from includes import keys
client = Wit(keys.wit_access_token)
def get_intent(res):
if not res: return None
try:
intent_raw= res['intents'][0]['name']
confidence =res['intents'][0]['confidence']
print(str(intent_raw) + " " +str(confidence))
if(confidence >= 0.8):
intent = intent_raw
else: intent=None
except:
intent=None
return intent
def get_res(message_text):
if not message_text: return message_text
try:
res = client.message(message_text)
except:
res=None
return res
def get_search(res):
if not res: return None
try:
return res['entities']['search:search'][0]['value']
except:
return None
def get_service(res):
if not res: return None
try:
a=res['entities']['service:service'][0]['value']
return a.strip()
except:
return None
def get_service_type(res):
if not res: return None
try:
return res['entities']['service_type:service_type'][0]['value']
except:
return None
def get_playlist(res):
if not res: return None
try:
return res['entities']['playlist:playlist'][0]['value'].strip()
except:
return None
def get_alarm_time(res):
if not res: return None
try:
b=res['entities']['wit$datetime:datetime'][0]['value']
print(b)
d,t = b.split("T")
time, _ = t.split(".")
hour , min, sec =time.split(":")
return d, hour, min, sec
except:
return None
def get_data_time(res):
if not res: return None
try:
return res['entities']['wit$datetime:datetime'][0]['value']
except:
return None
def get_map_places(res):
if not res: return None
try:
return res['entities']['map_places:map_places'][0]['value'].strip()
except:
return None
def get_network_device(res):
if not res: return None
try:
return res['entities']['network_device:network_device'][0]['value']
except:
return None
def get_accent(res):
if not res: return None
try:
return res['entities']['accent:accent'][0]['value']
except:
return None
def get_speak(res):
if not res: return None
try:
return res['entities']['speak:speak'][0]['value']
except:
return None