{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Defining AIML categories inline\n", "\n", "Instead of loading an external AIML DB, it is also possible to create a bot from scratch by executing notebook cells containing AIML code. This notebook offers a few examples." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Full AIML\n", "\n", "The most direct procedure is to add a fully-compliant [AIML](http://www.alicebot.org/TR/2001/WD-aiml/) document in a cell, preceded by the `%aiml` magic. This magic must be present alone in the first cell line, save for comment lines, i.e. lines starting with `#` (which are ignored).\n", "\n", "The XML preamble is optional; if missing it will be added automatically. Encoding is always UTF-8" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
Loaded 3 new patterns
" ], "text/plain": [ "Loaded 3 new patterns\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%aiml\n", "# Receiving a greeting and answering back\n", "\n", "\n", "\n", " \n", " # The \"good NNN\" greeting allows us to infer the time of the day\n", " \n", " GOOD *\n", " \n", " \n", "\n", " # A Hello greeting is less defining\n", " \n", " HELLO\n", " \n", " \n", "\n", " # This is the template creating the greeting response\n", " \n", " HI\n", " \n", " \n", "\n", "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "There can also be comment lines within the AIML document; they are ignored (of course, given that AIML is XML, we can also add comments as XML comments)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Test it" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
Good morning
" ], "text/plain": [ "Good morning\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "Good morning" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
Good morning
" ], "text/plain": [ "Good morning\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "Hello" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can inspect the session predicates, to check the \"*tod*\" (time-of-day) predicate that was (supposedly) assigned" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
Session fields:
tod = morning
" ], "text/plain": [ "Session fields:\n", " tod = morning\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%show session" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Simplified AIML\n", "\n", "Given that XML is rather verbose, a slightly simplified syntax is also possible by removing the outer wrapper tags: ``, ``, ``, `