AIML <condition>標記

<condition>標籤類似於編程語言中的switch語句。 它有助於ALICE響應匹配的輸入。

語法

<condition name = "variable-name" value = "variable-value"/>

例如,請考慮以下對話。

Human: How are you feeling today
Robot: I am happy!

在這裏,我們將happy存放爲ALICE的狀態,看看它是如何響應「I am happy!」。

示例

D:/software/ab/bots/test/aiml目錄中創建一個文件:condition.aiml,並在D:/software/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

執行程序

打開命令提示符。 進入目錄:D:/software/ab 並鍵入以下命令 -

java -cp lib/Ab.jar Main bot = test action = chat trace = false

執行上面示例代碼,得到以下結果 -

Human: How are you feeling today
Robot: I am happy!