AIML入門程式


在這章中,我們來學習如何建立一個機器人,當使用者鍵入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:

如下圖所示 -