AIML – Basic Tags
In this tutorial, we’ll discuss the basic tags of AIML.- <aiml> − defines the beginning and end of a AIML document.
- <category> − defines the unit of knowledge in Alicebot’s knowledge base.
- <pattern> − defines the pattern to match what a user may input to an Alicebot.
- <template> − defines the response of an Alicebot to user’s input.
1
2
3
4
5
6
7
8
9
10
11
| <? xml version = "1.0" encoding = "UTF-8" ?> < aiml version = "1.0.1" encoding = "UTF-8" ?> < category > < pattern > HELLO ALICE </ pattern > < template > Hello User </ template > </ category > </ aiml > |
<aiml> tag
<aiml> tag marks the start and end of a AIML document. It contains version and encoding information under version and encoding attributes. version attribute stores the AIML version used by ALICE chatterbot Knowledge Base, KB. For example, we’ve used 1.0.1 version. This attribute is optional.Encoding attributes provide the character sets to be used in the document. For example, we’ve used UTF-8. As a mandatory requirement, <aiml> tag must contain at least one <category> tag. We can create multiple AIML files where each AIML file contains a single <aiml> tag. The purpose of each AIML file is to add at least a single knowledge unit called category to ALICE chatterbot KB.
1
2
3
| < aiml version = "1.0.1" encoding = "UTF-8" ?> ... </ aiml > |
<category> tag
<category> tag is the fundamental knowledge unit of an ALICE Bot. Each category contains −- User input in the form of a sentence which can be an assertion, question, and exclamation etc. User input can contain wild card characters like * and _.
- Response to user input to be presented by Alicebot.
- Optional context.
1
2
3
4
5
6
7
8
| < category > < pattern > HELLO ALICE </ pattern > < template > Hello User </ template > </ category > |
<pattern> tag
The <pattern> tag represents a user’s input. It should be the first tag within the <category> tag. <pattern> tag can contain wild card to match more than one sentence as user input. For example, in our example, <pattern> contains HELLO ALICE.AIML is case-insensitive. If a user enters Hello Alice, hello alice, HELLO ALICE etc., all inputs are valid and bot will match them against HELLO ALICE.
1
2
3
4
5
6
7
8
| < category > < pattern > HELLO ALICE </ pattern > < template > Hello User </ template > </ category > |
<template> tag
<template> tag represents the bot’s response to the user. It should be the second tag within the <category> tag. This <template> tag can save data, call another program, give conditional answers or delegate to other categories.
1
2
3
4
5
6
7
8
| < category > < pattern > HELLO ALICE </ pattern > < template > Hello User </ template > </ category > |
AIML – <star> Tag
<star> Tag is used to match wild card * character(s) in <pattern> Tag.Syntax
1
| < star index = "n" /> |
Consider the following example −
1
2
3
4
5
6
7
8
| < category > < pattern > A * is a *. </ pattern > < template > When a < star index = "1" /> is not a < star index = "2" />? </ template > </ category > |
Example
Create star.aiml inside C > ab > bots > test > aiml and star.aiml.csv inside C > ab > bots > test > aimlif directories.star.aiml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
| <? 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 />. </ template > </ category > < category > < pattern >A * IS A *</ pattern > < template > How < star index = "1" /> can not be a < star index = "2" />? </ template > </ category > </ aiml > |
star.aiml.csv
1
2
| 0,I LIKE *,*,*,I too like < star />.,star.aiml 0,A * IS A *,*,*,How < star index = "1" /> can not be a < star index = "2" />?,star.aiml |
Execute the Program
Open the command prompt. Go to C > ab > and type the following command −
1
| java -cp lib/Ab.jar Main bot = test action = chat trace = false |
Verify the Result
You will see the following output −
1
2
3
4
| Human: I like mango Robot: I too like mango. Human: A mango is a fruit Robot: How mango can not be a fruit? |
AIML – <srai> Tag
<srai> Tag is a multipurpose tag. This tag enables AIML to define the different targets for the same template.Syntax
1
| < srai > pattern </ srai > |
- Symbolic Reduction
- Divide and Conquer
- Synonyms resolution
- Keywords detection
Symbolic Reduction
The symbolic reduction technique is used to simplify patterns. It helps to reduce complex grammatical patterns with simple pattern(s).For example, consider the following conversation.
1
2
3
4
| Human: Who was Albert Einstein? Robot: Albert Einstein was a German physicist. Human: Who was Isaac Newton? Robot: Isaac Newton was a English physicist and mathematician. |
1
2
| Human: DO YOU KNOW WHO Albert Einstein IS? Human: DO YOU KNOW WHO Isaac Newton IS? |
Step 1: Create categories
1
2
3
4
5
6
7
8
9
| < category > < pattern >WHO IS ALBERT EINSTEIN?</ pattern > < template >Albert Einstein was a German physicist.</ template > </ category > < category > < pattern > WHO IS Isaac NEWTON? </ pattern > < template >Isaac Newton was a English physicist and mathematician.</ template > </ category > |
1
2
3
4
5
6
7
8
| < category > < pattern >DO YOU KNOW WHO * IS?</ pattern > < template > < srai >WHO IS < star /></ srai > </ template > </ category > |
Example
Create srai.aiml inside C > ab > bots > test > aiml and srai.aiml.csv inside C > ab > bots > test > aimlif directories.srai.aiml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| <? 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 Isaac NEWTON </ pattern > < template >Isaac 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 > |
star.aiml.csv
1
2
3
| 0,WHO IS ALBERT EINSTEIN,*,*,Albert Einstein was a German physicist.,srai.aiml 0,WHO IS Isaac NEWTON,*,*,Isaac Newton was a English physicist and mathematician.,srai.aiml 0,DO YOU KNOW WHO * IS,*,*,< srai >WHO IS < star /></ srai >,srai.aiml |
Execute the Program
Open the command prompt. Go to C > ab > and type the following command −
1
| java -cp lib/Ab.jar Main bot = test action = chat trace = false |
Verify the Result
You will see the following output −
1
2
| Human: Do you know who Albert Einstein is Robot: Albert Einstein was a German physicist. |
Divide and Conquer
Divide and Conquer is used to reuse sub sentences in making a complete reply. It helps to reduce defining multiple categories.For example, consider following conversation.
1
2
3
4
| Human: Bye Robot: GoodBye! Human: Bye Alice! Robot: GoodBye! |
Let’s put <srai> tag to work here.
Step 1: Create category
1
2
3
4
| < category > < pattern >BYE</ pattern > < template >Good Bye!</ template > </ category > |
1
2
3
4
5
6
7
8
| < category > < pattern >BYE *</ pattern > < template > < srai >BYE</ srai > </ template > </ category > |
Example
Update srai.aiml inside C > ab > bots > test > aiml and srai.aiml.csv inside C > ab > bots > test > aimlif directories.srai.aiml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
| <? 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 Isaac NEWTON </ pattern > < template >Isaac 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 > |
star.aiml.csv
1
2
3
4
5
| 0,WHO IS ALBERT EINSTEIN,*,*,Albert Einstein was a German physicist.,srai.aiml 0,WHO IS Isaac NEWTON,*,*,Isaac Newton was a English physicist and mathematician.,srai.aiml 0,DO YOU KNOW WHO * IS,*,*,< srai >WHO IS < star /></ srai >,srai.aiml 0,BYE,*,*,Good Bye!,srai.aiml 0,BYE *,*,*,< srai >BYE</ srai >,srai.aiml |
Execute the Program
Open the command prompt. Go to C > ab > and type the following command −
1
| java -cp lib/Ab.jar Main bot = test action = chat trace = false |
Verify the Result
You will see the following output −
1
2
3
4
| Human: Bye Robot: GoodBye! Human: Bye Alice! Robot: GoodBye! |
Synonyms Resolution
Synonyms are words with similar meanings. A bot should reply in the same manner for similar words.For example, consider the following conversation.
1
2
3
4
| Human: Factory Robot: Development Center! Human: Industry Robot: Development Center! |
Let’s put <srai> tag to work here.
Step 1: Create category
1
2
3
4
| < category > < pattern >FACTORY</ pattern > < template >Development Center!</ template > </ category > |
1
2
3
4
5
6
7
8
| < category > < pattern >INDUSTRY</ pattern > < template > < srai >FACTORY</ srai > </ template > </ category > |
Example
Update srai.aiml inside C > ab > bots > test > aiml and srai.aiml.csv inside C > ab > bots > test > aimlif directories.srai.aiml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
| <? 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 Isaac NEWTON </ pattern > < template >Isaac 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 > |
star.aiml.csv
1
2
3
4
5
6
7
| 0,WHO IS ALBERT EINSTEIN,*,*,Albert Einstein was a German physicist.,srai.aiml 0,WHO IS Isaac NEWTON,*,*,Isaac Newton was a English physicist and mathematician.,srai.aiml 0,DO YOU KNOW WHO * IS,*,*,< srai >WHO IS < star /></ srai >,srai.aiml 0,BYE,*,*,Good Bye!,srai.aiml 0,BYE *,*,*,< srai >BYE</ srai >,srai.aiml 0,FACTORY,*,*,Development Center!,srai.aiml 0,INDUSTRY,*,*,< srai >FACTORY</ srai >,srai.aiml |
Execute the Program
Open the command prompt. Go to C > ab > and type the following command −
1
| java -cp lib/Ab.jar Main bot = test action = chat trace = false |
Verify the Result
You will see the following output −
1
2
3
4
| Human: Factory Robot: Development Center! Human: Industry Robot: Development Center! |
Keywords Detection
Using srai, we can return a simple response when the user types a specific keyword, say, School, no matter where “school” is present in the sentence.For example, consider the following conversation.
1
2
3
4
| 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. |
Let’s put <srai> tag to work here. We’ll use wild-cards here.
Step 1: Create category
1
2
3
4
| < category > < pattern >SCHOOL</ pattern > < template >School is an important institution in a child's life.</ template > </ category > |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
| < 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 > |
Example
Update srai.aiml inside C > ab > bots > test > aiml and srai.aiml.csv inside C > ab > bots > test > aimlif directories.srai.aiml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
| <? 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 Isaac NEWTON </ pattern > < template >Isaac 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 > |
star.aiml.csv
1
2
3
4
5
6
7
8
9
10
11
| 0,WHO IS ALBERT EINSTEIN,*,*,Albert Einstein was a German physicist.,srai.aiml 0,WHO IS Isaac NEWTON,*,*,Isaac Newton was a English physicist and mathematician.,srai.aiml 0,DO YOU KNOW WHO * IS,*,*,< srai >WHO IS < star /></ srai >,srai.aiml 0,BYE,*,*,Good Bye!,srai.aiml 0,BYE *,*,*,< srai >BYE</ srai >,srai.aiml 0,FACTORY,*,*,Development Center!,srai.aiml 0,INDUSTRY,*,*,< srai >FACTORY</ srai >,srai.aiml 0,SCHOOL,*,*,School is an important institution in a child's life.,srai.aiml 0,_ SCHOOL,*,*,< srai >SCHOOL</ srai >,srai.aiml 0,SCHOOL *,*,*,< srai >SCHOOL</ srai >,srai.aiml 0,_ SCHOOL *,*,*,< srai >SCHOOL</ srai >,srai.aiml |
Execute the Program
Open the command prompt. Go to C > ab > and type the following command −
1
| java -cp lib/Ab.jar Main bot = test action = chat trace = false |
Verify the Result
You will see the following output −
1
2
3
4
| 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. |
AIML – <random> Tag
<random> Tag is used to get random responses. This tag enables AIML to respond differently for the same input. <random> tag is used along with <li> tags. <li> tags carry different responses that are to be delivered to the user on a random basis.Syntax
1
2
3
4
5
6
| < random > < li > pattern1 </ li > < li > pattern2 </ li > ... < li > patternN </ li > </ random > |
1
2
3
4
| Human: Hi Robot: Hello! Human: Hi Robot: Hi! Nice to meet you! |
Example
Create random.aiml inside C > ab > bots > test > aiml and random.aiml.csv inside C > ab > bots > test > aimlif directories.random.aiml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| <? 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 > < category > </ aiml > |
random.aiml.csv
1
| 0,HI,*,*, < random >< li > Hello! </ li >< li > Hi! Nice to meet you! </ li ></ random >,random.aiml |
Execute the Program
Open the command prompt. Go to C > ab > and type the following command −
1
| java -cp lib/Ab.jar Main bot = test action = chat trace = false |
Verify the Result
You will see the following output −
1
2
3
4
| Human: Hi Robot: Hi! Nice to meet you! Human: Hi Robot: Hello! |
AIML – <set>, <get> Tags
<set> and <get> tags are used to work with variables in AIML. Variables can be predefined variables or programmer created variables.Syntax
<set> tag is used to set value in a variable.
1
| < set name = "variable-name" > variable-value </ set > |
1
| < get name = "variable-name" ></ get > |
1
2
3
4
| Human: I am Mahesh Robot: Hello Mahesh! Human: Good Night Robot: Good Night Mahesh! Thanks for the conversation! |
Example
Create setget.aiml inside C > ab > bots > test > aiml and setget.aiml.csv inside C > ab > bots > test > aimlif directories.setget.aiml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
| <? 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 > |
setget.aiml.csv
1
2
| 0,I am *,*,*, Hello < set name = "username" > < star />! </ set >,setget.aiml 0,Good Night,*,*, Hi < get name = "username" /> Thanks for the conversation!,setget.aiml |
Execute the Program
Open the command prompt. Go to C > ab > and type the following command −
1
| java -cp lib/Ab.jar Main bot = test action = chat trace = false |
Verify the Result
You will see the following output −
1
2
3
4
| Human: I am Mahesh Robot: Hello Mahesh! Human: Good Night Robot: Good Night Mahesh! Thanks for the conversation! |
AIML – <that> Tag
<that> Tag is used in AIML to respond based on the context.Syntax
1
| < that > template </ that > |
1
2
3
4
| Human: Hi Alice! What about movies? Robot: Do you like comedy movies? Human: No Robot: Ok! But I like comedy movies. |
Example
Create that.aiml inside C > ab > bots > test > aiml and that.aiml.csv inside C > ab > bots > test > aimlif directories.that.aiml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
| <? xml version = "1.0" encoding = "UTF-8" ?> < aiml version = "1.0.1" encoding = "UTF-8" ?> < category > < pattern >WHAT ABOUT 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 > |
that.aiml.csv
1
2
3
| 0,WHAT ABOUT MOVIES,*,*,Do you like comedy movies,that.aiml 0,YES,Do you like comedy movies,*,Nice! I like comedy movies too.,that.aiml 0,NO,Do you like comedy movies,*,Ok! But I like comedy movies.,that.aiml |
Execute the Program
Open the command prompt. Go to C > ab > and type the following command −
1
| java -cp lib/Ab.jar Main bot = test action = chat trace = false |
Verify the Result
You will see the following output −
1
2
3
4
| Human: What about movies? Robot: Do you like comedy movies? Human: No Robot: Ok! But I like comedy movies. |
AIML – <topic> Tag
<topic> Tag is used in AIML to store a context so that later conversation can be done based on that context. Usually, <topic> tag is used in Yes/No type conversation. It helps AIML to search categories written within the context of the topic.Syntax
Define a topic using <set> tag
1
2
3
| < template > < set name = "topic" > topic-name </ set > </ template > |
1
2
3
4
5
| < topic name = "topic-name" > < category > ... </ category > </ topic > |
1
2
3
4
5
6
| 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. |
Example
Create topic.aiml inside C > ab > bots > test > aiml and topic.aiml.csv inside C > ab > bots > test > aimlif directories.topic.aiml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
| <? 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 > |
that.aiml.csv
1
2
3
| 0,LET DISCUSS MOVIES,*,*,Yes < set name = "topic" >movies</ set >,topic.aiml 0,*,*,movies,Watching good movie refreshes our minds.,topic.aiml 0,I LIKE WATCHING COMEDY!,*,movies,I like comedy movies too.,topic.aiml |
Execute the Program
Open the command prompt. Go to C > ab > and type the following command −
1
| java -cp lib/Ab.jar Main bot = test action = chat trace = false |
Verify the Result
You will see the following output −
1
2
3
4
5
6
| 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. |
AIML – <think> Tag
<think> Tag is used in AIML to store a variable without notifying the user.Syntax
Store a value using <think> tag
1
2
3
| < think > < set name = "variable-name" > variable-value </ set > </ think > |
1
2
3
4
| Human: My name is Mahesh Robot: Hello! Human: Byeee Robot: Hi Mahesh Thanks for the conversation! |
Example
Create think.aiml inside C > ab > bots > test > aiml and think.aiml.csv inside C > ab > bots > test > aimlif directories.think.aiml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
| <? 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 > |
think.aiml.csv
1
2
| 0,My name is *,*,*, Hello! < think >< set name = "username" > < star /></ set ></ think >,think.aiml 0,Byeee,*,*, Hi < get name = "username" /> Thanks for the conversation!,think.aiml |
Execute the Program
Open the command prompt. Go to C > ab > and type the following command −
1
| java -cp lib/Ab.jar Main bot = test action = chat trace = false |
Verify the Result
You will see the following output −
1
2
3
4
| Human: My name is Mahesh Robot: Hello! Human: Byeee Robot: Hi Mahesh Thanks for the conversation! |
AIML – <condition> Tag
<condition> Tag is similar to switch statements in programming language. It helps ALICE to respond to the matching input.Syntax
1
| < condition name = "variable-name" value = "variable-value" /> |
1
2
| Human: How are you feeling today Robot: I am happy! |
Example
Create condition.aiml inside C > ab > bots > test > aiml and condition.aiml.csv inside C > ab > bots > test > aimlif directories.condition.aiml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
| <? 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 > |
condition.aiml.csv
1
2
3
4
5
6
7
| 0,HOW ARE YOU FEELING TODAY,*,*, < 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 >,condition.aiml |
Execute the Program
Open the command prompt. Go to C > ab > and type the following command −
1
| java -cp lib/Ab.jar Main bot = test action = chat trace = false |
Verify the Result
You will see the following output −
1
2
| Human: How are you feeling today Robot: I am happy! |
No comments:
Post a Comment