AIML - <set>、<get> 標籤



<set><get> 標籤用於在 AIML 中使用變數。變數可以是預定義變數或程式設計師建立的變數。

語法規則

<set> 標籤用於在變數中設定值。

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

<get> 標籤用於從變數中獲取值。

<get name = "variable-name"></get>

例如,思考一下以下對話。

Human: I am Mahesh
Robot: Hello Mahesh!
Human: Good Night
Robot: Good Night Mahesh! Thanks for the conversation!

例子

C > ab > bots > test > aiml 中建立 setget.aiml,在 C > ab > bots > test > aimlif 中建立 setget.aiml.csv。

setget.aiml

<?xml version = "1.0" encoding = "UTF-8"?>
<aiml version = "1.0.1" encoding = "UTF-8"?>
   <category>
      <pattern>I am *</pattern>
      <template>
         Hello <set name = "username"> <star/>! </set>
      </template>  
   </category>  
   
   <category>
      <pattern>Good Night</pattern>
      <template>
         Hi <get name = "username"/> Thanks for the conversation!
      </template>  
   </category>  
   
</aiml>

setget.aiml.csv

0,I am *,*,*, Hello <set name = "username"> <star/>! </set>,setget.aiml
0,Good Night,*,*, Hi <get name = "username"/> Thanks for the conversation!,setget.aiml

執行程式

開啟命令提示符。轉到 C > ab >,然後鍵入以下命令 −

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

驗證結果

你將看到以下輸出 −

Human: I am Mahesh
Robot: Hello Mahesh!
Human: Good Night
Robot: Good Night Mahesh! Thanks for the conversation!
廣告
© . All rights reserved.