AIML框架 初探
創(chuàng)建一個(gè) aiml_main.py 文件
AIML由Richard Wallace發(fā)明。他設(shè)計(jì)了一個(gè)名為 A.L.I.C.E. (Artificial Linguistics Internet Computer Entity 人工語(yǔ)言網(wǎng)計(jì)算機(jī)實(shí)體) 的機(jī)器人,并獲得了多項(xiàng)人工智能大獎(jiǎng)。AIML是一種為了匹配模式和確定響應(yīng)而進(jìn)行規(guī)則定義的 XML 格式。(摘自網(wǎng)絡(luò))
學(xué)習(xí)AIML框架之前,需要先了解 XML標(biāo)記語(yǔ)言。
XML:可擴(kuò)展標(biāo)記語(yǔ)言,為的是存儲(chǔ)數(shù)據(jù)
HTML:超文本標(biāo)記語(yǔ)言,為的是渲染頁(yè)面,展示數(shù)據(jù)。
AIML的安裝
安裝:pip install aiml
aiml的官網(wǎng)學(xué)習(xí)地址:https://www.tutorialspoint.com/aiml/index.htm
aiml_main.py是入口文件,啟動(dòng)aiml_main.py首先加載的是std-startup.xml文件,
std-startup.xml文件加載的是標(biāo)簽內(nèi)的語(yǔ)料庫(kù)
aiml_main.py 源碼
import aimlkernel = aiml.Kernel() #創(chuàng)建一個(gè)kernel對(duì)象 kernel.learn("std-startup.xml") #配置文件,入口文件,可以配置很多語(yǔ)料庫(kù) kernel.respond("load aiml b")while True:print(kernel.respond(input("請(qǐng)輸入你的問題>>")))std-startup.xml 源碼
創(chuàng)建 std-startup.xml 文件
<aiml version = "1.0.1" encoding = "UTF-8"><category> <!--aiml中元子級(jí)別的單元,--><pattern>LOAD AIML B</pattern ><!--template 是一個(gè)響應(yīng)的模板--><!--learn 里邊要配置一個(gè)aiml文件,learn標(biāo)簽可以是多個(gè) --><template><learn>basic_chat.aiml</learn></template></category></aiml>basic_chat.aiml 源碼
創(chuàng)建 basic_chat.aiml 文件
<aiml version = "1.0.1" encoding = "UTF-8"><category><pattern>* 你 * HELLO *</pattern><template>oh hello!!!</template></category><category><pattern>* YOU *</pattern><template>fine thank you!</template></category><category><pattern>我的名字是李雷</pattern><template>my name is hanmeimei</template></category></aiml>源碼里面埋了一個(gè)小小的坑,期待大家的發(fā)現(xiàn)
皮一下很開心!嘿嘿嘿,o( ̄︶ ̄)o
總結(jié)
- 上一篇: Linux抓包命令集锦(tcpdump抓
- 下一篇: 基于AIML2.0写一个机器人