- AIML 教程
- AIML - 主页
- AIML - 简介
- AIML - 环境设置
- AIML - 第一个应用程序
- AIML - 基本标签
- AIML - <star> 标签
- AIML - <set> 标签
- AIML - <random> 标签
- AIML - <set>、<get> 标签
- AIML - <that> 标签
- AIML - <topic> 标签
- AIML - <think> 标签
- AIML - <condition> 标签
- AIML 实用资源
- AIML - 快速指南
- AIML - 实用资源
- 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.
机器人在这里将“电影”作为话题进行回答。
示例
在 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.
广告