Say you asked the chatbot to learn “Rome is a city in Italy”. This would match the following category in learn.aiml:
<category>
<pattern>* IS A *</pattern>
<template>
Ok I will add that fact about<person/>to my database.
<srai>XEDUCATE WHAT IS XSPLIT <star index="1"/> XSPLIT <star index="2"/>/srai>
<srai>XEDUCATE WHERE IS XSPLIT <star index="1"/> XSPLIT <star index="2"/></srai>
<srai>XEDUCATE WHO IS XSPLIT <star index="1"/> XSPLIT <star index="2"/></srai>
<srai>XEDUCATE WHAT IS A XSPLIT <star index="1"/> XSPLIT <star index="2"/></srai>
<srai>XEDUCATE WHERE IS A XSPLIT <star index="1"/> XSPLIT <star index="2"/></srai>
<srai>XEDUCATE WHO IS A XSPLIT <star index="1"/> XSPLIT <star index="2"/></srai>
<srai>XEDUCATE WHAT _ IS A XSPLIT <star index="1"/> XSPLIT <star index="2"/></srai>
</template>
</category>
What this category does is prepare and teach the bot the following questions and answers:
WHAT IS Rome
WHERE IS Rome
WHO IS Rome
WHAT IS A Rome
WHERE IS A Rome
WHO IS A Rome
WHAT _ IS A Rome
As you can see, a few of these don’t make sense (WHO IS ROME for example) but it’s better to set too many categories up than too few. If we had said to the bot, “Charles is a man” then then question, “WHO IS CHARLES” makes more sense. As we don’t know the subject matter of the user’s question, we set up all the possibilities.
Let’s just take the first <srai> “WHAT IS ROME” and see how this works. It does this by calling the category “XEDUCATE WHAT IS XSPLIT Rome XSPLIT Italy”. Rome and Italy represent <star index=“1”> and <star index=“2”>.
The XEDUCATE category is as follows:
<category>
<pattern>XEDUCATE * XSPLIT * XSPLIT *</pattern>
<template>
<learn>
<category>
<pattern>
<eval><uppercase><star index="1"/><star index="3"/></uppercase></eval>
</pattern>
<template>
<eval><star index="2"/></eval>
</template>
</category>
</learn>
<learn>
<category>
<pattern>
<eval><uppercase><star index="1"/><star index="2"/></uppercase></eval>
</pattern>
<template>
<eval><star index="3"/></eval>
</template>
</category>
</learn>
</template>
</category>
What this does is to teach the bot a new category by using the <learn> tag. Anything between the <learn> and </learn> is learned by the chatbot. Ignore the first <learn> and </learn> tags for now. Between the second <learn> and </learn> tags we have:
<category>
<pattern>
<eval><uppercase><star index="1"/><star index="2"/></uppercase></eval>
</pattern>
<template>
<eval><star index="3"/></eval>
</template>
</category>
Which as you can see is a category in AIML. All that is missing is the pattern and template. Fortunately, we have supplied this by asking, “XEDUCATE WHAT IS XSPLIT Rome XSPLIT a city in Italy”.
As the XEDUCATE category is “XEDUCATE * XSPLIT * XSPLIT *”, this means that the following wil be set:
<star index=“1”>=WHAT IS
<star index=“2”>=Rome
<star index=“3”>=a city in Italy
Let’s see what the <eval> tag is doing here in <eval><uppercase><star index=“1”><star index=“2”></uppercase></eval>:
<eval> tells the interpreter to evaluate whatever is between the tags. So in this case it evaluates what we sent it in star indexes 1 and 2. This will give us “WHAT IS Rome”. I like to keep patterns in categories all uppercase and so we add an <uppercase> tag. This now gives us “WHAT IS ROME” and our <learn> category now looks like:
<category>
<pattern>
WHAT IS ROME
</pattern>
<template>
<eval><star index="3"/></eval>
</template>
</category>
Now it evaluates star index 3 to make our category complete:
<category>
<pattern>
WHAT IS ROME
</pattern>
<template>
a city in Italy
</template>
</category>
We don’t want star index 3 to be uppercase, as this is the reply the user will see. So now if the user asks, “What is Rome”, our new category is matched and the reply “a city in Italy” is given but what if the user asks, “What is a city in Italy”? This is where the first <learn> and </learn> tags in the XEDUCATE category come in.
<learn>
<category>
<pattern>
<eval><uppercase><star index="1"/><star index="3"/></uppercase></eval>
</pattern>
<template>
<eval><star index="2"/></eval>
</template>
</category>
</learn>
You will remember that the star indexes are:
<star index=“1”>=WHAT IS
<star index=“2”>=Rome
<star index=“3”>=a city in Italy
All the first <learn> tags do is to swap the question around. So now the first eval is now evaluating star index 1 and 3 to give “WHAT IS a city in Italy” and the second is setting the template to “Rome”. Using this means the user can ask “What is a city in Italy” and the bot will answer “Rome”.
Going back to the very first category (if you are still reading ), we now srai the other questions to the XEDUCATE category:
<srai>XEDUCATE WHERE IS XSPLIT Rome XSPLIT a city in Italy</srai>
<srai>XEDUCATE WHO IS XSPLIT Rome XSPLIT a city in Italy</srai>
<srai>XEDUCATE WHAT IS A XSPLIT Rome XSPLIT a city in Italy</srai>
<srai>XEDUCATE WHERE IS A XSPLIT Rome XSPLIT a city in Italy</srai>
<srai>XEDUCATE WHO IS A XSPLIT Rome XSPLIT a city in Italy</srai>
<srai>XEDUCATE WHAT _ IS A XSPLIT <Rome XSPLIT a city in Italy</srai>
and the whole thing starts again. Your bot can now answer the following:
WHAT IS ROME - a city in Italy
WHERE IS ROME - a city in Italy
WHO IS ROME - a city in Italy
WHAT IS A ROME - a city in Italy
WHERE IS A ROME - a city in Italy
WHO IS A ROME - a city in Italy
WHAT _ IS A ROME - a city in Italy
WHAT IS A CITY IN ITALY - Rome
WHERE IS A CITY IN ITALY - Rome
WHO IS A CITY IN ITALY - Rome
WHAT IS A A CITY IN ITALY - Rome
WHERE IS A A CITY IN ITALY - Rome
WHO IS A A CITY IN ITALY - Rome
WHAT _ IS A A CITY IN ITALY - Rome
(cont….)