AIML (Artificial Intelligence Markup Language) is a description language used in the development of natural language software agents like chatbots and virtual assistants. AIML was developed by Richard Wallace from 1995 to 2000, and it is based on XML (eXtensible Markup Language). AIML provides automated responses to users' questions because it is rule-based. The scripting language represents a data-driven programming paradigm. While writing the script for a conversational chatbot, all the conditions (the user's query) and actions (the chatbot's response) must be included.
Features of AIML
- data-driven: The user's queries are predefined as conditions and mapped with particular actions for generating automated responses for users.
- Rule-based Scripting language: If the conditions get satisfied, it performs an action based on the rule; if the condition does not get satisfied, then it stops.
- XML-based: AIML is easy to learn for programmers who know HTML or XML because it has a similar syntax to HTML and XML. It enables integration with XML editors using XML syntax.
- Flexibility: Customized tags and functions can be created for efficient code writing in development.
- Random Actions: Based on a single condition, multiple actions can be defined.
There are multiple elements and tags in AIML and we are going to see some basic elements with their syntax.
1. <aiml>: Inside this tag, all tags are defined. It constructs the starting and ending of an AIML document.
<aiml> <!-- all the tags that contain conditions and actions--> </aiml>
2. <category>: inside each category tag defines conditions and actions. category tags can be multiple inside the <aiml> tag.
<aiml>
<category>
<!--condition and action are defined-->
<category>
</aiml>
3. <pattern>: The condition is written inside the pattern tag.
<aiml>
<category>
<!--condition and action are defined-->
<category>
</aiml>
4. <template>: The action is written inside the template tag. Actions can be single or multiple, so the template tag is defined multiple times inside the category tag.
<aiml>
<category>
<pattern> <!--condition is defined--> </pattern>
<template> <!--Action is defined for condition--> </template>
<category>
</aiml>
AIML Examples
AIML Script is an XML Document, that contains elements defined using AIML schema. It must contain only one <aiml> element. The conditions and actions are defined within <category> element. For condition, <pattern> tag is used and for action, <template> tag is used.
Example 1: In this example, the condition is Hello and for that condition, the action is Hi, how can I help you? you can include multiple conditions and actions using multiple <category> elements.
XML
<?xml version="1.0" encoding="UTF-8"?>
<aiml>
<category>
<pattern>Hello</pattern>
<template>Hi, how can I help you</template>
</category>
</aiml>