In this section, we will be using AIML. AIML is an XML-based markup language used in developing AI applications, especially for software agents. It contains the rules or responses for user requests, which are used by NLU units internally. In simple terms, the more rules we add in AIML, the more intelligent and accurate our chatbot will be.
As AIML is an XML-based markup language; it starts with the root tag <aiml>, so a typical AIML file will look like this:
<?xml version="1.0" encoding="UTF-8"?>
<aiml>
</aiml>
To add questions and answers or responses for possible queries, the <category> tag is used. It is a base unit for the knowledge base of a chatbot. In simple words, <category> accepts the input and returns the output. All AIML elements must be enclosed in the <category> element. The <pattern> tag is used to match the user's input, and the <template> tag is the response to the user's input. Adding this to the previous code, the code should now look like the following:
<?xml version="1.0" encoding="UTF-8"?>
<aiml>
<category>
<pattern>Hello</pattern>
<template> Hello, How are you ? </template>
</category>
</aiml>
So, whenever a user inputs the word Hello, the bot will respond with Hello, How are you ?.
A * is used as a wild card character in the <pattern> tag to specify that anything can be put in place of star, and a <star> tag is used in the <template> tag to form the response, as shown here:
<?xml version="1.0" encoding="UTF-8"?>
<aiml>
<category>
<pattern>I like *.</pattern>
<template>Ok, so you like <star/></template>
</category>
</aiml>
Now, when the user says, "I like Mangoes", the response from the bot will be "Ok so you like mangoes". We can also use more than one *, as follows:
<?xml version="1.0" encoding="UTF-8"?>
<aiml>
<category>
<pattern>I like * and *</pattern>
<template> Ok, so you like <star index="1"/> and <star index="2"/></template>
</category>
</aiml>
Now, when the user says, "I like Mangoes and Bananas", the response from the bot will be "Ok so you like mangoes and bananas".
Next is the <srai> tag, which is used for different patterns in order to generate same template, as follows:
<?xml version="1.0" encoding="UTF-8"?>
<aiml>
<category>
<pattern>I WANT TO BOOK AN APPOINTMENT</pattern>
<template>Are you sure</template>
</category>
<category>
<pattern>Can I *</pattern>
<template><srai>I want to <star/></srai></template>
</category>
<category>
<pattern>May I * </pattern>
<template>
<srai>I want to <star/></srai>
</template>
</category>
</aiml>
The first category has a pattern of "I WANT TO BOOK AN APPOINTMENT" for which the response is "Are you sure". In the next category, if the user asks "Can I book an appointment" or "May I book an appointment", the response will be the same: "Are you sure".
The <srai> tag is used for many purposes like we saw here, and it can also be used for synonyms and keyword resolution.
For more tags, refer to http://callmom.pandorabots.com/static/reference/#aiml-2-0-reference.