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.


此处机器人以"电影"为主题进行回应.

示例

C > ab > bots > test > aiml 中创建topic.aiml 和在C > 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>


that.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


执行程序

打开命令提示符.转到 C> 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.