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.
廣告
© . All rights reserved.