Search code examples
aiml

AIML - context - why does context not have highest priority in all cases?


When using an AIML context (via <that>) I get some conversations I cannot explain. I expected that a (that) context would have priority over anything else.

Below I first show the script. Then I show a few conversations. I marked the inexpected parts with a // behind the response.

I added this Aiml file to the standard ALICE conversations.

The script:

<category><pattern>STEP 1</pattern>
  <template>Step 2</template>
</category>
<category><pattern>YES</pattern><that>STEP 2</that>
  <template>step 3</template>
</category>
<category><pattern>NO</pattern><that>STEP 2</that>
  <template>step 3</template>
</category>
<category><pattern>*</pattern><that>STEP 2</that>
  <template>step 3</template>
</category>
<category><pattern>*</pattern><that>STEP 3</that>
  <template>Step 4! and you typed '<star/>'</template>
</category>

In the following conversation I marked the unexpected responses with // ?

Human : step 1
Robot : Step 2
Human : yes
Robot : step 3
Human : yes
Robot : Step 4! and you typed 'yes'
Human : step 1
Robot : Step 2
Human : no
Robot : step 3
Human : no
Robot : So. // ? I expected here step 4
Human : step 1
Robot : Step 2
Human : any
Robot : any is a name. // ? I expected here step 3

Can you explain both UNexpected flows of conversation?


Solution

  • The <that> element takes priority over other patterns at the same pattern level. I don't know if you're using AIML v1 or v2, but broadly speaking there are 3 levels of patterns [but see note below]

    1. Most important level = patterns including underscore wildcards (_)
    2. Middle level = atomic patterns without any wildcards
    3. Lowest level = patterns including star wildcards (*)

    Your unexpected responses are because there is an ALICE response at a higher priority level. Eg when robot replies "step 3" and human says "no", you want <pattern>*</pattern><that>STEP 3</that> category to take effect. But if there is an ALICE response at a higher level (eg <pattern>NO</pattern> or <pattern>STEP _</pattern>) the ALICE responses will take effect over your level 3 category <pattern>*</pattern><that>STEP 3</that>. The quickest way of finding the ALICE category is just to ask "NO" and see what the bot replies. You could also search the ALICE files but this would be very time consuming.

    [note] In AIML v2 there are at least two extra levels: level 0 above underscore wildcards, and level 2.5 using pattern side sets. However the simpler levels of AIML v1 explain your anomalies.