-
Notifications
You must be signed in to change notification settings - Fork 0
/
actions.py
190 lines (137 loc) · 6.79 KB
/
actions.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
from typing import Any, Text, Dict, List
from rasa_sdk import Action, Tracker
from rasa_sdk.executor import CollectingDispatcher
from rasa_sdk.events import SlotSet, AllSlotsReset
import random
OOO_list = [("Cheese, milk, butter, yoghurt.", # the question that the system asks
"milk", # correct answer
"All the others are made FROM milk.", # explanation
"Think about how the items are produced."), # hint
("Airplane, raven, ostrich, hot air balloon.",
"ostrich",
"Ostrich is the only one that doesn't fly.",
"Think about the means of transportation."),
("Socks, boots, mittens, slippers",
"mittens",
"Mittens are worn on your hands, while all the others are worn on your feet.",
"Think about what they make warm."),
("Optician, police station, post office, pharmacy",
"police station",
"Police stations don't sell things, while the other places do.",
"Think about what you'd do in the different places."),
("Bus, lorry, bicycle, car",
"bicycle",
"A bicycle is moved by foot pedals, all the others are motorised.",
"Think about what makes them move."),
("Now, low, cow, vow",
"low",
"In 'low', -ow is pronounced differently from how it's pronouned in the rest.",
"Say them out loud."),
("Tough, puff, dough, enough",
"dough",
"Dough is the only one with the /oʊ/ sound, all the others have a /ʌf/ sound.",
"Try pronouncing them.")]
class ActionGameStart(Action):
def name(self) -> Text:
return "action_game_start"
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
former_rand = tracker.get_slot("rand")
former_ooo = tracker.get_slot("whatooo")
if (tracker.get_slot("OOO_list")) != None:
OOO_list = tracker.get_slot("OOO_list")
if former_ooo in OOO_list:
OOO_list.remove(former_ooo)
if len(OOO_list) != 0:
rand = random.choice(range(len(OOO_list)))
whatooo = OOO_list[rand]
setup_q = "Which one is the odd one out? "
dispatcher.utter_message(text=setup_q + (whatooo[0]))
return [SlotSet("rand", rand), SlotSet("whatooo", whatooo), SlotSet("OOO_list", OOO_list)]
else:
dispatcher.utter_message(text="Unfortunately I've run out of questions. Goodbye!")
return []
else:
OOO_list = [("Cheese, milk, butter, yoghurt.", # the question that the system asks
"milk", # correct answer
"All the others are made FROM milk.", # explanation
"Think about how the items are produced."), # hint
("Airplane, raven, ostrich, hot air balloon.",
"ostrich",
"Ostrich is the only one that doesn't fly.",
"Think about the means of transportation."),
("Socks, boots, mittens, slippers",
"mittens",
"Mittens are worn on your hands, while all the others are worn on your feet.",
"Think about what they make warm."),
("Optician, police station, post office, pharmacy",
"police station",
"Police stations don't sell things, while the other places do.",
"Think about what you'd do in the different places."),
("Bus, lorry, bicycle, car",
"bicycle",
"A bicycle is moved by foot pedals, all the others are motorised.",
"Think about what makes them move."),
("Now, low, cow, vow",
"low",
"In 'low', -ow is pronounced differently from how it's pronouned in the rest.",
"Say them out loud."),
("Tough, puff, dough, enough",
"dough",
"Dough is the only one with the /oʊ/ sound, all the others have a /ʌf/ sound.",
"Try pronouncing them.")]
setup_q = "Which one is the odd one out? "
rand = random.choice(range(len(OOO_list)))
whatooo = OOO_list[rand]
dispatcher.utter_message(text=setup_q + (whatooo[0]))
return [SlotSet("rand", rand), SlotSet("whatooo", whatooo), SlotSet("OOO_list", OOO_list)]
class ActionEvaluate(Action):
def name(self) -> Text:
return "action_evaluate"
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
#usermessageanswer = (tracker.latest_message['text']).lower()
user_intent = tracker.latest_message['intent']['name']
whatooo = tuple(tracker.get_slot("whatooo"))
print(tracker.latest_message)
print(tracker.latest_message['text'])
#print("latest message: ",tracker.latest_message)
print(tracker.latest_message['intent']['name'])
if user_intent == whatooo[1]:
dispatcher.utter_message(text="Correct! " + whatooo[2] + " Wanna go again?")
return []
else:
dispatcher.utter_message(text="Nope, try again!")
return []
class ActionRepeat(Action):
def name(self) -> Text:
return "action_repeat"
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
whatooo = tuple(tracker.get_slot("whatooo"))
setup_q = "Which one is the odd one out? "
dispatcher.utter_message(text=setup_q + whatooo[0])
return []
class ActionHint(Action):
def name(self) -> Text:
return "action_hint"
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
whatooo = tuple(tracker.get_slot("whatooo"))
dispatcher.utter_message(text=whatooo[3])
return []
class ActionExplain(Action):
def name(self) -> Text:
return "action_explain"
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
whatooo = tuple(tracker.get_slot("whatooo"))
setup_s = "The answer is "
another_q = "Do you want to have a go at another one?"
dispatcher.utter_message(text=setup_s + whatooo[1] + ". " + whatooo[2] + "\n" + another_q)
return []