π Rule-Based Syntax for Intents and Entities
Rule-based syntax is a simple, word-matching approach to triggering an intent or entity without relying on an NLP model.
Matching Basics
-
A sample matches any word that begins with the same characters as the sample.
Example:
- Sample
al
matchesaloha
andalcohol
, but notbanal
.
- Sample
-
A multiple-choice sample provides alternate options and is expanded into individual matches.
Example:
- Sample
Alibaba/Aladdin
matches bothAlibaba
andAladdin
.
- Sample
Handling Multiple Matches
When there are multiple matches for a given entity type:
-
Wrapper Handling:
- If the entity has a wrapper, it determines which match to keep.
-
First Match Preference:
- If no wrapper is used, the first match in the message is kept.
Example:
- If the sample is
Al
and the message is "Alibaba and Aladdin," both match, butAlibaba
is chosen since it appears first.
-
Matches Starting at the Same Position:
- If two samples start at the same position, conflicts arise. For example, if the entity type has samples
Al
(forAladdin
) andAlice
, then both matchAlice
.
Solution:
- Use
-
to exclude specific matches. For instance, useAl -Alice
to matchAladdin
and excludeAlice
.
Caution
If someone says "I want Aladdin, not Alice," you might still match
Alice
. - If two samples start at the same position, conflicts arise. For example, if the entity type has samples
Syntax Recap
- " / ": Separate multiple-choice options (e.g.,
Alibaba/Aladdin
) - " - ": Exclude specific matches (e.g.,
Al -Alice
) - " [ ] ": Enclose exact expressions (e.g.,
[Hello World]
)