Skip to content

Commit 7cd653b

Browse files
committed
Added exit clause to all flow conditions
1 parent abc5fa8 commit 7cd653b

File tree

4 files changed

+96
-18
lines changed

4 files changed

+96
-18
lines changed

bots/botflow/aiml/FLIGHTBOOK.aiml

Lines changed: 60 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
<template>
77
<think>
88
<set name="topic">FLIGHTBOOK</set>
9-
<set name="City" />,
10-
<set name="London" />,
11-
<set name="Destination" />,
12-
<set name="Date" />,
13-
<set name="Passengers" />,
14-
<set name="Class" />,
9+
<set name="City" />
10+
<set name="London" />
11+
<set name="Destination" />
12+
<set name="Date" />
13+
<set name="Passengers" />
14+
<set name="Class" />
1515
</think>
1616
<srai>FLIGHTBOOK STEP SOURCE</srai>
1717
</template>
@@ -24,7 +24,7 @@
2424
FLIGHTBOOK STEP SOURCE
2525
</pattern>
2626
<template>
27-
Where would you like to fly from - (London, Edinburgh, Glasgow, Manchester)
27+
Where would you like to fly from - (London, Edinburgh, Glasgow, Manchester or exit)
2828
</template>
2929
</category>
3030

@@ -43,12 +43,20 @@
4343
</template>
4444
</category>
4545

46+
<category>
47+
<pattern>EXIT</pattern>
48+
<that>Where would you like to fly from *</that>
49+
<template>
50+
<srai>EXIT FLIGHTBOOK</srai>
51+
</template>
52+
</category>
53+
4654
<category>
4755
<pattern>
4856
FLIGHTBOOK STEP LONDON
4957
</pattern>
5058
<template>
51-
Where from in London are you flying from - (Stanstead, Heathrow, Gatwick)
59+
Where from in London are you flying from - (Stanstead, Heathrow, Gatwick or exit)
5260
</template>
5361
</category>
5462

@@ -66,12 +74,20 @@
6674
</template>
6775
</category>
6876

77+
<category>
78+
<pattern>EXIT</pattern>
79+
<that>Where from in London are you flying from *</that>
80+
<template>
81+
<srai>EXIT FLIGHTBOOK</srai>
82+
</template>
83+
</category>
84+
6985
<category>
7086
<pattern>
7187
FLIGHTBOOK STEP DEST
7288
</pattern>
7389
<template>
74-
Where would you like to fly to - (New York, Washington, San Francisco)
90+
Where would you like to fly to - (New York, Washington, San Francisco or exit)
7591
</template>
7692
</category>
7793

@@ -89,12 +105,20 @@
89105
</template>
90106
</category>
91107

108+
<category>
109+
<pattern>EXIT</pattern>
110+
<that>Where would you like to fly to *</that>
111+
<template>
112+
<srai>EXIT FLIGHTBOOK</srai>
113+
</template>
114+
</category>
115+
92116
<category>
93117
<pattern>
94118
FLIGHTBOOK STEP DATE
95119
</pattern>
96120
<template>
97-
When would you like to fly - (DD/MM/YYYY)
121+
When would you like to fly - (DD/MM/YYYY or exit)
98122
</template>
99123
</category>
100124

@@ -111,12 +135,20 @@
111135
</template>
112136
</category>
113137

138+
<category>
139+
<pattern>EXIT</pattern>
140+
<that>When would you like to fly *</that>
141+
<template>
142+
<srai>EXIT FLIGHTBOOK</srai>
143+
</template>
144+
</category>
145+
114146
<category>
115147
<pattern>
116148
FLIGHTBOOK STEP PASSENGERS
117149
</pattern>
118150
<template>
119-
How many people are flying - (1 to 5)
151+
How many people are flying - (1 to 5 or exit)
120152
</template>
121153
</category>
122154

@@ -133,12 +165,20 @@
133165
</template>
134166
</category>
135167

168+
<category>
169+
<pattern>EXIT</pattern>
170+
<that>How many people are flying *</that>
171+
<template>
172+
<srai>EXIT FLIGHTBOOK</srai>
173+
</template>
174+
</category>
175+
136176
<category>
137177
<pattern>
138178
FLIGHTBOOK STEP CLASS
139179
</pattern>
140180
<template>
141-
What class do you want to fly - (Economy, Premium Economy, Business, First)
181+
What class do you want to fly - (Economy, Premium Economy, Business, First or exit)
142182
</template>
143183
</category>
144184

@@ -157,6 +197,14 @@
157197
</template>
158198
</category>
159199

200+
<category>
201+
<pattern>EXIT</pattern>
202+
<that>What class do you want to fly *</that>
203+
<template>
204+
<srai>EXIT FLIGHTBOOK</srai>
205+
</template>
206+
</category>
207+
160208
</topic>
161209

162210
</aiml>

bots/botflow/aiml/flightbookctrl.aiml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<pattern>EXECUTE FLIGHTBOOK</pattern>
1313
<template>
1414
Ok, I'll book a flight matching the following:
15-
flying from <get name="City" />,
15+
flying from <get name="City" />
1616
<get name="London" />,
1717
to <get name="Destination" />,
1818
on <get name="Date" />,
@@ -21,4 +21,11 @@
2121
</template>
2222
</category>
2323

24+
<category>
25+
<pattern>EXIT FLIGHTBOOK</pattern>
26+
<template>
27+
Thanks, ask again any time and I will help you
28+
</template>
29+
</category>
30+
2431
</aiml>

src/utils/botflow/botflow.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
#!/usr/bin/env bash
22

3+
clear
4+
5+
export PYTHONPATH=./src:.
6+
37
python3 src/botflow.py -flow "../../../bots/botflow/flow/flightbook.csv" -topic flightbook -aiml "../../../bots/botflow/aiml"

src/utils/botflow/src/botflow.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ def __init__(self, text):
3232
self._values = [x.strip() for x in values.split(",")]
3333

3434
def type_values_to_str(self):
35-
return ", ".join(self._values)
35+
text = ", ".join(self._values)
36+
text += " or exit"
37+
return text
3638

3739
def get_next_step(self, step, value):
3840
for condition in step._conditions:
@@ -64,7 +66,9 @@ def __init__(self, text):
6466
self._values.append(self.extract_values_between_brackets(text, "Date"))
6567

6668
def type_values_to_str(self):
67-
return self._values[0]
69+
text = self._values[0]
70+
text += " or exit"
71+
return text
6872

6973
def output_template(self, aiml_file, topic_name, step):
7074
if step._conditions:
@@ -96,9 +100,11 @@ def __init__(self, text):
96100

97101
def type_values_to_str(self):
98102
if len(self._values) == 2:
99-
return " to ".join(self._values)
103+
text = " to ".join(self._values)
100104
else:
101-
return " max %s" % self._values[0]
105+
text = " max %s" % self._values[0]
106+
text += " or exit"
107+
return text
102108

103109
def output_template(self, aiml_file, topic_name, step):
104110
if step._conditions:
@@ -216,6 +222,18 @@ def output_aiml(self, aiml_file, topic_name):
216222

217223
self._type.output_template(aiml_file, topic_name, self)
218224

225+
226+
aiml_file.write('\t\t\t</template>\n')
227+
aiml_file.write('\t\t</category>\n\n')
228+
229+
aiml_file.write('\t\t<category>\n')
230+
aiml_file.write('\t\t\t<pattern>EXIT</pattern>\n')
231+
if self._type._values:
232+
aiml_file.write('\t\t\t<that>%s *</that>\n' % self._prompt)
233+
else:
234+
aiml_file.write('\t\t\t<that>%s</that>\n' % self._prompt)
235+
aiml_file.write('\t\t\t<template>\n')
236+
aiml_file.write('\t\t\t\t<srai>EXIT FLIGHTBOOK</srai>\n')
219237
aiml_file.write('\t\t\t</template>\n')
220238
aiml_file.write('\t\t</category>\n\n')
221239

@@ -258,7 +276,7 @@ def write_entry_category(self, aiml_file, first_step):
258276
aiml_file.write('\t\t\t\t<set name="topic">%s</set>\n' % self._name)
259277
# Clear variables before we start
260278
for step in self._steps:
261-
aiml_file.write('\t\t\t\t<set name="%s" />, \n' % step._variable)
279+
aiml_file.write('\t\t\t\t<set name="%s" />\n' % step._variable)
262280
aiml_file.write('\t\t\t</think>\n')
263281
# Jump to the first step
264282
aiml_file.write('\t\t\t<srai>%s STEP %s</srai>\n' % (self._name, first_step))
@@ -297,6 +315,7 @@ def copy_supporting_files(self, from_dir, to_dir):
297315

298316

299317
if __name__ == '__main__':
318+
300319
parser = argparse.ArgumentParser(description='Program-Y Flow Bot')
301320

302321
parser.add_argument('-flow', dest='flowfile', help='Flow file to load')

0 commit comments

Comments
 (0)