-
Notifications
You must be signed in to change notification settings - Fork 135
AIML Tutorial
All AIML files start the same way, with an XML declaration and a root level tag
<?xml version="1.0" encoding="UTF-8"?>
<aiml version="2.0">
</aiml>
When you boil it down to the basics, all AIML interactions are made up of 2 parts, a question and an answer. Each interaction is called a 'category', the question is a 'pattern' and the 'answer' is a template. These take the form like
<?xml version="1.0" encoding="UTF-8"?>
<aiml version="2.0">
<category>
<pattern>HELLO</pattern>
<template>Hi there!</template>
<category>
</aiml>
AIML uses the pattern to match the incoming text you type into Y-Bot, and if it finds a match it executes and prints out the template. Running the bot with the above grammar and entering Hello as a question will show the following response
Loading, please wait...
No bot root argument set, defaulting to [/Users/keithsterling/Documents/Development/Python/Projects/AIML/program-y/bots/y-bot]
Y-Bot version 0.0.1, initiated March 14, 2017
Hi, how can I help you today?
>>> Hello
Hi there!
>>>
You can build a lot of simple questions and answers with this form, but it becomes unmanageable when you get to very large numbers. You end up repeating yourself and trying to guess every possible combination of a question someone might ask.
To solve this problem AIML comes with power pattern matching capabilities. Instead of including every possible world in every possible combination, an AIML developer uses special syntax which can be used to match one or more words. This allows the AIML developer to focus on the core aspects of the question.
The purpose of this is to allow the developer to ignore the unimportant parts of the question and focus only on the core aspects. As with most languages there many different ways to ask the question, but most are just variantions on a core theme. This is where pattern matching helps.
These matching operators are
- Priority. Matches the exact word specified by proceeding the word with a $
- 0 or more. Matches 0 or more words in a sequence. Can be either # or ^ depending upon precedence preference
- 1 or more. Matches 1 or more words in a sequence. Can be either _ or * depending upon precedence preference
- Sets. Matches a word as a member of a specific set. Sets are files of words, each file contains one set, such as colours or numbers.
- ISet. Similar to sets but, but the members are contained inline to the AIML
- Bot. Matches a word again a bot predicate, such as bot name, age, location etc
- Regex. Matches a one-word regular expression
For more information on pattern matching and operator precedence see Pattern Matching
In terms of precedence, the parser checks for each type of matching in a specific order defined by the following rules
Precedence
$ Priority
# 0 or more
_ 1 or more
word
set
iset
bot
regex
word
^ 0 or more
* 1 or more
Pattern Regex
<regex>^[a-z]$</regex>
<regex pattern="^[a-z]$" />
Template Regex
<regex template="telephone_number" />
<category>
<pattern>HELLO</pattern>
<that>WELCOME</that>
<template>Hi there, again!</template>
<category>
<category>
<pattern>HELLO</pattern>
<topic>GREETINGS</topic>
<template>Hi there, again!</template>
<category>
<bot name="someproperty" />
<set name="someproperty">somevalue</set>
<get name="someproperty" />
<set var="somevar">somevalue</set>
<get var="somevar" />
date
interval
id
program
size
vocabulary
input
request
response
star
topicstar
thatstar
sr
File based
Inbuilt
Dynamic
lowercase
uppercase
sentence
formal
normalize
denormalize
person
person2
gender
implode
explode
first
rest
log
learn
resetlearn
leanrf
resetlearnf
triples
add triples
delete triple
select
uniq
SRAIX
Search
system
See here for a full list of all Pattern Tags
See here for a full list of all Template Tags
Email: [email protected] | Twitter: @keiffster | Facebook: keith.sterling | LinkedIn: keithsterling | My Blog
- Home
- Background
- Guiding Principles
- Reporting an Issue
- Installation
- You And Your Bot
- Bots
- Clients
- Configuration
- AIML
- Sentence Splitting
- Natural Langauge Processing
- Normalization
- Spelling
- Sentiment Analysis
- Translation
- Security
- Hot Reload
- Logging
- Out of Band
- Multi Language
- RDF Support
- Rich Media
- Asynchronous Events
- Triggers
- External Services
- Dynamic Sets, Maps & Vars
- Extensions
- Pre & Post Processors
- Custom Nodes
- The Brain Tree
- Utilities
- Building It Yourself
- Creating Your Own Bot
- Contributing
- Performance Testing
- FAQ
- History
- Website