< set> 和< get> 标记用于处理AIML中的变量.变量可以是预定义变量或程序员创建的变量.
< set> tag用于设置变量中的值.
<set name = "variable-name"> variable-value </set>
< get> tag用于从变量中获取值.
<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 .
<?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>
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!