Thursday, March 26, 2009

<srai>: The basics II: Simple wildcard reductions

AIML uses a wildcard * (the star character) to stand for one or more words. An AIML pattern such as <pattern>I AM *</pattern>, taken by itself, matches a wide range of inputs such as "I am tired", "I am reading a book", "I am waiting for a reply" and so on. If the input is "I am tired", the wildcard is said to be bound to the word "tired" (1 word). If the input is "I am reading a book", the wildcard is bound to "reading a book" (3 words), and similarly, if the input is "I am waiting for a reply", the wildcard is bound to "waiting for a reply" (4 words).

Inside the template, AIML uses the <star/> tag to access wildcard bindings.

Trivially, the category

<category>
<pattern>*</pattern>
<template><star/></template>
</category>

will just echo the client's input:

Human: Hello!
Robot: Hello!
Human: Who are you?
Robot: Who are you?

The simplest form of AIML reduction using <srai> together with <star/>, involves reducing or simplifying the input by one or a few words:

<category>
<pattern>I AM ESPECIALLY *</pattern>
<template><srai>I AM <star/></srai></template>
</category>

If someone says, "I am especially tired", or "I am especially interested in this book", it is really no different logically from saying "I am tired" or "I am interested in this book". A philosopher might say, the word "especially" plays no logical role in the sentence. More practically, the bot may have a reply for "I am tired" and "I am interested in something", so reducing the input by removing the
word "especially" will link these inputs to appropriate responses.

The categories:

<category>
<pattern>I AM TIRED</pattern>
<template>Maybe you should take a nap?</template>
</category>

<category>
<pattern>I AM ESPECIALLY *</pattern>
<template><srai>I AM <star/></srai></template>
</category>

produce the dialog:

Human: I am especially tired.
Robot: Maybe you should take a nap?

As a bonus, these types of reduction categories can reduce a sentence with "I am" followed by any number of occurrences of "especially":

Human: I am especially especially especially tired.
Robot: Maybe you should take a nap?

A slightly related, also very common form of reduction, eliminates sequences of words (clauses) that can be eliminated from the input without changing its meaning significantly. Such clauses are decoration, added by the human personality, perhaps as social conventions, but again, the philosopher might say they have no logical purpose. "I will state that I warned you about his condition" is really the same as "I warned you about his condition", at least as far as the robot is concerned. The robot may already have a response to "I warned you about something", so by reducing the input, the bot stands a better chance of making an intelligent sounding reply.

In these cases we use a <pattern> with a wildcard, but end up throwing away all the words in the pattern except for the wildcard:

<category>
<pattern>I WILL STATE THAT *</pattern>
<template><srai><star/></srai></template>
</category>

Another example is a category for inputs that start with "At any rate..."

<category>
<pattern>AT ANY RATE *</pattern>
<template><srai><star/></srai></template>
</category>

A last example handles sentences that begin "I assure you that..."

<category>
<pattern>I ASSURE YOU THAT *</pattern>
<template><srai><star/></srai></template>
</category>

No comments:

Post a Comment