How to compare two variables

View: New views
3 Messages — Rating Filter:   Alert me  

Parent Message unknown How to compare two variables

by Square Bear :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Excuse the lengthy post. I was checking through some old mailshots and found
that someone was wondering how to compare two variables to see if they
matched and so created a piece of AIML to do the job.

With AIML, there is no easy way to compare two variables. Say for example,
you wanted to know if <get name="name"/> and <get name="friend"/> were the
same, you would have to do something like:

<set name="check"><get name="name"/><get name="friend"/></set>
<condition name="check">
<li value="PAUL PAUL">They match.</li>
<li value="STEVE STEVE">They match.</li>
<li value="ALICE ALICE">They match.</li>
....
....
....
and so on, including every name
....
....
....
<li>They do not match.</li>
</condition>

This would be ok if there were just a few options to check, but in the
example above, you would have to include EVERY possible person's name for
the category to work.

I have written some AIML to get around this problem:
http://www.square-bear.co.uk/aiml/botcompare.aiml

This contains a category called BOTCOMPARE which compares two values and
returns a variable called "match" which will be either YES if they are the
same, NO if they are different and FAIL if the BOTCOMPARE was called
incorrectly (no parameters or not enough parameters sent to BOTCOMPARE etc).

In the example above we can now say:

BOTCOMPARE <get name="name"/><get name="friend"/>

<condition name="match">
<li value="YES">They match.</li>
<li value="NO">They do not match.</li>
</condition>

The only limitation is that it can only check one word variables at the
moment.

How it works

It works by using the <eval> and <learn> tags of Pandorabots to create a
temporary category with the first value which it then checks using the
second value. Let's show an example.

BOTCOMPARE PAUL STEVE

This will set up a temporary category called BOTCHECK PAUL and then
<srai>BOTCHECK STEVE</srai>. As no category matches BOTCHECK STEVE, it calls
BOTCHECK * which sets the variable "match" to NO.

However, the example "BOTCOMPARE PAUL PAUL" will do the same as above but
this time the <srai> will be to BOTCHECK PAUL which matches the temporary
category and sets the variable "match" to YES.

One important thing to do after the comparison check is to clear the
temporary category. We do this by setting a new temporary category BOTCHECK
PAUL which is set to return "match" as NO and overwrites the original
temporary category. Otherwise BOTCHECK PAUL will exist and be called in
occurances such as BOTCHECK JAMES PAUL. This will return a match which would
be incorrect.

Hope that all makes sense.

You can see a demo of it by saying DEMOCOMPARE which will choose 10 random
things to compare.

As usual, feel free to use it as you wish, upload it to your Pandorabot,
republish and you can call BOTCOMPARE in any AIML you wish. Due to it using
<eval> and <learn>, it will only work in a Pandorabot.

Kind Regards
- Steve Worswick (Square Bear)
http://www.square-bear.co.uk

_______________________________________________
This is the pandorabots-general mailing list
To Post, reply to pandorabots-general@...
Unsubscribe and change preferences at http://list.pandorabots.com/mailman/listinfo/pandorabots-general
Learn netiquette at http://www.dtcc.edu/cs/rfc1855.html
Learn to read at http://www.literacy.org/

Parent Message unknown Re: How to compare two variables

by Dr. Rich Wallace :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

This is brilliant Steve.  I would have never thought of using <learn>
and <eval> to make a dynamic extension to the language.  The
possibilities are endless...

On Fri, Mar 28, 2008 at 4:08 PM, Dr. Rich Wallace <drwallace@...> wrote:

> This is brilliant Steve.  I would have never thought of using <learn>
> and <eval> to make a dynamic extension to the language.  The
> possibilities are endless...
>
> On Thu, Mar 27, 2008 at 12:22 PM, Square Bear <steve@...> wrote:
>
> > Excuse the lengthy post. I was checking through some old mailshots and found
> > that someone was wondering how to compare two variables to see if they
> > matched and so created a piece of AIML to do the job.
> >
> > With AIML, there is no easy way to compare two variables. Say for example,
> > you wanted to know if <get name="name"/> and <get name="friend"/> were the
> > same, you would have to do something like:
> >
> > <set name="check"><get name="name"/><get name="friend"/></set>
> > <condition name="check">
> > <li value="PAUL PAUL">They match.</li>
> > <li value="STEVE STEVE">They match.</li>
> > <li value="ALICE ALICE">They match.</li>
> > ....
> > ....
> > ....
> > and so on, including every name
> > ....
> > ....
> > ....
> > <li>They do not match.</li>
> > </condition>
> >
> > This would be ok if there were just a few options to check, but in the
> > example above, you would have to include EVERY possible person's name for
> > the category to work.
> >
> > I have written some AIML to get around this problem:
> > http://www.square-bear.co.uk/aiml/botcompare.aiml
> >
> > This contains a category called BOTCOMPARE which compares two values and
> > returns a variable called "match" which will be either YES if they are the
> > same, NO if they are different and FAIL if the BOTCOMPARE was called
> > incorrectly (no parameters or not enough parameters sent to BOTCOMPARE etc).
> >
> > In the example above we can now say:
> >
> > BOTCOMPARE <get name="name"/><get name="friend"/>
> >
> > <condition name="match">
> > <li value="YES">They match.</li>
> > <li value="NO">They do not match.</li>
> > </condition>
> >
> > The only limitation is that it can only check one word variables at the
> > moment.
> >
> > How it works
> >
> > It works by using the <eval> and <learn> tags of Pandorabots to create a
> > temporary category with the first value which it then checks using the
> > second value. Let's show an example.
> >
> > BOTCOMPARE PAUL STEVE
> >
> > This will set up a temporary category called BOTCHECK PAUL and then
> > <srai>BOTCHECK STEVE</srai>. As no category matches BOTCHECK STEVE, it calls
> > BOTCHECK * which sets the variable "match" to NO.
> >
> > However, the example "BOTCOMPARE PAUL PAUL" will do the same as above but
> > this time the <srai> will be to BOTCHECK PAUL which matches the temporary
> > category and sets the variable "match" to YES.
> >
> > One important thing to do after the comparison check is to clear the
> > temporary category. We do this by setting a new temporary category BOTCHECK
> > PAUL which is set to return "match" as NO and overwrites the original
> > temporary category. Otherwise BOTCHECK PAUL will exist and be called in
> > occurances such as BOTCHECK JAMES PAUL. This will return a match which would
> > be incorrect.
> >
> > Hope that all makes sense.
> >
> > You can see a demo of it by saying DEMOCOMPARE which will choose 10 random
> > things to compare.
> >
> > As usual, feel free to use it as you wish, upload it to your Pandorabot,
> > republish and you can call BOTCOMPARE in any AIML you wish. Due to it using
> > <eval> and <learn>, it will only work in a Pandorabot.
> >
> > Kind Regards
> > - Steve Worswick (Square Bear)
> > http://www.square-bear.co.uk
> >
> > _______________________________________________
> > This is the pandorabots-general mailing list
> > To Post, reply to pandorabots-general@...
> > Unsubscribe and change preferences at http://list.pandorabots.com/mailman/listinfo/pandorabots-general
> > Learn netiquette at http://www.dtcc.edu/cs/rfc1855.html
> > Learn to read at http://www.literacy.org/
> >
>
_______________________________________________
This is the pandorabots-general mailing list
To Post, reply to pandorabots-general@...
Unsubscribe and change preferences at http://list.pandorabots.com/mailman/listinfo/pandorabots-general
Learn netiquette at http://www.dtcc.edu/cs/rfc1855.html
Learn to read at http://www.literacy.org/

Parent Message unknown Re: How to compare two variables

by Square Bear :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks Doc,
It's an idea I had for a while but just couldn't figure out how to implement
it, then the other day it just clicked into place.
I saw on some old listings that it was an issue for a few people so
hopefully it is of some use.
Regards
- Steve Worswick (Square Bear)

PS Perhaps Pandorabots should start charging for bots over a certain amount
of responses (say 50,000 a day), as I notice the server has been pretty much
unavailable since Hector Van Daemon joined. I assume its owner has made a
donation to Pandorabots?


> Date: Fri, 28 Mar 2008 16:10:32 -0700
> From: "Dr. Rich Wallace" <drwallace@...>
> Subject: Re: [pandorabots-general] How to compare two variables
> To: pandorabots-general@...
> Message-ID:
> <d9aba65c0803281610o18dd12a7he9482b83635b64fa@...>
> Content-Type: text/plain; charset=ISO-8859-1
>
> This is brilliant Steve.  I would have never thought of using <learn>
> and <eval> to make a dynamic extension to the language.  The
> possibilities are endless...
>

_______________________________________________
This is the pandorabots-general mailing list
To Post, reply to pandorabots-general@...
Unsubscribe and change preferences at http://list.pandorabots.com/mailman/listinfo/pandorabots-general
Learn netiquette at http://www.dtcc.edu/cs/rfc1855.html
Learn to read at http://www.literacy.org/