5

I'm having a problem trying to understand how does AIML pattern matching works. What's the difference between _ and *? And how I should use them to get the best match?

I have this document only, but it lacks some good examples.

2 Answers2

4

A * will match anything unless a pattern of a word or several words are matched

A _ will match anything even if a pattern of a word or several words could match

<pattern>BYE _</pattern> does not make sense since <pattern>BYE *</pattern> matches the same patterns but <pattern>BYE _</pattern> will shadow <pattern>BYE * SEE YOU</pattern> whereas BYE * won't.

Use _ carefully, for example _ would match anything and your bot will give the same answer every times.

<pattern>_ A COUPLE OF WORDS *</pattern> and <pattern>_ A COUPLE OF WORDS</pattern> is the proper way to use _ if you want to catch every times A COUPLE OF WORDS is inside or at the end of a sentence.

Charlix
  • 41
  • 1
0

_ and * are both wildcards, the difference is where they should be used in pattern matching.

_ should be used before the word or phrase you're matching on
* should be used after the word or phrase you're matching on.

See: AIML spec

To understand this better it may be worth looking at examples in the existing AIML bots.

See: Downloads, this one Saluations.aiml has examples

Bravax
  • 10,453
  • 7
  • 40
  • 68
  • So that would mean that 'HELLO _' is an invalid expression? Right? –  Dec 03 '09 at 10:33
  • This is what I have found in http://www.alicebot.org/aiml/aaa/Salutations.aiml What's the essential difference between these two patterns? * BYE _ BYE Btw, thanks for the answer :) –  Dec 03 '09 at 10:41
  • I would say, based on the spec that HELLO _ is invalid yes. And that was a seriously bad example on my part. I don't think the * BYE would ever be evaluated. * BYE is in my view invalid, and should be BYE *. – Bravax Dec 03 '09 at 10:58