AIML - getting unknown values from set values

1.5k views Asked by At

I'm using recursion in AIML using the <srai> tag, like the following code:

<category><pattern>I LIKE *</pattern>
 <think><set name="name"><star/></set>
 <set name="it">
 <set name="topic"><star/>
 </set>             
 </set>    
 </think>
 <template><srai>I DIG</srai></template>
 </category>



 <category><pattern>I DIG</pattern>       
 <template>
 <random>
 <li>If you dig <get name="name"/>, plant something in it</li>
 <li>I dig <get name="name"/> too.</li>
 <li>If you dig <get name="name"/> deep enough, rabbits will live in it.</li>
 </random>
 </template>
 </category>

A few days ago, this code was working, but now it works as values have not been set. I'm getting:

If you dig unknown, plant something in it.

I dig unknown too.

If you dig unknown deep enough, rabbits will live in it.

what am I doing wrong?

3

There are 3 answers

0
Projesh Pal On BEST ANSWER

Your AIML is incorrect format. You can place <think>,<set> tags under template. So your AIML will be as follows

    <category>
      <pattern>I LIKE *</pattern>
      <template>
          <think>
             <set name="name"><star/></set>
             <set name="it">
                 <set name="topic"><star/></set>             
             </set>    
          </think>
          <srai>I DIG</srai>
     </template>
  </category>

  <category>
     <pattern>I DIG</pattern>       
     <template>
        <random>
           <li>If you dig <get name="name"/>, plant something in it</li>
           <li>I dig <get name="name"/> too.</li>
          <li>If you dig <get name="name"/> deep enough, rabbits will live in it.</li>
        </random>
     </template>
 </category>

This will return like following:
___________________________________________
Input:  I like Bird
Output: If you dig Bird, plant something in it

Input:  I like Bird
Output: If you dig Bird deep enough, rabbits will live in it.
0
A Bird Probably On

Unless Im reading& executing this code incorrectly, I think it has to do with the bit about setting the name. So if you tell it, "I dig birds!", and then ask it what your name is, it will say your name is birds.

This is AIML 2.0, correct?

0
Hamza Idrees On

This because these variables are session scoped. That means, if you assign value to a variable, it is globally accessible. So as you have same variable name for Bird and User, it will behave in the same way you've mentioned. What you can do is keep two variables:

<category>
      <pattern>I LIKE *</pattern>
      <template>
          <think>
             <set name="name"><star/></set>
             <set name="it">
                 <set name="topic"><star/></set>             
             </set>    
          </think>
          <srai>I DIG</srai>
     </template>
  </category>

And keep another variable for username e.g.

  <category>
      <pattern>My name is *</pattern>
      <template>Ok <think><set name="userName"><star/></set> </think></template>
  </category>


  <category>
      <pattern>What is my name?</pattern>
      <template>My name is <get name="userName"/></template>
  </category>