Search code examples
aiml

AIML - Wild Card Tags


I am writing the below AIML code.

<aiml>
<category>
<pattern>test</pattern>
<template>This is a test to try the third possible input. Yes / No ? </br> 
</template>
</category>

<category>
<pattern>Yes</pattern>
<that>This is a test to try the third possible *</that>
<template>Hey!. You have typed YES!</template>
</category>

<category>
<pattern>No</pattern>
<that>This is a test to try the third possible *</that>
<template>Hey!. You have typed No!</template>
</category>

<category>
<pattern>*</pattern>
<that>This is a test to try the third possible *</that>
<template>BINGO!!!!</template>
</category>
</aiml>

I would like to see "Bingo!!!" as a response when a user enters anything apart from Yes or No.

<pattern>*</pattern>

works fine when I use it separately, but not here. Where am I doing the mistake?


Solution

  • Some AIML libraries require the pattern value to be uppercase (this is good practice even for implementations which not force it). So for me the following code works as expected (tested under PyAIML):

    <aiml>
        <category>
            <pattern>TEST</pattern>
            <template>This is a test to try the third possible input. Yes / No ? <br /></template>
        </category>
    
        <category>
            <pattern>YES</pattern>
            <that>THIS IS A TEST TO TRY THE THIRD POSSIBLE *</that>
            <template>Hey!. You have typed YES!</template>
        </category>
    
        <category>
            <pattern>NO</pattern>
            <that>THIS IS A TEST TO TRY THE THIRD POSSIBLE *</that>
            <template>Hey!. You have typed No!</template>
        </category>
    
        <category>
            <pattern>*</pattern>
            <that>THIS IS A TEST TO TRY THE THIRD POSSIBLE *</that>
            <template>BINGO!!!!</template>
        </category>
    </aiml>
    

    Output:

    > test
    This is a test to try the third possible input. Yes / No ?
    > yes
    Hey!. You have typed YES!
    > test
    This is a test to try the third possible input. Yes / No ?
    > no
    Hey!. You have typed No!
    > test 
    This is a test to try the third possible input. Yes / No ?
    > Foo
    BINGO!!!!
    > 
    

    Instead of <that> tags you can also try to use <topic>, e.g.:

    <aiml>
        <category>
            <pattern>TEST</pattern>
            <template>
                This is a test to try the third possible input. Yes / No ? <br />
                 <think><set name="topic">THREE OPTIONS</set></think>
            </template>
        </category>
    
    <topic name="THREE OPTIONS">
        <category>
            <pattern>YES</pattern>
            <template>Hey!. You have typed YES!</template>
        </category>
    
        <category>
            <pattern>NO</pattern>
            <template>Hey!. You have typed No!</template>
        </category>
    
        <category>
            <pattern>*</pattern>
            <template>BINGO!!!!</template>
        </category>
    </topic>
    </aiml>