# The AIML Chatbot kernel¶

The AIML Chatbot kernel wraps the pyAIML Python library to create a conversational bot within a notebook. The bot behaviour is defined by loading AIML categories. A "category" in AIML is akin to a rule, and defines a pattern-template pair

Input cells are messages for the bot, which get interpreted and the bot output is the result of the cell execution. Additionally, a few magics for both control (cells starting with apercent sign) are available; these are not passed to the bot as user messages, but executed to change the bot behaviour in some way.

## First steps¶

On an empty bot there is nothing to do (the bot does not produce any output, since it does not have rules to work with). So when creating an (empty) AIML notebook, any input cell will just return the general help message

In [1]:
Hello

AIML Chatbot

%learn alice | standard | <dbdirectory> | <xml-file>

For "alice" & "standard" databases, the rules will
automatically be activated. For a custom database,
you will need to launch the "load <name>" command
defined in it.

Once loaded, you can start chatting with the bot.

Use "%lsmagic" to see all the available magics.

## Getting help¶

This same help message can also be obtained at any time by using the %help magic command

In [2]:
%help

AIML Chatbot

%learn alice | standard | <dbdirectory> | <xml-file>

For "alice" & "standard" databases, the rules will
automatically be activated. For a custom database,
you will need to launch the "load <name>" command
defined in it.

Once loaded, you can start chatting with the bot.

Use "%lsmagic" to see all the available magics.

And the %lsmagics command lists all available magics with their meaning

In [3]:
%lsmagics

Available magics:
%aiml %forget %help %learn %load %lsmagics %save %setp %show bot %show session %show size

%forget : reset the bot
%help : show general help
%learn alice | standard | <dbdirectory> | <xml-file> : learn an AIML db
%lsmagics : list all magics
%save <name> : save bot state to a file
%setp [bot] <name> <value> : set a predicate, or a bot predicate
%show bot : show the defined bot predicates
%show session : show the predicates defined in the session
%show size : show the number of categories loaded in the bot

## Learning¶

The most important of these magics is %learn, which loads an AIML database into the bot.

There are three versions for that:

1. Learning a predefined database: use %learn alice or %learn standard. AIML categories defined in the DB will be automatically loaded.
2. Learning a custom database: use %learn <directory> where directory is a directory containing a set of AIML files to learn, plus an startup.xml file referencing them. A load <name> command is needed afterwards to load the learned rules into the bot
3. Learning a single AIML file: use %learn <file.xml> or %learn <file.aiml>

See 02-chatbot-alice.ipynb for an example of the first type.

An additional way of creating rules is by writing them directly in notebook cells, using the %aiml magic. Such rules are immediately added to the bot when the cell is executed. You can:

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