AI Zone Admin Forum Add your forum

NEWS: Chatbots.org survey on 3000 US and UK consumers shows it is time for chatbot integration in customer service!read more..

_ and * clarification
 
 

Hey,

Can someone help me with a little question on the AIML wild cards please ?

I think I am right in saying that a _ will always trump a *.

So considering these two lines :

I LIKE _
I LIKE 

The interpreter will chose to match the first one (_) and ignore the second one (*) ?

Okay what if there is a mix like this.

I LIKE _ BECAUSE ITS *
I LIKE BECAUSE ITS 

Will it still default to the line with the _ ?

So in short as a rule so long as a pattern contains an _ in any place whatsoever it will always be picked over a matching pattern with *‘s ?

Cheers smile

 

 
  [ # 1 ]

Edited to give better example.

 

 
  [ # 2 ]

Also, how is this handled please ?

I LIKE _ BECAUSE ITS *
I LIKE BECAUSE ITS _ 
 

 
  [ # 3 ]

Hiya, Roger! smile

Yes, the _ wildcard always trumps the *

But bear in mind that the _ wildcard also trumps a direct match, as well. For example, let’s say you have 2 AIML categories that have the following patterns:

I LIKE _ BECAUSE ITS *
I LIKE PIZZA BECAUSE ITS 

If someone types in “I like pizza because its got cheese”, the first category will get selected instead of the direct match. In fact, because pattern #1 exists, pattern #2 will never get selected, ever, because the _ wildcard takes precedence. Furthermore, of the 2 examples that you list in your most recent post, the second one will also never be selected, for exactly the same reason. The _ wildcard is so powerful that it should only be used under very specific circumstances. The most common use is the removal of adverbs or other “filler words”, in a process known as “symbolic reduction”. Here are some full examples:

<category>
  <
pattern>_ JUST *</pattern>
  <
template><srai><star index="1"/> <star index="2"/></srai></template>
</
category>

<
category>
  <
pattern>_ REALLY *</pattern>
  <
template><srai><star index="1"/> <star index="2"/></srai></template>
</
category>

<
category>
  <
pattern>_ VERY *</pattern>
   <
template><srai><star index="1"/> <star index="2"/></srai></template>
</
category>

<
category>
  <
pattern>I M  _</pattern>
   <
template><srai>I AM <star index="1"/></srai></template>
</
category

These categories will reduce inputs from these:

I just went to the store last night
She is really pretty
I’m very sorry

To these:

I went to the store last night
She is pretty
I am sorry

This is very useful for reducing the number of AIML categories that have to be written, but again, care must be used, because sometimes words are important, and removing the wrong word in a sentence can completely change the meaning.

Another potential use for the _ wildcard is for pre-processing every single input. Below is an example of such a pre-processing AIML category, similar to ones used in a popular Second Life chatbot script:

<category>
  <
pattern>_ NPCID * * * * * * * * *</pattern>
  <
template>
    <
think>
      <
set name="parm1"><star index="2"/></set>
      <
set name="parm2"><star index="3"/></set>
      <
set name="parm3"><star index="4"/></set>
      <
set name="parm4"><star index="5"/></set>
      <
set name="parm5"><star index="6"/></set>
      <
set name="parm6"><star index="7"/></set>
      <
set name="parm7"><star index="8"/><set>
      <
set name="parm8"><star index="9"/></set>
      <
set name="parm9"><star index="10"/></set>
    </
think>
    <
sr/>
  </
template>
</
category

In the example above, the SL script generates all of the content from “NPCID” to the end, and appends it to the user’s chat input. This pre-processor category then sets all of the passed parameters, and then sends the user’s chat along to be parsed. When used in this way, it’s extremely useful, and generally won’t cause issues.

I hope that this helps. cheese

 

 

 
  [ # 4 ]

Be wary of using too many wildcards in one pattern though, as the interpreter has to travel many more paths to find a match and will slow the response time down.

 

 
  [ # 5 ]

Very true there, Steve. This was the most “near to hand” example I had to share, and it’s an “edge case”, so I thought it would be fitting to use here. smile

BTW, Program O doesn’t have the same performance issues with multiple wildcards, since it doesn’t use the Graph-master (or anything even remotely similar). Where Program O has a performance hit is with categories with lots of <srai> calls (though I’ve recently found a solution for that). wink

 

 
  [ # 6 ]

I knew I could count on you guys smile

Thanks a lot that helps a great deal. I am confused on one aspect still…

Furthermore, of the 2 examples that you list in your most recent post, the second one will also never be selected.

Sorry for being dim, but out of these two…

I LIKE _ BECAUSE ITS *
I LIKE BECAUSE ITS _ 

...only the first one will match ? Is that because in the first one the _ comes first in the pattern ? Sort of beating the second pattern into second place ?

The reductions make a lot more sense now you have explained it Dave. I was looking at some of the AAA reductions and I had an inkling that they were working like that, but wasn’t sure until you confirmed it.

@ Steve, noted thanks smile

Cheers smile

 

 
  [ # 7 ]

Yes the _ will always take priority over ANYTHING else. As you say, it come first in the pattern and the interpreter checks from left to right.

 

 
  [ # 8 ]

Yes, that’s exactly right, Fre… er… Roger. smile

Since the 2 patterns are identical except for the placement of the wildcards, and since the _ wildcard matches before anything else, the second pattern will never “see the light of day”, and is more or less superfluous.

[edit]
I see Steve snuck in there ahead of me. Good answer, too. :thumbsup: (Yes, I know, that emoticon doesn’t work here)
[/edit]

 

 
  [ # 9 ]

Hehe , I get so used to being called Freddy smile

Thanks again chaps, that’s all helped me a lot.

 

 
  [ # 10 ]

Can you confirm my thinking chaps ?

I’m working on my interpreter. Am I right in thinking that this is the order of precedence in my examples. The top pattern being the best hit and the last being the lesser. So they trump each other in that order.

WHAT IS _
WHAT IS A RED 
*
WHAT IS A *
WHAT IS 

Cheers smile

 

 
  [ # 11 ]

That is, indeed, correct, Roger. The more “direct match” words there are in the input, the higher the “score” (if you’re using a scoring system, and not a GraphMaster).

Program O version 2 uses a scoring system to determine the “best match”, but for version 3, I’m looking for something more closely matching GraphMaster, and the way matches are determined that way.

 

 
  [ # 12 ]

Thanks Dave. I’m using a scoring system too, at the moment it looks like it is working right. smile

 

 
  [ # 13 ]

Another one here. I’m trying to work out when something just gets ignored.


If I have these two patterns.

_ WORDA _ WORDB _
WORDA 

I know you’d probably not use these, but I need to know for my interpreter.

So if the input is :

SOMETHINGA WORDA SOMETHINGB

The first pattern has a partial match on _ wildcards, but not a full match so I ignore it.

But since the first pattern is ignored should I go on to match it with the * wildcard pattern ?

Or does the first pattern still override the stars (*) despite being a partial match ?

Thanks.

 

 
  [ # 14 ]

Given the conditions you set forth, along with the input you provided, the pattern:

_ WORDA _ WORDB _ 

will never get selected, because “WORDB” wasn’t part of the input. Even if you had this for an input:

SOMETHINGA WORDA SOMETHINGB WORDB

It wouldn’t “fire”, because of the last underscore in the pattern. As a result, the pattern

WORDA 

will be used in both cases.

{I HATE typing on my laptop!}

 

 
  [ # 15 ]

Great thanks Dave. smile

This was baking my noodle a bit - been staring at code all day. I had thought that…

WORDA 

...would be the one to select. It just made more sense.

Cheers !

 

 1 2 > 
1 of 2
 
  login or register to react