2

Hey I am just learning AIML, and I want to give my chat bot a word, which it then saves and will recognize when I say it back later

Here is how I am trying to do it:

   <?xml version = "1.0" encoding = "UTF-8"?>
   <aiml>
       <category>
         <pattern> secret word is *</pattern>
         <template>
           <set name = "secretWord"><star/></set>? Ok got it.
         </template>
       </category>

       <category>
       <pattern> <get name = "secretWord"/> </pattern>
       <template>Thats the secret word</template>
       </category>
   </aiml>

as of now it just doesn't respond once I say the secret word

perhaps there is a better/more standard way to do this? Or is this impossible in aiml?

2 Answers2

1

What you want is possible using a different approach. The basic problem is you can't use <get name="secretWord"/> in the <pattern> element, so you need a different pattern using plain text and stars (*). So you would edit your second category to ask a question, as follows:

<category>
<pattern> IS MY SECRET WORD * </pattern>
<template>
  <condition>
    <li name="secretWord"><value><get name="secretWord"/></value>
      That's the secret word
    </li>
    <li>
      Sorry, "<star/>" is not the secret word
    </li>
  </condition>
</template>
</category>

This works by requiring the client to type "Is my secret word FOO?" to validate their secret word, and the category will confirm it or not. The <condition> element checks the "secretWord" property against its current value and says "That's the secret word" if there is a match. The default <li> ... </li> causes the "Sorry..." text to be shown if the client got the secret word wrong.

Also, note this relies on AIML v2 which uses the value sub-element, and it's conventional to write the patterns in upper case.

Ubercoder
  • 711
  • 8
  • 24
1

You can do this using the learn tag in AIML. It allows the bot to set up a new category. This is how many AIML bots learn new information from their users.

<category>
<pattern>SECRET WORD IS *</pattern>
<template>
The secret word is <star/>? Ok got it.

    <learn>
        <category>
            <pattern>
            <eval><uppercase><star/></uppercase></eval>
            </pattern>
            <template>
            SECRET CATEGORY ACTIVATED!!!
            </template>
        </category>
    </learn> 

</template>
</category>

The new category that the bot creates will look like this (assuming you say, "Secret word is foo"):

<category>
    <pattern>FOO</pattern>
    <template>SECRET CATEGORY ACTIVATED!!!</template>
</category>
Steve Worswick
  • 880
  • 2
  • 5
  • 11