--------------------[ Aine Language Tutorial ]---------------------
"Everything should be as simple as it is, but not simpler."
- Albert Einstein
ainebot consists of several programs which provide a distinct
interface to the ainebot 'brain'. The 'brain' consists of several
files, some of which are compiled or 'binary-encoded' for better
bot performance. The brain is compiled from source files which are
written in the Aine Language. Aine Language is based on the AIML
language ( www.alicebot.org ), which uses the XML format. Compared
to AIML, Aine Language is easier to read, more compact and includes
extra features and 'tags' which are not included in AIML. Still,
Aine Language is similar to AIML, so that if you already know how
to edit or create AIML files, you should have no trouble grasping
the Aine Language.
This tutorial covers only the basics of programming in Aine
Language, but you can learn more by looking at ready-made *.aine
files. The ainebot distribution includes one complete bot
'personality', Amy, which is based on the Anna personality, which
was based on the original 'A.L.I.C.E.' used by the C-Alice program.
--------------------------------------------------------------------
The 'raw' Aine Language files use a very simple format consisting of
two types of entries, what the user says to the bot and what the bot
will reply. In AIML, each pair of lines is referred to as a
'category'. What the user inputs is referred to as a 'pattern'
and what the bot responds is called the 'template'. A typical AIML
category has the following form:
WHAT THE USER SAYS
What the bot will reply
The same 'category' in Aine Language is simpler to write and read:
+[WHAT THE USER SAYS]
-[What the bot will reply]
user input (everything in +[HERE] ) *must* be in UPPERCASE letters.
Learning by example:
1) HELLO BOT
--------------------------------------------------------------------
The simplest example of Aine Language code.
+[HELLO BOT.]
-[Hello human!]
This will work exactly as above:
+[HELLO BOT]
-[Hello human!]
See Section 8 for notes on using punctuation in input and output.
2) Wildcards
--------------------------------------------------------------------
Wildcard characters are supported and can be used in both
input and output, with some limitations. Up to 10 'stars' can be
used in the input and can be placed before, after or among the
textual content of the input 'category'.
+[HELLO *]
-[Hi there.]
'*' - stands for the input text fragment matching the pattern '*'.
So taking the above example, if the user says to the bot:
"hello bot" or "hello aine" or "hello nice aine" or "hello anything
here", the bot will reply "Hi there."
The other wildcard character is the underscore: '_'. It functions
much the same as the '*' wildcard, except patterns which use the
underscore have first priority when matched to the input. It can
only be used in input 'patterns'.
When using 'stars' in the output 'template', they are written as
a 'tag' with enclosing less-than/greater-than characters: <*>
3) Random Responses
--------------------------------------------------------------------
The tags means "random" and tells the bot to choose a random
answer from a list of items. Each item in the list is enclosed
between and tags.
+[HI]
-[Hello!Hi.Hi there.
]
If the user says "Hi", the bot will choose a random reply: "Hello!",
"Hi." or "Hi there.". Most Aine Language 'tags' use both an opening
and a closing tag -in the same way that AIML or other 'markup'
languages do. Note that even though we are indenting the code for
easier reading, the aine-compiler ignores such formatting when
parsing the *.aine files to produce the compiled brain.
4) Recursion
--------------------------------------------------------------------
The ainebot interpreters can perform 'recursive' operations. This
means that the output of the 'category' gets used as input for
another category. Recursion is the most powerful tool in ainebot
and provides the basis for creating Aine Language code which is able
to simplify or 'reduce' many similar inputs so that they all get
answered by a single category. In AIML, the recursion tags are
and . Aine Language simplifies this by using { and }.
+[I AM VERY SLEEPY]
-[{I AM SLEEPY}]
+[I AM SLEEPY]
-[Maybe you should take a nap.]
{THIS} call is recursive. So, if the user says: "I am very sleepy",
the bot will answer "Maybe you should take a nap.".
Another example of recursion:
+[PLEASE TELL ME MORE ABOUT *]
-[{TELL ME MORE ABOUT <*>}]
+[TELL ME MORE ABOUT *]
-[{TELL ME ABOUT <*>}]
+[TELL ME ABOUT *]
-[{<*>}]
+[APPLE]
-[Apple is a fruit. But Apple is also a computer company.]
Now, if the user says "Please tell me more about apple", or
"Tell me more about apple" or "tell me about apple", the bot will
reply "Apple is a fruit. But Apple is also a computer company."
See Section 10 below for how to use multiple-choice patterns to
eliminate most recursive categories.
5) Operations on variables
--------------------------------------------------------------------
shows the value of the a_variable in output. If the
variable is not initialized - it will show ' ' (space).
David sets variable "name" to "David"
Example:
+[MY NAME IS DAVID]
-[Nice to meet you David.]
+[WHAT IS MY NAME]
-[As far as I remember, your name is .]
More advanced example:
+[MY NAME IS *]
-[Nice to meet you <*>.]
Note that the tag is a single tag which uses no
closing tag. The tag must be used with a closing
tag. Everything between the and tags
is assigned to the variable a_variable. You can use any variable
names you like, but there are several standard variable names
whose values are usually set during startup of the program by
reading them from the file defvars.txt. Variables which are found
in the defvars.txt file are saved when the ainebot interpreter
is shutdown.
6) Keeping track of conversation with 'that' tags
--------------------------------------------------------------------
Imagine this conversation:
bot: Hi user. What is your name?
user: Agnes.
How bot will match "Agnes" with the name? By using a category with
a 'that' tag which contains the last response from the bot:
+[*]WHAT IS YOUR NAME?
-[Nice to meet you <*>.
If WHAT IS HERE matches the previous bot reply - this
category will be used to respond to the user, while setting the
variable 'name' to the value input by the user. You can also use
the wildcard '*' inside the 'that' tags. You can also use '\' in
the tag to perform a partial match:
\SOMETHING
will search in the last bot output for the string SOMETHING. The
last reply doesn't have to be equal to word "something", it only
has to contain the word "something". (Partial matching is not
available in the standard AIML language.)
7) Conditional replies
--------------------------------------------------------------------
Another powerful tool in the Aine Language is the ability to choose
the reply based on 'conditions' -much like 'if ... then ... else'
statements used in other programming languages. Condition tags match
the value of variable names shown above. The response is chosen
according to a list of values, each with a different response.
The format is:
first replysecond reply*Optional* default reply
Example:
-[You are quite
attractive. handsome. ... huh.. wait, what is your gender?
]
Here, the value of the variable 'gender' is matched against the
values from each list item. If 'gender' is set to female the bot
responds: 'You are quite attractive.' If 'gender' is male the bot
replys: 'You are quite handsome.' If the variable 'gender' has not
been set with any value, the bot will answer: 'You are quite ...
huh.. wait, what is your gender?'
Each item in the list is enclosed bewteen and tags. The
default response uses simply as the opening tag, or you can
also use ...
8) Punctuation
--------------------------------------------------------------------
Inside the user input tag (+[INPUT]) the period '.' is the default
"end character" so you don't have to type it. The period also
matches the '?' and '!' characters and no end character at all.
+[HELLO BOT]
-[Hello human!]
If the user inputs "Hello bot", "Hello bot.", "Hello bot?" or
"Hello bot!" the bot will reply "Hello human!". This behaviour is
the same as with AIML.
However, Aine Language allows you to distinguish between input which
ends in a period, a question mark or an exclamation point. Input
'patterns' which end in a question mark ('?') *only* match response
'templates' with a question mark. The same goes for input patterns
which end with an exclamation point '!'.
In Aine Language you can write:
+[YOUR NAME?]
-[My name is .]
and
+[YOUR NAME]
-[What's with my name?]
If user asks your bot "Your name?" the bot will reply to the
question. If, in the user input, there isn't an question mark, the
second category will get used (with output "What's with my name?").
Punctuation can be freely used in output 'templates' (-[Output]).
9) Comparison between AIML and Aine Language
--------------------------------------------------------------------
Since Aine Language is based on AIML. Let's look at an example
written both ways:
HELLO MY NAME IS *
Hi, nice too meet you
MY NAME IS
Code in Aine Language which does exactly the same:
+[HELLO MY NAME IS *]
[Hi, nice to meet you <*>{MY NAME IS <*>}]
As you can see: Aine Language is much more readable -at least the
developers think so. Less typing = less work. Less file size = less
wasted time to skim them, less wasted time to search for something
in them, etc. ainebot=better bot
If you already know AIML, you will quickly find yourself in Aine
Language. There is no tag in Aine Language. There is no
need for it. Here's a comparison table of the Aine Language tags
which differ from their AIML counterparts:
Aine Language AIML
---------------------------------------------------------
+[ ]
-[ ]
(in condition code)
{ } /think>
("h" means "Hide")
<*>
<*=2>
<*=3> (up to *=9) yawnyawnyawnyawn
Tags which are the same in both AIML and Aine Language:
See Section 11 'Advanced tags' for further explanation of some of
these tags whose usage is not so obvious or is different from the
usage in standard AIML.
10) Aine Language extensions
--------------------------------------------------------------------
Aine Language supports some features and tags which are not available
in the standard AIML language and its' interpreters. In addition to
the support for distinguishing input punctuated with '?' or '!'
marks, as mentioned in Section 8, ainebot has a 'mood' which can
be affected by the users' input. It also supports the and
tags which are helpful for 'picking up' the conversation
with the user. And it supports multiple-choice patterns.
Using mood tags:
----------------
Mood values are used inside tags and look like this:
where A=Arousal, V=Valence and S=Stance. You can think of 'valence'
as standing for 'happiness-sadness', 'stance' standing for
'sympathy-anger' and 'arousal' as standing for the level of
excitement-motivation. (The AVS values are based on those used by
MIT's facial-expression robot, Kismet.) Each aspect of the bots'
mood can have a value from 0 to 9.
Initial mood values can be set in the defvar.txt file read at
program startup. Then, the bots' mood can be changed while running
by placing code in the *.aine files to increase or decrease any,
or all, of the values, according to the situation. By default
the values are all set to 5 at program startup.
If Arousal = 0, Aine is very bored.
If Arousal = 9, Aine is very excited.
If Valence = 0, Aine is very sad.
If Valence = 9, Aine is very happy.
If Stance = 0, Aine is very stern or mad at user.
If Stance = 9, Aine likes user very much and is more accepting.
In the CGI version of aine, the bot will even stop responding to user
when the bot feels 'angry'.
Mood can be change by "mood changer" tag:
+[I DO NOT LIKE YOU]
-[Ok, I will not like you too./=54]
/=555 means no change to any mood value
/=545 means happiness -1
/=565 means happiness +1
/=567 means happiness +1; sympathy + 2;
/=355 means arousal -2
Imagine this exchange:
+[I HATE YOU]
-[Why do you hate me?/=444]
This tells the bot to decrease each of the AVS values by 1.
+[I'M SORRY]
-[Well, that makes me a little happier./=565]
This tells the bot to increase the value of V (happiness) by 1.
Values are 'normalized' after each response so that:
(9 + anything) = 9
(0 - anything) = 0
Accessing the values is done from inside the 'random' tags:
+[WHAT IS YOUR MOOD]
-[Indifferent.I am very happy. :-)I am very happy.I am OK. :-)I am sad...Get lost...I don't think you really care about my mood...
]
When the user asks: "What is your mood?", the response is still
chosen randomly, but if the bot is sad there are far more chances
that it will reply "I am sad".
Using and tags:
---------------------------------
The pair of tags can be used to store a 'pickup'
response which can be used to help keep the conversation going,
by 'recalling' the saved response using the tag.
Suppose you have the following 'category' which gets matched when
the user asks "Are you a robot?":
+[I LIKE TO CHAT WITH CHAT BOTS]
-[Why do you like chatting with chat bots? :)
I see. You are not the only one :)
]
(The sentence between tags won't be showed to
the user. It will be just put on a stack of "emergency answers".)
+[HMM]
-[Huh?]
+[*]
-[Could you rephrase it?I don't understand youNot many people express in that way.
]
(The user is saying something and the bot doesn't know how
to reply. But instead of a silly default reply, it will reply
from the stack of "use/usesaved" replies (if there are any).
An example conversation:
Me: I like to chat with chat bots.
Bot: I see. You are not the only one.
Me: hmm.
Bot: Huh?
Me: You know, bots are boring, they don't really understand people.
Without