A bot can do more than just react to a key word or phrase with a pat response.
It can use some of the user's own words in its reply. For example, if the user
says
I love my computer.
the bot is able remember the word that comes after 'my' and respond with something like
Tell me more about your computer.
The bot uses 'regular expression' codes to create patterns for the bot to
respond to. You can see the patterns your bot is responding to already by
typing
'seepatterns <botname>'
The first example (Tell me more about your computer)
demonstrates the use of the built-in 'my pattern'.
A bot using the 'my pattern' responds to anything it hears containing the word 'my'. It remembers the first word that follows 'my' and uses
that word to form one of three different responses. Suppose the bot heard someone say:
I wish my dog didn't eat so much.
The bot remembers the word 'dog' and uses it to construct one of the following three
responses:
The captured <SINGLEWORD> is referred to with the code %1 in responses like these:
(If there were more than one coded elements to remember they are numbered %2, %3, etc.)
Here's another example we can call the "IS
pattern". When the bot hears something like
THE WORLD IS BIG
AND ROUND
it might respond with
SUPPOSE THE WORLD WERE
NOT BIG AND ROUND? WHAT THEN
The bot is responding to the pattern
<ANYTHING(1)> is <ANYTHING(2)>
In this case <ANYTHING> matches any string of characters the user types in no
matter what.
The Moo code for <ANYTHING> is %(.*%)
Therefore the pattern is
%(.*%) is %(.*%)
The response is
Suppose <ANYTHING(1)> were not
<ANYTHING(2)>? What then?
which in Moo coding would be
Suppose %1 were not %2? What then?
Additional responses to the "IS pattern" include
What is so %2 about %1?
%1? How so?
Here are all the bot's default patterns and responses. You can usually adapt one of these patterns for just about any pattern you would like to create, so they are well worth studying.
PATTERNS:
1 your %(.*%)
my %1? Why do you wish to know?
I would rather not discuss my '%1' if it's allright with you...
Tell me yours first!
2 what is %(.*%)
Don't you know?
%1? I'm not sure i understand..
3 .* you are %(.*%)
Why do you think I am %1?
Perhaps it is you who are %1!
4 my %(%w*%)
Please tell me more about your %1...
Is your %1 important to you?
What about your %1?
5 why not
Hmm, thats a good question, why not indeed!
6 I %(.*%) you
You %1 me? Why?
Why do you say you %1 me?
I really %1 you too..
7 %(%w*%) is %(.*%)
Suppose %1 were not %2? What then?
What is so %2 about %1?
%1? how so?
8 it's %(.*%)
'%1' you say? How so?
Why is it %1?
9 I am %(.*%)
You say you are %1?
%1? How so?
Why are you %1?
10 I'm %(.*%)
You are %1? How come?
Now let's build a new pattern! Suppose we want the
bot to respond to sentences such as
I believe the world is round
with
Why do you believe that the world is
round?
the world is round? You must be kidding?
It seems unlikely to me that the world is round.
Our pattern will be
I believe that <ANYTHING(1)>
or, in Moo code
I believe that %(.*%)
with the responses
Why do you believe that %1?
%1? You must be kidding!
It seems unlikely to me that %1.
To add your new pattern type
'@addpat
<botname>'
and enter your pattern
I believe that %(.*%)
when asked to do so.
Then hit return and type in the first response form.
Why do you believe that %1?
Hit return.
Add the remaining responses one at a time, pressing Return each time.
Finally, enter a period on a single line and Return.
That's it. Drop your bot. Activate it, and test your new pattern! If you want to build super sophisticated patterns beyond the examples given you will need to study up on Regular Expressions, but you know enough now to really create some cool bots!