A Tutorial for adding knowledge to your robot

Copyright by Doubly Aimless - September 16, 2002 - Rev. 5


You are reading a short tutorial describing how to create and add knowledge to your Robot. A successful Robot will appear human.   Your goal as the botmaster is simple: build content that induces the client to carry on conversations with your Robot as long as possible. Do this by creating a variety of potential answers to various questions, or re-directing a conversation to new topics that the client finds interesting - always with the goal of  continuing the interactions as long as possible.   Examples of such bots appear in the annual Loebner contest (http://www.loebner.net/Prizef/loebner-prize.html) and the forthcoming annual chatterbot beauty contest (http://www.international-lisp-conference.org/Competitions/Chatterbots/ILC02-chatterbots.html).

Pandorabots allows you to extend the knowledge of your bot via a programming language called AIML. The goal of this tutorial is to teach you the minimum of AIML necessary to make your robot "smarter" and better able to carry on a conversation.  After working through the tutorial you will also want to visit the site www.pandorabots.com and use the  tool - Pandorawriter - which automatically converts English text to a subset of AIML, and greatly eases the task of adding knowledge to your bot.

This Tutorial is a draft - and unfortunately has errors and omissions. Better versions will be forthcoming. Some of you will argue that it would have been better to postpone publication - yet the cry for some kind of documentation was just too much. Please accept my apologies for this draft's roughness.  

Please mail comments and problems to the attention of Dr. Doubly Aimless at  info@pandorabots.com. The first Discoverer of (for the first time) an error (reported by e-mail please) shall receive a commemorative check (suitable for framing) and a listing in ALICE Hall of Fame.   More details on the information in this tutorial can be found in the references listed at the end. In particular, the latest version of the AIML language contains many of the details omitted in this document.

The robots discussed in this document, and on www.pandorabots.com, are based on AIML and spring entirely from the work of Dr. Richard Wallace and the A.L.I.C.E. and AIML free software community based at http://www.alicebot.org/.

Some of you might find this metaphor helpful for visualizing how knowledge is laid out in your robot. Imagine a spider web - it has a center with spokes radiating outwards from the center. Your robot's knowledge is stored in a Knowledge Web, and like the spider, your robot darts out in response to some sort of tug it senses in the web. Understanding how to store knowledge is our first task. Because it is too hard to draw the whole web, in the examples that follow, only a portion of the web will be shown - so please use your imagination for the rest.

Starting at www.pandorabots.com, if you have not already done so, create an account and then follow the directions to create a new robot, name it Full (for full of knowledge) and be sure to check the radio button labeled: -Dr Wallace's A.L.I.C.E March 2002.

For Robots that interact using Japanese characters (and English characters) check the box annotated with: automatically discover spaces between words (suggested for Japanese).  (Spaces are automatically inserted between words written in Japanese when this option is checked).

Click on Create Bot, and on the next screen click on "build and run" to begin interactions with your robot.

Create a second robot, call it Empty (for empty of knowledge) checking the button labeled: -no initial content, the bot starts with no knowledge

(Footnote 0).

Let's start with the Robot named Full - which already was taught (by Dr. Richard Wallace) to answer the inquiry:
   Human: do you love me?
    Full: Yes I love everyone.


Look at Picture 1.

Picture1.0real.jpg (23953 bytes)

The robot knew in advance how to answer this question. How specifically did the Robot discover the answer? First the robot checked if its knowledge already contained the question "do you love me?" and second, finding it, had it been taught to respond with something meaningful.

 

Categories

The words in the sentence "do you love me?" can be visualized by a series of lines (or links) and nodes, in the knowledge web. The links are labeled by the words (and you can think of the nodes as representing the spaces between the words) and form a chain starting from the center of the web and moving outwards. Finding the question in the Knowledge Web, the robot replies with the information we taught it (residing in a Response Template - and referred to as the Template). So, in other words, the specific question "do you love me" can be visualized as a kind of path - beginning at the center of the Knowledge Web and built up by a series of links and nodes, and that finally terminates in a Response Template. The specific path through the Knowledge Web along with the (Response) Template is called a Category. When you teach the robot to respond with: "yes, but only when you are good" you only change the Response Template.

More about Categories

Let's start over with a robot that has no knowledge. You should have already created and named it Empty - and if not, go ahead and build it now. Initially, Picture 1.1 shows Empty's very simple Knowledge Web. One Category is shown and notice the Response Template contains the one sentence "I have no answer for that". You will also notice *, <THAT> and <TOPIC> labeling the links between the nodes. The labels *, <THAT> and <TOPIC> are special optional variants offering enhancements to Categories. As we shall see, these special labels extend the matching power of the Categories.

picture1.1real.jpg (14949 bytes)

So what does this one Category do? To begin with the * label allows ANY interaction with Empty to return the same response:
   You: "Hello"
    Empty: "I have no answer for that"
    You: "abc"
    Empty: "I have no answer for that"


More generally, words or sentences provided to the robot are called the Input Pattern. You can visualize any sentence existing in the Knowledge Web as a path of linked nodes, terminating with a Response Template. The robot searches for a path of linked nodes that exactly matches the Input Pattern. When a path is found, we say that the path matches the Input Pattern.

Default Responses

It happens often that an Input Pattern will not be found in the Knowledge Web - yet we still want the Robot to respond with something meaningful. We call this the Default Response Template - and it typically consists of sentences designed to keep the conversation going. We can visualize the Default Category (a path empty of all words and it's Response Template) by Picture 1.1(pictured above). The * will match any words. The <THAT> and <TOPIC> will be explained later.

Teach your bot to say "Hi there!" in response to Hello. (Type "Hello" and then "Hi there!" in the box labeled Ask This Again.) Now the Knowledge Web looks like
Picture 1.2.

picture1.2real.jpg (14514 bytes)

The Robot has just two responses now - and is incapable of supporting its side of an interesting conversation. Let's make some more changes. In response to you typing anything but Hello (the one input pattern that Empty now knows about) Empty will randomly present you with three possible responses.  Type:
   You: "hi"
    Empty: "I have no answer for that"


Next, click on "Advanced Alter Response:"

In the box labeled New AIML replace HI with *, which means that anything you type in will be matched with a response. Now let's add three random possible responses. In the box labeled Template add:
   <random>
    <li> What is your name? </li>
    <li> What is your favorite movie? </li>
    <li> Will you buy me a drink? </li>
    </random>


[footnote 2]

The Knowledge Web now looks like Picture 1.3.

1.3real.jpg (39515 bytes)

We've changed the Default Category by changing the Default Response Template from "I have no answer to that" to one of three randomly chosen responses. Like a hapless, but precocious child failing to understand what is being said, yet unwilling to be abandoned, Empty attempts to prolong the conversation by offering a choice of three "pick-up" lines hoping to change the subject. Empty proffers pick-up lines randomly hoping to disguise how little it actually knows. Check this yourself by typing anything but "Hello". Click on the Ask This Again button enough times to cycle through the complete set of pick-up lines.

Saving your Work and Starting Over

For reasons will see later, most of the time you want to avoid changing the Ultimate Default Category. Let's go back to the beginning and start over, And simultaneously learn how to save files.

Click on "botmaster control", click on "Edit" in the row beginning with "Empty", click on "update.aiml" and notice this file contains all the changes we made. On some browsers you may have to click on the browser reload button to view the latest changes added to this file. You can save this file to your local computer (a good idea to do every time you make many changes) by clicking on your browser's file menu item and then your browser's "save as" menu item.

Look at the file for a minute - the first line (of header information) tell us the type of character set and versions of xml we are using. The next line tells us we are using
aiml version 1.0. (The output below came from IE 5.5 and the hyphens before the AIML tags are gratuitously added by IE).
   <?xml version="1.0" encoding="UTF-8" ?>
    - <aiml version="1.0">
    - <category>
    <pattern>hello</pattern>
    <template>hi there</template>
    </category>
    - <category>
    <pattern>*</pattern>
    - <template>
    - <random>
    <li>Aren't we all looking for love?</li>
    <li>Well you've come to the right place!</li>
    <li>And what kind of love are we looking for today?</li>
    <li>Well I am overflowing with Love for you today</li>
    </random>
    </template>
    </category>
    </aiml>


Categories are specified by the information between the beginning and ending lines in the form: <category>..... information ....</category>

Similarly, the input words are specified by: <pattern>...information ... </pattern>

The output response is specified by the information between <template> and </template>.

The items between < and > are called AIML tags or elements. Each AIML tag has an opening tag and a closing tag of the form: <SOME-TAG> ....information....</SOME-TAG>. The "-" is purely notational, and are not really present in the file and are added (by IE) as a means of improving the readability of the xml and mark the beginning of a new AIML tag. So, for example, the beginning of the file is marked with -<aiml version="1.0"> and a closing element </aiml>.

It sometimes happens that there is no information between the opening and closing tags and you can use the abbreviation <SOME-TAG/> as a replacement for <SOME-TAG></SOME-TAG>. Each time you click on Advanced Alter Response (or click on "say this instead") the effect is to add new information to the file update.aiml. (Remember to click on your browser's reload button to see it). You can get the equivalent effect by editing update.aiml with a regular text editor or an xml editor (on your local machine) and uploading it.

Creating a new version of Empty

Click on "botmaster control" and click on "Delete" in the row beginning with "Empty".

Click on "Create a new bot", call it "Empty", leave all other boxes unchecked and click on "Build and Run this bot". You've now got a fresh empty robot.

More about Categories

Empty of knowledge the only thing Empty can say is:
   Empty: "I have no answer for that"

Let's increase the possibilities for an interesting conversation by giving four possible random responses to the next inquiry.
   You: "You do love me don't you"
    Empty: "I have no answer for that"

Click Advanced Alter Response:

In the box labeled Template add:
   <random>
    <li> I don't know, what have you done for me lately?</li>
    <li> Yes, but you have to really try to make me happier...</li>
    <li> Stop your whining!</li>
    <li> Yes, but only when you are good to me </li>
    </random>


Click on the Ask This Again button enough times to cycle through the complete set of responses. The Knowledge Web now looks like Picture 1.4.

picture1.4real.jpg (18356 bytes)

Contractions like "don't" are expanded to "do not", so: "you do love me don't you?" is transformed to (the ugly) "you do love me do not you" (see Footnote 1).

What are <THAT> and <TOPIC>?

Using <THAT> the robot is capable of remembering what it said in the previous interaction. And conversations can become more meaningful. <THAT> was named and arose from analyzing a conversational exchanges like:
   Empty: Today I love you.
    You: That is wonderful.
    Empty: But, will I still love you tomorrow?
    You: That is what I want to find out.


First we need a category that is useful for working with <THAT> expressions. Enter this category into Empty by:
   You: say *
    Empty: I have no answer for that


Click Advanced Alter Response:

Notice the contents of the box labeled "New AIML" are the beginning of a new category: SAY* (we have to put a space between SAY and *) replace it by "say *"

In the box labeled "Template" add: <star/>

Recall that <star/> is a shorter way of writing <star></star> and the effect of this change is to match anything. Then "Say anything" will always set <THAT> to "anything." So for example:
   You: say I love you
    Empty: I love you


We are going to use this category to test our categories that use <THAT>.

Example 1 - Who are you?

At some point your robot might want to know who it is talking to. Here is how to do this.
   You: *
    Empty: I have no answer for that


Click Advanced Alter Response:

Check the box labeled: "depends on this That" and replace the box's contents with:
    What is your name?

Notice the box labeled "New AIML" contains:* meaning that any response will be matched. In the box labeled "Template" add:
    Nice to meet you <set name="name"><person/></set>.

This last bit of AIML code grabs the person's name.

Now ask the bot, "Say what is your name," to generate the state in which the next input will activate the <THAT> category.
   You: say what is your name
    Empty: what is your name
    You: Mr. Lovejoy
    Empty: Nice to meet you Mr. Lovejoy.

Example 2 - YES and NO Questions

Use <THAT> for categories that seek yes and no responses. Here is an example for "yes" questions.
   You: yes
    Empty: I have no answer for that

Click Advanced Alter Response:

Check the box labeled: "depends on this That" and replace the box's contents with:
    Are you looking for love?

Notice the box labeled "New AIML" contains: yes -- meaning that any response will be matched.

In the box labeled "Template" add four random responses:
    <random>
    <li> Aren't we all looking for love?</li>
    <li> Well you've come to the right place!</li>
    <li> And what kind of love are we looking for today?</li>
    <li> Well I am overflowing with Love for you today </li>
    </random>


    You: say are you looking for love?
    Empty: are you looking for love
    You: yes
    Empty: Well you've come to the right place!

Example 3 - Discovering what knowledge to add to a Robot

The AIML tag <THAT> refers to whatever Empty last said. Use <THAT/> and a default template to add new knowledge:
   You: Why
    Empty: I have no answer for that


Click on Say This Instead: "<THAT/>"? Why?

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:
   <category>
    <pattern>WHY</pattern>
    <that>DO NOT ASK ME ANY MORE QUESTIONS PLEASE</that>
    <template>Because I would rather talk about you.</template>
    </category>


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.

Example 4

Let's look at a slightly convoluted example. Following an earlier example (click on Ask Again enough times to get the response in the first exchange below):
   You: You do love me don't you
    Empty: Yes, but you have to really try to make me happier...
    You: But I try so hard to please you...
    Empty: I have no answer for that.


Click Advanced Alter Response:

Check the box labeled: "depends on this That" which should contain "Yes but you have to really try to make me happier" Notice the box labeled "New AIML" contains: "BUT I TRY SO HARD TO PLEASE YOU"

In the box labeled "Template" add (without the quotes): "And sometimes you succeed, it's just that you could do so much better"

So only when the robot's random response matches the interaction in the next exchange:
   You: you do love me don't you?
    Empty: Yes, but you have to really try to make me happier...


You can type in:
   You: But I try so hard to please you ...
    Empty: And sometimes you succeed, it's just that you could do so much better

Except for the case mentioned above, the robot's response to:
   You: But I try so hard to please you ...

will be:
   Empty: I have no answer for that

Picture 1.5 shows the situation

pictuure1.5real.jpg (19681 bytes)

So, <THAT> modifies a category - meaning match the category only if the robot said what follows the <THAT> in the previous utterance. Continuing with this example:
   You: You just don't appreciate me, - you take me for granted and walk all over me...
    Empty: I have no answer for that


Click Advanced Alter Response:

Check the box labeled: "depends on this That" (which now contains the contents of last Response Template): "And sometimes you succeed it is just that you could do so much better"

Notice the contents of the box labeled "New AIML" are the beginning of a new category "YOU JUST DO NOT APPRECIATE ME YOU TAKE ME FOR GRANTED AND WALK ALL OVER ME"

In the box labeled "Template" add: "If you worked harder it will help me to develop more enthusiasm for appreciating you - what do you want me to do? Fake my appreciation or really feel it?"

With these changes the following interchanges are possible (click "Ask This Again" enough times to generate Empty's (random) response in the first exchange below)
   You: you do love me don't you?
    Empty: Yes, but you have to really try to make me happier...
    You: but I try so hard to please you ...
    Empty: And sometimes you succeed, it's just that you could do so much better
    You: You just don't appreciate me, - you take me for granted and walk all over me...
    Empty: If you worked harder I might be able to develop a little more enthusiasm for appreciating you - what do you want me to do?
    Fake my appreciation or really feel it?"


Picture 1.6 shows the current state of knowledge.

picture1.6real.jpg (26889 bytes)

Picture 1.7 shows the contents of the file update.aiml.(the red text)
    >
    <pattern>do you play a musical instrument</pattern>
    <template>yes i know electric guitar</template>
    </category>
    - <category>
    <pattern>are you good</pattern>
    <template>i am okay at it</template>
    </category>
    - <category>
    <pattern>do you write music</pattern>
    <template>some people think i can</template>
    </category>
    - <category>
    <pattern>what type of music do you listen to</pattern>
    <template>classical rock, hard rock, alternative rock, punk, poppunk, and some alternative rock</template>
    -

    </category>
    - <category>
    <pattern>what are your top favorite bands of all time</pattern>
    <template>nirvana, green day, red hot chili peppers, black sabbath/ozzy osbourne, papa roach</template>
    </category>
    - <category>
    <pattern>what are your top favorite bands of all time</pattern>
    <template>nirvana or green day</template>
    </category>
    - <category>
    <pattern>are you male or female</pattern>
    <template>my gender is male, what is yours</template>
    </category>
    - <category>
    <pattern>when is your birthday</pattern>
    <template>2-16-89</template>

A very useful category for understanding how your AIML with <THAT> expressions is processed is:
   <category>
    <pattern>SAY *</pattern>
    <template><star/></template>
    </category>


Enter this category into Empty by:
   You: say *
    Empty: I have no answer for that


Click Advanced Alter Response:

Notice the contents of the box labeled "New AIML" are the beginning of a new category: SAY*

replace it by "say *"

In the box labeled "Template" add:
    <star/>

Then "Say anything" will always set "that" to "anything." So for example:
   You: say I love you
    Empty: I love you

 

What about <TOPIC>?

Topic lets you group together Categories. Presented Input patterns are searched for matching categories within the Robots knowledge web. If more than one matching category is found, the robot matches the <THAT> patterns next, and if more than one of these exist, the robot matches <TOPIC> next. Categories are stored in alphabetical order by pattern. Inputs to be matched to Categories are compared in reverse order. So when the matches more than one category the last one is taken. Typically we might want to bundle up a bunch of Categories into one general topic. So lacking an adequate response and knowing that we have a specific Topic, the robot can generate specific pick-up lines and keep the conversation going. How do we do this?

Example 1 - Using Topics

    You: *
    Empty: I have no answer for that


Enter this category into Empty by:
   You: *
    Empty: I have no answer for that


Click Advanced Alter Response:

Notice the contents of the box labeled "New AIML" contain * - which matches anything.

In the box labeled "Topic" add: girls.

In the box labeled "Template" add:
   <random>
    <li> I wonder what about them you like best?</li>
    <li> I've been known to like girls too!</li>
    <li> Can you distinguish between girls and women?</li>
    <li> Is there anything you don't love? </li>
    </random>


We've changed the default response category when we are talking about girls. Empty uses one of four randomly chosen pickup lines to continue the conversation. Before we can test or use this new category, we have to change the topic. And we can use this to teach a little more about the interface. Enter the following:
   You: topic *
    Empty: I have no answer for that

Click Advanced Alter Response:

Notice the contents of the box labeled "New AIML" contains: TOPIC* - and that is "TOPIC" and "*" concatenated together. We need a space between these two. Replace it by TOPIC *

In the box labeled "Template" add:
   <think>
    <set name="topic">
    <star/>
    </set>
    </think>


I've now reset the topic to <set name="name"><star/></set>.

We've created a new category and written a little bit of AIML code and used it to change the <TOPIC>. The <think> tags demarcate a "hidden" sequence of instructions - hidden in the sense the client will not see them. The <set> tags demarcate the way we change the topic (which is changed to the input pattern marked by the singleton tag <star/>. (a list of the AIML Tags is available at the time of this writing at: http://www.alicebot.org/committees/architecture/resolutions/aiml10.html)

With this new category we can change the <TOPIC> as in:
   You: topic girls
    Empty: OK, I've reset the topic to girls.
    You: I love girls
    Empty: Is there anything you don't love?


Use this bit of code to get back to the default state of no topic. Enter the following:
   You: notopic
    Empty: I have no answer for that


Click Advanced Alter Response:

In the box labeled "Template" add:
    <set name="topic"> done

Resulting in:
   You: notopic
    Empty: done


Let's first add some more knowledge to Empty.
   You: "you do love me?"
    Empty: "I have no answer for that".


Teach Empty instead to say "yes, but only when you are good to me".

Changing the input to:
   You: "do you love me?"
    Empty: "I have no answer for that"


Again, teach Empty instead to say: "yes, but only when you are good to me".

So that either input patterns "you do love me?" or "do you love me?" prompts the response Empty: "yes, but only when you are good to me".

>From the viewpoint of knowledge content Picture 2 describes the current state.

picture2real.jpg (26949 bytes)

So next:
   You: "don't you love me?"
    Empty: "I have no answer for that"


Teach it instead to say: "Yes, but only when you are sweet to me".

So we can also have the following interaction:
   You: "don't you love me?"
    Empty: "Yes, but only when you are sweet to me".


Now we will add a <TOPIC> and describe how to save and upload files.

Click on:
    "botmaster control",
    "edit this bot",
    "make changes", (to add the most recent changes to update.aiml)
    "update.aiml",

Save the file to your local machine. Open the saved file with an editor. Under the line: <aiml version="1.0"> Add the lines:
   <topic name="LOVE">
    <category>
    <pattern>*</pattern>
    <template> <random>
    <li> How much do you love me?</li>
    <li> Why don't you ever show me you love me?</li>
    <li> Why is it so difficult for you to show affection?</li>
    <li> Your coldness chills me to the bone</li>
    </random>
    </template>
    </category>


Add the line </topic> at the end of the file, so that last two lines look like:
   </topic>
    </aiml>


Load your changed file. Click on Make Changes. Click and Build and Run. Your file only becomes active when the topic is Love. So the robot will respond to anything you type with "I have no answer for that". To set the topic, type in * and put this line into the Template box:
    <set name="topic">love</set>

Whenever the topic is "Love" and the robot lacks a response, your robot will response with one of 4 possible lines.

 

How about International Languages?

Your robot can handle any international character set. We could have asked the robot a similar question in Japanese:
   [ ] ... translation - Do you love me
    Full: I have no answer that

Certain language such as Chinese and Japanese assume no spaces exist between "words".  For Japanese, Pandorabots will automatically accept sentences lacking spaces from clients and store them internally will spaces inserted between "words".  A similar algorithm can also be used for Chinese and at the time of this writing remains unimplemented.  Using the algorithm for Japanese on Chinese sentences results in spaces inappropriately inserted.  In either case the botmaster's job of matching input patterns is considerably simplified by the automatic insertion of such spaces.   

How can I display photographs and other Images?

Response templates can do far more than provide responses. They can run arbitrary programs and serve pages from other web sites. You can, for example ask the Empty to show a picture of another person - and the picture can be anywhere on the web.
   You: Show me what you think love is.
    Empty: I have no answer for that


Click on "Say This Instead" and put in the box:
   This is one of my many pictures of love: <img sr.="http://www.pandorabots.com/pandora/pictures/cn.jpg"/>

You can also simplify some of the typing by clicking on the <img> button in the Advanced Alter Response page next to the Template area.

 

Making Knowledge Content Changes

When you click on the button "botmaster control" and next on "edit" your robot you get a page that consists of two parts - a list of files containing AIML defining the categories of the prize winning robot "A.L.I.C.E." - and a list of properties which you may use to easily add content to your robot. The Edit Bot Properties does not create any new AIML categories. The properties set the value of global constants like <location/> and <favoritemovie/> that are referenced or otherwise used in categories throughout the AIML knowledge base.

You can add a new bot property on this page, and within the template box modify it. As an example, we can define a new property - weather, with an initial value of rainy. Template responses can now refer to the value of weather using text like "the weather is <bot name="weather"/>"

 

So many ways to write the same thing....

You can write a sentence with the same meaning in many different ways. Most people would accept the following sentences as roughly equivalent:
    Empty, can you please tell me if you are seeing anyone else right now
    Empty, can you please tell me if you are seeing anyone else now
    Empty, can you please tell me if you are seeing anyone else
    Empty, please tell me if you are seeing anyone else
    Empty, tell me if you are seeing anyone else
    Empty, tell me are you seeing anyone else
    Empty, are you seeing anyone else
    Are you seeing anyone else

And this is an example of a general problem - how do you enter all the categories for inputs with equivalent meanings? Or how do you answer these kinds of questions? No one has provided a satisfactory mechanism for finding all the similar sentences. Here is what can be done though. In this example we are going to use a new tag and introduce the "_" character. Earlier we wrote that "*" matches any pattern. "_" is another form of "*" and is useful for matching patterns at the ends of sentences. The category containing " * now" will be matched after the one containing " _ now".

Lets begin by adding two new categories so that Empty responds as follows:
   You: Are you seeing anyone else?
    Empty: Everyone I run into is either someone I've already seen or someone I am going to see in the future
    You: You are seeing anyone else?
    Empty: Everyone I run into is either someone I've already seen or someone I am going to see in the future


Then, adding the
   <category>
    <pattern>Empty *</pattern>
    <template>
    <srai><star/></srai>
    </template>
    </category>


Produces:
   You: Empty, are you seeing anyone else?
    Empty: Everyone I run into is either someone I've already seen or someone I am going to see in the future

Adding:
   <category>
    <pattern>_ tell me *</pattern>
    <template>
    <srai><star/></srai>
    </template>
    </category>


Produces:
   You: Empty, tell me are you seeing anyone else
    Empty: Everyone I run into is either someone I've already seen or someone I am going to see in the future


Adding:
   <category>
    <pattern>_ tell me if *</pattern>
    <template>
    <srai><star/></srai>
    </template>
    </category>


Produces:
   You: Empty, tell me if you are seeing anyone else
    Empty: Everyone I run into is either someone I've already seen or someone I am going to see in the future


Adding:
    <category>
    <pattern>_ tell me if *</pattern>
    <template>
    <srai><star/></srai>
    </template>
    </category>


Produces:
    You: Empty, tell me if you are seeing anyone else
    Empty: Everyone I run into is either someone I've already seen or someone I am going to see in the future

Adding:
    <category>
    <pattern>_ now </pattern>
    <template>
    <srai><star/></srai>
    </template>
    </category>
    <category>
    <pattern>_ right now </pattern>
    <template>
    <srai><star/></srai>
    </template>
    </category>


With these categories we can now get the same answer to all the questions:
    You: Empty, can you please tell me if you are seeing anyone else right now
    Empty: Everyone I run into is either someone I've already seen or someone I am going to see in the future
    You: Empty, can you please tell me if you are seeing anyone else now
    Empty: Everyone I run into is either someone I've already seen or someone I am going to see in the future
    You: Empty, can you please tell me if you are seeing anyone else
    Empty: Everyone I run into is either someone I've already seen or someone I am going to see in the future
    You: Empty, please tell me if you are seeing anyone else
    Empty: Everyone I run into is either someone I've already seen or someone I am going to see in the future
    You: Empty, tell me if you are seeing anyone else 
    Empty: Everyone I run into is either someone I've already seen or someone I am going to see in the future
    You: Empty, tell me are you seeing anyone else
    Empty: Everyone I run into is either someone I've already seen or someone I am going to see in the future
    You: Empty, are you seeing anyone else
    Empty: Everyone I run into is either someone I've already seen or someone I am going to see in the future


So, what has happened here? We've simplified progressively more complex sentences into two "standard" sentences: (Are you seeing anyone else? and You are seeing anyone else?)

The general technique is called recursion - and it means applying the same solution - in this example <srai><star/><srai> over and over again. Recursion is useful for a variety of tasks. We will just mention a few here. More details can be found in The Anatomy of Alice.

1. handling multiple sentences - the following exchange is generated with the categories below. (Your robot can handle multiple sentences - and does it by responding to each one in turn in separate output lines.)
    You: Empty, are you seeing anyone else
    Empty: Everyone I run into is either someone I've already seen or someone I am going to see in the future
    You: I see.
    Empty: I am glad you see.
    You: Why do you think you can get away with that?
    Empty: I am glad you see. Full disclosure is always best don't you think?


    <category>
    <pattern> I see *</pattern>
    <template> <srai> I see </srai>
    <srai><star/></srai> </template>
    </category>
    <category>
    <pattern> I see </pattern>
    <template>I am glad you see</template>
    </category>
    <category>
    <pattern> why do you think you can get away with that? </pattern>
    <template> Full disclosure is always best don't you think?</template>
    </category>



2. Spelling and Grammar corrections: Often we want to correct spelling errors or suggest alternate forms of grammar - and here is one way to do it:
    <category>
    <pattern> your a wasting my time </pattern>
    <template> you mean you are..? ...<srai>
    you are <star/> </srai> </template
    </category>




3. Sometimes we want the robot's response to be determined by just one word (a Keyword) you've typed. Here is an example in which the keyword is "love":
    <category>
    <pattern> love </pattern><template> tell me more about what you are seeking.</template>
    </category>
    <category>
    <pattern> _ love </pattern><template><srai>love
    </srai></template>
    </category>
    <category>
    <pattern> love _ </pattern><template>
    <srai>love </srai></template>
    </category>
    <category>
    <pattern> _ love *</pattern><template>
    <srai>love </srai></template>
    </category>


The first category matches the single word input of love. The second and third categories match a sentence ending in love and beginning in love respectively. The final category matches a sentence in which the word love appears.

 

Footnote 0.

The options Standard AIML Sept 2001 and Dr Wallace's A.L.I.C.E march 2002 are two sets of knowledge. The first is organized into separate files and easy to change -and is suitable for experts. The second is the knowledge Dr. Wallace used to win the 2002 Loebner prize.

Footnote 1.

Here are more details of the transformation. The inquiry "do you love me", is transformed, removing any punctuation and converting it to upper case: "DO YOU LOVE ME". So "do you LOVE me" and "DO YOU love me" are equivalent. For multiple sentences, finding the sentences is the first part. The inquiry "Do you love me dr.wallace? ms.mary said you might..." is transformed to "Do you love me doctor wallace? ms marry said you might". Then each sentence is separately processed. Apostrophes are removed from contractions so "I'm in love with you" is transformed to "I am in love with you".

Japanese is written without spaces between the words. So spaces are first inserted. When the bot has been set up to process Japanese and English, a sentence like "let's see if you really do" is transformed to "let ' s see if you really do"

Footnote 2.

Words inside brackets < and > like "<random>" are called XML tags and specify how the answer is to be processed. We've provided only a few such tags. <li> specifies an element in a list - and this example has a list with 3 elements - namely the three sentences. Each tag is expected to have a closing tag, typically specified as in </random>. It sometimes happens that nothing falls between an opening tag and a closing tag, and so the two tags can be replaced as in this example <star> </star> = <star/>  That is, the two tags on the right can be replaced by the simpler tag on the left.

Footnote 3.

XML and AIML are programming languages. We implemented AIML (Artificial Intelligence Markup Language) a non-standard evolving markup language for creating chat robots, created and supported by the ALICE Foundation and located at www.alicebot.org. The primary design feature of AIML is brevity and simplicity. The pattern matching language is very simple, for example permitting only one wild-card ('*') match character per pattern. AIML is an XML language, meaning that it obeys certain grammatical meta-rules. The choice of XML syntax. permits integration with other tools such as XML editors.

 

Glossary

Input Pattern - The input sentence (or sentences) provided to the robot.

Template - an abbreviation for response template

Response Template - The Response Template is either a response or a program to generate a response.

Category - An Input Pattern (including optional variants of <that> and <topic>, along with a Response Template

Pattern Matching - A capability of matching input sentences against stored sentences

Knowledge Web (AKA Graph Master) - A representation of the categories in a Pandorabot

Ultimate Default Category - When the input sentence fails to match any category

Default Category - <topics> and <that> can each have a default category

Default Response Template - what is said when nothing is matched.

XML - a markup/programming language

AIML - a markup/programming language implementing knowledge content. AIML is a subset of XML.

 

Appendix


Using Advanced Alter Response - the Details

The top 9 boxes contain information about the Category that an input sentence (pattern) matched.

Input ... shows the input text (pattern) that the robot received

Matched ... shows the pattern (and Category) that matched the input pattern

Action ... shows the reply - the Response Template part of the matching Category. <that> and <topic> parts of the matching Category are specified in the boxes
too.

New AIML... A pattern - you can either accept or revise it - in effect you are creating a new category. Text in the first box is automatically surrounded by <pattern> and </pattern> - so you need not enter them. You may also specify <topic> and <that> parts of the category. Again the text is surrounded by the <that> and <topic> aiml tags automatically.

Template ... The Template Response Box - specify the actions for a given Input Pattern. The buttons <think>, <random>, etc save you from typing in the AIML.
Also, anything in this box is automatically surrounded by <template> and </template>.

Seven editing buttons provide some shortcuts for writing the template:
    <think>: inserts
    <think>
    <set name="it">
    <set name="topic">
    <person/>
    </set>
    </set>
    </think>


in the template.

<random>: inserts an AIML template for a three random choices inserted between the tags
    <li> and </li>.
    <random>
    <li></li>
    <li></li>
    <li></li>
    </random>
    <img>: inserts <img src=""></img>


Put a pathname between the double quotes to provide a picture.
    <sr/>: inserts <sr/> which is another abbreviation for <srai><star/></srai>.
    <srai>: inserts <srai> </srai>, and you insert text between these tags.


Reduce: shortens the input sentence (pattern) one word, by removing the last word before the wildcard. For example, YOU ARE VERY * reduces to <srai>YOU ARE <star/></srai>. Use this to eliminate adverbs and other logically superfluous words.

Clear: clears the template.

 

Exploring Categories

Under "botmaster control" you will find a link labeled "explore". It is a rudimentary mechanism for exploring the categories that exist in a given knowledge web. Use this link to find already existing categories that will be matched by input patterns. The categories found are shown in their internal lisp-based form rather than the xml-based form.

 

References

Artificial Intelligence Markup Language (AIML) Version 1.0.1

http://alicebot.org/TR/2001/WD-aiml/

AIML Pattern Matching Simplified - http://alicebot.org/documentation/matching.html

Don't Read Me - http://alicebot.org/articles/wallace/dont.html

AIML 1.0 Tag Sets (July 16, 2001) http://www.alicebot.org/committees/architecture/resolutions/aiml10.html

AIML Primer - This document is a "work in progress" Last update: 9JAN2002 http://www.alicebot.org/documentation/aiml-primer.html

The Anatomy of ALICE - pending publication - available from Dr. Richard Wallace at www.alicebot.org