AI Zone Admin Forum Add your forum

NEWS: Chatbots.org survey on 3000 US and UK consumers shows it is time for chatbot integration in customer service!read more..

Usage <learnf>-tag and getting only username
 
 

Hello!

I’ve a few questions about AIML 2.0:

1. The <learnf> tag:

I tried to use the tag this way, but it doesn’t work:

<category>
      <
pattern>I AM YEARS OLD</pattern>
      <
template>You are <learnf><set name="age"><star/></set></learnfyears old.</template>
</
category

HUMAN: I am 20 years old.
BOT: You are years old.

The first problem: Where is the “20” in “You are years old.”? And the second problem: The <learnf> creates the “pand_learn.aiml” automatically. But this file is empty (apart from the <aiml> tag)!


Can you help me to use the <learnf> tag correctly (a simple example would be great!)

2. only name input
I don’t know whether this is really a problem, but I don’t know how to solve it. How can I create a pattern that accepts only the name of the human?

...like this way:
BOT: What’s your name?
HUMAN: Otto.
BOT: Hello Otto.

At the moment I have to write it this way:
BOT: What’s your name?
HUMAN: My name is Otto.
BOT: Hello Otto.

<pattern>My name is *</pattern>
<
template>Hello <star/>.</template

Only the name would mean something like this:

<pattern>*</pattern>
<
template>Hello <star/>.</template

But this can’t be right, because every word would match with this pattern. I’m a bit confused. Can you help me? red face


 

 
  [ # 1 ]

First of all, I’d like to state I’m using Program AB. If you’re using Pandorabots, this might not necessarily work.
The main error here is that the <learnf> tag is meant to be wrapped around the entire category you wish to create. In turn, the <learnf> category is wrapped around a <template> tag.
In your case, we’d like:

<category>
      <
pattern>I AM YEARS OLD</pattern>
      <
template>
            <
learnf>
                  <
category>
                        <
pattern>HOW OLD AM I</pattern>
                        <
template>You are <eval><star index="1"/></eval> years old.</template>
                  </
category>
            </
learnf>
      </
template>
</
category

Notice the <eval> tag is used to ‘run’ something before we create the new category.
However, I think the solution you’re really looking for uses a <learn> tag since <learnf> makes the changes global - everyone will have your age until they too change it.

Perhaps the best solution is the following:

<category>
      <
pattern>I AM YEARS OLD</pattern>
      <
template>You are <set name="age"><star/></setyears old.</template>
</
category>

<
category>
      <
pattern>HOW OLD AM I</pattern>
      <
template><condition name="age"><li value="unknown">You have not told me your age.</li><li>You are <get name="age"/> years old.</li></condition></template>
</
category

You’re next point is quite easy to solve.

<!-- this is just an example category -->
<
category>
 <
pattern>WHAT WOULD YOU LIKE TO ASK ME</pattern>
 <
template>What is your name?</template>
</
category>

<
category>
 <
pattern>*</pattern>
 <
that>WHAT IS YOUR NAME</that>
 <
template>Hello <star/></template>
</
category

You might also want to wrap the <star> tag in a <set> tag as you did in the age example. Then you can store it and use it later.

Thanks for the question and good luck,
Mush.

 

 
  [ # 2 ]

Thanks, Mush! You helped me so much. red face
I am using Program AB too. So your solution works.

But I have another question concerning the <that>-tag. smile
With your help I could write something like this:

<category>
      <
pattern>WHAT WOULD YOU LIKE TO ASK ME</pattern>
      <
template>What is your name?</template>
  </
category>


  <
category>
      <
pattern>*</pattern>
        <
that>WHAT IS YOUR NAME</that>
        <
template>Hello <set name="username"><star/></set>! How old are you?
            <
learnf>
                <
category>
                    <
pattern>WHAT IS MY NAME</pattern>
                    <
template>YOUR NAME IS <eval><star index="1"/></eval></template>
                </
category>
            </
learnf>
        </
template>
   </
category

The next problem is: How can I connect this template…

Hello <set name="username"><star/></set>! How old are you

...with another category using the <that>-tag? I don’t know how to write this template with <set> and <star> into the <that>-tag. Is it possible?

My idea was something like

<that>HELLO<star/> HOW OLD ARE YOU</that

..because I know that something like…

<srai>MY NAME IS <star/></srai

...works inside <srai>, but my idea doesn’t work because of the <star>-tag inside the <that>-tag.

Best regards
Otto

 

 
  [ # 3 ]

Dear Otto,
There are two or three I think you could achieve this.
The first approach is to create the category in the <learnf> tag. We simply use <eval> like before!

<aiml>
 <
category>
  <
pattern>WHAT WOULD YOU LIKE TO ASK ME</pattern>
  <
template>What is your name?</template>
 </
category>

 <
category>
  <
pattern>*</pattern>
  <
that>WHAT IS YOUR NAME</that>
  <
template>Hello <set name="username"><star/></set>! How old are you?
   <
learnf>
    <
category>
     <
pattern>WHAT IS MY NAME</pattern>
     <
template>YOUR NAME IS <eval><star index="1"/></eval></template>
    </
category>

    <
category>
     <
pattern>*</pattern>
     <
that>HELLO <eval><star index="1"/></eval> HOW OLD ARE YOU</that>
     <
template><set name="age"><star index="1"/></set>? What a brilliant age!</template>
    </
category>
   </
learnf>
  </
template>
 </
category>
</
aiml

Note: I would strongly recommend using the <learn> tag rather than <learnf>. <learnf> switches to using AIMLIF on my computer.

Another technique is using <that>* HOW OLD ARE YOU</that> instead of <that>HELLO <eval><star index=“1”></eval> HOW OLD ARE YOU</that>. It’s just a bit shorter.

There are a few other techniques but they just feature not using the <learn> tag at all!
Anyway, I hope that helps and thanks for the question,
Mush.

 

 
  [ # 4 ]

Thanks again. It’s easier than I expected grin
There is just one little mistake concerning <learnf> in your code. This would save the whole line:

<category><pattern>*</pattern><that>* HOW OLD ARE YOU</that><template><set name="age"><star index="1"/></set>? What a brilliant age!</template></category

I’ve tested these things with Pandorabots and Program AB. Connecting the templates with <that> and using <learnf> tag with <eval> is working with Pandorabots and Program AB.
Something like

<that>HELLO <eval><star index="1"/></eval> HOW OLD ARE YOU</that
or
<that>* HOW OLD ARE YOU</that

isn’t working with Pandorabots. The problem is the <star> tag. And the “*” just don’t work without any error message.
I don’t know whether it will work with Program AB. I will test it this evening and hope it will work.

Best regards,
Otto

 

 
  [ # 5 ]

I think it isn’t only a problem of the <star> tag or something like the “*”. It’s also a problem of connecting a template with two or more sentences with <that>, because something like

<that>HELLO OTTO HOW OLD ARE YOU</that

isn’t working, too - in Pandorabots.

 

 
  [ # 6 ]

A little Update: I’ve solved the problem (for Pandorabots and Program AB) and it was easier than I’ve expected. red face grin

If the bot’s last response consists of multiple sentences like…

<template>Hello <set name="username"><star/></set>! How old are you?</template

...the <that>-tag will only match the bot’s last sentence.

So…

<that>HOW OLD ARE YOU</that

...will match!

Best regards,
Otto

 

 
  [ # 7 ]

Hi All,

Can you please explain what is expected from user to enter so that interpretator understands that this text should be added in learnf.aiml and if user ask same q again then its response correctly.

For example : apple color is not present in aiml files so user wants to add apple color.

thanks in advance

 

 

 

 
  [ # 8 ]

Hi All,

I got resolution use learn tag
Human : Learn apple is red

then this text added in learnf.aiml.csv file

Next time if user asked what is apple then Robot reply red

 

 
  [ # 9 ]

Hi,

I have just modified the external library making Program AB learnf tag work as the specification for AIML 2.0. You can refer my modification below.
https://gist.github.com/yeulam1thienthan/73a884f74736c5aa2457a2feedc67f1f

 

 
  [ # 10 ]

@Giang Nguyen: Thank you! This is really great. But I’m a bit confused - I’ve used the ProgramAB.jar from https://code.google.com/archive/p/program-ab/.
How can I update this .jar with your modification? Or do you already have created a modified version of this .jar?

 

 
  [ # 11 ]

Oh, so sorry, I have received any notification. You should change the file src/main/java/org/alicebot/ab/AIMLProcessor.java, this file is in program-ab package, and the github has been changed to: https://gist.github.com/luulinh90s/73a884f74736c5aa2457a2feedc67f1f

 

 
  login or register to react