forked from giblet37/myAI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
intent.py
81 lines (60 loc) · 2.52 KB
/
intent.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
"""
The "Intent" class represents an action to be performed
"""
import re
import settings
from apis import api_lib
from functions.intent_parser import IntentParser
def speak(phrase, jsonObjects):
siteId = jsonObjects['siteId']
sessionId = jsonObjects['sessionId']
if phrase == None:
jsonString = "{\"sessionId\":\"" + sessionId + "\"}"
print jsonString
else:
jsonString = "{\"text\":\"" + phrase + "\",\"sessionId\":\"" + sessionId + "\"}"
print jsonString
api_lib['mqtt'].publish_item("hermes/dialogueManager/endSession", jsonString)
'''
hermes/dialogueManager/endSession
When the handler received the intents it needs, or when the handler wants to explicitly end a running session, it should send this endSession message with the given sessionId.
Key Value
sessionId String - Session identifier to end.
text Optional String - The text the TTS should say to end the session.
If the text is null, the Dialog Manager will immediately send a endedSession message after receiving this message, otherwise, the endedSession will be sent after the text is said.
'''
def slotValue(jsonObjects, slotName):
return IntentParser.get_slot_value(jsonObjects,slotName)
def slotDateValue(jsonObjects, slotName):
return IntentParser.parse_date_value(jsonObjects,slotName)
def slotDateRange(jsonObjects, slotName):
return IntentParser.parse_date_range(jsonObjects,slotName)
def mqttPostTopic(topic,message=None):
api_lib['mqtt'].publish_item(topic, message)
def parseDateRawValue (jsonObjects, slotName):
return IntentParser.parse_date_raw_value(jsonObjects,slotName)
class Intent(object):
speak = staticmethod(speak)
slotValue = staticmethod(slotValue)
slotDateValue = staticmethod(slotDateValue)
slotDateRange = staticmethod(slotDateRange)
parseDateRawValue = staticmethod(parseDateRawValue)
def action(self, intent, objs):
""" Execute the intent action """
return
def onError(self):
""" Execute the intent error action """
return
class ActiveIntent(Intent):
def __init__(self,intent=None, user=[]):
""" intent to match from the NLU return """
self.intent = intent
self.user = user
def match(self, intent):
""" Check if the nlu intent matches an activeintent object """
is_match = False
for intent_item in self.intent:
if intent_item == intent:
is_match = True
break
return is_match