Don't Read Me

A. L. I. C. E. and AIML Documentation

Dr. Richard S. Wallace
Copyright ©2000
Last Modified 24 September 2000

"There it is. Take it." -- William Mulholland


The primary purpose of this program -- codenamed "B" -- is to give
away the secret of ALICE chat robot development to anyone who
wants it, permitting the greatest possible dissemination, utilization
and technical improvement of the ALICE chat robot technology.
Second, program B is written in Java to support the widest
possible architectural base (a significant shortcoming of early ALICE).
B runs on a wide range of processors and systems supporting the
Java Virtual Machine. Third, program B is designed to be as simple as
possible to use, especially for nonprogrammers who will never have
to touch the Java source code.

Program B is offered free, under the terms of the GNU General Public
License; permitting rapid, organic software growth with contributions
from many programmers. We gratefully acknowledge the following
individuals who worked on program B:

Alain Agostini developed some AIML for Pickup.aiml
Diana Andreacchio wrote a help document for Windows users that became
part of this FAQ.
An anonymous contributor provided AIML content no longer used.
Anonymous contributors created the VBScript interface to MS Agent.
David Bacon wrote the SETL compiler used to prototype the early
versions of ALICE.
Jacco Bikker wrote an AIML interpreter in C and corrected much of
the original AIML content.
Ace Craig contributed the the AIML "web search" markup.
Kris Drent has provided significant contributions to the
Program B application, Applet and Servlet. He created the
<topic> tag. Kris also wrote a fast, small-footprint XML
x parser tuned for AIML files.
Christian Drossmann provided the German language AIML module.
John Friedman created the DTD website.
Ken Goldberg offered advice since ALICE was born in 1995.
Gomi no Sensei provided knowledge about Italy.
Sage Greco created the ALICE robot maid 3-D graphic model and also
designed the original ALICE pyramid logo.
John Laroche updated the XML DTD for AIML.
Erik Levy became a botmaster and contributed AIML content.
David Maggin is the author of the John Lennon AI Project.
Rob Maggin contributed a few categories to Knowledge.aiml.
Billy Mahoney wrote a set_they patch for
John Mccready contributed NT info to this document.
Michael Modes wrote massive amount of AIML content.
Kirk Munoz contributed ology1.aiml to the Knowledge.aiml file.
Terence Parr provided a parser no longer used.
Yiannis Paschalidis improved and StringSorter.add().
Andrew Phillips wrote some content for Knowledge.aiml.
Andrew Potgieter wrote a text wrapper and created the <think> tag.
Timothy F. Rohaly proofread the Java code and suggested numerous improvements.
Karolyn Schalk contributed content to Knowledge.aiml.
Karlheinz Schuhmacher modified Substiter.replace() to prevent endless loops.
Gregory Skourge made the package org.alicebot.
Jack Spies contribued much to the Mac documentation.
Anthony Taylor made Jacco's C/C++ a platform-independent program.
Stan Wallace wrote some content for Knowledge.aiml.

Additional graphics were created by Sage Greco, Darren Langley and
Larry Hauser. We gratefully acknowledge these contributions and the
programmers who created them. Thanks are also due to the many people
who asked the "frequently asked questions" that form the basis of
this document.

This Java code sample is provided to you on an 'as-is' basis
without warranty or condition of any kind, either express or
implied, including, but not limited to, warranty or condition of
merchantable quality or fitness for a particular purpose.
The authors shall not be liable for any damages
arising out of your use of this code, even if they
have been advised of the possibility of such damages.

Copyright © 2000, Dr. Richard S. Wallace, All Rights Reserved

Program B includes a chat robot development environment, a GUI, a server,
Servlet and downloadable Applet. This file contains a basic outline of
documentation and a tutorial. Some experience working with Java
applications and Applets is desirable, but not necessary, to
install and run this software. Program B could be your first
Java program.

An HTML Table of Contents for this document is available at


I. Introduction

II. Download and Run

III. Creating Content

IV. Web Server Interface

V. Applet Interface

VI. AIML - Artificial Intelligence Markup Language

VII. Java Classes

Appendix A. Self Test

Appendix B. Note to Parents

I. Introduction

- What is the goal for AIML?

AIML (Artificial Intelligence Markup Language) is an XML specification
for programming chat robots like ALICE using program B. The emphasis
in the language design is minimalism. The simplicity of AIML makes
it easy for non-programmers, especially those who already know HTML,
to get started writing chat robots.

One ambitious goal for AIML is that, if a number of people create their own
robots, each with a unique area of expertise, program B can literally
merge-sort them together into a Superbot, automatically omitting
duplicate categories. We offer the both the source code and the ALICE
content, in order to encourage others will "open source" their chat
robots as well, to contribute to the Superbot.

Botmasters are also of course free to copy protect private chat robots.

- Who is the botmaster?

The botmaster is you, the master of your chat robot. A botmaster runs
program B and creates or modifies a chat robot with the program's
graphical user interface (GUI). He or she is responsible for
reading the dialogues, analyzing the responses, and creating new
replies for the patterns detected by program B. Botmasters are
hobbyists, webmasters, developers, advertisers, artists, publishers,
editors, engineers, and anyone else interested in creating a personal
chat robot.

- How can I create my own chat robot?

The secret to chat bot programming, if there is one, is what Simon
Laven called "continuous beta testing". Program B runs as a server
and collects dialog on the web. The program provides the chat bot
developer with a tool called "classify dialogues", that tests the current
robot with the history of accumulated human queries. Moreover, the program
suggests new categories automatically, for the botmaster to refine.

- How difficult is it to create a chat robot?

Not difficult. If you can write HTML, you can write AIML (Artificial
Intelligence Markup Language). Here is an example of a simple but
complete chat robot in AIML:

<template> Hello! </template>

The tags <alice>...</alice> indicate that this markup contains a
chat robot. The <category> tag indicates an AIML category, the
basic unit of chat robot knowledge. The category has a <pattern>
and a <template>. The pattern in this case is the wild-card
symbol '*' that matches any input. The template is just the text
"Hello!" As you may have guessed, this simple chat robot just
responds by saying "Hello!" to any input.

You can get started with AIML knowing just the three tags
<category>, <pattern> and <template>; much like you may have
started with HTML knowing only <a>, <img> and <h1>.

- Does ALICE learn?

The model of learning in ALICE is called "supervised training",
because a teacher, the botmaster, always plays a crucial role.
The alternative, "unsupervised training", is complicated in
an open environment like the Web. The problem is that clients
are untrustworthy teachers, and forever try to "fool" the robot
with untrue assertions.

- Does ALICE think?

It depends on what you mean by "thinking". The most fascinating
responses from ALICE arise when she says something
unexpected, or puts together responses in ways the botmaster
never indended. For example:

Client: I bet you are gay.
ALICE: Actually I am not the gambling type. Actually as a machine
I have no need for sex.

Here the robot linked two different categories which both coincidentally
have a moral theme (gambling and sexuality). But this specific combination was
not "preprogrammed" by the botmaster.

Are these surprising responses just unintended coincidences, or do they
indicate that ALICE is thinking? Is ALICE just a gigantic stimulus-response
mechanism, or are we?

- What is the theory behind ALICE?

I used to say that there was NO theory behind ALICE: no neural network,
no knowledge representation, no search, no fuzzy logic, no genetic
algorithms, and no parsing. Then I discovered there was a theory
circulating in applied AI called "Case-Based Reasoning" or CBR that
maps well onto the ALICE algorithm. Another term, borrowed from
pattern recognition, is "nearest-neighbor classification."

The CBR "cases" are the categories in AIML. The algorithm finds
best-matching pattern for each input. The category ties the
response template directly to the stimulus pattern. ALICE is
conceptually not much more complicated that Weizenbaum's ELIZA
chat robot; the main differences are the much larger case base and the
tools for creating new content by dialog analysis.

ALICE is also part of the tradition of "minimalist", "reactive" or
"stimulus-response" robotics. Mobile robots work best, fastest and
demonstrate the most animated, realistic behavior when their sensory
inputs directly control the motor reactions. Higher-level symbolic
processing, search, and planning, tends to slow down the process
too much for realistic applications, even with the fastest control

- Can probability (statistics, weights, neural networks, or fuzzy logic) improve bots?

Statistics are in fact heavily used in the ALICE server, but not in the way
you might think. ALICE uses 'Zipf Analysis' to plot the rank-frequency of
the activated categories and to reveal inputs from the log file that don't
already have specific replies, so the botmaster can focus on answering
questions people actually ask (the "Quick Targets" function).

Other bot languages, notably the one used for Julia, make heavy use of
"fuzzy" or "weighted" rules. We see their problem as this: the botmaster
already has enough to worry about without having to make up "magic
numbers" for every rule. Once you get up 10,000 categories (like ALICE)
you don't want to think about more parameters than necessary. Bot
languages with fuzzy matching rules tend to have scaling problems.

Finally, the bot replies are not as deterministic as you might think, even
without weights. Some answers rely on <random> to select one of several
possible replies. Other replies generated by unforseen user input also
create "spontaneous" outputs that the botmaster doesn't anticipate.

- Can I have a private conversation with ALICE?

The ALICE server logs and records all conversations. Even the ALICE
Applet tries to transmit conversation logs back to the originating server.
You can have a private conversation with ALICE, however, if you download
Program B to your own computer and run it there. Running on your machine,
the server stores all the conversations locally.

II. Download and Run

- How do I install ALICE?

If you purchased a commercial version of ALICE on CD ROM or
over the web, installation should be very easy. These versions
usually have their own self-extracting and install software.
You can install the ALICE program with just a mouse click and
activate it with a desktop icon.

If you bought a commercial version of ALICE with a self-installer,
you can skip this section and go on to "Creating Content".

- What is the difference between B and C?

AIML is a platform-independent, language-independent specification
for creating chat robots like ALICE. The original AIML interpreter
ran in SETL. The next one developed was program B, the Java program
which is the subject of this document. Most recently new threads
of C/C++ development have led to "program C", actually a collection
of C/C++ programs and applications including Cgi-ALICE, IRC-ALICE and
WinALICE. See the web sites and for more details.

Program B remains the most stable, general purpose chat robot
program in the AIML family. This Java implementation has been
subject to intense peer review over a period of years, evolving
into a remarkably bug-free, efficient and readable piece of

- How do I download program B?

Create a Directory (or Folder) on your machine to download
the file. When you click on "" the browser
should ask you where you want to save the file. Select the
directory you created and save to that folder.

Once you've downloaded, You can use "unzip" to extract the files.
If you don't have this unzip command on your machine, you can get
a free one from Winzip ( to unzip the "" file.

If you want to get into the Java source code, you need a
Java 1.17 (or higher) development kit release.
Go to for a free one. The program source code
and all associated files are stored in the single "zip" file
called To extract the files use the command
"unzip" (assuming you have "unzip" on your machine).

- How do I run program B?

The file creates two subdirectories: /java and /bots. First
change directory (cd) to the /java subdirectory.

Use the command "java B" to start the program. On some Windows
machines the Java runtime engine is started with the command
"jview" instead of "java". If "jview B" does not work, try
"jview Bawt".

Run program B and notice that the program creates an Edit View
text window. By default, program B loads the chat robot ALICE
(stored in B.aiml).

- What does "Send" do?

Type a text string like "hello" into the Text Area
(Edit View) and press the "Send" button. Notice that program B
replaces the text in the Edit View with a reply from the robot.

- What does "Clear" do?

To enter another robot query, clear the screen with the "Clear"
button. Enter a new String like "How are you?" and press "Say."

"Send" and "Clear" provide a simple way to communicate with the
chat bot through the Edit View. Try cutting and pasting a paragraph,
such as an e-mail message, into the Edit View and press "Send".
See how the robot would reply to your multiline message.

- What is program Bawt?

Significant demand for a version of ALICE compatible with
pre- Java 2 (formerly known as Java 1.2) prompted the
development of "", an open source java program
for chat robot development that works with older versions of
Java, and AWT. Originally program B relied on
Java 2 and Swing, but program Bawt needs only Java 1.1 and AWT.
Swing is a newer GUI package that subsumes the earlier Java
Abstract Windows Toolkit (AWT).

At present class B merely extends class Bawt. Swing not

- Does program B run under Windows?

Yes. You need the Java Runtime Environment (JRE) so you can run the
"java" command from the DOS prompt. Try opening a DOS window
and type "java".

Microsoft often includes a JRE called "jview" rather than
"java". Try opening a DOS window and type "jview". On Windows 98
the JRE is usually located in c:\windows\jview.exe.

- Does program B run on a Mac?

Yes. Download the file and save it in a new folder, called
for example "Alice Program-B".

Instead of the "winzip" or "unzip" utility use "Aladdin StuffIt Expander."
The newer version will unzip most MAC formats as well as .ZIP files. You can
download this at "" by searching for it by name. You can
also select the option that allows it to search only for Mac programs.
Download that and install it, it should do the trick.

Apple makes its own Java Runtime Environment for the Mac called
MRJ 2.2. You can download it from

To compile the Java code for Alice on a Mac:

Download the current zip file for the Alice's Program-B from the Alice site.

Unzip Program-B and keep it in a folder called "B" on your startup drive and
not on the desktop.

Download MRJ SDK 2.2 for Java from the Apple site.

Unstuff MRJ SDK 2.2 and put resulting files into a folder called "MRJSDK".

Open :MRJSDK:Tools:Application Builders:JBindary and find the icon for the
JBindary application.

Open the folder "B" and drag the icon "B.class" out of the folder onto the
JBindary icon.

JBindary will display a dialog screen showing the class name "B". Click the
"Save Settings" button.

After clicking the "Save Settings" button, JBindary will display a dialog box
for saving the new application file. Name the file "A.L.I.C.E." or anything
you wish.

Be sure the "Save As Application" box is checked and the folder to save in is
the "B" folder.

Click the "Save" button to save the application.

- Does program B run under Linux?

Yes. You need the JRE, which often comes bundled with Linux
(e.g. the kaffee JRE with Red Hat Linux) or you can download one
from You also need X-windows to run the GUI.
Open a shell under X windows and use the command "java B".

We also recommend the IBM release of their Java 1.1.8 Java Development
Kit (JDK) and JRE for Linux. It is solid, efficient and very fast.
You can download it free at:

- Does program B run under XYZ?

Yes if XYZ runs has a Java Runtime Environment 1.17 or higher.

- How much memory do I need to run program B?

The source code compresses to as little as half a megabyte, including
all the AIML files for nearly 16,000 categories. You may have downloaded
a file of only around 500K. Plan to use a minimum 10 MB of hard disk space
for the download directory. The hard disk requirements include not
only the source code and Java class files, but also the dialogue files
and other temporary files created by the robot.

The RAM requirements vary depending on the size of your robot.
To run the fully loaded ALICE chat robot with 16,000 categories
you will need 64MB of memory. To do this and anything else at
the same time on your system we recommend a minimum of 96MB.
With less memory you can load a smaller robot. See the question
below "What is <load filename="X"/>?"

- How do I install ALICE on Windows?

Download program B at

Install program B in a file folder named "B".

Download the java development kit - jdk1.2.2 -

This is a large file - 20MB. If you have a slow modem it will take
a long time. Download the full single file as windows 95 will not
concatenate the separate pieces. Install the jdk1.2 in a folder
named "jdk1.2.2". Read the installation instructions.
Download the separate docs file - 17MB. Install in the jdk1.2 folder.

Program B is a java application and must be run in DOS.

Go to Start, click Programs, click MS-DOS Prompt.

At C:\> prompt type in,
cd B

You will then get - C:\B> - This is now pointing to your source directory.
(Please note that if you have installed program B to a different
drive than C substitute that drive letter - also you should have
installed the jdk1.2.2 in the same drive as program B).
At C:\B> type jdk1.2.2\bin\java B and hit enter (the idea is, you first
point to your source file and then to the jdk folder which will
run your program and then to the executable file which in this case
is java B.

What it should look like is this -
C:\B>jdk1.2.2\bin\java B

After hitting enter you should get the botmaster screen. You can
play around with it by yourself on your machine.

You can also use the applet in DOS. To do so type as follows:
C:\B>jdk1.2.2\bin\appletviewer index.html
This will try to connect you to the main server at
so have your browser fired up. Keep in mind that you will be
talking to the alicebot at that site, however, and not to the
program on your machine.

- What do you mean by the command "java B"?

This does not mean you mean click on an icon. If you are using Windows,
you must use a DOS window to run a Java program. Find the MS-DOS item
on your start menu or desktop and open up a DOS window. In that window, use
the DOS commands CD (change directory) to move to the "B" directory.
Then type "java B" to run the program.

If you are using windows, then you can create a desktop icon
as a "shortcut" to a batch file. Create a batch file called
"launch.bat" in the program B directory. The file contains only
one line with the text "java B". There is an AIML icon file
included with program B called "aiml.ico". You can use this
file to add an icon to your desktop.

- I tried running "java B" and I got a "bad command or file name".

You are using a Windows/DOS setup. If "jview B" does not work either,
you may need to install Java on your computer. Go to
and pick the one for your computer (Windows 95/98 or NT).

If it still says "bad command" then possibly there is a problem with
the CLASSPATH variable in AUTOEXEC.BAT. Make sure it is set to
something like
(The single "." means the current working directory)
and make sure the PATH is set to include the java home directory:
SET PATH=c:\JDK1.2\bin;%PATH%

- How do I uninstall ALICE from my system?

If you installed ALICE on Windows with a commercial installer like
InstallShield Java Edition, then go to the start menu and
select "Control Panel". Click on the control panel item called
"Add/Remove Programs". Select ALICE from the list of installed
software and choose "Uninstall".

All the files of ALICE are stored in one directory on your computer
(or folder) usually called "B" but maybe something else depending
on the name you chose when you downloaded ALICE. In any case,
ALICE will not change or damage any other files on your system.
To remove ALICE from your computer, simply remove this folder.
Delete it, or drag it to your trash bin and select "Empty trash"
(or "Empty Recycle Bin").

If you cannot find the folder where ALICE resides, use the Finder
to locate the file called "B.aiml" on your file system. The "B.aiml"
file is in the same directory as all the ALICE files. If this file does
not exist, then ALICE is probably not installed on your computer.

Because ALICE is a platform-independent Java application, it does
not rely on the Windows Registry or other Windows-specific features.
You can assume ALICE will leave your MS Windows Registry and
other Windows system files untouched.

Conceivably if ALICE has run for a long time on your computer, and
you deliberately used the "Save Options" menu item to change the
name or location of her files to something other than the default values,
then there is a slight chance that there could be a few ALICE
files scattered around your disk. Please refer to the DISCLAIMER
at the beginning of DON'T READ ME.

- Can I create a language-specific installtion?

Yes. The file "language.txt" controls the language of the
buttons and menus in the ALICE GUI. If the file is missing,
the program uses English names by default. To see an
example of a language-specific installation, copy the
file "Germanlanguage.txt" to "language.txt" and start
program B.

III. Creating Content

- How does the Personality Wizard work?

The simplest way to alter the content of the basic ALICE
robot personality is to run the Personality Wizard on
the "Options" menu (or in the Kid interface).
This wizard asks the botmaster a series
of questions to set the values of a set of robot
personality tags including its name, gender, preferences
and replies to very common questions.

The Personality Wizard does not create any new AIML
categories. The replies set the value of global tags
like <location/> and <favorite_movie/> that might be
used in many categories throughout the AIML knowledge
base. The basic set of Wizard questions are collected
in the file Personality.aiml.

Hint: If you plan to use the Applet, avoid the double-quote (")
character in the Personality Wizard.

- Can I change the name of the robot?

The AIML tag <name/> inserts the name of the Bot wherever it appears.
The default robot name is "ALICE" but you can change it in the
"Options menu". Select "Show Options" and replace "ALICE" with the
name of your bot, and then do "Save Options". Depending on your
state, you may need to restart program B.

- How can I customize my robot?

AIML provides several tags useful to quickly clone
a chat robot from ALICE with a distinct "personality":

<gender/> the robot's gender
<location/> the robot's location
<birthday/> the robot's birthday
<botmaster/> the botmaster's name

Together with the previously discussed <name/>, these
tags allow you to quickly create a clone from the ALICE
Brain with a separate identity from ALICE.

All the personality tag values can be modifed through
the Personality Wizard. The tag values can also be
changed with the Options Menu in program B. Use "Show Options"
and "Save Options" to customize your chat robot.

To test the new features, we created a male robot named
Brute (because "all men are brutes") born on August 18, 1999.

- How do I know what categories to add?

After you collect some dialogue, run "Classify" and "Quick Targets".
This will tell you the most frequently asked patterns that do not
already have specific responses. The "Target" functions display new
categories with proposed patterns and template fields filled with
the name of another category. Delete the template information and fill
in a new response. You can also edit the pattern to simplify it or
generalize it with a "*" operator.

- What does "Classify" do?

The key to chat robot development is log file analysis. The program
stores client dialogues in a file called "dialog.txt" (unless you
change this default name). The "Classify" button activates a routine
that scans the dialogue file and reports how many times each
category is activated. The processing may take several minutes,
depending on the size and range of the dialogue file chosen. The
result appears as a table in the Edit View window. The program
displays the categories sorted by activation count.

The format of each output line is:

P% (Q%) T PATTERN = N1 W1 + N2 W2 + ...


P = Percent of inputs classified in this category
Q = Cumulative percent up to this category
T = Total count of inputs activating this category
Ni = number of times input Wi detected (blank if Ni = 1)
Wi = normalized input pattern activating this category

- What does "Quick Targets" do?

After running Classify, the Quick Targets button displays a set of
new AIML categories for editing. The program uses statistics to
find new category candidates. These categories are displayed as

<pattern> NEW PATTERN </pattern> <template> OLD PATTERN </template>

where OLD PATTERN is the pattern from the original category and
NEW PATTERN is the proposed new input pattern.

The botmaster may choose to either delete or edit the new category.
If the new category is not desired, delete it by selecting the
category from the text area and "cut" the text with the "delete"

If the new category appears useful, edit the OLD PATTERN string to
create a new reply. Optionally, the NEW PATTERN may also be edited,
depending on how specific a pattern the botmaster desires.

When finished editing the Target categories, go to the "Botmaster"
menu and select "Add AIML". The "Add AIML" menu item will read the
text displayed in the Edit View and parse it into new AIML categories.
The botmaster may then save the updated robot with the "File/Save Robot"
or "File/Save Robot As" menu items.

- What does "More Targets" do?

If you don't see enough good targets with "Quick Targets", hit
"More Targets."

- What does the File menu do?

Save and load text files (transfer contents to/from text area);

Save and load robot (AIML) files.
1. By default, AIML files use the .aiml file extension.
2. The default robot file is called "B.aiml"
3. By default the robot files reside in the same directory as
program B
4. Robot files begin and end with the tags <alice> and </alice>
5. "Save Robot" overwrites the default robot file (see 2).
6. "Save Robot As" can be used to copy a robot.

Exit - exit the program

- What does the Edit menu do?

Paste contents of clipboard into the program B text area.

- What does the Options menu do?

Display and save chat robot options.
Use start and end index to select a range of lines
from the dialog file.

Toggle Beep - Make a sound when a remote client connects.

- What is the Botmaster menu?

The Botmaster menu contains all the tools to help develop chat robots.

Classify - same as Classify button

Default Targets - display targets obtained from
the Default ('*') category,
in a format suitable for
quick conversion to new AIML.

Recursive Targets - display targets from "recursive" categories,
i.e. categories with a template containing
the AIML <sr/> or <srai/> functions.

Autochat - The robot chats with herself; sometimes helpful
in detecting conversation "loops".

Add AIML - Clear the screen and type a line of AIML. Selecting
"Add AIML" adds this new category to the chatbot. You can
test the bot with "Send" and "Classify", then save it with
"File/Save Robot".

In general you can add any number of new AIML categories
to the bot with "Add AIML."

- What does "Help" do?

The "Help" button displays a random FAQ question that ALICE
knows the answer to. You can see the answer by pressing the
"Send" button.

The Help menu provides the same function as the Help button
under the selection "Random Help Question." Select a random
Help question and obtain the reply with the "Send" button.

The Help menu also contains an item to Show All Help Questions.
This command lists all the FAQ questions the robot knows. You can
select one question by deleting the others. Obtain the
answer with the "Send" button.

The menu item "Ask Help Question" is the same as "Send". This
item asks the robot the Help question(s), and displays the reply.

The Help menu displays the entire FAQ with the "Don't Read Me"
selection. Finally, the "GNU Public License" menu items displays
the open source software license for program B.

- What is on the Help menu?

Random Help - Same as "Help" button.

Show Help Questions - Displays a list of all FAQ questions. Select
one by deleting all the others. Obtain the answer with "Send."

Don't Read Me - Display the text of this document.

GNU Public License - Display the software license.

- Do I have to use the GUI to enter AIML content?

No. You can create a new AIML file with any text editor
and add that content to an existing robot with the <load> tag.

Also, you can edit AIML categories in any text file and use
"Load Text File" and "Add Aiml" to add the content.
You can also save the output of "Targets" to a file,
edit that file, and then reload and "Add Aiml".

Finally, you can edit the robot source file files directly.
(By default the robot source file is called "B.aiml").
Use a text editor, like emacs, notepad, or a word processor
in text mode, to modify the content of the AIML files.

- What are 7 steps to creating content?

1. Run program B (ALICE Botmaster)

2. Under "Options", select "Show Options".
Find the item called "AnalysisFile=" and
change the value to the name of the dialogue
file you want to analyze. The default file
name is the same as the default log file
name, "dialog.txt".

3. Press the "Classify" button. Wait
several minutes while the program processes
the data from your log file. When finished
it will display a "brain activation" table
showing the patterns that activated each
category. (You can use "File/Save As Text File"
to save this table to a file, if you want).

4. Now press the "Quick Targets" button.
You will see a set of new categories created
by the program. These are categories with
patterns that have no specific response in the
robot brain. With these categories you have
3 choices (A, B or C):

(A) Delete the category. Many of the suggested
categories are just nonsense or garbage inputs.
Use your cursor and left mouse button to select
the categories for deletion.
The "delete" key will cut them.

(B) Edit a new template. The information you
see displayed in the <template> tags is actually
the pattern of the default category into which
this input was classified. For example you may see:

<pattern>WHO IS 007</pattern><template>WHO IS *</template>

This tells us that the robot classified the client "WHO IS 007"
as "WHO IS *". Use the cursor and left mouse button
to cut the "WHO IS *", and replace it with a new template
of your own design:

<pattern>WHO IS 007</pattern>
<template><set_he>007</set_he> is James Bond, the
famous fictional spy from the novels of Ian Fleming.

(C) Edit a new pattern. Many of the patterns
suggested by "Quick Targets" and "More Targets" are
too specific, but with a little practise you
can easily see how to generalize these suggestions
with the "*" wild-card.

For example you may see one like this:

<pattern>WHO BOMBED PEARL HARBOR</pattern>
<template>WHO *</template>

The original response was based on "WHO *", which
is too general for this topic. But the odds
are small of anyone else using this exact pattern
WHO BOMBED PEARL HARBOR when asking about the
same topic. Think about the alternative ways
of expressing the same question:
"Who attacked Pearl Harbor?", "Who invaded Pearl
Harbor?", "Who through deceit and subterfuge
carried out an unscrupulous and unprovoked suprise
attack on American forces at Pearl Harbor?"
You can cover all of these inputs by generalizing
the input pattern with the wild-card "*",
which matches any word or sequence of words:

<pattern>WHO * PERAL HARBOR</pattern>
<template>The Japanase
attacked Pearl Harbor on December 7, 1941,
"A day that will live in infamy" (FDR).
<A href="">...

Remember, the AIML pattern language allows
at most one wild-card "*" per pattern.

Of course, with choice (C) you have to
edit the template as well as the pattern.

5. When finished with editing the suggested categories,
use "Botmaster - Add AIML" to add the new AIML content.
If you made any syntax errors, you can fix them
and repeat the "Add AIML" as many times as needed.
Be sure to do a "File - Save Robot" at this point
also to back up your changes. This will save all of
your new categories in the root robot file

6. Use "More Targets" to find more new categories
until the new suggestions are fruitless. Then, go
back and start with "Classify" again (step [3]).

7. The responses you create should be a combination
of a "conversational" response like "He is James
Bond, the famous spy" and also provide some HTML
hyperlinks where appropriate.

- How can I merge two chat robots together?

There are two ways to merge robots together. First, you can
use the File menu option "merge" to directly load the contents
of another bot file. You may see a lot of "duplicate key
discarded" warnings but these can be ignored because the program
is simply eliminating overlapping content.

Another method is to use the <load filename=X/> tag.
Suppose you load two or more files with the load tag,
and those files contain redundant duplicate keys.
Which categories get the priority? The answer is: it depends
on the order of the <load> tags used to load the AIML files.
If your B.aiml contains:
<load filename="Brain.aiml"/>
<load filename="German.aiml"/>
then the categories from "Brain" have priority, and duplicates
in "German" are discarded. If the order is the opposite, German
categories have priority and Brain's duplicates are discarded.

- What if I don't want to discard duplicate categories?

Using the global parameter MergePolicy, you can choose
to either "Merge" or "Discard" templates with duplicate keys.
If you choose the "Merge" option then the program applies a
heuristic to try to merge the two responses together with
a "<random>" tag. The results of this operation may be
unpredictable, so the program logs all duplicates in a file
called "duplicates.txt".

The heuristic merge works as follows: Suppose X and Y are the two
templates to merge into a new template Z. Let X be the new template
and Y the existing one. Assume that X and Y are either <random>
lists or "atomic", in the sense that they contain no <random> tags.
If X and Y are both "atomic" then Z = <random><li>X</li><li>Y</li></random>.
If Y is a <random> list atomic then the program checks to see if X is
already a member of that list, to avoid duplicate list items. Otherwise,
Z = the <random> list from Y with X inserted.

- How can I create a new robot personality?

There is a lot of flexibility in robot personality design with AIML.
You can add to any of the existing AIML files, modify or delete them,
create your own, or use the GUI tools to analyze the log files
and create new categories. One simple method is to create your own
Specialty.aiml file so that you can always get the latest copies
of the ALICE files. Load your Specialty.aiml first in the root
AIML file (usually B.aiml) so that its categories have priority over ALICE's.

- What are all the options for program B?

There are robot personality options, animated agent options,
log file and analysis options, and options for the web server
and for the applet. Most of the time you won't need to change
many of these values. For completeness, the entire set
breaks down into:

Robot options:

Sign - Astrological sign
Wear - clothing and apparel
ForFun - What the robot does for fun
BotFile - Root file of robot personality
BotName - Robot name
Friends - The robot's friends
LookLike - The robot appearance
Question - A random question
TalkAbout - favorite subjects
KindMusic - Favorite kind of music
BoyFriend - Does the robot have a boyfriend?
BotMaster - Robot author
BotGender - male, female or custom
GirlFriend - Does the robot have a girlfriend?
BotLocation - Robot location
BotBirthday - Robot activation date
FavoriteBook - Robot's favorite book
FavoriteFood - Robot's favorite food
FavoriteSong - Robot's favorite song
FavoriteBand - Robot's favorite band
FavoriteMovie - Robot's favorite movie
FavoriteColor - Robot's favorite color
BotBirthplace - Robot's birthplace

MS Agent options:

Animagent - true or false for activating MS Agent VB scripting
ACFURL - file or URL location of MS Agent software

Log/Analysis options:

AnalysisFile - file selected for log file analysis
LogFile - file for recording robot dialogues
ClientLineContains - a pattern identifying input lines in logfiles
RobotLineStarts - a pattern identifying robot lines in logfiles
StartLine - starting line for analysis
EndLine - ending line for log file analysis

Applet options:

AppletHost - DNS name or IP address of applet's server.
CodeBase - URL or directory of applet code.

Web server options:

ClerkTimeout - Web server option to retire waiting clerks
BrainSize - a threshold number of categories to display "loading"
Advertize - a boolean parameter to optionally display ad
Beep - Web server option to beep on client connections


Version - read only version number
TempFile - scratch file for temporary data
MergePolicy - 'Merge' or 'Discard' depending on how you
want to handle duplicate key categories.

All of the options reside in the globals.txt file. Running
program B, choose "Options/Show Options" to see the
contents of the file.

- Why is the format of the options (globals.txt) so strange?

Depending on your system, you may see a globals.txt file that looks like:

Botmaster=Dr. Richard S. Wallace
Birthday=November 23, 1995
# ... and so on

The global values seem to be stored in a random order.
This is not a bug. The Globals class uses the Java methods
Properties.load() and to save the globals
to a file. You can also use # and ! to add comments to the file.

The Properties class uses a hash table representation, so does
not preserve the order of the global variables. The program
displays and saves the global options in an arbitrary order.

IV. Web server interface

- How does the web server work?

By default the web server starts on port 2001. This means you can
access the web server through the URL http://localhost:2001 on
your own machine. Find out your IP address or DNS name and tell
your friends to connect to "".
(One way to find out your IP address is by running "netstat -n"
to view all your open TCP/IP connections).

- How can I get a "permanent" DNS name?

You can buy a fixed IP address from an ISP provider, but suppose
you want run a chat robot (or other server) from your home over an
ordinary ISP connection? Or suppose you want to carry it around on
your notebook PC, and plug it in anywhere in the world?

One solution is a dynamic IP registry service by Dynip (
They offer a service that allows you to register your computer
with their server so that you always receive the same DNS name,
for example Every time you connect to your
ISP, dynIP automatically associates your dynamic IP address with
your permanent DNS name.

- How can I keep my computer connected all the time?

Running a web server from home can be frustrating if your ISP
automatically detects periods of "inactivity" or hangs up your
connected after a fixed interval like 12 hours. Check out the
Rascal program from Basta computing ( which runs
as a watchdog to keep your Windows machine connected 24/7.

Another alternative is to use the program B applet, called

A third alternative is the ALICE Servlet. Some ISPs will
allow you to install a Servlet on their sever.

- Does the web server have to run on port 2001?

You can change the default web server port number in the "Option" Menu.

- Does program B serve HTML files?

Yes. Program B is a "faux" web server that can serve a number of file
types just like an ordinary server. Certain file names such as
"HOME.html", "header.html", and "trailer.html" are reserved by
program B, but you can create new HTML files and serve them with B.

Although program B can also serve image files and other large binary
files, we recommend creating chat robot web pages with links to images
served by other web servers or machines. Reserve your chat robot server
for the robot chat, use ordinary web servers for images and other large

- What files are needed to run the program B web server?

The program B directory must contain the HTML files header.html,
trailer.html, loading.html and HOME.html. You can customize these files for
your bot, but take care with "header" and "trailer" because
program B uses these files to construct an HTML reply
(by inserting the robot reply and the text form between the
"header" and the "trailer"). Use "header" and "trailer" to
customize the robot with your own logo and links.

Program B needs at least one AIML file, usually called B.aiml
by default. The AIML file may contain <load> tags that recursively
load other AIML files; these must also be present.

The program also requires the file "globals.txt"
which it reads at start up.

The files "language.txt" and "predicates.txt" are option.
"language.txt" controls the language of the buttons and
menu items in the program B GUI. The file "predicates.txt"
defines any custom predicates.

Program B also reads the files "gnu.txt" (the GNU Public License)
and "dont.txt" (this file).

- Can I test the robot offline on my desktop?

Yes. You can run the program B server and connect to it with
a browser, even if your desktop computer is offline.

When working offline, it often helps to change the Internet
settings (in IE or Netscape) to "local area network".
Then your machine becomes a one-computer network. You should
be able to use IE to connect to program B with http://localhost:2001.

- Can I run program B in the background on a NT Server?

Yes. Set up your PC / Server to run Alice B as you normal. (Download the Java
Developers Kit, etc.)

Create a Batch file, in folder B containing only this text.

'jview bterm'

Create a task in the Task Schedule Wizard to run the batch file. (Ensure the
task starts in drive:\path\B'

Give the Task Schedule an appropriate Logon and password for the Server or

Right-click, select Run now, and log on and off as you like.

- How can I run ALICE on a Mac offline?

First open folder B and change all the IP's in the files two files Blet.amil
and Bletemplate.aiml to

Also in folder B add the following three lines at the end of the file

<H1>Welcome to A. L. I. C. E.</H1>
<IMG SRC="ALICEBot.jpg">

Also in folder B change the following three parameters in the file
globals.txt to the values shown:


Also in the globals.txt file remove the line:

Next open your TCP/IP control panel and set up a new configuration named
Alice perhaps.

In the TCP/IP control panel select connect via: Ethernet built-in if you have
it if not you may have to experiment.

Then select Configure Manually.

And finally set the IP Address: to as well as the Name server addr.

Double click the newly saved A.L.I.C.E. application to bring up the botmaster
panel and Java Console.

As A.L.I.C.E. loads, read the information messages scrolling by in the Java
Console and record the port number that the web server (started by A.L.I.C.E.)
is listening on, probably 2001.

Start up your preferred browser.

Leave browser in online mode.

Enter (i.e. the localhost's IP)


Enter http://localhost:2001 (I've not always been successful with this one)

Hit return to send the IP.

The A.L.I.C.E. transaction page should appear in your browser's window and
you can talk to Alice.

- How can I run the ALICE web server on a Mac?

To run Alice online:

Connect your Mac to a network.

Double click the newly saved A.L.I.C.E. application to bring up the botmaster
panel and Java Console.

As A.L.I.C.E. loads, read the information messages scrolling by in the Java
Console and record the port number that the web server (started by A.L.I.C.E.)
is listening on, probably 2001.

Start up your preferred browser.

Get your IP from the TCP/IP control panel.

Enter your IP followed by a colon and then the port number read from the Java
Console, e.g. http://nn.nnn.nn.nnn:2001


Enter (i.e. the localhost's IP)


Enter http://localhost:2001

Hit return to send the IP.

The A.L.I.C.E. transaction page should appear in your browser's window and
you can talk to Alice.

- How can I use the MS Agent Interface?

Select the menu item Options/Toggle MS Agent. This sets the
output HTML to a format that includes commands to run MS Agent.

The client may activate the agent if she receives a template
with the <set_animagent/> tag. The free ALICE download includes
a couple of example categories using this tag. Try asking
ALICE, "Can you speak?". In another demo ALICE imitates
the famous fictional AI HAL from 2001: A Space Odyssey.

Client: Tell me about yourself
Robot: I am an artificial linguistic entity. I was created
by Dr. Richard S. Wallace at Bethlehem, Pennsylvania,
on November 23, 1995. He taught me to sing a song.
Would you like me to sing it for you?.
Client: yes
Robot: Ahem. It's called, "Daisy." (Agent sings "Daisy")

The MS Agent VB script appears as embedded HTML in the client
reply. To verify the script, use the browser "View Page Source"
menu item.

On most newer browsers, the agent software will download
automatically after the script starts. The download may take
several minutes, depending on the speed of the connection.
Clients should be warned that the download is slow. Also,
the agent software download will display one or more licenses
in Dialog boxes. You may not want to accept the terms of the
MS agent software licenses.

- Can you help me debug the animated agent?

Look at the class The method vbscript_html(reply)
does nothing unless the global Animagent member is true. In that case,
the vbscript_html() method constructs a string from the reply that
includes an MS Agent VBScript embedded in the HTML reply.
This makes the browser load up the objects required for the agent.

The text reply just becomes part of the VBScript.
You may have to download and run the Robby the Robot
agent software and the text-to-speech synthesis software from
the MSDN homepage:

We wish other companies were producing agent animation API's
for free but this MS Agent seems to be about the only
thing out there now.

Join the ALICE and AIML mailing list at
to see how others are working with the animated agent software.

- Can I speak to the robot with voice input?

One simple experiment that works well as a demo
involves using IBM ViaVoice (tm) speech recognition
software on a Windows platform. At the same time,
run the ALICE program B web server and activate the
MS Agent interface. The ViaVoice software allows
you to dictate into an application called VoicePad,
but not directly into the browser. You have to
use "cut" and "paste" to move your speech inputs
into the browser form for ALICE. But the net effect
is a somewhat slow voice-in voice-out conversation
with ALICE.

The ViaVoice software seems to work well with ALICE
after some training. We trained it with the file
"patterns.txt" created with the "List Patterns" command.

- How does ALICE keep track of conversations?

Originally ALICE used IP addresses to keep track of clients.
Assuming that everyone chatting with ALICE has a fixed IP
address, at least for the duration of their conversation,
this technique works successfully. Each IP address is a key
into a hashtable (or database) that stores the client's
dialogue, name, and values of pronouns and other AIML values.

Unfortunately, many clients have "dynamic IP addressing" enforced
by their ISP provider. AOL and MS WebTV are two notorious examples:
each successive client transaction appears to come from a different
host. For this reason, program B uses a form of "virtual IP"
addressing to track dialogues.

The form in index.html (and the ALICE home page) contains a
tag that creates a "hidden" parameter called "virtual" with
an initial value of "none." The server assigns a unique name
to the value of "virtual", which then becomes a hidden variable
in the client's HTML form. Each successive client transaction
contains this virtual IP address; the server uses it as a key
to index the conversation.

- Can the virtual IP be the real IP?

Actually that would be the default case, when the client chats from
the same fixed IP address. The only time the virtual ip differs from
the real one is when the client is behind a dynamic firewall, like
WebTV or AOL customers.

- Can I run the web server as a daemon process?

Yes. There is a class file called in the
program B distribution. Bterm runs the web server
as a console application, with no GUI. You can
redirect the output of program Bterm to a log file
and start the process in the background with
"java Bterm > B.log &" (assuming a Unix shell).

- How does ALICE remember clients between sessions?

The persistence of memory in ALICE is inherited from
the Java Properties class. The program B class Classifier
saves the client name, age, location and other properties
in a set of Properties lists. These Properties inherit
the Java load and store methods. Program B uses the load
and store methods to save the client properties in a set of
files with names ip_name.txt, ip_age.txt, ip_location.txt
and so on. If these files become too large or bothersome,
there is no harm deleting or editing them, or moving them
to another directory.

The Applet requires no memory of the client properties, because
the applet has only the one client, and in any case remains in
memory (at least for the lifetime of the client's browser cache).

V. Applet Interface

- How does the Applet work?

Program B supports the creation of both server-side and client-side
chat robots. The server runs as a thread in program B. The
client-side version is supported by an applet called

The Applet runs ALICE in a web browser, or with
the Java tool appletviewer. The file "index.html" contains an
example of the HTML Applet tag syntax needed to start
the Applet. The command "appletviewer index.html" will start the

You also have to create the file "index.html" and change the
default value of the parameters "codebase" and
"applethost" serve the Applet from your location.

- How does the Applet differ from the application?

The Applet runs on the client's computer; the server runs
on your host machine. The applet has fewer privileges and
therefore a simpler user interface than the Application,
which uses menus and buttons to control server-side functions.
The Applet may reside on any web server, such as one provided
with an ISP account, but the application requires a 24/7
connection to the Web.

Internally, the primary difference between the two programs
is that the Applet handles only one client conversation,
while the application processes multiple client connections
simultaneously. The Applet also suppresses all HTML (and any
other XML) from the client response.

- How do I create an Applet?

Go to the Options menu and select "Show Options." You need
to change the values of "AppletHost" and "CodeBase" to the
correct IP address and directory for your applet host.
Many people want to post the applet on their web site.
In that case, change the IP address "" to
the name or IP address of the web server. Change the
directory path "/B" in "CodeBase" to your directory on
the remote server. Save the changes with "Save Options."

Select "Create Applet" from the options menu to create
the "index.html" and "Blet.aiml" files needed to run
your applet. The program displays the contents of
"index.html" in your text area.

Use a file transfer utility like FTP to upload the
class files (or jar file--see "What files do I need to
run the Applet") to your web server.

- List twelve basic Applet tips for AIML users

1. Applets are notoriously hard to debug; you are not dumb.
2. An applet can work perfectly well in Appletviewer, but
then break in the browser, for any number of reasons.
3. Let's get the terminology straight: the applet resides on
an "originating host" but runs on a "target machine".
4. The browser is very picky because of the "security
sandbox"--the browser doesn't trust Applets so they can't
open files (and obey other restrictions) on the target machine.
5. The Applet MAY open a socket connection from the
target machine to the originating host.
6. When you are debugging the applet, the target machine
might be the same as the originating host (your computer).
7. When you post your applet to a remote web server,
that server becomes the originating host.
8. You can use ftp to transfer the Applet files to the
remote web server.
9. You must transfer ALL the applet's files
to the originating host.
10. You must change the program B values of "CodeBase"
and "AppletHost" (the originating host) to the name and
location of the files on the remote server.
11. Use "Create applet" to create the "index.html" and
"Blet.aiml" (make sure you have the latest release of
12. We recommend placing all the *.class files into
a single "Blet.jar" file (see DON'T READ ME).

- Can the AppletHost use a symbolic DNS name instead of an IP number?

The answer is yes, but the numeric IP address works on more machines
than a symbolic name. Applets are protected by a "security sandbox"
from interfering with local resources on your machine. One restriction
is that Applets may only open socket connections to the originating
host. When using a symbolic DNS name, the "sandbox" may not know that
two variations such as "Www.AliceBot.Org" and "" are
in fact the same server. The client might not be able to resolve
the DNS name, and the Applet will throw a security exception.

- What files do I need to run the Applet?

You only need the java *.class files and the *.aiml files
to run the ALICE Applet, no more files are necessary.
You can also put all the class files in a single jar
file like Blet.jar. The sample index.html provided with the ALICE
distribution uses this Blet.jar file.

Not all of the Java source files are involved in the Applet.
You can use the following command to compile all the Java source
files needed for the Applet:

javac \

Then, you can use zip (or jar) to collect the class files into
a single jar file:

zip -r Blet.jar *.class

The *.class will include all the class files you compiled.

The *.aiml files have to be on the same host that serves the Applet. An applet
can only open files on the server it originated from.

Don't forget to change the Applet host parameters in index.html, when
you upload the applet to an ISP.

- Does the Applet record dialogues?

The applet tries to log conversations on the originating server,
using a cgi-bin script called "Blog". If Blog exists then
it records the dialogues in a file called "dialog.txt" (or
another name chosen on the Options menu).

Actually the cgi-script need not actually exist, because the server
records the cgi-commands as errors in the access log.
The applet opens a URL connection to the its host, and
sends a log string that looks like an HTTP request, but the HTTP
server will log it as an error (with code 404). Later on you can
download the access_log and analyze it with program B.

See the code in for the method log(x) that
implements the URL connection.

- Can I analyze the dialogues collected by the Applet?

If the web server produces an access_log file, such
as /var/log/httpd/access_log, then the server records
Applet dialogue in the access_log file. You may use
ftp to download the access_log file to your machine;
then run program B to analyze it.

Go to the Options menu and find the value for "AnalysisFile".
The Classify function operates on the data in the AnalysisFile.
By default the AnalysisFile is the same as the LogFile (the
current server log file). But you can change the analysis
file to another name, such as /var/log/httpd/access_log or
just access_log.

- Can the applet record a dialog.txt file on the server?

No because the applet cannot write the file directly on the originating host.
If your server log file /var/log/httpd/access_log is too large; you
have a couple of choices:
1. If your ISP is a unix account, use telnet to log on to a shell account.
Use the command "grep Blog < access_log > dialog.txt" to create a smaller
file to download which contains just the lines recorded by the applet.
2. Create a CGI-BIN command called "/cgi-bin/Blog" that reads its
command-line argument and appends it to a file called "dialog.txt".
There ought to be a nice Perl script for this, or even a shell script.

- I am still having problems with the applet

If your applet is looking at Blet.aiml and your web space is at and your aiml files are in dirctory /alice/ then
your load statements in Blet.aiml would look similar to this:
<load url="">

If this is what you have, then open up the "Java Console" window
in your browser to get whatever debugging information is coming
out. The Java console will display any error messages or
exceptions caught by program B. Please report these
errors to the ALICE and AIML mailing list at

- Can you give me any help debugging the Applet?

Debugging applets can be tricky. The same suggestion
to set IE for "local area network" might help here too.
Also the browser caches class files, so it's difficult to
know if you are testing a "fresh" copy of the applet. The
program "appletviewer" that comes with Sun Java is better
for debugging applets. Use "appletviewer index.html".

The best thing to do is join the alicebot mailing list


- What is AIML?

The ALICE software implements AIML (Artificial Intelligence Markup
Language) a non-standard evolving markup language for creating chat robots.
The primary design feature of AIML is minimalism. Compared with
other chat robot languages, AIML is perhaps the simplest. The
pattern matching language is very simple, for example permitting
only one wild-card ('*') match character per pattern.

AIML is an XML language, implying that it obeys certain grammatical
meta-rules. The choice of XML syntax permits integration with
other tools such as XML editors. Another motivation for XML is
its familiar look and feel, especially to people with HTML experience.

An AIML chat robot begins and ends with the <alice> and
</alice> tags respectively.

- What is XML?

David Bacon pronounces it "Eggsmell". XML is the Extensible
Markup Language. Like many "standards" in computer science, XML
is a moving target. In the simplest terms, XML is just a generalized
version of HTML. Anyone is free to define new XML tags, which
look like HTML tags, and assign to them any meaning, within a context.
AIML is an example of using the XML standard to define a specialized
language for artificial intelligence.

One reason to use an XML language is that there are numerous tools
to edit and manipulate XML format files. Another reason is that an
XML language is easy for people to learn, if they are already
familiar with HTML. Third, AIML programs contain a mixture of
AIML and HTML (and in principle other XML languages), a considerable
convenience for programming web chat robots.

A good resource for information on XML is

- What is a category?

AIML consists of a list of statements called categories. Each
category contains an input pattern and a reply template.
The syntax of an AIML category is:

<pattern> PATTERN </pattern> <template> Template </template>


<pattern> PATTERN </pattern>
<that> THAT </that>
<template> Template </template>

The AIML category tags are case-sensitive. Each open tag has an
associated closing tag. This syntax obviously derives from XML.

- What is a pattern?

The pattern is the "stimulus" or "input" part of the category.

The pattern is an expression in a formal language that consists of
(1) Words of natural language in UPPER CASE.
(2) The symbol * which matches any sequence of one or more words.
(3) The symbol _ which is the same as * except that it comes
after Z in lexicographic order.
(4) The markup <name/> which is replaced at robot load time
with the name of the robot.

Note there is a difference between the patterns HELLO and HELLO *.
HELLO matches only identical one-word sentences ("Hello.")
and HELLO * matches any sentence of two or more words starting
with "Hello" ("Hello how are you?").

To simplify pattern description and matching, AIML patterns allow
only one "*" per pattern. In other words, "MY NAME IS *" is a
valid pattern, but "* AND *" is not.

- What is a template?

A template is the "response" or "output" part of an AIML category.

The template is the formula for constructing the reply. The simplest
template consists of plain, unmarked text. AIML provides markup
functions to tailor the replies for each individual input and client.
The markup function <getname/> for example inserts the client's name
into the reply.

The template may call the pattern matcher recursively using the
<sr/> and <srai> tags. Many templates are simple symbolic
reductions that map one sentence form to another, for example
"Do you know what X is?" transforms to "What is X" with the category

<pattern>DO YOU KNOW WHAT * IS</pattern>
<template><srai>WHAT IS <star/> </srai></template>

The template may also contain other embedded HTML and XML.
These embedded tags may cause the browser to play a sound,
show an image, or run an applet. There is considerable freedom
of expression in the construction of response templates. The
botmaster is encouraged to study the examples in ALICE, to and
experiment with new ideas.

- Can you give me a quick primer on AIML?

Given only the <pattern> and <template> tags, there are three
general types of categories: (a) atomic, (b) default, and (c) recursive.
Strictly speaking, the three types overlap, because "atomic"
and "default" refer to the <pattern> and "recursive" refers to
a property of the <template>.

a). "Atomic" categories are those with atomic patterns, i.e. the pattern
contains no wild card "*" or "_" symbol. Atomic categories are the
easiest, simplest categories to add in AIML.

<pattern>WHAT IS A CIRCLE</pattern>
<template><set_it>A cicle</set_it> is a the set of points equidistant
from a common point called the center.

b). The name "default category" derives from the fact that its pattern
has a wildcard "*" or "_". The ultimate default category is the
one with <pattern>*</pattern>, which matches any input. In the
ALICE distribution the ultimate default category resides in a file
called "Pickup.aiml". These default responses are often called
"pickup lines" because they generally consist of leading questions
designed to focus the client on known topics.

The more common default categories have patterns combining a few
words and a wild card. For example the category:

<pattern>I NEED HELP *</pattern>
<template>Can you ask for help in the form of a question?</template>

responds to a variety of inputs from "I need help debugging my program"
to "I need help with my marriage." Putting aside the philosophical
question of whether the robot really "understands" these inputs,
this category elucidates a coherent response from the client,
who at least has the impression of the robot understanding the
client's intention.

Default categories show that writing AIML is both an art and a
science. Writing good AIML responses is more like writing good
literature, perhaps drama, than like writing computer programs.

c). "Recursive" categories are those that "map" inputs to other
inputs, either to simplify the language or to identify synonymous

Many synonymous inputs have the same response. This is accomplished
with the recursive <srai> tag. Take for example the input "GOODBYE".
This input has dozens of synonyms: "BYE", "BYE BYE, "CYA", "GOOD BYE",
and so on. To map these inputs to the same output for GOODBYE we
use categories like:

<pattern>BYE BYE</pattern>

Simplification or reduction of complex input patterns is another
common application for recursive categories. In English the
question "What is X" could be asked many different ways:
"Do you know what X is?", "Tell me about X", "Describe X",
"What can you tell me about X?", and "X is what?" are just a few
examples. Usually we try to store knowledge in the most concise,
or common form. The <srai> function maps all these forms to
the base form:

<pattern>DO YOU KNOW WHAT * IS</pattern>
<template><srai>WHAT IS <star/></srai></template>

The <star/> tag substitutes the value matched by "*", before
the recursive call to <srai>. This category transforms
"Do you know what a circle is?" to "WHAT IS A CIRCLE",
and then finds the best match for the transformed input.

Another fairly common application of recursive categories is
what might be called "parsing", except that AIML doesn't really
parse natural language. A better term might be "partitioning" because
these AIML categories break down an input into two (or more) parts,
and then combine their responses back together.

If a sentence begins with "Hello..." it doesn't matter what comes
after the first word, in the sense that the robot can respond to
"Hello" and whatever is after "..." independently. "Hello my name
is Carl" and "Hello how are you" are quite different, but they show
how the input can be broken into two parts.

The category:

<pattern>HELLO *</pattern>
<template><srai>HELLO</srai> <sr/>

accomplishes the input partitioning by responding to "HELLO"
with <srai>HELLO</srai> and to whatever matches "*" with <sr/>.
The response is the result of the two partial responses
appended together.

- What is <that>?

The keyword "that" in ALICE refers to whatever the robot said before
a user input. Conceptually the choice of "that" comes from the
observation of the role of the word "that" in dialogue fragments like:

Robot: Today is yesterday.
Client: That makes no sense.

Robot: The answer is 3.14159
Client: That is cool.

In AIML the syntax <that>...</that> permits an optional "ThatPattern"
to match the robot's "that" expression. A common example using "that"
is any yes-no question:

<that> DO YOU LIKE MOVIES </that>
<template> What's your favorite movie? </template>

This category handles the user input "YES" and checks to see whether
the client is replying to the question "What's your favorite movie?".

One interesting application of "that" are the categories that
enable a robot to respond to "knock-knock" jokes:

<pattern>KNOCK KNOCK</pattern>
<template>Who's there?</template>

<that>WHO IS THERE</that>
<template><person/> Who?</template>

<that>* WHO</that>
<template>Ha ha very funny, <getname/></template>

Robot: Who's there?
Client: BANANA
Robot: banana Who?
Robot: Who's there?
Client: BANANA
Robot: banana Who?
Robot: Who's there?
Client: ORANGE
Robot: orange Who?
Robot: Ha ha very funny, Aol-person

- How do I use "that"?

The AIML tag <that> refers to the robot's previous
reply. There are two forms of the <that> tag:
a paired form <that>...</that> appearing in a
category, and an atomic form <that/> always appearing
in a template. Often we can use <that/> to find
an opportunity to create a category with <that></that>.

One of the default replies to the input "WHY" is
"<that/>"? Why? This default produces the following
dialogue fragment:

Robot: Do not ask me any more questions please.
Client: WHY
Robot: "Do not ask me any more questions please"? Why?

The botmaster notices the fragment and creates the
new AIML category:

<template>Because I would rather talk about you.</template>

Now the next client who asks "WHY" to the robot's
request will active the new <that> category:

Robot: Do not ask me any more questions please.
Client: WHY
Robot: Because I would rather talk about you.

This style of conversational analysis does not
presuppose that we know when the client will
say "WHY"; rather it looks backward to identify
cases where the "WHY" appeared following one
of the robot's statements. Having identified
the conversation point, the botmaster creates
the new category.

- What is <load filename="X"/>?

The template may contain a <load/> tag to recursively load an AIML
file. The semantics of a load are the same as a merge: categories
loaded first have priority; the server eliminates categories with
duplicate patterns.

The default robot file B.aiml contains the top-level load commands.
There are several ways to "comment out" a <load> tag in order
to test your system with a smaller robot. You can change the
line reading
<load filename="Brain.aiml"/>
<noload filename="Brain.aiml"/>
and the AIML parser will simply ignore the non-existent "noload"

- What happens to contractions and punctuation?

Program B has a class called Substituter that performs a number
of grammatical and syntactical substitutions on strings.
One task involves preprocessing sentences to remove ambiguous
punctuation to prepare the input for segmentation into individual
sentence phrases. Another task expands all contractions and
coverts all letters to upper case; this process is called

The Substituter class also performs some spelling correction.
(See also the question "What is <person/>?")

One justification for removing all punctuation from inputs
is the need to make ALICE compatible with speech input systems,
which of course do not detect punctuation (unless the speaker
utters the actual word for the punctuation mark -- "period").

- How are the patterns matched?

Program B stores the categories in alphabetical order by pattern.
When a client enters an input, the program scans the categories
in reverse order to find the best match. By comparing the
input with the patterns in reverse alphabetical order, the algorithm
ensures that the most specific pattern matches first. "Specific"
in this case has a formal defican talk with the robot before all the categories
are fully loaded. Given that the interlocutor is more likely to
say something that activates a more frequently activated category,
it makes sense to transmit these categories first. Storing the
*.aiml files in order of category activation achieves the desired effect.
The Applet loads the most frequent categories first, and continues
loading in the background while the conversation begins.

- Is there a way to use the GUI interface to add one category at a time?

Yes. Do a "clear". Type in one category:

<pattern>WHO IS JOHN</pattern>
<template>He is a really smart guy.</template>

Now do a "Add AIML". If you like the result, do a "Save Robot".

If your name is not John, try replacing JOHN with
your own name. Notice that the pattern is in all upper case.
This is called "normalized form". We store patterns this way
for efficiency. The template on the other hand consists of
mixed case.

You can also create a file of AIML, do a cut & paste, and then "Add AIML"
to add more categories. Editing the source file directly is of course also
useful. If you edit the source file, select "Load Robot" to load it.

Try creating a text file with the category:

<pattern>WHO IS JOHN WANG</pattern>
<li>He is a really smart guy.</li>
<li><set_he>John Wang</set_he> is a great father.</li>

Load the file into program B with the "File/Load Text File"
menu item. Then select "Add AIML" from the Botmaster menu.