3

in AIML, if I have multiple files matching for the same pattern, how can I give precedence to match in one file ?

Preetham R U
  • 316
  • 5
  • 6

3 Answers3

4

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.

  1. "$" : indicates that the word now has higher matching priority than "_"
  2. "#" : 0 or more words
  3. "_" : 1 or more words
  4. word : exact word match
  5. "^" : 0 or more words
  6. "*" : 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.

Ida
  • 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 moves". 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:33
2

Hope this helps you

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?

jettimadhuChowdary
  • 1,058
  • 1
  • 13
  • 23
1

The Alice site has the following notes on how priority is determined:

  1. At every node, the "_" has first priority, an atomic word match second priority, and a "*" match lowest priority.

  2. The patterns need not be ordered alphabetically, only partially ordered so that "_" comes before any word and "*" after any word.

  3. The matching is word-by-word, not category-by-category.

  4. 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.

  5. The matching algorithm is a highly restricted version of depth-first search, also known as backtracking.

  6. 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 .

From Alicebot.org

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.

Philip Kirkbride
  • 21,381
  • 38
  • 125
  • 225