AIML入门程序

在这章中,我们来学习如何创建一个机器人,当用户键入Hello Alice时,它能简单地用Hello User问候用户。

创建项目结构

与在AIML环境设置中一样,基于以下目录结构(D:/software/ab)。

序号目录描述说明
1D:/software/ab/bots存储AIML机器人
2D:/software/ab/lib存储Java库
3D:/software/ab/outJava类文件目录
4D:/software/ab/run.bat用于运行Program AB 的批处理文件

接下来,在D:/software/ab/bots中创建一个目录:test,并在test目录中创建以下子目录。

序号目录描述说明
1D:/software/ab/bots/test/aiml存储AIML文件
2D:/software/ab/bots/test/aimlif存储AIMLIF文件
3D:/software/ab/bots/test/config存储配置文件
4D:/software/ab/bots/test/sets存储AIML设置文件
5D:/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:

如下图所示