Basic AIML coding instructions
The files that control what Anna says are written in a special markup language called AIML - Artificial Intelligence Markup Language. Since AIML is an XML specification, it relies on tags (enclosed in <brackets> to operate. If you have ever edited an HTML document, you will see the similarities quickly.
This guide is intended to show you the fundamentals of editing AIML - it is recommended that you open up a small AIML file, such as anna_brain/1.aiml while reading this document so you can follow along easily. Essentially, a pattern is matched within the <pattern> tags and the response that is given back is in the <template> tag. Since only the most appropriate pattern is matched, only one output is generated for each input.
The * represents a "wildcard match" that matches one or more words in the <pattern> tag.
Like the *, the _ also represents wildcard matching, but with more precedence than other matches.
<?xml version="1.0" encoding="ISO-8859-1"?>
The first line of the AIML document, it specifies the document as the appropriate XML type. This tag is essential for all XML applications. Since AIML is an extended XML subset, this tag is required at the start of all valid AIML files.
<aiml> ...... </aiml>
This tag is the parent tag for the entire AIML document. It is normally the second statement in the AIML file. Dont try to write AIML without one of these sets.
<category> ...... </category>
This tag is the container tag for the "Meat" of the AIML language. Within the catgory tag, there should be two sets of tags, the "matching" part of the expression and the "returning" part of the expression. Generally these are represented by the <pattern> and <template> tags, but other tags may be used.
<pattern> ...... </pattern>
Specifies the pattern to match. Can involve Wildcards, like *, which matches 1 or more word.
<this> ...... </this>
The <this> tag is placed immediately after the </pattern> and immediately before the <template> tags. It specifies the last thing Anna has said. It is most appropriately used when the response is ambiguous. For instance, look up any name and see that is has a <this> tag specifying whether or not to respond through a name. This reduces duplications and makes Anna seem more human.
<template> ...... </template>
How Anna responds when the <pattern> tag within the <category> is matched.
<random> ...... </random>
This tag selects a random element from the list of <li>s that appear witin it.
<li> ...... </li>
Specifies a list item. Used within the <random> tag.
<srai> ...... </srai>
Perhaps the most fundamental tag. It specifies recursion, where anything within the tag is acted on as if it were input to Anna, but without displaying anything. Stands for a bunch of stuff, but I like to think of it as something exotic and powerful. You should to. This tag allows for the same question to be "passed around" to different parts of the program. Very useful. For instance, the pattern "DO YOU LIKE CHICKEN?" can be passed to "WHAT KINDS OF FOODS DO YOU LIKE", without the user seeing anything. Quite cool.
Used when embedded in an <srai> tag, this matches whatever information was gerenalized with the * (or the underscore)in the pattern tag. For instance, using the above example, the pattern "DO YOU LIKE *?", using the <star /> tag makes the word "CHICKEN" substitute for the <star /> tag.
Shortcut for <srai><star /></srai>. See above for what this means, it is only effective when the * in the pattern is holding a useful match.
<think> ...... </think>
This tag essentially makes Anna perform whatever is between the tags but not output anything to the user. Most useful when combined with <set> or <get>.
<topic name="VALUE"> ...... </topic>
The topics appear in the star.aiml file. If there has been a topic <set> matching the query, then this tag will be utilized. See star.aiml for examples of use.
<set name="VALUE"> ...... </set>
Sets whatever is within the tags to the variable VALUE. Can be retrieved through use of the <get> tag.
<get name="VALUE" />
Outputs whatever is in the variable VALUE. If VALUE has not been <set>, defaults to "".
This tag is like <star /> only it replaces it when not enclosed in an <srai> tag.
<!-- ...... -->
The comment tag. whatever is between the tag is not parsed - allowing developers to make helpful notes while coding.