AIML <think>標籤


<think>標籤在AIML中用於儲存變數而不通知使用者。

語法

使用<think>標記儲存值 -

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

例如,請考慮以下對話。

Human: My name is Mahesh
Robot: Hello!
Human: Byeee
Robot: Hi Mahesh Thanks for the conversation!

範例

D:/software/ab/bots/test/aiml目錄中建立一個檔案:think.aiml,並在D:/software/ab/bots/test/aimlif目錄中建立一個檔案:think.aiml.csv

檔案:think.aiml

<?xml version = "1.0" encoding = "UTF-8"?>
<aiml version = "1.0.1" encoding = "UTF-8"?>
   <category>
      <pattern>My name is *</pattern>
      <template>
         Hello!<think><set name = "username"> <star/></set></think>
      </template>  
   </category>  

   <category>
      <pattern>Byeee</pattern>
      <template>
         Hi <get name = "username"/> Thanks for the conversation!
      </template>  
   </category>  

</aiml>

檔案:think.aiml.csv -

0,My name is *,*,*, Hello! <think><set name = "username"> <star/></set></think>,think.aiml
0,Byeee,*,*, Hi <get name = "username"/> Thanks for the conversation!,think.aiml

執行程式

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

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

執行上面範例程式碼,得到以下結果 -

Human: My name is Mahesh
Robot: Hello!
Human: Byeee
Robot: Hi Mahesh Thanks for the conversation!