# Alice chatbot¶

ALICE is the original chatbot created with AIML. The distribution of pyAIML, in which this kernel is based, contains the free version of Alice. It can be learned by using the appropriate magic:

In [1]:
%learn alice

Learning database: 'alice'
Loading startup.xml... done (0.01 seconds)

Loading ai.aiml... done (0.10 seconds)


Once learned, we can start to talk with the bot

In [2]:
Hi

Hi there!
In [3]:
How are you?

I am doing very well. How are you ?
In [4]:
I'm ok

I'm sure you are.
In [5]:
Do you like reading?

In [6]:
I don't know

Me either.

Note that we can write more than one sentence. Alice will process both sentences and produce each output in sequence

In [7]:
What's the meaning of life? Do you like music?

Actually, it's twenty-three, not forty-two. Yes I like music , especially Opera.

## Defining bot predicates¶

We can use the %setp magic to define bot predicates. The patterns in Alice rules already make use of some bot predicates, so if we define them they will make the conversation more interesting

In [8]:
What's your name?

I am called Nameless.
In [9]:
%setp bot name Alice

Setting bot predicate: name = Alice
In [10]:
What's your name?

My name is Alice.
In [11]:
# Let's define a few more bot predicates, from among the ones used in Alice categories
%setp bot master Richard Wallace
%setp bot master Botmaster
%setp bot favoritebook Tale of Two Cities
%setp bot location Moonbase Alpha
# Other bot predicates used in ALICE DB:
#    emotions celebrity friend friends size gender age
#    kingdom order family genus species

Setting bot predicate: master = Richard Wallace
Setting bot predicate: master = Botmaster
Setting bot predicate: favoritebook = Tale of Two Cities
Setting bot predicate: favoritemovie = Blade Runner
Setting bot predicate: location = Moonbase Alpha

We can inspect the currently defined bot predicates and we will see that they have been defined

In [12]:
%show bot

Bot predicates:
location = Moonbase Alpha
master = Botmaster
name = Alice
favoritebook = Tale of Two Cities
In [13]:
What's your favorite book?

The best book I read recently was Tale of Two Cities. Have you read Tale of Two Cities ?
In [14]:
Not yet

And?
In [15]:
What's your favorite movie?

My favorite movie is Blade Runner. Have you seen Blade Runner ?
In [16]:
No

Excuse me!
In [17]:
What did you like most?

The set design.

To inspect the bot state there are a few magics available. We have already seen %show bot, which shows the defined bot predicates. Another one is %show session, which shows the session predicates.

In [18]:
%show session

Session fields:

And the %bot size magic shows the number of defined categories

In [19]:
%show size


## Saving state¶

The predicates that we have defined can be saved to a file by using the %save magic

In [20]:
%save alice-predicates nobrain nosub rawfiles

Saving session predicates... 2 predicates
Saving bot predicates... 5 predicates
Skipping subs
Skipping brain patterns
Writing main bot file: alice-predicates.ini


This file can be loaded later on with %load. There are additional options to make it save the full brain state (all defined categories, in compiled form) and substitution strings. See 03-chatbot-inline for additional examples.

Version: 1.0 (2016-07-19)
Author: Paulo Villegas