AIML应答机器人(一)aiml简介
文章列表
AIML應(yīng)答機(jī)器人(一)aiml簡介
AIML應(yīng)答機(jī)器人(二)java實(shí)現(xiàn)
想做一款和上圖一樣的自動(dòng)應(yīng)答機(jī)器人嗎,跟著博客,咱們一步步實(shí)現(xiàn),現(xiàn)在開始第一個(gè)內(nèi)容,簡單了解下什么是AIML語言
AIML
????????AIML:人工智能標(biāo)記語言(Artificial Intelligence Markup Language)
????????AIML(人工智能標(biāo)記語言)是一種XML兼容的語言,很容易學(xué)習(xí),并且可以開始定制艾爾博特(Alicebot)或分分鐘創(chuàng)建一個(gè)scratch機(jī)器人。AIML最重要的單元有:
????????開始和結(jié)束一個(gè)AIML文檔的標(biāo)簽(tag)
????????標(biāo)志著一個(gè)艾爾博特知識(shí)庫(Alicebot's knowledge base)的“知識(shí)單元”標(biāo)簽<</font>類別>
????????用于包含匹配用戶給艾爾博特(an Alicebot)機(jī)器人可以說或鍵入字符的一個(gè)簡單模式(simple pattern)<<font face="宋體">模式>
????????包含對(duì)用戶輸入(user input)的響應(yīng)<<font face="宋體">模板>
AIML文件中經(jīng)常發(fā)現(xiàn)有20個(gè)左右或附加多個(gè)標(biāo)簽(tags),創(chuàng)建自己所謂“自定義謂詞(custom predicates)”是可能的。現(xiàn)在,AIML Primer提供一個(gè)AIML初學(xué)者指南。免費(fèi)Alice機(jī)器人人工智能標(biāo)記語言(The free Alice機(jī)器人 AIML)包括一個(gè)約41000分類的知識(shí)庫(knowledge base)
舉例:
<?xml version="1.0" encoding="UTF-8"?> <aiml><category><pattern>今天天氣挺好*</pattern><template>是嗎?我這里下雨了。要是沒下雨,我就出去玩了!</template></category><category><pattern>_天氣_</pattern><template>url:http://wap.baidu.com/s?word=<star index="1" />天氣</template></category><category><pattern>_百度下_</pattern><template>url:http://wap.baidu.com/s?word=<star index="2" /></template></category></aiml>????以上片段再加上html的支持,就可以實(shí)現(xiàn)查詢天氣,與百度內(nèi)容
????下面簡單介紹下,每個(gè)標(biāo)簽的用法,含義,如果大家心急,可以先跳過這一步,直接去第二篇博客進(jìn)行系統(tǒng)搭建了。
標(biāo)簽
1、基本標(biāo)簽
????<aiml>:定義在AIML文件的開頭和結(jié)尾。 它包含在版本和編碼屬性的版本和編碼信息。
????<category>:定義unit ofknowledge中Alicebot的知識(shí)庫。每個(gè)類別包含在一個(gè)句子的形式,用戶輸入可以是一個(gè)斷言,問題和感嘆號(hào)等用戶的輸入可以包含通配符的字符,如*和_。用<category>標(biāo)簽必須有<pattern>和<template>標(biāo)記。
????<pattern>:定義圖案什么用戶可輸入匹配到Alicebot。
????<template> :定義一個(gè)Alicebot的用戶的輸入的響應(yīng)。<template>標(biāo)簽可以保存數(shù)據(jù),可以調(diào)用另一個(gè)程序,能夠給條件答案或委托給其他類別。
2、<*> :用于匹配通配符*character(s)在<pattern>標(biāo)簽。
???
3、<random> :用于獲取隨機(jī)響應(yīng)。
4、<li> :用來表示多個(gè)響應(yīng)。
6、<get> :用于獲取存儲(chǔ)在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>7、<that> :在AIML用于應(yīng)對(duì)基于上下文。表示先前機(jī)器人說的話。
<?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存儲(chǔ)上下文,這樣以后可以談話基于這一背景下進(jìn)行。
?<?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存儲(chǔ)變量不通知用戶。
<?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來匹配輸入作出響應(yīng)。
?<?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>:多用途標(biāo)簽,用來調(diào)用其它/匹配的類別。(符號(hào)縮減、分而治之、同義詞分辨率、關(guān)鍵詞檢測(cè))
?<?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轉(zhuǎn)換成大寫形式:XIAOXIE
13、<system><system>元素表示調(diào)用系統(tǒng)函數(shù),例如:<system>date</system>表示取系統(tǒng)當(dāng)前日期。
14、<sentence>元素用來格式化句子,比如:<sentence>this is some kind ofsentence test.</sentence>可以格式化成:This is some kind of sentence test.即把句子首字母大寫。
15、<pattern>表示匹配模式,里面的內(nèi)容必須大寫,可以有星號(hào)* 或下劃線_,但必須空格隔開,星號(hào)表示匹配所有,任意情況;下劃線的意義跟星號(hào)一樣,除了不能匹配字典里面Z后面的字母。
16、<lowcase></lowcase>表示把中間的內(nèi)容變成小寫,對(duì)應(yīng)的是<upcase>把內(nèi)容變成大寫
?????????? 中文無效。
17、<learenfilename=”xxx.aiml”>元素表示讓機(jī)器人學(xué)習(xí)某個(gè)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>那么回復(fù)將被格式化成首字母大寫輸出:Jon Baer,對(duì)中文無效。
20、<NUM/>元素,匹配數(shù)字
21、約束匹配模式
<category><pattern that="你好">你好啊</pattern><template><random>
????????????<li>你好,我們剛剛說過一遍了。</li>
????????????<li>你好,客氣啥!</li>
????</random>
????</template>
</category>
上述示例中,并不會(huì)直接命中”你好啊“,而是在上一次是匹配的”你好“,當(dāng)又匹配了”你好啊“才會(huì)命中上述category,即上次和當(dāng)前次的連續(xù)匹配總結(jié)
以上是生活随笔為你收集整理的AIML应答机器人(一)aiml简介的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Linux系统下安装Tomcat8
- 下一篇: AIML教程