Building a personal chatbot: likes & dislikes using AIML sets
For a second dive into AIML, weāre going to create interaction patterns so your bot can tell chatters where youāve travelled and some personal thoughts about those locations.
If you havenāt done so already, head over to Pandorabots and set up a free AIML-based bot on their platform. Add the Rosie bot as your base, which will assist with creating input patterns that your chatbot can recognize.
AIML set basics
Sets are one of the key ways to efficiently expand the scope and realism of your bot. They are ideal for collections of words or phrases that would have the same response. This makes them perfect for questions like, āHave you visited ________?ā
Weāre ultimately going to create four sets for four categories of responses: places Iāve visited and liked, places Iāve visited and didnāt like, places Iād like to travel to, and a catch-all for the remainder.
Create a visitedplaces.set file and add a list of places youāve been.
[[āCanadaā], [āBarcelonaā], [āSpainā], [āthe beachā], [āVancouverā], [āNew Yorkā], [āNew York Cityā], [āOaklandā], [āMontrealā], [āSan Franciscoā], [āNew Orleansā]]
Scroll to the end of your personality.aiml file and add the following code:
<category><pattern>HAVE YOU VISITED <set>visitedplaces</set></pattern>
<template>I have been there and really enjoyed it!</template>
</category>
Great! The bot will look in the visitedplaces.set file after anything starting with āHave you visitedā. Now letās repeat that for another set.
Create a wishfulplaces.set file similar to visitedplaces.set with locations youād like to visit, and add this code to your personality.aiml file:
<category><pattern>HAVE YOU ^ VISITED <set>wishfulplaces</set> ^</pattern>
<template>I havenāt been to <star index=ā2"/> but Iād very much like to visit!</template>
</category>
Thereās a little more going on here ā weāve got wildcards (the ^ character represents zero or more words), and weāre referencing the variable from the set in the botās response. The index=ā2" means itās in the second position in the pattern, between the two ^ wildcards.
Your conversation should look like this (in Pandorabotsā test platform).
Looking good!
Note the bot capitalized āHawaiiā even though the human didnāt, because it is using the value from the set file. If you need to capitalize user input in a response, use <formal> tags around the element.
AIML and <srai>
This is great if everyone talks the same way. What about the many other forms in which this question can be asked?
Weāre going to add one more major enhancement to our interaction that is a huge part of building your chatbot ā redirecting equivalent patterns to the conversation. The <srai> (Symbolic Reductions AI) tag simply says: if you match this pattern, go to this other pattern.
This allows you to easily add variations, such as, āHave you been to Hawaii?ā and have them redirect to our previous response template.
Add another category in your personality file:
<category><pattern>HAVE YOU BEEN TO <set>wishfulplaces</set> ^</pattern>
<template><srai>HAVE YOU ^ VISITED <set>wishfulplaces</set> <star/></srai></template>
</category>
Save and now your bot should say something like this:
Maybe our bots can meet on the beach in Hawaii someday ;)
the project
First published in 2000, StephTheGeek is an online presence with a giant case of scope creep. StephTheBot is an attempt to bring disparate sources of personal data together in friendly, timely, chatbot form. You can read about the projectand chat with her now (work in progress).