In aiml how to get multiple learnf facts instead of only one? For example
<category>
<pattern>Learn * means *</pattern>
<template>Aight
<learnf>
<category>
<pattern>What is <eval><star/></eval></pattern>
<template>It means <eval><star index="2"/></eval></template>
</category>
</learnf>
</template>
</category>
Human: Learn life means to pursue something.
Robot:aight
Human:what is life?
Robot:it means to pursue something
But what if if I taught the same question with different response?
Human: Learn life means to live at fullest
Robot:aight
Human: what is life?
Robot:It means to live at fullest.
The fact taught previously for same question gets replaced by new one. How to retrieve the previously learned fact as well as the new one for same question?
You can do this by setting a predicate called <star/> and appending the value of each interaction to it, like this.
<category>
<pattern>LEARN * MEANS *</pattern>
<template>
Aight
<think>
<condition><name><star/></name>
<li value="unknown"><set><name><star/></name><star index="2"/></set></li>
<li><set><name><star/></name><get><name><star/></name></get>, <star index="2"/></set></li>
</condition>
</think>
<learnf>
<category>
<pattern>What is <eval><star/></eval></pattern>
<template>It means <eval><get><name><star/></name></get></eval></template>
</category>
</learnf>
</template>
</category>
The condition checks that the predicate exists and if it does, append <star index="2"/> to it. Otherwise, create a new predicate called <star/> with a value of <star index="2"/>
This will produce a conversation as follows:
Related
in aiml i am trying to make bot detect if user has lied there name or not. for instance if a user tells two different names to bot then bot will detect that user is lying by retrieving previous values. here is the code
<category>
<pattern>MY NAME IS *</pattern>
<template>
cool name!
<think>
<set name="name"><star/></set>
<set name="naem">naem</set>
</think>
</template>
</category>
<category>
<that>cool name</that>
<pattern>MY NAME IS *</pattern>
<template>
i thought you are <get name="name"></get>
</template>
</category>
there are 2 scenarios of this code
HUMAN: My name is jessop
ROBOT: cool name!
HUMAN: My name is siemens
ROBOT: I thought you are jessop
The above scenario works as it is but in second scenario it doesnt make any sense
HUMAN: My name is jessop
ROBOT: cool name!
HUMAN: My name is jessop
ROBOT: I thought you are jessop
I want to make sure that bot should able to recognize if user has told their name twice which are similar. like this one
HUMAN: My name is jessop
ROBOT: cool name!
HUMAN: My name is jessop
ROBOT: I know you are jessop
is there any possibility to achieve output like above scenario?
Assuming you are using UNKNOWN for the default value of predicates
<category>
<pattern>MY NAME IS *</pattern>
<template>
<condition name="name">
<li><value><star/></value>I know you are <star/>!</li>
<li value="UNKNOWN"><think><set name="name"><star/></set></think>cool name!</li>
<li>I thought you are <get name="name"/></li>
</condition>
</template>
</category>
In aiml how to get out of topic which has underscored wildcard. Here is the code
<category>
<pattern>TOPIC</pattern>
<template>ok <think><set name="topic">ctt</set></think></template>
</category>
<topic name="ctt">
<category>
<pattern>_</pattern>
<template>no</template>
</category>
<category>
<pattern>CHANGE TOPIC</pattern>
<template>YES <set name="topic"></set></template>
</category>
</topic>
The output is
Human: TOPIC
Robot: ok
Human: CSA
Robot: no
Human: CHANGE TOPIC
Robot: no
How to fix it without using conditions?
The reason for this is that the underscore wildcard takes priority over everything else, even a direct match.
Hopefully, you are using AIML 2 rather than AIML 1 and so you can simply change the <pattern>CHANGE TOPIC</pattern> to <pattern>$CHANGE TOPIC</pattern>.
The dollar wildcard means if your input exactly matches the pattern, the template will be activated.
If you are not using AIML 2, I would have to ask why, but if for whatever reason you are not, you will need a condition tag to do the same action. Swap your underscore category for this one instead. It checks the input and if it matches CHANGE TOPIC, the topic is reset.
<category>
<pattern>_</pattern>
<template>
<think><set var="userinput"><star/></set></think>
<condition var="userinput">
<li value="CHANGE TOPIC">YES <set name="topic"></set></li>
<li>no</li>
</condition>
</template>
</category>
Lets say I want the user to have a single response to multiple greetings for the bot. Is there a better way to write this using an "or" statement or a list instead of writing each case out with all the templating like this to redirect the pattern?
<category>
<pattern> HELLO</pattern>
<template>
Hello User!
</template>
</category>
<category>
<pattern> HI</pattern>
<template>
<srai> HELLO</srai>
</template>
</category>
<category>
<pattern> HOWDY</pattern>
<template>
<srai> HELLO</srai>
</template>
</category>
You could create a set called "greetings" containing the different ways of saying hello, like this:
And then write this category:
<category>
<pattern>^ <set>greetings</set> ^</pattern>
<template>Hello User!</template>
</category>
But to me, it's far easier to make new categories for each option and <srai> to your main one, as in your original example.
I want to create a chatbot that asks questions that, according to their answers, travel down a tree of templates. I'm not very experienced in the coding world, so excuse me if my jargon isn't right!
Here's an example.
I want to write custom reports based on a user's input into a chatbot. Let's imagine the user wants some daily, custom motivation.
How are you feeling today?
Based on user inputs this is categorized into:
"GOOD - BAD - SAD - HAPPY - EXCITED" etc...
Depending on which one, we travel down a "template tree," so any templates that would exist under the "BAD" category are disregarded if the user writes "Pretty Good" and it's categorized as "Good."
Then we ask questions like, "What's your name?", that are stored as variables to incorporate into a text template once we find the right template based on their inputs.
What's the best platform to build this? Is it indeed a chatbot?
Thank you so much for the help!
I tried Pandorabots but it seems too linear - as in a input > response model, there's not much conditional logic. I'm ready to research and learn, so any tips on which platform / approach would be very helpful!
Pandorabots uses AIML to create a chatbot and you can certainly do conditional logic in it. Here's some code that will solve your request:
<?xml version="1.0" encoding="UTF-8"?>
<aiml version="2.0">
<category>
<pattern>HI</pattern>
<template>
Hi there. What is your name?
</template>
</category>
<category>
<pattern>*</pattern>
<that>WHAT IS YOUR NAME</that>
<template>
<think><set name="name"><star/></set></think>
How are you feeling today?
</template>
</category>
<category>
<pattern>*</pattern>
<that>HOW ARE YOU FEELING TODAY</that>
<template>
<think><set name="mood"><star/></set></think>
<condition name="mood">
<li value="good">That's great <get name="name"/>.</li>
<li value="bad">Sorry to hear that <get name="name"/>. Can I help?</li>
<li value="sad">Cheer up <get name="name"/>, it's a beautiful day!</li>
<li value="happy">Oh wow <get name="name"/>. I'm so pleased for you!</li>
<li value="excited">Amazing <get name="name"/>! What's happened?</li>
<li>The day is yours to command <get name="name"/>.</li>
</condition>
</template>
</category>
</aiml>
A sample conversation would look like this:
Using the pattern side tag, you can also do this with Pandorabots to group similar answers together. Create sets called "good" and "bad" with all the emotions that should trigger the templates. Example of the "good" set:
[
["amazing"],
["good"],
["happy"],
["great"]
]
And then use a categories like this:
<category>
<pattern>I FEEL <set>good</set></pattern>
<template>Great to hear!</template>
</category>
<category>
<pattern>I FEEL <set>bad</set></pattern>
<template>Sorry to hear that. Can I help?</template>
</category>
Hope that helps. Pandorabots is capable of FAR more than input - response and I've won the Loebner Prize 4 times for having the world's most humanlike conversational AI using AIML and Pandorabots.
Since you already tried Pandorabots then I assume you are familiar with XML and aiml, that's why I am proposing program O Program O on Github
aiml has a functionality call which can be used to build interactive tree chats.
check my example below. though I guess you might have come across aiml in your research.
<?xml version = "1.0" encoding = "UTF-8"?>
<aiml version = "1.0.1" encoding = "UTF-8"?>
<category>
<pattern>hi</pattern>
<template>How are you feeling today?</template>
</category>
<category>
<pattern>GOOD</pattern>
<that>How are you feeling today?</that>
<template>Nice, I like it that way.</template>
</category>
<category>
<pattern>BAD</pattern>
<that>How are you feeling today?</that>
<template>
<randon>
<li>Ok! I think you need an appointment with a doctor?</li
<li>How exactly are you feeling?</li>
</random>
</template>
</category>
<category>
<pattern>SAD_</pattern>
<that>How are you feeling today?</that>
<template>
<randon>
<li>Ok! what happened?</li
<li>how can i help?</li>
</random>
</template>
</category>
<category>
<pattern>HAPPY_</pattern>
<that>How are you feeling today?</that>
<template>
<randon>
<li>great! its good for you</li
<li>thats what up.</li>
</random>
</template>
</category>
</aiml>
I want to make a chatbot,so my doubt is how can i respond in multiple ways for a single pattern in aiml ?
for example if the user asks whats next the chat bot should respond step1
if again he asks whats next it should respond step2.
You can use "that" tags in the template, which remember the last bot statement and answer accordingly, although this gives you just one level of control. If you want more levels, a better way is to set topics using the "think" tags, and then defining topic specific templates which will be used first.
To have multiple responses for a single <pattern>, you can use the <random> and <li> tags:
<category>
<pattern>WHATS NEXT</pattern>
<template><random>
<li>Step 1</li>
<li>Step 2</li>
</random></template>
</category>
However, the responses will be generated randomly and not in a certain order.
For instance, if the user inputs "What's next?" for the first time, the response might be "Step 1" and the next time the user inputs the same keyword, the response might still be "Step 1".
First you need a category that knows the steps, and returns the answer in a defined format. In my example the format is
MAKE TOAST STEP * *
where the first star is the step number and the second star represents the remainder of the returned text. Here is the category:
<category>
<pattern>MAKING TOAST STEP *</pattern>
<template>
<set var="step"><star/></set>
<condition var="step">
<li value="1">Make toast step 1, get some bread</li>
<li value="2">Make toast step 2, put the bread in the toaster</li>
<li value="3">Make toast step 3, wait until it pops up</li>
<li>Make toast step 4, eat the toast</li>
</condition>
</template>
</category>
Then you need a category that calls the next step but only if the previous answer was a toast-making question. This category uses the that tag to ensure it is activated only during the toast making conversation. It uses thatstar to get the previous step number, then adds one to the step number:
<category>
<pattern>WHAT IS NEXT</pattern>
<that>MAKE TOAST STEP * *</that>
<template>
<set var="step"><calculate><thatstar/>+1</calculate></set>
<srai>MAKING TOAST STEP <get var="step"/></srai>
</template>
</category>
Then you need a category to kick off the whole sequence:
<category>
<pattern>HOW DO I MAKE TOAST</pattern>
<template>
<srai>MAKING TOAST STEP 1</srai>
</template>
</category>
The caveats with this approach are (1) it uses the calculate tag which is not standard AIML but should be coded quite easily. (2) It uses AIML v2 elements such as variables used with get and set. (3) I have not tested it, but I am confident the process should work.
<category>
<pattern>TEST SPLIT</pattern>
<template>
I don't want to talk about that now.
<split/>
I would rather talk about you.
</template>
</category>
Do <split/>
Output
Reference