AIML <set> & <get> Tags
Last Updated :
16 Oct, 2023
AIML <set> and <get> tags are used by the chatbot to interact with users to create more personalized responses.
AIML <set> Tag
The <set> tag is used to set the value of a variable. In AIML, variables are used to store and manipulate data. It helps the chatbot or conversational agent to remember information.
Syntax:
<set name="variable_name">value_to_set</set>
Now you know, <set> is used to set the value to a variable. So, for example, if the chatbot asks the user what is your favorite color and the user replies with violet, the chatbot needs to store this information in a variable for future use. For this purpose, the <set> tag is used.
Example 1: Here is an example to illustrate how to use <set> tag.
XML
< category >
< pattern >My favorite color is *</ pattern >
< template >
< set name = "favorite_color" >< star /></ set >
Thank you for letting me know that your favorite color is
< get name = "favorite_color" />
</ template >
</ category >
|
Example 2: In a similar way, the <set> tag can be used to store the age of the user.
XML
<? xml version = "1.0" encoding = "UTF-8" ?>
< aiml version = "2.0" >
< category >
< pattern >My age is *</ pattern >
< template >
< set name = "user_age" >< star /></ set >
Thank you for providing your age.
You are < get name = "user_age" /> years old.
</ template >
</ category >
< category >
< pattern >How old am I?</ pattern >
< template >You are < get name = "user_age" /> years old.</ template >
</ category >
< category >
< pattern >*</ pattern >
< template >I'm sorry, I don't understand that.</ template >
</ category >
</ aiml >
|
AIML <get> Tag
The <get> tag is used to retrieve the value which was stored in the variable using <set> tag. In AIML, it helps chatbots and conversational agents to access and use information that has been stored in variables during the course of a conversation.
Syntax:
<get name="variable_name"/>
Example 1: Suppose, a user have set his name to “Rohan” using <set> tag. Now he wants to retrieve the stored value. This can be done using the <get> tag.
XML
< category >
< pattern >What is my name?</ pattern >
< template >Your name is < get name = "user_name" />.</ template >
</ category >
|
Output: The value of user_name is retrieved using <get> tag.
User: What is my name?
Chatbot: Your name is Rohan.
Example 2: In a similiar way, <get> tag can be used to retrieve value of the favourite place stored by the chatbot.
XML
<? xml version = "1.0" encoding = "UTF-8" ?>
< aiml version = "2.0" >
< category >
< pattern >My favorite food is *</ pattern >
< template >
< set name = "favorite_food" >< star /></ set >
Thank you for sharing your favorite food. You love
< get name = "favorite_food" />!
</ template >
</ category >
< category >
< pattern >What is my favorite food?</ pattern >
< template >Your favorite food is
< get name = "favorite_food" />.</ template >
</ category >
< category >
< pattern >*</ pattern >
< template >I'm sorry, I don't understand that.</ template >
</ category >
</ aiml >
|
Note: The <set> tag is used to store data in variables during a conversation, while the <get> tag is used to retrieve and use that data in responses.
Share your thoughts in the comments
Please Login to comment...