AIML 标签

AIML topic标签

<topic>标签在AIML中用于存储上下文,以便以后的对话可以基于该上下文完成。 通常,<topic>标签用于是/否类型对话。 它有助于AIML搜索在主题上下文中编写的类别。

语法

使用<set>标记定义主题 -

<template> 
   <set name = "topic"> topic-name </set>
</template>

使用<topic>标记定义类别 -

<topic name = "topic-name">
   <category>
      ...
   </category>     
</topic>

例如,请考虑以下对话。

Human: let discuss movies
Robot: Yes movies
Human: Comedy movies are nice to watch
Robot: Watching good movie refreshes our minds.
Human: I like watching comedy
Robot: I too like watching comedy.

这里的机器人以“movies”为主题。

示例

D:/software/ab/bots/test/aiml目录中创建一个文件:topic.aiml,并在D:/software/ab/bots/test/aimlif目录中创建一个文件:topic.aiml.csv

文件:topic.aiml

<?xml version = "1.0" encoding = "UTF-8"?>
<aiml version = "1.0.1" encoding = "UTF-8"?>
   <category>
      <pattern>LET DISCUSS MOVIES</pattern>
      <template>Yes <set name = "topic">movies</set></template>  
   </category>

   <topic name = "movies">
      <category>
         <pattern> * </pattern>
         <template>Watching good movie refreshes our minds.</template>
      </category>

      <category>
         <pattern> I LIKE WATCHING COMEDY! </pattern>
         <template>I like comedy movies too.</template>
      </category>

   </topic>
</aiml>

文件:topic.aiml.csv -

0,LET DISCUSS MOVIES,*,*,Yes <set name = "topic">movies</set>,topic.aiml
0,*,*,movies,Watching good movie refreshes our minds.,topic.aiml
0,I LIKE WATCHING COMEDY!,*,movies,I like comedy movies too.,topic.aiml

执行程序

打开命令提示符。 进入目录:D:/software/ab 并键入以下命令 -

java -cp lib/Ab.jar Main bot = test action = chat trace = false

执行上面示例代码,得到以下结果 -

Human: let discuss movies
Robot: Yes movies
Human: Comedy movies are nice to watch
Robot: Watching good movie refreshes our minds.
Human: I like watching comedy
Robot: I too like watching comedy.