Skip to content

Instantly share code, notes, and snippets.

@manojrammurthy
Last active August 29, 2015 14:22
Show Gist options
  • Select an option

  • Save manojrammurthy/9b6dfc641f2d51cf648b to your computer and use it in GitHub Desktop.

Select an option

Save manojrammurthy/9b6dfc641f2d51cf648b to your computer and use it in GitHub Desktop.
AIML Description is done here
AIML stands for Artificial Intelligence Modelling Language. AIML is XML based markup language meant to create artificial intelligent application to create human interface while keeping the implementation simple to program, easy to understand and highly maintainable.
AIML was developed by the Alicebot free software community and Dr. Richard S. Wallace during 1995-2000.
<AIML>= BEGINNING OF aiml FILE
<CATEGORY>=IT DEFINES A UNIT OF KNOWLEDGE
<PATTERN>=DEFINES a pattern to match what a user may input to bot
<TEMPLATE>= defines a pattern of response of bot to user
</TEMPLATE>
</PATTERN>
</CATEGORY>
</AIML>
<STAR> = used to match wildcard characters in pattern tag
<srai> its a multipurpose tag used to call match the category
<random> used to get random responses
<li> used to get multiple responses
<set> used to set the value in aiml variable
<get> used to get the value stored in the aiml variable
<that>used in aiml based on context
<topic>Used in AIML to store a context so that later conversation can be done based on that context.
<think> Used in AIML to store a variable without notifying the user.
<condition> Similar to switch statements in programming language. It helps ALICE to respond to matching input.
setting the condition
like setting the state of the bot to be happy or sad etc
<?xml version="1.0" encoding="UTF-8"?>
<aiml version="1.0.1" encoding="UTF-8"?>
<category>
<pattern> HOW ARE YOU FEELING TODAY </pattern>
<template>
<think><set name="state"> happy</set></think>
<condition name="state" value="happy">
I am happy!
</condition>
<condition name="state" value="sad">
I am sad!
</condition>
</template>
</category>
</aiml>
as the name suggests random tag is used to get random responses for the same input
usually random tags are associated with li tags
li tags will be having different patterns
<random>
<li>pattern1</li>
<li>pattern2</li>
<li>pattern3</li>
.
.
.<li>patternN</li>
</random>
example:
<?xml version="1.0" encoding="UTF-8"?>
<aiml version="1.0.1" encoding="UTF-8"?>
<category>
<pattern>HI</pattern>
<template>
<random>
<li> Hello! </li>
<li> Hi! Nice to meet you! </li>
</random>
</template>
</aiml>
set and get tags are used to create user defined or programme defined variables
<set name = "variable-name"> variable-value </set> is used to set the variable
<get name ="variable-name"></get> is used to get the variable
<?xml version="1.0" encoding="UTF-8"?>
<aiml version="1.0.1" encoding="UTF-8"?>
<category>
<pattern>I am *</pattern>
<template>
Hello <set name="username"> <star/>! </set>
</template>
</category>
<category>
<pattern>Good Night</pattern>
<template>
Hi <get name="username"/> Thanks for the conversation!
</template>
</category>
</aiml>
example :
Human: I am Mahesh
Robot: Hello Mahesh!
Human: Good Night
Robot: Good Night Mahesh! Thanks for the conversation!
It helps to reduce defining multiple categories.
example= bye
bot = goodbye
example = bye manoj
bot goodbye
here bot is supposed to say goodbye when it encounters bye at the starting of the message .
1) general category
<category>
<pattern>BYE</pattern>
<template>Good Bye!</template>
</category>
2)generating generic category using srai
<category>
<pattern>BYE *</pattern>
<template>
<srai>BYE</srai>
</template>
</category>
<?xml version="1.0" encoding="UTF-8"?>
<aiml version="1.0.1" encoding="UTF-8"?>
<category>
<pattern> WHO IS ALBERT EINSTEIN </pattern>
<template>Albert Einstein was a german physicist.</template>
</category>
<category>
<pattern> WHO IS ISSAC NEWTON </pattern>
<template>Issac Newton was a english physicist and mathematician.</template>
</category>
<category>
<pattern>DO YOU KNOW WHO * IS</pattern>
<template>
<srai>WHO IS <star/></srai>
</template>
</category>
<category>
<pattern>BYE</pattern>
<template>Good Bye!</template>
</category>
<category>
<pattern>BYE *</pattern>
<template>
<srai>BYE</srai>
</template>
</category>
</aiml>
no matter where the word is in a pattern bot should output a specific template
example:
Human: I love going to school daily.
Robot: School is an important institution in a child's life.
Human: I like my school.
Robot: School is an important institution in a child's life.
step1: create category
<category>
<pattern>SCHOOL</pattern>
<template>School is an important institution in a child's life.</template>
</category>
step2: create generic category
<category>
<pattern>_ SCHOOL</pattern>
<template>
<srai>SCHOOL</srai>
</template>
</category>
<category>
<pattern>_ SCHOOL</pattern>
<template>
<srai>SCHOOL</srai>
</template>
</category>
<category>
<pattern>SCHOOL *</pattern>
<template>
<srai>SCHOOL</srai>
</template>
</category>
<category>
<pattern>_ SCHOOL *</pattern>
<template>
<srai>SCHOOL</srai>
</template>
</category>
<?xml version="1.0" encoding="UTF-8"?>
<aiml version="1.0.1" encoding="UTF-8"?>
<category>
<pattern> WHO IS ALBERT EINSTEIN </pattern>
<template>Albert Einstein was a german physicist.</template>
</category>
<category>
<pattern> WHO IS ISSAC NEWTON </pattern>
<template>Issac Newton was a english physicist and mathematician.</template>
</category>
<category>
<pattern>DO YOU KNOW WHO * IS</pattern>
<template>
<srai>WHO IS <star/></srai>
</template>
</category>
<category>
<pattern>BYE</pattern>
<template>Good Bye!</template>
</category>
<category>
<pattern>BYE *</pattern>
<template>
<srai>BYE</srai>
</template>
</category>
<category>
<pattern>FACTORY</pattern>
<template>Development Center!</template>
</category>
<category>
<pattern>INDUSTRY</pattern>
<template>
<srai>FACTORY</srai>
</template>
</category>
<category>
<pattern>SCHOOL</pattern>
<template>School is an important institution in a child's life.</template>
</category>
<category>
<pattern>_ SCHOOL</pattern>
<template>
<srai>SCHOOL</srai>
</template>
</category>
<category>
<pattern>_ SCHOOL</pattern>
<template>
<srai>SCHOOL</srai>
</template>
</category>
<category>
<pattern>SCHOOL *</pattern>
<template>
<srai>SCHOOL</srai>
</template>
</category>
<category>
<pattern>_ SCHOOL *</pattern>
<template>
<srai>SCHOOL</srai>
</template>
</category>
</aiml>
a bot should reply in same manner for similiar words.
example: Industry
bot: development center
example: factory
bot: development center
step1: create category
<category>
<pattern>FACTORY</pattern>
<template>Development Center!</template>
</category>
step2: create generic category
<category>
<pattern>INDUSTRY</pattern>
<template>
<srai>FACTORY</srai>
</template>
</category>
<?xml version="1.0" encoding="UTF-8"?>
<aiml version="1.0.1" encoding="UTF-8"?>
<category>
<pattern> WHO IS ALBERT EINSTEIN </pattern>
<template>Albert Einstein was a german physicist.</template>
</category>
<category>
<pattern> WHO IS ISSAC NEWTON </pattern>
<template>Issac Newton was a english physicist and mathematician.</template>
</category>
<category>
<pattern>DO YOU KNOW WHO * IS</pattern>
<template>
<srai>WHO IS <star/></srai>
</template>
</category>
<category>
<pattern>BYE</pattern>
<template>Good Bye!</template>
</category>
<category>
<pattern>BYE *</pattern>
<template>
<srai>BYE</srai>
</template>
</category>
<category>
<pattern>FACTORY</pattern>
<template>Development Center!</template>
</category>
<category>
<pattern>INDUSTRY</pattern>
<template>
<srai>FACTORY</srai>
</template>
</category>
</aiml>
<srai> pattern </srai>
srai is used for symbol reduction , divide and conquere, synomyns resolution, keywords detection
symbolic reduction = it helps complex grammatical patterns with simple patterns
<category>
<pattern>WHO IS ALBERT EINSTEIN?</pattern>
<template>Albert Einstein was a german physicist.</template>
</category>
<category>
<pattern> WHO IS ISSAC NEWTON? </pattern>
<template>Issac Newton was a english physicist and mathematician.</template>
</category>
create generic category using srai
<category>
<pattern>DO YOU KNOW WHO * IS?</pattern>
<template>
<srai>WHO IS <star/></srai>
</template>
</category>
<?xml version="1.0" encoding="UTF-8"?>
<aiml version="1.0.1" encoding="UTF-8"?>
<category>
<pattern> WHO IS ALBERT EINSTEIN </pattern>
<template>Albert Einstein was a german physicist.</template>
</category>
<category>
<pattern> WHO IS ISSAC NEWTON </pattern>
<template>Issac Newton was a english physicist and mathematician.</template>
</category>
<category>
<pattern>DO YOU KNOW WHO * IS</pattern>
<template>
<srai>WHO IS <star/></srai>
</template>
</category>
</aiml>
example = do you know who albert einstein is
bot = Albert Einstein was a german physicist
<category>
<pattern> A * is a *. </pattern>
<template>
When a <star index="1"/> is not a <star index="2"/>?
</template>
</category>
<?xml version="1.0" encoding="UTF-8"?>
<aiml version="1.0.1" encoding="UTF-8"?>
<category>
<pattern>I LIKE *</pattern>
<template>
I too like <star/>. ((<star index="1"/> is often used as <star />))
</template>
</category>
<category>
<pattern>A * IS A *</pattern>
<template>
How <star index="1"/> can not be a <star index="2"/>?
</template>
</category>
</aiml>
example = i like mango
bot = i too like mango
example = mango is a fruit
bot = how mango can not be a fruit
that tag is used to respond based on the context
<?xml version="1.0" encoding="UTF-8">
<aiml version="1.0.1" encoding="UTF-8">
<category>
<pattern>what about the movies</pattern>
<template>do you like comedy movies</template>
</category>
<category>
<pattern>yes</pattern>
<that>do you like comedy movies</that>
<template>Nice, i like comedy movies too </template>
</category>
<category>
<pattern>no</pattern>
<that> do you like comedy movies</that>
<template> ok, but i like comedy movies</template>
</category>
</aiml>
so based on the above aiml responses would be
Human: What about movies?
Robot: Do you like comedy movies?
Human: No
Robot: Ok! But I like comedy movies.
<think> <set name="variable-name"> variable-value </set></think>
<?xml version="1.0" encoding="UTF-8"?>
<aiml version="1.0.1" encoding="UTF-8"?>
<category>
<pattern>My name is *</pattern>
<template>
Hello!<think><set name="username"> <star/></set></think>
</template>
</category>
<category>
<pattern>Byeee</pattern>
<template>
Hi <get name="username"/> Thanks for the conversation!
</template>
</category>
</aiml>
example output :
Human: My name is Mahesh
Robot: Hello!
Human: Byeee
Robot: Hi Mahesh Thanks for the conversation!
in aiml topic tag is used to store context for future conversation
example :
<?xml version="1.0" encoding="UTF-8"?>
<aiml version="1.0.1" encoding="UTF-8"?>
<category>
<pattern>LET DISCUSS MOVIES</pattern>
<template>Yes <set name="topic">movies</set></template>
</category>
<topic name="movies">
<category>
<pattern> * </pattern>
<template>Watching good movie refreshes our minds.</template>
</category>
<category>
<pattern> I LIKE WATCHING COMEDY! </pattern>
<template>I like comedy movies too.</template>
</category>
</topic>
</aiml>
Human: let discuss movies
Robot: Yes movies
Human: Comedy movies are nice to watch
Robot: Watching good movie refreshes our minds.
Human: I like watching comedy
Robot: I too like watching comedy.
@parthsood
Copy link

Good job, Manoj!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment