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.