in AIML, if I have multiple files matching for the same pattern, how can I give precedence to match in one file ?
3 Answers
You should use AIML's wildcards to control the priority of pattern matching.
AIML 1.0 only has * and _ to match 1 or more words. AIML 2.0 adds ^ and # to match 0 or more words.
Below is the priority rank of AIML 2.0 wildcards, from the highest matching priority to the lowest.
- "$" : indicates that the word now has higher matching priority than "_"
- "#" : 0 or more words
- "_" : 1 or more words
- word : exact word match
- "^" : 0 or more words
- "*" : 1 or more words
Please see AIML 2.0 working draft for details, specifically chapter 5.A.Zero or more words wildcards for wildcards and priority description.

- 2,919
- 3
- 32
- 40
-
Is there a way to match any one of a set of words? for example,
can you [jump|shout|run] , or do I have to define three different rules for them? – chesscov77 May 29 '17 at 03:37 -
Yes, with the
tag. In your example, put a file called "moves.txt" (or whatever) into the bot's "sets" directory. Your pattern is then " can you ". IMO reusing the keyword "set" here is unintuitive since "set" now means different things in different contexts. But it's what they did. – Mark Phillips Sep 06 '19 at 18:33moves
The AIML 1.0 wildcards * and _ are defined so that they match one or more words. AIML 2.0 introduces two new wildcards, ^ and #, defined to match zero or more words. As a shorthand description, we refer to these as “zero+ wildcards”. Both ^ and # are defined to match 0 or more words. The difference between them is the same as the difference between * and _. The # matching operator has the highest priority in matching, followed by _, followed by an exact word match, followed by ^, and finally * has the lowest matching priority. When defining a zero+ wildcard it is necessary to consider what the value of (as well as and ) should be when the wildcard match has zero length. In AIML 2.0 we leave this up to the botmaster. Each bot can have a global property named nullstar which the botmaster can set to “”, “unknown”, or any other value. What’s new in AIML 2.0?

- 1,058
- 1
- 13
- 23
The Alice site has the following notes on how priority is determined:
At every node, the "_" has first priority, an atomic word match second priority, and a "*" match lowest priority.
The patterns need not be ordered alphabetically, only partially ordered so that "_" comes before any word and "*" after any word.
The matching is word-by-word, not category-by-category.
The algorithm combines the input pattern, the pattern, and the pattern into a single "path" or sentence such as: "PATTERN THAT TOPIC" and treats the tokens and like ordinary words. The PATTERN, THAT and TOPIC patterns may contain multiple wildcards.
The matching algorithm is a highly restricted version of depth-first search, also known as backtracking.
You can simplify the algorithm by removing the "_" wildcard, and considering just the second two steps. Also try understanding the simple case of PATTERNs without and .
Based on this you could use the '_' to give something presidence. Take the following example:
<category>
<pattern>_ BAR</pattern>
<template>Which bar?</template>
</category>
<category>
<pattern>FOO BAR</pattern>
<template>Don't you mean FUBAR? That's an old military acronym, that roughly translates to "broken". I can't directly translate it because I don't curse.</template>
</category>
<category>
<pattern>* BAR</pattern>
<template>There are a lot of bars. There's a crow bar, the state bar, a bar for drinking, and foo bar.</template>
</category>
The _
takes highest priority being matched first. The simple BAR
is second in priority and the *
is last.

- 21,381
- 38
- 125
- 225