在這章中,我們來學習如何創建一個機器人,當用戶鍵入Hello Alice
時,它能簡單地用Hello User
問候用戶。
創建專案結構
與在AIML環境設置中一樣,基於以下目錄結構(D:/software/ab
)。
序號 | 目錄 | 描述說明 |
---|---|---|
1 | D:/software/ab/bots |
存儲AIML機器人 |
2 | D:/software/ab/lib |
存儲Java庫 |
3 | D:/software/ab/out |
Java類檔目錄 |
4 | D:/software/ab/run.bat |
用於運行Program AB 的批處理檔 |
接下來,在D:/software/ab/bots
中創建一個目錄:test
,並在test
目錄中創建以下子目錄。
序號 | 目錄 | 描述說明 |
---|---|---|
1 | D:/software/ab/bots/test/aiml |
存儲AIML檔 |
2 | D:/software/ab/bots/test/aimlif |
存儲AIMLIF檔 |
3 | D:/software/ab/bots/test/config |
存儲配置檔 |
4 | D:/software/ab/bots/test/sets |
存儲AIML設置檔 |
5 | D:/software/ab/bots/test/maps |
存儲AIML映射 |
創建原始檔案
在D:/software/ab/bots/test/aiml
目錄中創建:test.aiml
檔,以及在D:/software/ab/bots/test/aimlif
目錄中創建:test.aiml.csv
檔。
檔:test.aiml -
<?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>
檔:test.aiml.csv -
0,HELLO ALICE,*,*,Hello User,test.aiml
執行程式
打開命令提示符,轉到目錄:D:/software/ab
並鍵入以下命令 -
D:/software/ab> java -cp lib/Ab.jar Main bot = test action = chat trace = false
驗證結果
執行上面命令後,將會看到以下輸出 -
D:\software\ab>java -cp lib/Ab.jar Main bot=test action=chat trace=false
Working Directory = D:\software\ab
Program AB 0.0.4.2 beta -- AI Foundation Reference AIML 2.0 implementation
bot=test
action=chat
trace=false
trace mode = false
Name = test Path = D:\software\ab/bots/test
D:\software\ab
D:\software\ab/bots
D:\software\ab/bots/test
D:\software\ab/bots/test/aiml
D:\software\ab/bots/test/aimlif
D:\software\ab/bots/test/config
D:\software\ab/bots/test/logs
D:\software\ab/bots/test/sets
D:\software\ab/bots/test/maps
Preprocessor: 0 norms 0 persons 0 person2
Get Properties: D:\software\ab/bots/test/config/properties.txt
Loading AIML Sets files from D:\software\ab/bots/test/sets
Loading AIML Map files from D:\software\ab/bots/test/maps
AIML modified Thu Dec 20 21:16:03 CST 2018 AIMLIF modified Thu Dec 20 21:16:17 CST 2018
No deleted.aiml.csv file found
No deleted.aiml.csv file found
Loading AIML files from D:\software\ab/bots/test/aimlif
Loaded 1 categories in 0.007 sec
--> Bot test 1 completed 0 deleted 0 unfinished
(1[6])--HELLO-->(1[5])--ALICE-->(1[4])--<THAT>-->(1[3])--*-->(1[2])--<TOPIC>-->(1[1])--*-->(0[null,null]) Hello User...
7 nodes 6 singletons 1 leaves 0 shortcuts 0 n-ary 6 branches 0.85714287 average branching
輸入Hello Alice
並查看結果,然後鍵入其他任何內容以查看更改的結果。
Human: hello alice
Robot: Hello User
Human: bye
Robot: I have no answer for that.
Human:
如下圖所示 -
上一篇:
AIML環境安裝設置
下一篇:
AIML基本標籤