AIML Basics and MakeAiml Templates Tutorial
Introduction
In this tutorial you will learn how to create and use <pattern> and <template> tags in the MakeAiml language.
AIML Basics
An AIML file always begins with <aiml> and ends with </aiml>. Between these start and end tags comes a series of <category> tags containing one <pattern> tag and one <template> tag. The basic format of an AIML document is:
<aiml>
<category>
<pattern> ... </pattern>
<template> ... </template>
</category>
<category>
<pattern> ... </pattern>
<template> ... </template>
</category>
<category>
<pattern> ... </pattern>
<template> ... </template>
</category>
</aiml>
The <template> tag is one of the most basic AIML tags available and is always paired with a <pattern> tag. The pattern defines input that the AI needs to watch for and the template defines the AI's response to that input. So, given the following AIML document:
<aiml>
<category>
<pattern> HELLO </pattern>
<template> Hi! How are you? </template>
</category>
</aiml>
An artificial intelligence will wait for the user to input "Hello" and would respond by saying "Hi! How are you?" The method in which this exchange occurs is up to the programmer for the bot. The most often used method is an exchange of pure text (see A.L.I.C.E. Bot for an example of bot communication). There are many bot hosting websites like PandoraBots that will host a bot and allow the user simply upload their database of AIML files to define how the bot responds.
Another way to allow the exchange to occur is through speech. One way to do this is to overlay a text-to-speech (TTS) engine over an existing bot. Festival is a free TTS engine available on Linux, on Windows an AI programmer can use the Microsoft Speech API (SAPI).
Using MakeAiml to simplify
Anyone can see that the simple example above contains more markup text surrounding the input and the response than the input and the response themselves require. This is where MakeAiml comes in. MakeAiml allows a programmer to reduce the amount of work required to write an AIML file by providing a shorthand way to represent AIML tags and their contents. MakeAiml files are simply text files filled with sentences. Each sentence must start with a character (to identify the corresponding AIML tag to generate) and contain no newlines (created when a user hits the enter key).
The previous example can be re-written very simply in MakeAiml with the following:
p Hello
t Hi! How are you?
That's it! Two simple lines of MakeAiml text to replace six lines of AIML. Once the MakeAiml file is written, all a programmer has to do is run MakeAiml, load the MakeAiml file, and click the "Generate" button. The user interface is very simple and has absolutely no learning curve.
Comments
Comments are AIML tags that humans can read and bots will ignore. Comments allow a programmer to clarify parts of an AIML file or to provide an explanation of why something is the way it is. A comment can be inserted into an AIML document by typing:
<!-- Insert some text here -->
So, to add a comment to the previous AIML example:
<aiml>
<category>
<!-- A bot will not know this line is here -->
<pattern> HELLO </pattern>
<template> Hi! How are you? </template>
<category>
</aiml>
A comment's abbreviation in MakeAiml shorthand is an exclamation mark !. The above aiml file can now be written in MakeAiml by adding one line:
! A bot will not know this line is here
p Hello
t Hi! How are you?
Like before, a single character will designate the line as a comment and MakeAiml will generate the appropriate markup text accordingly.
Long MakeAiml Lines
As time progresses, AIML files will become very big and the responses can become very long. In order to get around this (because MakeAiml sentences are designated on a line-by-line basis) a user should use a single backslash character \ to let MakeAiml know that the next line is a continuation of the previous line. Here's an example:
p Hello
t Hi there! I hope you are \
having a great day!
Leading and trailing spaces in the continued line are ignored by MakeAiml, so a user is able to format their MakeAiml files however they want to so it reads easily. The above MakeAiml will cause "Hi there! I hope you are having a great day!" to be generated entirely on one line between the <template> and </template> tags.
About the Author
Grant Dryden works in the defense industry as a computer engineer. He writes software in C and C++ for embedded systems as well as firmware in VHDL. He has a Bachelor of Science in Computer Engineering and is currently working towards a a Master of Science in Information Security.

