Introduction to AIML
Witold Paluszyński
Department of Cybernetics and Robotics
Faculty of Electronics
Wroclaw University of Technology
http://kcir.pwr.edu.pl/~witold/
2014
This work is licensed under the
Creative Commons Attribution-
Share-Alike 3.0 Unported License
Permission is granted to copy, distribute and/or modify this document
according to the terms in Creative Commons License, Attribution-ShareAlike
3.0. The license requires acknowledging the original author of the work, and the
derivative works may be distributed only under the same conditions (rights may
not be restricted or extended in any way).
Background Rule-based language
AIML is an XML-based description language designed for creating natural AIML is a rule-based language, which means the program is created as
language software agents. It was developed by Richard Wallace starting in 1995 a collection of rules. This represents the so-called data-driven programming
and was the basis for the conversation agent A.L.I.C.E. (“Artificial Linguistic paradigm, which is different from sequential programming.
Internet Computer Entity”), which won the annual Loebner Prize Competition in
Artificial Intelligence three times (2000, 2001, and 2004), and was also the The rules are small entities consisting of two parts: condition and action.
Chatterbox Challenge Champion in 2004. The system works by selecting one rule which has its condition satisfied, and
then executing the action of the selected rule. More precisely, an instantiation of
The A.L.I.C.E. AIML set was released under the GNU GPL license and the the rule’s action is executed, since during the evaluation of the rule’s condition,
development of the language was continued with the participation of the free some variables can be assigned values, which instantiates the action part of the
software community. rule.
This document describes the basic elements of AIML corresponding mostly to The execution of some rule’s action is called its firing. The process of selecting
version 1 of AIML. In 2013 work has been started on version 2 of AIML. As of and firing a rule forms the basic work cycle of the system, performed by
March 2014 a working draft is available. a language interpreter. In general, the interpreter of a rule-based system may
repeat the cycle some specified number of times, or as long as there is at least
one rule, which has the condition part satisfied. The AIML interpreter fires
exactly one rule (if at all possible), and may fire additional rules if so instructed
under the recursion mechanism (see the srai tag below).
Introduction to AIML — background 3 Introduction to AIML — rule-based systems 4
The ordering of firing rules The AIML program
More than one rule can have their conditions satisfied at any time. If so An AIML program is an XML document consisting of the elements defined in
happens, it is called a conflict. The interpreter must have a strategy for the AIML schema. It must consist exactly one aiml element:
resolving conflicts, so that exactly one rule is selected for firing. If no rule has
the condition satisfied, the system stops, or fails. <aiml>
</aiml>
It is important to note, that in most rule-based systems, the order in which the
rules are written in the program has no influence on the selection of the rules Theoretically, a file might just contain a plain aiml tag like that. In practice,
for firing. In other words, ordering of the rules in the program does not affect many AIML interpreters might require a more complete XML header pointing to
the order of their execution. The sequence of the fired rules is only determined the AIML schema location:
by their content, and the data provided to the rules.
<?xml version="1.0" encoding="UTF-8"?>
<aiml version="1.0.1"
xmlns="http://alicebot.org/2001/AIML-1.0.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://alicebot.org/2001/AIML-1.0.1
http://aitools.org/aiml/schema/AIML.xsd">
</aiml>
Introduction to AIML — rule-based systems 5 Introduction to AIML — program structure 6
The elements of a rule The wildcards and the star tag
A rule is defined with the category element, so the AIML document should The condition pattern can contain wildcards * which allow writing more general
contain a sequence of the category elements. Each one should contain one patterns:
pattern element and one template element, which define the condition and
action parts, respectively: <category>
<pattern>MY NAME IS *</pattern>
<aiml> <template>OK, nice to meet you.</template>
<category> </category>
<pattern>HELLO</pattern>
<template>Hi, how are you?</template> The star tag allows using in the template the text matched to the wildcard in
</category> the pattern:
</aiml>
<category>
The above program will answer “Hi, how are you?” if the user first says <pattern>MY NAME IS *</pattern>
“HELLO”. If the user says anything else, the program will fail, since there is no <template>OK, nice to meet you <star/></template>
rule possible to select. </category>
Introduction to AIML — categories 7 Introduction to AIML — wildcards 8
The srai tag and the recursion Randomized actions
It often happens, that the same user question or phrase can be stated in The action part of a rule can select one of a several responses randomly:
different ways, but should be handled in the same way. In such cases, the srai
tag can be used to refer to a specific rule from another rule: <category>
<pattern>How are you doing?</pattern>
<category> <template>
<pattern>How do I get to the train station?</pattern> <random>
<template>Go to the main street and then turn right. <li>I’m fine.</li>
</template> <li>OK, I am doing alright.</li>
</category> <li>Quite well, thanks.</li>
<li>Good, good, and you?</li>
<category> </random>
<pattern>How do I get to the supermarket?</pattern> </template>
<template>Follow the main street out of town.</template> </category>
</category>
<category>
<pattern>What is the way *</pattern>
<template><srai>How do I get <star/></srai></template>
</category>
Introduction to AIML — srai and recursion 9 Introduction to AIML — randomized actions 10
Global variables Using global variables in conditionals
AIML allows the program to use global variables. Any rule can assign a text A value assigned to a global variable can be placed in any output test using the
value to any variable, and it can be referenced in any rule: get tag. It can also be used in a conditional expression:
<category>
<category>
<pattern>MY NAME IS *</pattern>
<pattern>WOULD YOU LIKE TO DANCE WITH ME?</pattern>
<template>OK, nice to meet you
<template>
<set name="userName"><star/></set> .
Sure, it will be a pleasure.
</template>
<condition name="userName" value="">
</category>
Can you tell me your name?
</condition>
<category>
</template>
<pattern>MY NAME IS *</pattern>
</category>
<template>OK, nice to meet you.
<think><set name="userName"><star/></set></think>
In the above rule, the template checks, in addition to answering the question,
</template>
that the program has learned the name of the user. Empty value of the
</category>
userName variable means, that the variable has not been set. In such case, the
program asks for the name. If the user provides it, the previous rule will fire,
The think tag in the last rule allows its content to be processed like the first
which will record the name.
one, but prevents it from being merged to the output string and being displayed.
Introduction to AIML — global variables 11 Introduction to AIML — global variables 12
Grouping rules using the topic tag <topic name="PAYMENT">
It is possible to control the topic of the conversation using the topic tag. The <category>
topic element(s) must occur at the top level of the program, alongside other <pattern>How can i pay?</pattern>
rules (which do not belong to any topic). The topic can be changed at any <template>You can pay cash or use a credit card.
time, effectively moving to a different group of rules. </template>
</category>
<category>
<pattern>Can I buy a train ticket?</pattern> </topic>
<template>Yes, this is the ticket office.</template>
</category>
<category>
<pattern>Can I buy a ticket to * ?</pattern>
<template>Yes, you can.
<think><set name="userDestination"><star/></set>
<set name="topic">PAYMENT</set></think>
<srai>How can i pay?</srai>
</template>
</category>
Introduction to AIML — topics 13 Introduction to AIML — topics 14
AIML interpreters — Program D Important references
There exist many AIML interpreters — program that execute the AIML work The “home page” of AIML — a repository of resources related to AIML:
cycle when loaded with a set of AIML categories (from one or more files). For
http://www.alicebot.org/aiml.html
some reason, most are named as Program X where X is some letter, like:
Program D, Program E, Program M, Program O, Program P, Program Q,
Program R, Program V, Program Y, Program #, etc. They are written in The AIML tutorial by it author Richard S. Wallace:
a wide selection of programming languages and offer different range of http:
additional functionality, beside the basic AIML interpretation. //www.pandorabots.com/pandora/pics/wallaceaimltutorial.html
A simple but well-established interpreter written in Java is Program D. It has
a text version which can be run in a text terminal, and a window GUI which
opens a window showing the dialog.
After starting the text version, a new program can be loaded with:
/load filename
The file can be placed in the ProgramD directory, or specified with a full disk
path. After successfully loading a program, the user can start the dialog.
Introduction to AIML — AIML interpreters 15 Introduction to AIML — references 16