AIML <topic> no match - chatbot

<category>
<pattern>Q3 income _</pattern>
<template><delay>2</delay>
<set name = "topic">Q4</set> I am from UK. May I know What your home town is. </template>
</category>
<topic name = "Q4">
<category>
<pattern>_</pattern>
<that>_ MAY I KNOW WHAT YOUR HOME TOWN IS</that>
<template><delay>1</delay><set name = "topic">Q5</set> Good to know.</template>
</category>
</topic>
The hometown question's answer can't be captured by topic Q4.

The underscore wildcard indicates 1 or more words, but in the sentence you are checking, you have no more words before "May I know....". Miss out the underscore and it will work.
<topic name = "Q4">
<category>
<pattern>_</pattern>
<that>MAY I KNOW WHAT YOUR HOME TOWN IS</that>
<template>
<delay>1</delay>
<set name="topic">Q5</set> Good to know.
</template>
</category>
</topic>

Related

How to make lie detection possible in aiml?

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>

AIML How to get out of topic from underscored wildcard

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>

AIML multiple patterns with one response

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.

Why isn't my wildcard + think + condition detected?

I'm new to aiml and I'm trying to figure out why this isn't being detected. This is basically the example from docs modified with a wildcard.
<category>
<pattern>You want to buy some *</pattern>
<template>
<think><set name = "product"><star index="1"/></set></think>
<condition name = "product" value = "deathsticksss">
You don't want to sell me <star index="1"/>...you want to go home and rethink your life
</condition>
</template>
You need to put </category> at the end of your category.

How can I create a chatbot that organizes input into selected templates?

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>