AIML Reference Manual

This document is a "work in progress"
Last  update:  September 01, 2001



Document by: Thomas Ringate
Copyright 2001
Contributing Authors: Dr. Richard S. Wallace; Anthony Taylor: Jon Baer


AIML TAG REFERENCE TABLE

AIML 0.9 AIML 1.0 Tag Type Note
<alice> <aiml> AIML block delimeter [Closing tags not shown]
<name/> <bot name="name"/> Built-in bot parameter may appear in pattern
(see Note 2.) <bot name="XXX"/> Custom bot parameter <srai>BOT XXX</srai>
<justbeforethat/> <that index="2,1"/> Built-in predicate See Note 4.
<that/> <that index="nx,ny"/> Built-in predicate default "that"
<that> <that> AIML that pattern contains AIML pattern
<category> <category> AIML category  
<justthat/> <input index="2"/> Built-in predicate  
<beforethat/> <input index="3"/> Built-in predicate  
<condition name="X" value="Y"> <condition name="X" value="Y"> Conditional branch  
<condition> <condition> Conditional branch  
<gender> <gender> Gender substitution Exchange "he" and "she"
<date/> <date/> Built-in predicate date and time
<get_ip/> <id/> Built-in predicate default "localhost"
<getname/> <get name="xxx"/> Built-in predicate default "X-person"
<getsize/> <size/> Built-in predicate # of categories loaded
<star/> <star index="n"/> Built-in predicate binding of *
<thatstar/> <thatstar index="n"/> Built-in predicate binding of * in that
<gettopic/> <get name="topic"/> Built-in predicate default "you"
<topicstar/> <topicstar index="n"/> Built-in predicate binding of * in topic
<getversion/> <version/> Built-in predicate AIML program version
<get_xxx/> <get name="xxx"/> Custom predicate Botmaster defined XXX, default (3)
<gossip> <gossip src="X"/> Append to file  
<load filename="X"/> <learn>X</learn> AIML loading  
<li name="X" value="Y"> <li name="X" value="Y"> Conditional branch item used by <condition>
<li value="Y"> <li value="Y"> Conditional branch item used by <condition name="X">
<li> <li> General list item used by <random>, <condition>
<pattern> <pattern> AIML Pattern contains AIML pattern
<person/> <person/> Prounoun transform macro <person><get_star/></person>
<person2> <person2> Prounoun transform swap 1st & 2nd person
<person2/> <person2/> Prounoun transform macro <person2><get_star/></person2>
<person> <person> Prounoun transform swap 1st & 3rd person
<random> <random> Random selection Random uniform selection
<setname> <set name="name"> Built-in predicate returns contents
<settopic> <set name="topic"> Built-in predicate returns contents
<set_XXX> <set name="XXX"> Custom predicate See Note 3.
<sr/> <sr/> Recursion macro <srai><get_star/></srai>
<srai> <srai> Recursion  
<system> <system> Execute OS shell platform-dependent
<template> <template> AIML template  
<think> <think> Nullify output  
<topic name="X"> <topic name="X"> AIML topic group X is AIML pattern
  <uppercase> Text manipulation convert all text to Uppercase
  <lowercase> Text manipulation convert all text to Lowercase
  <sentence> Text manipulation capitalize the first word
  <formal> Text manipulation capitalize every word
  <if name="X" value=Y"> Conditional branch  
  <else> Conditional branch  
  <javascript> AIMLScript Javascript

<aiml version="xxx"> </aiml>

Supported in versions: AIML 01.0
Must be within: an AIML file
Can be within: N/A
Can contain: <topic> <category>
Must Contain: could be empty

Description:
This is the first and last tag of each separate AIML file.

Every new file of AIML starts with <aiml version="xxx"> and ends with </aiml>.

Example:
<aiml version="1.0">

<category>
<pattern>*</pattern>
<that>WHO IS THERE</that>
<template><star/> Who?</template>
</category>

</aiml>


<alice> </alice>

Supported in versions: AIML 0.9  (This is a deprecated TAG)
Must be within: an AIML file
Can be within: N/A
Can contain: <topic> <category>
Must Contain: could be empty

Description:
This is the first and last tag of each separate AIML file. Every new file of AIML starts with <alice> and ends with </alice>.
See <aiml> tag.



<beforethat/>

Supported in versions: AIML 0.9 (This is a deprecated TAG)
Must be within:UNKNOWN
Can be within: <template>
Can contain: nothing
Must Contain: nothing

Description:
<beforethat/> experimental AIML tags. This tag gives access to the third last response that the client/user made.
See <input index="n"> tag.



<category> </category>

Supported in versions: AIML 1.0
Must be within: <aiml>
Can be within: <aiml> <topic>
Can contain: <that> <pattern> <template>
Must Contain: <pattern> <template>

Description:
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:

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

or

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

The AIML category tags are case-sensitive. Each open tag has an associated closing tag.


<condition name="name" value="value"> </condition>
<condition name="name" contains="value"> </condition>
<condition name="name" exists="value"> </condition>

Supported in versions: AIML 1.0
Must be within: UNKNOWN
Can be within: <template>
Can contain: any template-side AIML expression
Must Contain: can be empty

Description:

The <condition> tag has three forms.  The "multi condition" the "list-condition", and the "single name list-condition".
The difference between the forms is that the "multi condition tags" will all be evaluated, but the "list-condition" and the "single name list-condition" tags stop after the first <li> test is true.
Note:

  1. There may be multiple <condition> tags in the <template>. [But nesting doesn't work yet.]
  2. The value string may contain an AIML pattern with up to one wild-card "*" symbol.
  3. The test for the <condtion> being true uses Unifier.unify() to compare the stored predicate value with the value string. This is the same way <that> and <topic> work.
  4. If the test returns true, then the response contains whatever is inside the <condition>...</condition> tags, otherwise those contents are ignored.

This category illustrates the function of the (template-side) condition tag. The input pattern is "TEST COND":

<category>
<pattern>TEST COND</pattern>
<template>
This category has two condition statements.<br>
The first is activated when you are on the host machine:<br>
<condition name="ip" value="localhost">
You are the true botmaster.<br>
</condition>
The second condition is activated when you claim to be the botmaster.<br>
<condition name="name" value="* WALLACE">
Impostor! You are not my real botmaster.<br>
</condition>
 

Two dialogues from different hosts show two possible outputs of this category:
 

--------------------dialup.mindspring.com--------------
Client: MY NAME IS DR WALLACE.
Robot: OK I will call you Dr Wallace.
Client: TEST COND.
Robot: This category has two condition statements.
The first is activated when you are on the host machine:
The second condition is activated when you claim to be the botmaster.
Impostor! You are not my real botmaster.
That concludes our test of the condition tag.
---------------------localhost-------------------------
Client: TEST COND.
Robot: This category has two condition statements.
The first is activated when you are on the host machine:
You are the true botmaster.
The second condition is activated when you claim to be the botmaster.
That concludes our test of the condition tag.
 

Another example using the different types of lists.

This category illustrates the function of the (template-side) condition tag. The input pattern is "I AM BLOND".
The response will vary between "You sound very attractive." or "You sound very handsome." depending on the gender of the user.

FORM: multi condition tags:

<category>
<pattern>I AM BLOND</pattern>
<template>You sound very
<condition name="gender" value="female"> attractive.</condition>
<condition name="gender" value="male"> handsome.</condition>
</template>
</category>

FORM: list-condition tag:

<category>
<pattern>I AM BLOND</pattern>
<template>You sound very
<condition>
<li name="gender" value="female"> attractive.</li>
<li name="gender" value="male"> handsome.</li>
</condition>
</template>
</category>

FORM: single name list-condition tags

<category>
<pattern>I AM BLOND</pattern>
<template>You sound very
<condition name="gender">
<li value="female"> attractive.</li>
<li value="male"> handsome.</li>
</condition>
</template>
</category>

Another way to write the above list-condition category is to have the last list entry be the default expression.  The last entry is executed if none of the previous list entries are true.

<category>
<pattern>I AM BLOND</pattern>
<template>You sound very
<condition>
<li name="gender" value="female"> attractive.</li>
<li> handsome.</li>
</condition>
</template>
</category>


<formal>text</formal>

Supported in versions: AIML 1.0
Must be within: <template>
Can be within: UNKNOWN
Can contain: UNKNOWN
Must Contain: UNKNOWN

Description:
This tag allows for word formating within the tag boundries. Capitalize every word

Example:
<category>
<pattern>DO FORMAL</pattern>
<template>
My name is <formal>jon baer</formal>.
</template>
</category>

This will give the following output: My name is Jon Baer.


<gender></gender>

Supported in versions: AIML 1.0
Must be within: <template>
Can be within: <template>
Can contain:
Must Contain:

Description:
The <gender> tag works like the <person> tag, but changes gender, not pronoun.
The following example shows this swapping of the gender.
<gender>She told him to take a hike..</gender>
Would produce the output of "He told her to take a hike".



<get name="xxx"/>

Supported in versions: AIML 1.0
Must be within: <template>
Can be within: <pattern>
Can contain: nothing
Must Contain: nothing

Description:



<get_xxx/>

Supported in versions: AIML 0.9 (This is a deprecated TAG)
Must be within: <template> A <template> “can” contain a <get_xxx/> but it doesn't have to.
Can be within: <pattern> see special note on read-only tags
Can contain: nothing
Must Contain: nothing

Description:
Get methods are logically atomic tags, i.e. they enclose no text.
There are two types of get tags, "read only" and "client".

READ ONLY GET TAGS:

The robot tags are read only.
Read-only tags cannot be set by the AIML.  These properties are assumed to be set by some process running outside the AIML, such as the underlying interpreter or operating system, or set by the botmaster when defining the personality.

LIST OF READ ONLY GET TAGS

<beforethat/> previous client input line
<bot_name/> Robot's name
<bot_location/> Robot's location
<bot_gender/> Robot's gender
<bot_birthday/> Robot's birthday
<bot_master/> Robot's botmaster name
<bot_birthplace/> Robot's birthplace
<bot_boyfriend/>Does the robot have a boyfriend?
<bot_favoritefood/> Robot's favorite food
<bot_favoritemovie/> Robot's favorite movie
<bot_favoriteband/> Robot's favorite band
<bot_favoritebook/> Robot's favorite book
<bot_favoritecolor/> Robot's favorite color
<bot_favoritesong/> Robot's favorite song
<for_fun/> What the robot does for fun
<bot_friends/> The robot's friends
<bot_girlfriend/> Does the robot have a girlfriend?
<bot_wear/> Robot's clothing and apparel
<bot_sign/> Robot's astrological sign
<bot_looklike/> The robot appearance
<bot_music/> Robot's favorite kind of music
<bot_talkabout/> Robot's favorite subjects
<getsize/> A string indicating robot memory size
<getversion/> The ALICE program version
<that/> previous robot response
<justthat/> current client input line
<justbeforethat/> previous previous robot response
<question/> A random question

CLIENT GET TAGS:

The "client" tags can be set and have an associated <set_name>xxx</set_name> tag.
All the "client get" tags retrieve values stored relative to a particular client user ID (UID).
A client get tag can not be used in a <pattern> tag.  They are permitted only in <template> level tags.
Custom client get/set tags can be created by simply adding the tag.
See the information on custom tags.

LIST OF STANDARD CLIENT GET TAGS

<get_name/> client's name
<get_topic/> The "topic" of conversation
<get_ip/> Get the client's IP address
<get_it/> the value of "it"
<get_they/> the value of "they"
<get_we/> the value of "we"
<get_gender/> a string like "female" or "male" for client gender
<get_location/> the client's geographic location
<get_age/>
<get_has/>



<gossip> </gossip>

Supported in versions: AIML 1.0
Must be within: undefined
Can be within: <template>
Can contain: any template-side AIML expression (TSAE?)
Must Contain: can be empty

Description:
<gossip> X </gossip> Save X as gossip.

Gossip is an interesting "learning" feature of AIML. The best way to illustrate the gossip function is with an example. Consider the category with the pattern "I * " and the template:

Thanks for the gossip:
<gossip><get name="name"/> said <get_gender/> <person2/> </gossip>.

The gossip() function tells AIML that the botmaster wants to save this tidbit as gossip. The <get_gender/> function returns "he" or "she" as determined by the markup functions <set_female> and <set_male/>. The <person2/> function converts the statement * to second person.
At present the robot stores the gossip collected in a file called "gossip.txt".



<if> </if>

Supported in versions: AIML 1.0
Must be within: UNKNOWN
Can be within: UNKNOWN
Can contain: UNKNOWN
Must Contain: UNKNOWN

Description:

<if name="topic" value="cars"></if>
<if name="topic" contains="cars"></if>
<if name="topic" exists="true"></if>

<template>
<if name="name" exists="true">
Your name is <get_name/>.
<else/>
What is your name?
</if>
</template>

I am *guessing* that <if name="name" value=""> should work as well.

I've added an <if> tag for javascript evaluation:

<category>
<pattern>*</pattern>
<template>
<if expr="getFoo() == true">It was true.</if> This is a test.
</template>
</category>

Syntax:

<if expr="javascript expression">Will be sent back if evaluates to "true"</if>



<input index="number"/>

Supported in versions: AIML 1.0
Must be within: UNKNOWN
Can be within: UNKNOWN
Can contain: UNKNOWN
Must Contain: UNKNOWN

Description:
The <input index="n"/> tag gives the entire user input response. The value "n" is a backward reference to the previous user response. A value of "1" will give the last user response, the value "2" will give the second to the last user response, the value "3" will give the third last user response, and so on.
The index="n" is optional, and if left off, the index value of "1" is assumed. The tag <input/> is equivilant to <input index="1"/>.

Client: MY NAME IS BILL.
Robot: Bill, are you married?
Client: YES.
Robot: What kind of a car do you drive?
Client: I DRIVE A MAZDA.

 In this example, at the end of this exchange, here are the values of <input index="n"/>
<input index="1"/> = I DRIVE A MAZDA
<input index="2"/> = YES
<input index="3"/> = MY NAME IS BILL


<javascript> </javascript>

Supported in versions: AIML 1.0
Must be within: undefined
Can be within: <template>
Can contain: nothing
Must Contain: nothing

Description:



<justbeforethat/>

Supported in versions: AIML 0.9 (This is a deprecated TAG)
Must be within:UNKNOWN
Can be within: <template>
Can contain: nothing
Must Contain: nothing

Description:
<justbeforethat/> experimental AIML tag. This tag gives access to the second last response that the bot made.
It has been replaced with the <that index="2,1"/> tag.
See <that index="nx,ny/"> tag.



<justthat/>

Supported in versions: AIML 0.9 (This is a deprecated TAG)
Must be within:UNKNOWN
Can be within: <template>
Can contain: nothing
Must Contain: nothing

Description:
<justthat/> experimental AIML tag. This tag gives access to the second last response that the client/user made.
See <input index="n"> tag.



<learn filename="X"/>

Supported in versions: AIML 1.0
Must be within: undefined
Can be within: <template>
Can contain: nothing
Must Contain: X must be a valid AIML file.

Description:
The template may contain a <learn/> 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, startup.aiml contains a global <learn> tag to load all files in the bot directory.



<li> </li>

Supported in versions: AIML 1.0
Must be within: <condition> or <random>
Can be within: <condition> or <random>
Can contain: could be empty
Must Contain: could be empty

Description:
List element.
Currently the list can be used within the <random> and <condition> tag sets.

A list element can contain standard text as well as any AIML tag that is permitted within the <template> tag set.



<load filename="X"/>

Supported in versions: AIML 0.9 (This is a deprecated TAG)
Must be within: undefined
Can be within: <template>
Can contain: nothing
Must Contain: X must be a valid AIML file.

Description:
See the <learn> tag.


<lowercase>text</lowercase>

Supported in versions: AIML 1.0
Must be within: <template>
Can be within: UNKNOWN
Can contain: UNKNOWN
Must Contain: UNKNOWN

Description:
This tag allows for word formating within the tag boundries. all lower case.

Example:
<category>
<pattern>DO LOWERCASE</pattern>
<template>
This is a <lowercase>LOWERCASE</lowercase> test.
</template>
</category>

This category will give the following outout: This is a lowercase test.



<pattern </pattern>

Supported in versions: AIML 1.0
Must be within: <category>
Can be within: undefined
Can contain: * _ <name/>
Must Contain: Normalized text "Pattern-side AIML expressions (PSAE)."

Description:
The pattern is the "stimulus" or "input" part of the category.
The <pattern> tag is permitted only within a <category> tag set.  Only one pattern tag is permitted to exist, and it must be the first tag to appear after a <category>
tag.

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 <name/> tag 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.



<person> </person> <person/>

Supported in versions: AIML 1.0
Must be within: UNKNOWN
Can be within: <template>
Can contain: UNKNOWN
Must Contain: UNKNOWN

Description:
The <person> and <person2> tags indicate a place where the AIML interpreter changes the personal pronouns in a sentence.

<person2> X </person2> change X from 1st to 2nd person
<person> X </person> exchange 1st and 3rd person

<person2> is not often used. The main application is "gossip":

Client: I admire robots like you.
Robot: That's good information: Joe said he admire robots like me.

The transformation is a combination of:

1. change the first person pronouns to second person.
2. change the third person pronouns to first person.

The <person> substitution is much more common and easier to understand, because it simply exchanges 1st and 3rd person pronouns. The main issue with <person> in English is knowing when to use "I" and when to use "me".

The XML specification requires that every start tag such as  <person> be followed by a matching end tag like </person>. HTML is more relaxed about this requirement, exemplified by the liberal use of the <IMG> tag without a corresponding </IMG>. XML supports a shorthand notation for the "atomic" tags. The <star/> tag is an example of a shorthand AIML tag. <person/> is another example:

<person/> = <person><star/></person>


<person2> </person2> <person2/>

Supported in versions: AIML 1.0
Must be within: undefined
Can be within: <template>
Can contain: TSAE
Must Contain: could be empty

Description:
<person2/> = <person2><star/></person2>

See <person> tag for more information about <person2/>.


<personf> </personf> <personf/>

Supported in versions: AIML 0.9 (This is a deprecated TAG)
Must be within: undefined
Can be within: <template>
Can contain: TSAE
Must Contain: could be empty

Description:
The value of <personf/> (a "formatted" personal pronoun transformation) is shown by the example

<category>
<pattern>WHAT IS A *</pattern>
<template>
What does
<A HREF="http://www.dictionary.com/cgi-bin/dict.pl?term=<personf/>">
<set_it> <person/> </set_it>
</A> mean? <BR>
Or Ask Jeeves:
<A HREF="http://www.ask.com/AskJeeves.asp?ask=WHAT%20IS%20A%20<personf/>">
What is a <person/>?
</A>
</template>
</category>

The search strings formatted for the Webster Dictionary and for the Ask.com search engine utilize <personf/>. The effect is the same as <person/>, but the formatting inserts an escaped "%20" in places of the spaces returned by <person/>. These escape sequences permit the HTTP GET methods to transmit multiple-word queries.



<random> </random>

Supported in versions: AIML 1.0
Must be within: undefined
Can be within: <template>
Can contain: <li>
Must Contain: <li>

Description:
Its purpose is random selection of one of a set of list items.

<random>
<li>A</li>
<li>B</li>
<li>C</li>
</random>

Say one of A, B or C randomly

The <random> tag has higher precedence than other AIML tags.
Moreover, the AIML parser interprets only the markup inside the selected random list item. AIML tags inside other list items are ignored.


<sentence>text</sentence>

Supported in versions: AIML 1.0
Must be within: <template>
Can be within: UNKNOWN
Can contain: UNKNOWN
Must Contain: UNKNOWN

Description:
This tag allows for word formating within the tag boundries. Capitalize only the first word

Example:
<category>
<pattern>DO SENTENCE</pattern>
<template>
<sentence>this is some kind of sentence test.</sentence>
</template>
</category>

This category will give the following outout: This is some kind of sentence test.


<set_animagent/>

Supported in versions: AIML 0.9 (This is a deprecated TAG)
Must be within: undefined
Can be within: <template>
Can contain: nothing
Must Contain: nothing

Description:



<set_female/>

Supported in versions: AIML 0.9 (This is a deprecated TAG)
Must be within: undefined
Can be within: <template>
Can contain: nothing
Must Contain: nothing

Description:
Note <set_female/> = <set_gender>female</set_gender>

These are “shortcuts”.



<set_it></set_it>

Supported in versions: AIML 0.9 (This is a deprecated TAG)
Must be within: undefined
Can be within: <template>
Can contain: nothing
Must Contain: nothing

Description:
The guiding principle in creating content is dialogue analysis. The principle applies to pronouns like "it", "he" and "we". This example shows how a couple of tricks helps us find places where the pronoun tags improve the dialogue.

Client: HELLO
Robot: Hi there!
Client: HOW ARE YOU
Robot: I am functioning within normal parameters.
Client: I AM BROKE
Robot: Do you mean your name is broke.
Client: NO I HAVE NO MONEY
Robot: I see. Would you like to have it?
Client: YES
Robot: "Would you like to have it"? Yes?

One of the default responses to a YES pattern is
"<that/>?" Yes?

The conversation breaks down somewhat at this point, but the robot nonetheless conveys an illusion of understanding the client's response. With its response, the robot is really telling the botmaster to create a new "YES" reply specific to this situation:

<category>
<pattern>YES</pattern><that>WOULD YOU LIKE TO HAVE IT</that>
<template>Where do you usually get <get_it/>?</template>
</category>

Now the next time we run the dialogue it ends with:

Client: NO I HAVE NO MONEY
Robot: I see. Would you like to have it?
Client: YES
Robot: Where do you usually get money?

There is no automated technique to finding the conversation points where the pronoun tags improve the flow of conversation. This is the "art" of AIML programming. The example shown here with '"<that/>?" Yes?' exemplifies one approach to finding these conversation way points. There are no doubt countless other tricks like this, and the field is wide open to linguists and writers to help us uncover them.

Here is an example that might help clarify the meaning of the pronoun "it."

The category with the pattern "DO YOU LIKE *" is a kind of default category for a whole class of inputs matching "Do you like X?", when the input does not match a category with a more specific pattern like "DO YOU LIKE CATS". No matter what the client says, we want the robot to remember that "it" stands for "X".

Many inputs activate this default category, so the botmaster tries to create a variety of replies using the <random> tag twice.

<category>
<pattern>DO YOU LIKE *</pattern>
<template>
<think><set_it><person/></set_it></think>
<random>
<li>I don't know if I like <person/>. </li>
<li>I've heard other people say they like that. </li>
<li>Some people like it. </li>
<li>Do you like it? </li>
</random>
<random>
<li><for_fun/>. </li>
<li>I like pets. </li>
<li>I like trains. </li>
<li>But I like cats. </li>
<li>But I think airplanes are cool. </li>
<li>I like to talk about movies and music. </li>
</random>
</template>
</category>

<think><set_it><person/></set_it></think>

results in the pronoun "it" being bound to the value of "*", rewritten in third person. With this category, the robot has the following dialogue:

Client: Do you like Dr. Who
Robot: How old are you? I like to make new friends.

The robot response is a combination of two random selections.

Client: It is a TV program
Robot: Dr. Who is a TV program. I suppose that makes sense.

To generate the final response, the robot applied its category:

<category>
<pattern>IT IS A *</pattern>
<template><get_it/> is a <person/>. I suppose that makes sense.</template>
</category>

The robot is correct that the reply does indeed make sense. Does this example suggest that in our human mind "it" is just a temporary storage register for a fragment of text?



<set_male/>

Supported in versions: AIML 0.9 (This is a deprecated TAG)
Must be within: undefined
Can be within: <template>
Can contain: nothing
Must Contain: nothing

Description:
Note <set_male/> = <set_gender>male</set_gender>

These are “shortcuts”.



<set_xxx> </set_xxx>

Supported in versions: AIML 0.9 (This is a deprecated TAG)
Must be within: undefined
Can be within: <template>
Can contain: nothing
Must Contain: nothing

Description:
Set tags consist of single-tag and double-tag markup.
 

single-tag:
<set_male/> the client gender is male
<set_female/> the client gender is female
<set_animagent/> activates the animation agent.

double-tag:
<set_name> X </set_name> sets the client name to X (make note this is not the same as <set_xxx>)
<set_it> X </set_it> sets the value of "it" to X
<set_location> X </set_location> sets the value of client location
<set_xxx> X </set_xxx> will create the predicate of "xxx" and set it's value to X



<srai> </srai> <sr/>

Supported in versions: AIML 1.0
Must be within: undefined
Can be within: <template>
Can contain: TSAE (<srai> form only, <sr/> must be empty)
Must Contain: <sr/> must be empty

Description:
The recursive function <srai> stands for "Stimulus-Response artificial intelligence" and means that the text between the tags should be sent recursively to the pattern matcher and the result interpreted. The resulting text replaces the original text in the markup.

<srai> X </srai> calls the pattern matcher recursively on X.
<sr/> recursive call to chat robot

<sr/> abbreviates <srai> <star/> </srai>
 

The most common application of <srai> is "symbolic reduction" of a complex sentence form to a simpler one:

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

so the botmaster can store most knowledge in the simplest categories:

<category>
<pattern>WHAT IS LINUX</pattern>
<template><set_it>Linux</set_it> is the best operating system.</template>
</category>

With all the "symbolic reduction" categories, the robot gives the same answer for:

"What is Linux?"
"Do you know what Linux is?"
"Define Linux"
"Alice please tell me what Linux is right now"

Sometimes the response consists of two symbolic reductions together:

<category>
<pattern>YES *</pattern>
<template><srai>YES</srai> <sr/></template>
</category>

With this category the robot will reply to all "Yes something" inputs by combining the reply to "Yes" with the reply to "something".
Remember, <sr/> is an abbreviation for <srai><star/></srai>.

The <srai> tag is also the answer to the question: Can I have more than one pattern in the same category? Suppose you want the same answer for two different patterns. You might think of writing something like this:

<category>
<pattern>BYE</pattern>
<pattern>GOODBYE</pattern>
<template>See you later.</template>
</category>

Right now you can't put two patterns in one category, but with <srai> you can get the same effect:

<category>
<pattern>GOODBYE</pattern> <template><srai>BYE</srai></template>
</category>

<category>
<pattern>BYE</pattern> <template>See you later.</template>
</category>

If you look through the AIML files you will see many examples of <srai> mapping multiple patterns to the same reply.

Another interesting usage of the <srai> tag is that of a "call" to another category which performs a specific task.  Here is an example of this usage in the user login.
When the user responds to the initial question What can I call you", the <srai> tag is used to call the "GET NAME GENDER" category.  The only function of this
category is to search for a match of some names, and if found set the user gender.  If no match is found, then the question "ARE YOU A MAN OR A WOMAN" is
asked.  The reason for making this an independent category is to allow this function to be called by other categories that may need to set the user gender.

<category>
<pattern>*</pattern><that>WHAT CAN I CALL YOU</that>
<template>
<think><set_personality>average</set_personality><setname/></think>
Nice to meet you <getname/>.
<srai>GET NAME GENDER</srai>
</template>
</category>

<category>
<pattern>GET NAME GENDER</pattern>
<template>
<condition name ="name">
<li value="JEB"><think><set_gender>male</set_gender></think></li>
<li value="ANDERS"><think><set_gender>male</set_gender></think></li>
<li value="ANDRE"><think><set_gender>male</set_gender></think></li>
<li value="ALLI"><think><set_gender>female</set_gender></think></li>
<li value="ALLIE"><think><set_gender>female</set_gender></think></li>
<li><br>Are you a man or a woman?</li>
</condition>
</template>
</category>



<star/>

Supported in versions: AIML 0.9 (This is a deprecated TAG)
Must be within: undefined
Can be within: <template>
Can contain: nothing
Must Contain: nothing

Description:
The <star/> tag indicates the input text fragment matching the pattern '*'.
See <star index="number"/>



<star index="number"/>

Supported in versions: AIML 1.0
Must be within: undefined
Can be within: <template>
Can contain: nothing
Must Contain: nothing

Description:
The <star index="n"/> tag indicates the input text fragment matching the "n" pattern '*'.
<star index="1"/> yields the first matching text fragment.
<star index="2"/> yields the second matching text fragment.
<star index="3"/> yields the third matching text fragment.
And so on....
The index="n" is optional, and if left off, the index value of "1" is assumed. The tag <star/> is equivilant to <star index="1"/>.

Example:
CLIENT: "Hello there, my name is Tom"

<pattern>HELLO * MY NAME IS *</pattern>
<star index="1"/> = there
<star index="2"/> = tom



<system> </system>

Supported in versions: AIML 1.0
Must be within: undefined
Can be within: <template>
Can contain: TSAE (Template-side AIML Expression)
Must Contain: could be empty

Description:
The <system>X</system> tag will run the shell command X.
The command X is assumed to produce its output in line-oriented format suitable for a BufferdReader to read line by line.

A simple example of this command in an AIML script is:

<category>
<pattern>WHAT TIME IS IT</pattern>
<template>The local time is: <system>date</system></template>
</category>

The "date" command is a system command that generates a text string containing the date and time. (Note that this might not work on Windows).

Take extreme care in using the <system> tag because it potentially permits remote clients to run a command on your system.


<template> </template>

Supported in versions: AIML 1.0
Must be within: <category>
Can be within: undefined
Can contain: TSAE (Template-side AIML Expression)
Must Contain: could be empty

Description:
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 <get_name/> 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

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

The template may also contain other embedded HTML, JAVAScript, 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, and experiment with new ideas.



<that> </that>

Supported in versions: AIML 1.0
Must be within: <category>
Can be within: undefined
Can contain: * _ NORMALIZED TEXT (PSAE)
Must Contain: could be empty

Description:
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:

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

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:

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

<category>
<pattern>*</pattern>
<that>WHO IS THERE</that>
<template><person/> Who?</template>
</category>

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

Client: KNOCK KNOCK
Robot: Who's there?
Client: BANANA
Robot: banana Who?
Client: KNOCK KNOCK
Robot: Who's there?
Client: BANANA
Robot: banana Who?
Client: KNOCK KNOCK
Robot: Who's there?
Client: ORANGE
Robot: orange Who?
Client: ORANGE YOU GLAD I DID NOT SAY BANANA
Robot: Ha ha very funny, Aol-person



<that/>

Supported in versions: AIML 1.0
Must be within: <category>
Can be within: <template>
Can contain: * _ NORMALIZED TEXT
Must Contain: NORMALIZED TEXT

Description:
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:

<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.



<that index="nx,ny"/>

Supported in versions: AIML 1.0
Must be within: UNKNOWN
Can be within: UNKNOWN
Can contain: UNKNOWN
Must Contain: UNKNOWN

Description:
This tag gives access to a previousresponse that the bot made.
<justbeforethat/> has been replaced with <that index="2,1"/>
The index="nx,ny" is optional, and if left off, the index value of "1,1" is assumed. The tag <that/> is equivilant to <that index="1,1"/>.



<thatstar/>

Supported in versions: AIML 0.9 (This is a deprecated TAG)
Must be within: undefined
Can be within: <template>
Can contain: nothing
Must Contain: nothing

Description:
The <thatstar/> tag returns the input text fragment matching the pattern '*' contained in a <that>...</that> tag set.
See <thatstar index="n"/> tag.

 



<thatstar index="n"/>

Supported in versions: AIML 1.0
Must be within: undefined
Can be within: <template>
Can contain: nothing
Must Contain: nothing

Description:
The <thatstar index="n"/> tag returns the input text fragment matching the "n" pattern '*' contained in a <that>...</that> tag set.
The index="n" is optional, and if left off, the index value of "1" is assumed. The tag <thatstar/> is equivilant to <thatstar index="1"/>.

Example:
<category>
<pattern>*</pattern> <that>WHAT IS YOUR FAVORITE *</that>
<template>
<srai>MY FAVORITE <thatstar/> IS <star/></srai>
</template>
</category>  

This category takes care of all the questions asked by the robot about favorites: "What is your favorite movie?", "What is your favorite color?", and so on, reducing the responses to a single declarative sentence.

Suppose the robot asks a number of questions like, "What kind of computer is it?"  "What kind of car is it?", "What kind of dog is it?"    Then you can capture a lot of "default" replies with the category:  
<category>
<pattern>*</pattern><that>WHAT KIND OF * IS IT</that>
<template><person/> is a
<random>
<li>pretty good</li>
<li>popular</li>
<li>decent</li>
</random> kind of <thatstar/>.
</template>
</category>

So now you can get:

Robot: What kind of computer is it?
Client: Pentium 4GHz
Robot: Pentium 4GHz is a decent kind of computer.  
Robot: What kind of car is it?
Client: VW Beetle
Robot: VW Beetle is a popular kind of car.  
and so on.


<think> </think>

Supported in versions: AIML 1.0
Must be within: UNKNOWN
Can be within: UNKNOWN
Can contain: UNKNOWN
Must Contain: UNKNOWN

Description:
The simple purpose of the <think> X </think> tag pair is to evaluate the AIML expression X, but "nullify" or hide the result from the client reply.

A simple example:

<category>
<pattern>I AM FEMALE</pattern>
<template>Thanks for telling me your gender. <think><set_gender>female</set_gender></think>
</template>
</category>

The <set_gender>female</set_gender> tag normally returns a string "female". But the <think> tag hides the text output of <set_gender>female</set_gender> from the reply, which contains only the text:

Thanks for telling me your gender.



<topic name="X"> </topic>

Supported in versions: AIML 1.0
Must be within: <aiml>
Can be within: UNKNOWN
Can contain: UNKNOWN
Must Contain: <category>

Description:
1. <topic> allows ALICE to prefer responses that deal with the topic currently being discussed. This creates topical conversation, yet still has the ability to move from one subject to another.
2. <topic> allows ALICE to have duplicate patterns in different contexts (topics) allowing ALICE to have different responses to the same input patterns depending on the topic. For example, "overriding" the " * " pattern for different topics. (I'll give an example with this.)
3. As always, you can still use the <get_topic/> tag to refer to the topic in your output statements (templates).
4. As always, you can add topics on top of all your existing AIML to keep your bot's current personality.
 

Where does the <topic> tag appear?

Topic tags are placed around one or more categories. (Usually many.) The categories (with each respective "pattern", "that", and "template") within a set of <topic> </topic> tags would be associated with the defined topic. The name of the topic would be given by a "name" property in the beginning topic tag. Here would be the full AIML format with topic:

<aiml>

<topic name="THE TOPIC">

<category>
<pattern> phrase </pattern>
<that> phrase </that>
<template> phrase </template>
</category>

</topic>

</aiml>

How do I use the <topic> tag?

The concept is that the botmaster uses the <set_topic> tags to set the current topic being discussed. Once the topic is set, when the client types in a statement for ALICE to find a response for, the categories defined within the <topic> tags matching the current topic will be searched first-- before any of the non-topic categories, or the default categories. If there is not a matching category defined in the current topic, then any categories that are not defined in topic tags are searched. As mentioned before, you can create categories with identical <pattern> phrases in different topics, each with different responses that cater to the current topic.

An proof of concept example:
A very useful topic entry might be the default "*" input for specific topics. If ALICE were set up on a pet store web site and a person was talking to ALICE about dogs, a useful entry might be:

<topic name="DOGS">

<category>
<pattern> * </pattern>
<template>
<random>
<li> Dogs are one of the most popular pets to have.</li>
<li> Have you ever met a Chihuahua you didn't like?</li>
<li> What else do you know about dogs? </li>
<li> Do you have any questions about dogs? </li>
</random>
</template>
</category>

//more dog categories....

</topic>

Normally there would be many entries in a topic, but in this example, we simply entered the default "*". In this case, if the person said something that ALICE didn't have a specific programmed response for, she could still respond intelligently within the current topic. (Note: this is all assuming there are existing categories that might set the current topic to "DOGS")

Also, though topics can only have one name, they can contain the wild characters "*" or "_" just like a pattern. Also, while sticking with the pattern criteria, only one wildcard character is allowed per name. This would allow topics like "CARING FOR DOGS" or "GROOMING DOGS" to also fall into the "_ DOGS" topic. As with patterns, the more specific topics would gain preference over the wildcarded topic. This means that if the topic is currently "GROOMING DOGS" and yet there is not a programmed response for the input in that category, then "_ DOGS" would be checked, and then next the default categories.



<topicstar/>

Supported in versions: AIML 0.9 (This is a deprecated TAG)
Must be within: undefined
Can be within: <template>
Can contain: nothing
Must Contain: nothing

Description:
The <topicstar/> tag returns the input text fragment matching the pattern '*' contained in a <topic>...</topic> tag set.
See <topicstar index="n"/> tag.



<topicstar index="n"/>

Supported in versions: AIML 1.0
Must be within: undefined
Can be within: <template>
Can contain: nothing
Must Contain: nothing

Description:
The <topicstar index="n"/> tag returns the input text fragment matching the pattern "n" '*' contained in a <topic>...</topic> tag set.
The index="n" is optional, and if left off, the index value of "1" is assumed. The tag <topicstar/> is equivilant to <topicstar index="1"/>.


<uppercase>text</uppercase>

Supported in versions: AIML 1.0
Must be within: <template>
Can be within: UNKNOWN
Can contain: UNKNOWN
Must Contain: UNKNOWN

Description:
This tag allows for word formating within the tag boundries. all upper case

Example:
<category>
<pattern>DO UPPERCASE</pattern>
<template>
This is an <uppercase>uppercase</uppercase> test.
</template>
</category>

This category will give the following output: This is an UPPERCASE test.


NORMALIZED TEXT
_, *, and <name/> (at present)

PSAE
AIML broadly breaks down into two parts: "Pattern Side AIML expressions" that can appear in the <pattern>, <that>, and <topic> and "Template-Side AIML
expressions" that appear inside the <template>.  Pattern-side AIML expressions (PSAE):

TSAE
TSAE expressions are comprised of ordinary text, optionally marked up with all the other tags.  Generally speaking, it doesn't make sense to use PSAE's in the
template or TSAE's in the pattern, topic or <that>...</that>.  The sole exception at this point is <name/>.