AIML - <条件> 标签


<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。

条件目标

<?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>

条件.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!