AIML - <condition> 标签
<condition> 标签类似于编程语言中的 switch 语句。它帮助 ALICE 响应匹配的输入。
语法
<condition name = "variable-name" value = "variable-value"/>
例如,考虑以下对话。
Human: How are you feeling today Robot: I am happy!
在这里,我们将 happy 存储为 ALICE 的状态,这就是它响应"我很开心!"的方式。
示例
在 C > ab > bots > test > aiml 目录中创建 condition.aiml,并在 C > ab > bots > test > aimlif 目录中创建 condition.aiml.csv。
condition.aiml
<?xml version = "1.0" encoding = "UTF-8"?>
<aiml version = "1.0.1" encoding = "UTF-8"?>
<category>
<pattern> HOW ARE YOU FEELING TODAY </pattern>
<template>
<think><set name = "state"> happy</set></think>
<condition name = "state" value = "happy">
I am happy!
</condition>
<condition name = "state" value = "sad">
I am sad!
</condition>
</template>
</category>
</aiml>
condition.aiml.csv
0,HOW ARE YOU FEELING TODAY,*,*,
<think>
<set name = "state"> happy</set>
</think>
<condition name = "state" value = "happy">I am happy!</condition>
<condition name = "state" value = "sad">I am sad!</condition>,condition.aiml
执行程序
打开命令提示符。转到 C > ab > 并输入以下命令 −
java -cp lib/Ab.jar Main bot = test action = chat trace = false
验证结果
您将看到以下输出 −
Human: How are you feeling today Robot: I am happy!

