AIML Basic Tags
What is AIML?
AIML stands for Artificial Intelligence Markup Language which is a XML-based scripting language for creating rule-based chatbots or virtual assistants. It uses a pattern-matching mechanism to determine the appropriate response based on the input.
Table of Content
- Basic tags in AIML:
- Other useful tags in AIML:
- Steps to execute your Bot:
Basic tags in AIML:
The following are the basic tags used in AIML:
1. <aiml>: The purpose of the `<aiml>` tag is to encapsulate the entire AIML document.
Syntax:
<aiml>
<!-- The content of the document -->
</aiml>
2. <pattern>: The purpose of the `<pattern>` tag is to hold the input that the chatbot will respond to.
Syntax:
<aiml>
<pattern>...</pattern>
</aiml>
3. <template>: The purpose of the `<template>` tag is to hold the response that the chatbot will generate based on the input pattern.
Syntax:
<aiml>
<pattern>...</pattern>
<template>...</template>
</aiml>
4. <category>: The purpose of the `<category>` tag is to represent a rule of category combining pattern and template.
Syntax:
<aiml>
<category>
<pattern>...pattern>
<template>...</template>
<category>
</aiml>
Example: Let’s take a look at an example that can help us understand how the tags mentioned above work. For instance, we can examine an XML-based script for creating a bot that responds to the input “Hey! What is the capital of India?” with “New Delhi“.
XML
<? xml version = "1.0" encoding = "UTF-8" ?> < aiml > < category > < pattern >Hey! What is the captial of India?</ pattern > < template >New Delhi</ template > </ category > </ aiml > |
Output:
5. <random> and <li>: The purpose of the `<random>` tag is to allow the chatbot to reply with any of the provided list of options each enclosed in the `<li>` tag.
Syntax:
<random>
<li>...</li>
<li>...</li>
</random>
Example:
XML
<? xml version = "1.0" encoding = "UTF-8" ?> < aiml > < category > < pattern >Suggest me an odd number</ pattern > < template > < random > < li >1</ li > < li >3</ li > < li >5</ li > </ random > </ template > </ category > </ aiml > |
Output:
6. <that>: The purpose of <that> is to refer to previous response of the chatbot. The <that> is followed by <pattern> tag of the current category.
Syntax:
<aiml>
<category>
<pattern>...</pattern>
<template>...response1...</template>
</category>
<category>
<pattern>...</pattern>
<that>...response1...</that>
<template>...</template>
</category>
</aiml>
Example:
XML
<? xml version = "1.0" encoding = "UTF-8" ?> < aiml > < category > < pattern >Hey Good morning</ pattern > < template >Good morning Geek</ template > </ category > < category > < pattern >I need your help</ pattern > < that >Good morning Geek</ that > < template >How can I help you</ template > </ category > < category > < pattern >I need your help</ pattern > < template >I will try my best to help you</ template > </ category > </ aiml > |
Output:
Explanation: When the user entered “I need your help” for the first time, based on the previous response of the bot i.e. “Good morning Geek” it reply with “How can I help you” and for the next time it responds with “I will try my best to help you” for the user’s input.
7. <star>: The purpose of the <star> is to match the wildcard segments with user’s input.
Syntax:
<aiml>
<category>
<pattern>*</pattern>
<template><star /></template>
</category>
</aiml>
Example:
XML
<? xml version = "1.0" encoding = "UTF-8" ?> < aiml > < category > < pattern >I want to know about *</ pattern > < template >Please specify what do you want to know about < star /></ template > </ category > </ aiml > |
Output:
Other useful tags in AIML:
These are the basic tags in AIML and there are many other useful tags like:
- <think>: The purpose of <think> is to process the input internally without generating intermediate results.
- <set>: The purpose of <set> is to assign and set a value to the variable, store and use in the program wherever needed.
- <condition>: The purpose of <condition> is to allow the bot to choose the specific response to the input based on the value of the variable.
- <get>: The purpose of <get> is to retrieve the value of the variable which has been set using <set>.
- <srai>: The purpose of <srai> is to invoke another category inside the current category.
Steps to execute your Bot:
Ensure that you sign-up to pandorabots for free.
- Create your bot and navigate to AIML folder in the folder structure and start writing your XML code in the udc file.
- Once you wrote the code, click on the chat option button on the right-bottom corner and start your conversation with your bot.