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.