Ai Dreams Forum

Chatbots => A.L.I.C.E (AIML) => Topic started by: Freddy on July 20, 2014, 01:45:11 pm

Title: <topic> <that> precedence
Post by: Freddy on July 20, 2014, 01:45:11 pm
I'm working on my AIML interpreter and need to know this.

Squarebear or Dave can you help at all please ?

I need to understand in what order to process <topic> and <that>.

I'm thinking it's like this :


So that's in order of precedence.

Cheers :)
Title: Re: <topic> <that> precedence
Post by: Freddy on July 20, 2014, 01:53:13 pm
P.S. Clearly the first rule is correct as a <topic> cannot occur in a <that> at least I don't think it can ? Can things be nested ?

But what if a pattern has a match for <topic> and <that> ?

Do I return both ?
Title: Re: <topic> <that> precedence
Post by: DaveMorton on July 20, 2014, 02:04:55 pm
I was right there with you , right up until you asked, "Do I return both?"

Then it all fell apart on me. :o

With regard to your first post, the order you've listed is the correct one. Matches of topic/that trump matches of just topic, and matches of just topic trump matches of just that.

Now your second post has me all confusticated, I'm afraid. Can you please expand and elucidate a bit?
Title: Re: <topic> <that> precedence
Post by: Freddy on July 20, 2014, 02:17:50 pm
Sorry Dave,

I forgot <that> is the bot's last response.

I also just realised the input would probably would never match both <topic> and <that> unless both the bot and the user are repeating themselves, I think...

Scrap that.  :-X

Thanks for the confirmation of the order though and welcome back to the site  :)

Title: Re: <topic> <that> precedence
Post by: Freddy on July 20, 2014, 02:27:10 pm
In fact even if they are repeating I don't think they could possibly match.

All this recursion I am playing with is driving me nuts  :D
Title: Re: <topic> <that> precedence
Post by: squarebear on July 20, 2014, 10:52:07 pm
You can easily match both topic and that. One category could have set the topic and a category inside the topic could have a <that>. Fairly rare though.
Title: Re: <topic> <that> precedence
Post by: Freddy on July 20, 2014, 11:06:12 pm
I thought there must exist the possibility that it could happen, couldn't figure out how though so thanks Steve.

Can you share an example please ?

In that scenario do you think it's best to return both responses or one or the other ?

What's accepted practice ?

Cheers :)
Title: Re: <topic> <that> precedence
Post by: DaveMorton on July 20, 2014, 11:50:28 pm
If there's a "tie" between two or more inputs that match topic, that and pattern identically, you have a choice (none of which involve returning more than one response). You can either:

a.) choose the "first" category encountered (ignoring all others), or...
b.) choose the "latest" category encountered (again, ignoring all others), or...
c.) randomly choose between ALL identically matched categories

Pandorabots (I believe) uses option "b", while Program O uses option "c". There are advantages to both, though option "b" makes it easier to troubleshoot when things go wrong. :)
Title: Re: <topic> <that> precedence
Post by: Freddy on July 21, 2014, 02:05:45 pm
Presumably this would occur when an programmer has unwittingly supplied more than one pattern that matches. I imagine they would only want one response.

As it's impossible to read minds, I think I will default to the topic for now and maybe review it later.
Title: Re: <topic> <that> precedence
Post by: squarebear on July 21, 2014, 08:13:25 pm
Here is an example:

Human: do you like cats
Bot: Sure. I like them very much. Do you like them?
Human: yes
Bot: Cool. My favourite is Garfield.
Human: yes
Bot: What do you mean "yes"?

Code
<category> 
    <pattern>DO YOU LIKE CATS</pattern>
        <template>
            <think><set name="topic">cats</set></think>
            Sure. I like them very much. Do you like them?
        </template>
</category>

<category>
<pattern>YES</pattern>
<that>DO YOU LIKE THEM</that>
    <template>
    Sorry. Who are "they"?
    </template>
</category>


<topic name="CATS">
    <category>
        <pattern>YES</pattern>
        <that>DO YOU LIKE THEM</that>
        <template>
            Cool. My favourite is Garfield.
        </template>
    </category>

    <category>
    <pattern>YES</pattern>
    <template>
        What do you mean "yes"?
    </template>
    </category>

</topic>

However, this is a contrived example for demonstration, as you could do this with just <that> unless you had loads of "Do you like them?" type categories.

In the case of duplicates, I personally would go for Dave's option B. Sometimes, it's easier just to add a duplicate category than to search back through your AIML files to find the original. Option C would be a nightmare to debug, especially if you had a few hundred AIML files with matching categories. Bad practice I know but you will get people who do this.
Title: Re: <topic> <that> precedence
Post by: Freddy on July 21, 2014, 08:38:29 pm
Steve by 'matching categories' you must mean categories with the same patterns ?

In my interpreter there will only ever be one category/pattern because at the time of making the Graphmaster I avoid duplication - I thought this was beneficial because why would anyone want say five answers to one pattern ? Aside from the scenario you mention that because it's easier to just add a new category.

If say they wanted random replies shouldn't that be done using the built in method of the <random> tag ?

To help things along when the Graphmaster is built I can output debug information on duplicates. But I would have to decide on which duplicate to use. So I would at some point chose to use the first one found or the last one found. Since internally AIML has no dating scheme I don't know how one would find the 'latest' category...

Sorry if I am not getting the point or have overlooked something. I really don't want to cater to bad practice to be fair, I'm designing it following the documentation...
Title: Re: <topic> <that> precedence
Post by: Freddy on July 21, 2014, 08:48:43 pm
I guess you could date it from the time the file was last updated, but still that's catering to bad practice and I don't feel that should be the case. I think I will just produce an import report once the AIML has been looked over. Then one can remove duplicates from the AIML.

Thanks for the example :)
Title: Re: <topic> <that> precedence
Post by: squarebear on July 22, 2014, 10:52:56 am
Of course, you are quite correct and shouldn't cater for bad practice and people should use random for multiple replies.
An import report would be cool. There used to be a free utility called Shadow Checker which would report on duplicate categories and also categories that would never be called because another one (probably with an underscore wildcard) was blocking them. Unfiortunately, this doesn't seem to be about any more since XP became defunct.
Title: Re: <topic> <that> precedence
Post by: Freddy on July 22, 2014, 03:35:18 pm
Thanks Steve. I remember that shadow checker program, never got around to trying it though.

OK I will just do the import report then, thanks for your thought's Steve and Dave, much appreciated.
Title: Re: <topic> <that> precedence
Post by: Freddy on July 26, 2014, 09:34:59 pm
Continuing with <topic> I found that topics can have a wildcard, but only one.

So is the same rule of precedence followed as per patterns ? I couldn't really make out what the documentation here meant :

http://www.alicebot.org/documentation/aiml-reference.html#topic (http://www.alicebot.org/documentation/aiml-reference.html#topic)

I was thinking it goes _, KEYWORD, * as per the way pattern does.

Also in the case of...

Code
<topicstar index="n"/>

Why would one have the index of 'n' when only one wildcard is allowed ?

Thanks for any guidance :)
Title: Re: <topic> <that> precedence
Post by: DaveMorton on July 27, 2014, 04:26:02 am
Um... Freddy? I think that particular bit of documentation is a bit out of date. You're allowed multiple wildcards within  the <topic> tag; they just aren't used that much "in the wild". Structurally, <pattern>, <that> and <topic> tags are all pretty much the same, with the sole notable exception that the <pattern> tag allows use of the <bot> tag as a sort of wildcard; and even that exception is rather limited. While the document you've referenced mentions "pattern-side AIML elements", it never denotes what they are. This document (http://www.alicebot.org/TR/2001/WD-aiml/#section-pattern-side-bot-elements) also mentions "pattern-side bot elements", but again no real details are forthcoming. I'm still scouring the net for other mentions of what is allowed within a <pattern> tag, but so far, no luck. Some of the documents I seek are at least 10 years old, so may not "exist" anymore. :(
Title: Re: <topic> <that> precedence
Post by: Freddy on July 27, 2014, 02:36:14 pm
Thanks for the reply. Yes it's an old document, but it's about the best I have found so far.

Quote
Structurally, <pattern>, <that> and <topic> tags are all pretty much the same..

OK so the <topic> can have more than one wild card. Is the wildcard precedence the same as <pattern> then ?

Like this ?  _ KEYWORD *

I'll see if I can find some more up to date texts.
Title: Re: <topic> <that> precedence
Post by: DaveMorton on July 27, 2014, 03:21:09 pm
Wildcards behave exactly the same in all cases. It doesn't matter if it's in a <pattern>, <that> or <topic> tag. :)

I've been looking for better documentation as well, especially with regard to the GraphMaster. I know that there are some Power Point presentations floating around the net somewhere, but I have yet to locate them. Perhaps I should email Rich (AKA Dr. Richard Wallace) about this, and see if I can obtain the documentation directly. :)

BTW, speaking of the GraphMaster, I finally got the array structure I was looking for, but I haven't yet created a successful search algorithm. Still working on it, though. :)
Title: Re: <topic> <that> precedence
Post by: Freddy on July 27, 2014, 03:38:14 pm
Cheers Dave, I am glad the wildcards work the same. :)

Congrats on getting your structure right. :)

I got my search algorithm working okay. But I found a few odd things that I need to do in the GM (Graphmaster) building stage, like adding a * where there is no <topic> or <that>.  That confused me at first, but I believe that would mean only one search of the GM is needed. I was going to do three, but now that makes sense, so I am happy.

What we really could do with is a detailed run down (in the same manner as that old doc) for AIML 2. Then we would would have up-to-date information. There's some inconsistency in the information I have found so far.
Title: Re: <topic> <that> precedence
Post by: DaveMorton on July 27, 2014, 03:43:26 pm
What we really could do with is a detailed run down (in the same manner as that old doc) for AIML 2. Then we would would have up-to-date information. There's some inconsistency in the information I have found so far.

lol I think that's the understatement of the year. :D

There is some fairly good documentation about AIML 2.0 that helps answer a lot of questions about the "new stuff", and helps clarify a lot of the "old stuff", as well. I'll see if I can locate the docs in question, and post links to them..
Title: Re: <topic> <that> precedence
Post by: Freddy on July 27, 2014, 03:52:21 pm
Yeah I was holding back on that statement  ;D

It would be good to see those docs you mention, thanks  O0
Title: Re: <topic> <that> precedence
Post by: DaveMorton on July 27, 2014, 04:19:38 pm
Well, here's the AIML 2.0 Working Draft (https://docs.google.com/document/d/1wNT25hJRyupcG51aO89UcQEiG-HkXRXusukADpFnDs4/pub) for starters. As a bonus, the first thing in the document is a visual representation of part of an AIML GraphMaster (which, incidentally, has exactly the same structure that I came up with :) ). That should prove at least a little bit useful. :)
Title: Re: <topic> <that> precedence
Post by: Freddy on July 27, 2014, 04:49:36 pm
Yeah it looks a lot like my GM too.

Thanks for the link Dave :)
Title: Re: <topic> <that> precedence
Post by: DaveMorton on July 29, 2014, 04:01:12 pm
Hey, Freddy, can I 'swipe' your search algorithm? I'm having a bit of trouble with mine, and I want to compare it with yours, in hopes that I can see where mine is failing. :)
Title: Re: <topic> <that> precedence
Post by: Freddy on July 29, 2014, 04:10:17 pm
Give me a couple more days and I will send you what I have.

I'm still doing some testing here, but it's been so hot that it's a bit of a grind sitting at the PC for long.
Title: Re: <topic> <that> precedence
Post by: Freddy on July 29, 2014, 04:10:59 pm
I think the way I am building the GM is slightly different to the way you are doing it, but you might be able to adjust it.
Title: Re: <topic> <that> precedence
Post by: DaveMorton on July 29, 2014, 04:12:47 pm
Take all the time you need, Mate. :) And not to worry about the structure. Doesn't matter how we get there, so long as we do. :D
Title: Re: <topic> <that> precedence
Post by: Freddy on July 29, 2014, 05:19:53 pm
I had some time to look at this, it seems to be working okay so I have sent you a zip. :)
Title: Re: <topic> <that> precedence
Post by: DaveMorton on July 29, 2014, 05:34:54 pm
Got the file, but will have to wait till this evening to have a look. Off to run errands now. :)
Title: Re: <topic> <that> precedence
Post by: Freddy on August 01, 2014, 11:48:54 am
Any joy with the code I sent you Dave ?
Title: Re: <topic> <that> precedence
Post by: DaveMorton on August 01, 2014, 11:52:59 am
Been a bit too hectic here to get much into it, I'm afraid. Mom & Grandma got back from their 3 week trip on Wednesday and were all getting settled in. Hopefully I'll be able to get to it today. :)
Title: Re: <topic> <that> precedence
Post by: Freddy on August 01, 2014, 11:58:39 am
No worries, just curious. Hope they had a good time :)