1、基本标签
<aiml>:定义在AIML文件的开头和结尾。 它包含在版本和编码属性的版本和编码信息。
<category>:定义unit ofknowledge中Alicebot的知识库。每个类别包含在一个句子的形式,用户输入可以是一个断言,问题和感叹号等用户的输入可以包含通配符的字符,如*和_。用<category>标签必须有<pattern>和<template>标记。
<pattern>:定义图案什么用户可输入匹配到Alicebot。
<template> :定义一个Alicebot的用户的输入的响应。<template>标签可以保存数据,可以调用另一个程序,能够给条件答案或委托给其他类别。
《例子的使用方式:打开命令提示符,cd到工程目录下,在工程目录下执行是:
java -cp lib/Ab.jar Main bot = test action= chat trace = false》
2、<*> :用于匹配通配符*character(s)在<pattern>标签。
例子:
<category><pattern> A * is a *.</pattern>
<template>When a <starindex="1"/> is not a <star index="2"/>?</template>
</category>
human:A mango is a fruit.
Robot:When a mango is nota fruit?
3、<random> :用于获取随机响应。
4、<li> :用来表示多个响应。
例子:
<?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>
Human: Hi
Robot: Hi! Nice to meet you!
Human: Hi
Robot: Hello!
5、<set> :使用在AIML变量设定值。
6、<get> :用于获取存储在AIML变量的值。
例子:
<?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>GoodNight</pattern>
<template>Hi <getname="username"/> Thanks for the conversation!</template>
</category>
</aiml>
Human: I am Mahesh
Robot: Hello Mahesh!
Human: Good Night
Robot: Good Night Mahesh! Thanks for theconversation!
7、<that> :在AIML用于应对基于上下文。表示先前机器人说的话。
例子:
<?xml version="1.0"encoding="UTF-8"?>
<aiml version="1.0.1"encoding="UTF-8"?>
<category><pattern>WHAT ABOUTMOVIES</pattern>
<template>Do you like comedymovies</template>
</category>
<category><pattern>YES</pattern>
<that>Do you like comedymovies</that>
<template>Nice, I like comedy moviestoo.</template>
</category>
<category><pattern>NO</pattern>
<that>Do you like comedymovies</that>
<template>Ok! But I like comedymovies.</template>
</category>
</aiml>
Human: What about movies?
Robot: Do you like comedy movies?
Human: No
Robot: Ok! But I like comedy movies.
即:如果机器人先前问用户“一起聊聊电影好吗?”,而且现在用户回答了“好”,那么匹配正确,回复内容为:“那你喜欢什么电影那?”
8、<topic> :用于AIML存储上下文,这样以后可以谈话基于这一背景下进行。
例子:
<?xml version="1.0"encoding="UTF-8"?>
<aiml version="1.0.1"encoding="UTF-8"?>
<category><pattern>LET DISCUSSMOVIES</pattern>
<template>Yes <setname="topic">movies</set></template>
</category>
<topic name="movies">
<category><pattern> *</pattern>
<template>Watching good movierefreshes our minds.</template>
</category>
<category>
<pattern> I LIKE WATCHING COMEDY!</pattern>
<template>I like comedy moviestoo.</template>
</category>
</topic>
</aiml>
Human: let discuss movies
Robot: Yes movies
Human: Comedy movies are nice to watch
Robot: Watching good movie refreshes ourminds.
Human: I like watching comedy
Robot: I too like watching comedy.
9、<think>:用于AIML存储变量不通知用户。
例子:
<?xml version="1.0"encoding="UTF-8"?>
<aiml version="1.0.1"encoding="UTF-8"?>
<category><pattern>My name is*</pattern>
<template>Hello!<think><setname="username"> <star/></set></think></template>
</category>
<category><pattern>Byeee</pattern>
<template>Hi <getname="username"/> Thanks for the conversation!</template>
</category>
</aiml>
Human: My name is Mahesh
Robot: Hello!
Human: Byeee
Robot: Hi Mahesh Thanks for theconversation!
10、<condition>:类似的切换在编程语言语句。 它有助于ALICE来匹配输入作出响应。
例子:
<?xml version="1.0"encoding="UTF-8"?>
<aiml version="1.0.1" encoding="UTF-8"?>
<category><pattern> HOW ARE YOUFEELING TODAY </pattern>
<template><think><setname="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>
Human: How are you feeling today
Robot: I am happy!
11、<srai>:多用途标签,用来调用其它/匹配的类别。(符号缩减、分而治之、同义词分辨率、关键词检测)
例子:
<?xml version="1.0"encoding="UTF-8"?>
<aiml version="1.0.1"encoding="UTF-8"?>
<category><pattern> WHO ISALBERT EINSTEIN </pattern>
<template>Albert Einstein was agerman physicist.</template>
</category>
<category><pattern> WHO ISIsaac NEWTON </pattern>
<template>Isaac Newton was a englishphysicist and mathematician.</template>
</category>
<category><pattern>DO YOU KNOWWHO * 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>DevelopmentCenter!</template>
</category>
<category><pattern>INDUSTRY</pattern>
<template><srai>FACTORY</srai></template>
</category>
<category><pattern>SCHOOL</pattern>
<template>School is an importantinstitution 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>
Human: I love going to school daily.
Robot: School is an important institutionin a child's life.
Human: I like my school.
Robot: School is an important institutionin a child's life.
12、<upcase>xiaoxie</upcase>元素用来把xiaoxie转换成大写形式:XIAOXIE
13、<system><system>元素表示调用系统函数,例如:<system>date</system>表示取系统当前日期。
14、<sentence>元素用来格式化句子,比如:<sentence>this is some kind ofsentence test.</sentence>可以格式化成:This is some kind of sentence test.即把句子首字母大写。
15、<pattern>表示匹配模式,里面的内容必须大写,可以有星号* 或下划线_,但必须空格隔开,星号表示匹配所有,任意情况;下划线的意义跟星号一样,除了不能匹配字典里面Z后面的字母。
16、<lowcase></lowcase>表示把中间的内容变成小写,对应的是<upcase>把内容变成大写
中文无效。
17、<learenfilename=”xxx.aiml”>元素表示让机器人学习某个aiml文件。
18、<if>元素,判断元素,有以下形式:<if name="topic"value="cars"></if> <if name="topic"contains="cars"></if> <if name="topic"exists="true"></if>
19、<formal>元素,用来格式化输出,例如:<formal>jon baer</formal>那么回复将被格式化成首字母大写输出:Jon Baer,对中文无效。
20、<NUM/>元素,匹配数字
21、约束匹配模式
<category>
<pattern that="你好">你好啊</pattern>
<template>
<random><li>你好,我们刚刚说过一遍了。</li>
<li>你好,客气啥!</li>
</random></template> </category>
上述示例中,并不会直接命中”你好啊“,而是在上一次是匹配的”你好“,当又匹配了”你好啊“才会命中上述category,即上次和当前次的连续匹配。
注:匹配优先级别分别是文字>#>^
参考链接:http://www.w3ii.com/zh-CN/aiml/default.html
http://blog.csdn.net/woowindice/article/details/302298