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!