Aiml-topic-tag
提供:Dev Guides
AIML-<topic>タグ
*<topic>* タグはAIMLでコンテキストを保存するために使用され、そのコンテキストに基づいて後の会話を行うことができます。 通常、 *<topic>* タグは* Yes/Noタイプの会話*で使用されます。 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>ボット>テスト> aiml* およびtopic.aiml.csv内にtopic.aimlを *C> ab>ボット> test> aimlif* ディレクトリ内に作成します。
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.