Skip to content

Commit

Permalink
Added exit clause to all flow conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
keiffster committed Jan 16, 2018
1 parent abc5fa8 commit 7cd653b
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 18 deletions.
72 changes: 60 additions & 12 deletions bots/botflow/aiml/FLIGHTBOOK.aiml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
<template>
<think>
<set name="topic">FLIGHTBOOK</set>
<set name="City" />,
<set name="London" />,
<set name="Destination" />,
<set name="Date" />,
<set name="Passengers" />,
<set name="Class" />,
<set name="City" />
<set name="London" />
<set name="Destination" />
<set name="Date" />
<set name="Passengers" />
<set name="Class" />
</think>
<srai>FLIGHTBOOK STEP SOURCE</srai>
</template>
Expand All @@ -24,7 +24,7 @@
FLIGHTBOOK STEP SOURCE
</pattern>
<template>
Where would you like to fly from - (London, Edinburgh, Glasgow, Manchester)
Where would you like to fly from - (London, Edinburgh, Glasgow, Manchester or exit)
</template>
</category>

Expand All @@ -43,12 +43,20 @@
</template>
</category>

<category>
<pattern>EXIT</pattern>
<that>Where would you like to fly from *</that>
<template>
<srai>EXIT FLIGHTBOOK</srai>
</template>
</category>

<category>
<pattern>
FLIGHTBOOK STEP LONDON
</pattern>
<template>
Where from in London are you flying from - (Stanstead, Heathrow, Gatwick)
Where from in London are you flying from - (Stanstead, Heathrow, Gatwick or exit)
</template>
</category>

Expand All @@ -66,12 +74,20 @@
</template>
</category>

<category>
<pattern>EXIT</pattern>
<that>Where from in London are you flying from *</that>
<template>
<srai>EXIT FLIGHTBOOK</srai>
</template>
</category>

<category>
<pattern>
FLIGHTBOOK STEP DEST
</pattern>
<template>
Where would you like to fly to - (New York, Washington, San Francisco)
Where would you like to fly to - (New York, Washington, San Francisco or exit)
</template>
</category>

Expand All @@ -89,12 +105,20 @@
</template>
</category>

<category>
<pattern>EXIT</pattern>
<that>Where would you like to fly to *</that>
<template>
<srai>EXIT FLIGHTBOOK</srai>
</template>
</category>

<category>
<pattern>
FLIGHTBOOK STEP DATE
</pattern>
<template>
When would you like to fly - (DD/MM/YYYY)
When would you like to fly - (DD/MM/YYYY or exit)
</template>
</category>

Expand All @@ -111,12 +135,20 @@
</template>
</category>

<category>
<pattern>EXIT</pattern>
<that>When would you like to fly *</that>
<template>
<srai>EXIT FLIGHTBOOK</srai>
</template>
</category>

<category>
<pattern>
FLIGHTBOOK STEP PASSENGERS
</pattern>
<template>
How many people are flying - (1 to 5)
How many people are flying - (1 to 5 or exit)
</template>
</category>

Expand All @@ -133,12 +165,20 @@
</template>
</category>

<category>
<pattern>EXIT</pattern>
<that>How many people are flying *</that>
<template>
<srai>EXIT FLIGHTBOOK</srai>
</template>
</category>

<category>
<pattern>
FLIGHTBOOK STEP CLASS
</pattern>
<template>
What class do you want to fly - (Economy, Premium Economy, Business, First)
What class do you want to fly - (Economy, Premium Economy, Business, First or exit)
</template>
</category>

Expand All @@ -157,6 +197,14 @@
</template>
</category>

<category>
<pattern>EXIT</pattern>
<that>What class do you want to fly *</that>
<template>
<srai>EXIT FLIGHTBOOK</srai>
</template>
</category>

</topic>

</aiml>
9 changes: 8 additions & 1 deletion bots/botflow/aiml/flightbookctrl.aiml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<pattern>EXECUTE FLIGHTBOOK</pattern>
<template>
Ok, I'll book a flight matching the following:
flying from <get name="City" />,
flying from <get name="City" />
<get name="London" />,
to <get name="Destination" />,
on <get name="Date" />,
Expand All @@ -21,4 +21,11 @@
</template>
</category>

<category>
<pattern>EXIT FLIGHTBOOK</pattern>
<template>
Thanks, ask again any time and I will help you
</template>
</category>

</aiml>
4 changes: 4 additions & 0 deletions src/utils/botflow/botflow.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#!/usr/bin/env bash

clear

export PYTHONPATH=./src:.

python3 src/botflow.py -flow "../../../bots/botflow/flow/flightbook.csv" -topic flightbook -aiml "../../../bots/botflow/aiml"
29 changes: 24 additions & 5 deletions src/utils/botflow/src/botflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ def __init__(self, text):
self._values = [x.strip() for x in values.split(",")]

def type_values_to_str(self):
return ", ".join(self._values)
text = ", ".join(self._values)
text += " or exit"
return text

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

def type_values_to_str(self):
return self._values[0]
text = self._values[0]
text += " or exit"
return text

def output_template(self, aiml_file, topic_name, step):
if step._conditions:
Expand Down Expand Up @@ -96,9 +100,11 @@ def __init__(self, text):

def type_values_to_str(self):
if len(self._values) == 2:
return " to ".join(self._values)
text = " to ".join(self._values)
else:
return " max %s" % self._values[0]
text = " max %s" % self._values[0]
text += " or exit"
return text

def output_template(self, aiml_file, topic_name, step):
if step._conditions:
Expand Down Expand Up @@ -216,6 +222,18 @@ def output_aiml(self, aiml_file, topic_name):

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


aiml_file.write('\t\t\t</template>\n')
aiml_file.write('\t\t</category>\n\n')

aiml_file.write('\t\t<category>\n')
aiml_file.write('\t\t\t<pattern>EXIT</pattern>\n')
if self._type._values:
aiml_file.write('\t\t\t<that>%s *</that>\n' % self._prompt)
else:
aiml_file.write('\t\t\t<that>%s</that>\n' % self._prompt)
aiml_file.write('\t\t\t<template>\n')
aiml_file.write('\t\t\t\t<srai>EXIT FLIGHTBOOK</srai>\n')
aiml_file.write('\t\t\t</template>\n')
aiml_file.write('\t\t</category>\n\n')

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


if __name__ == '__main__':

parser = argparse.ArgumentParser(description='Program-Y Flow Bot')

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

0 comments on commit 7cd653b

Please sign in to comment.