<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!
示例
在D:/software/ab/bots/test/aiml
目录中创建一个文件:setget.aiml
,并在D:/software/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
执行程序
打开命令提示符。 进入到目录:D:/software/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!