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 > aimlC > ab > bots > test > aimlif 目錄內建立 condition.aiml 和 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!
廣告
© . All rights reserved.