Pattern
Annotation | <Pattern> |
---|---|
Definition | Used to declare an SIML Pattern used to activate a Model |
Children | This element MAY contain one or more <Item> elements the values of which SHOULD be a valid SIML pattern. It MAY contain one <If> or <Js> element. If no children elements are specified a <Pattern> element MUST contain a valid SIML pattern as an arbitrary text. |
Occurrence | This <Pattern> element MUST occur as a child of |
A <Pattern>
element is used to declare an SIML pattern. The above pattern in the Model section is called an atomic pattern because the pattern comprises of only words and no symbols. In SIML there are a number of ways of declaring a valid pattern by either using wildcards, sets, regular expressions, variable state comparison (conditionals) or even JavaScript.
Symbols in Pattern
Symbol | Description |
---|---|
^ | Top priority word match |
% | Zero or more word wildcard match |
_ | One or more word wildcard match |
word | Exact word match |
[word] | Match found in SIML Set |
(Word1|Word2|Word3) | Dynamic Set declaration |
@ | Match found in SIML Regular Expression Set |
$ | Zero or more word wildcard match |
{Word1 Word2} | Sentence Match |
* | One or more word wildcard match |
Caret
Firstly the ^ symbol. This symbols ensures that the word after the symbol is to be evaluated ( or looked for ) before any other word or symbol.
Example
SIML Code
<Model>
<Pattern>HI THERE</Pattern>
<Response>Heya user</Response>
</Model>
<Model>
<Pattern>^HI THERE</Pattern>
<Response>Hello user</Response>
</Model>
User Input
Hi there
Bot Output
Heya User
Explanation
The symbol ^ in the above example speaks for itself by pointing upwards which implies that the word Hi in the first pattern declared in the first Model has the highest priority. So if the user says Hi there the bot will respond Hello user despite the fact that the pattern HI THERE has been defined before the pattern ^HI THERE.
Percent
The % symbol is used to denote a pattern that will match zero or more words.
Example
SIML
<Model>
<Pattern>HELLO SIML</Pattern>
<Response>Life is awesome!</Response>
</Model>
<Model>
<Pattern>% SIML</Pattern>
<Response>You Rock!</Response>
</Model>
User Input
Hello Siml
Bot Output
You Rock!
Explanation
Since % has higher priority than an exact word SIML Bot will accept the second model with the pattern % SIML and generate a response.Note: If the user says SIML the response will still be You Rock! this is because the Percent symbol accepts 0 or more words.
Underscore
The underscore symbol matches one or more words unlike the percent symbol that matches zero or more words.
Example
SIML
<Model>
<Pattern>_ MY NAME IS LESLIE</Pattern>
<Response>Good to meet you.</Response>
</Model>
<Model>
<Pattern>HI MY NAME IS LESLIE</Pattern>
<Response>Well, Hi there.</Response>
</Model>
User Input
Hi my name is Leslie
Bot Output
Good to meet you.
Explanation
The _ symbol has a priority lesser than % but higher than an exact word. This symbol is useful if you wish to ignore a word or sentence especially the name of the Bot when declaring commands.
A Word
A word in any language ranks 4 under the evaluation tree in SIML. Words are matched as such and no match indexing is generated. SIML uses UTF-8 encoding to address multiple languages.
Example
SIML
<Model>
<Pattern>HOW ARE YOU</Pattern>
<Response>I am fine.</Response>
</Model>
<Model>
<Pattern>HOW ARE YOU DOING TODAY</Pattern>
<Response>I am doing great.</Response>
</Model>
User Input
How are you
Bot Output
How are you
Explanation
Words and their locations are matched as such. If you remove the Model with the Pattern How are you SIML won’t activate the second Model containing the pattern How are you today
Set
A Set is a collection of words or sentences. SIML Interpreter uses state-of-the-art technology to make sure large sets do not affect the performance of matching text fragments against a collection of words in a set.
A set declaration requires that you give the set a unique name. A set is addressed using Square Brackets so to use a set of colors with the name COLOR you would use [COLOR]
Two different sets with different names must not hold common values.
Example
SIML
<Model>
<Pattern>I LIKE THE COLOR [COLOR]</Pattern>
<Response>Me too!</Response>
</Model>
User Input
I like the color blue
Bot Output
Me too!
Explanation
[COLOR] is a collection of colors (names of colors)
Sets in SIML can be declared in using the <Set>
Tag and can be accessed ( once declared ) using Round Brackets around their names.
Set Declaration
Annotation | <Set> |
---|---|
Definition | Declares an SIML Set |
Children | The element MUST contain one or more <Item> element OR a comma separated arbitrary value. |
Attributes | Required Name Unique name given to the Set. |
Occurrence | One or more of this element MAY occur as children of <Siml> element. |
<Set Name="Color">
<Item>RED</Item>
<Item>GREEN</Item>
<Item>BLUE</Item>
<Item>ORANGE</Item>
</Set>
Or
<Set Name="Color">Red, Green, Blue, Orange</Set>
Reserved Set Names
SIML comes with reserved Set names that can help developers address Bot, User and Map items directly within a Pattern. The name of the Set and the parameter part are separated using a colon.
Like all set names, the name and the parameter part of the reserved variables are case-insensitive. Reserved sets are also dynamic. Hence, at run-time if the value of any variable is changed the pattern will then match the new value.
Bot Set
To indicate a bot variable the set name Bot is followed by the name of the bot variable.
Example
SIML
<Model>
<Pattern>Is your name [Bot:Name]</Pattern>
<Response>
Yes, my name is <Match />
</Response>
</Model>
User Input
Is your name Maya?
Bot Output
Yes, my name is Maya
Explanation
At run-time the pattern is evaluated after replacing the value of
[Bot:Name]
with the name of the Bot as Is your name Maya.
User Set
Example
SIML
<Model>
<Pattern>Is my name [User:Name]</Pattern>
<Response>
Yes, your name is <Match />
</Response>
</Model>
User Input
Is my name Leslie?
Bot Output
Yes, your name is Leslie
Explanation
At run-time the pattern is evaluated after replacing the value of
[User:Name]
with the name of the user as Is your name Leslie.
Map Set
Example
SIML
<Model>
<Pattern>Is your [Map:Family-Gender] a researcher</Pattern>
<Response>
Yes, my <Match /> is a researcher.
</Response>
</Model>
User Input
Is your father a researcher?
Bot Output
Yes, my father is a researcher
Explanation
The family-gender Map may contain
father
,mother
,brother
andsister
and their gender values. While parsing the Content value of the<MapItem>
is treated as a Set value.
Choices
Example
<Model>
<Pattern>I LIKE THE COLOR (RED|GREEN|BLUE)</Pattern>
<Response>Me too!</Response>
</Model>
Priority of Choices and Normal Sets are the same. Conflicts between choices and listed sets can be ignored as the former serves the same purpose but within a limited domain.
Ampersat
The @ symbol is used to denote a Regular Expression in SIML. Every regular expression a user creates is stored in an optimized manner for speed and consistency. Bot developers will find regular expression in SIML to be extremely fast.
Example
SIML
<Model>
<Pattern>I LIKE THE COLOR @COLOR</Pattern>
<Response>Me too!</Response>
</Model>
User Input
I like the color blue
Bot Output
Me too!
Explanation
@Color is a regular expression with the unique name COLOR
Dollar
The $ symbol matches 0 or more words and has less priority than its sibling symbol %.
Example
SIML
<Model>
<Pattern>YOU ARE $ COOL</Pattern>
<Response>Yes, I am.</Response>
</Model>
User Input
You are so cool
Bot Output
Yes, I am.
Explanation
The dollar symbol will match so. If the user writes You are cool the pattern will still hold as the symbol matches 0 or more words.
Curly Brackets
{} allows developers to define a set of words that should exist in a sentence. Any number of words can exist before, between and even after the specified collection of words but the order of appearance of these words should match their orders defined within the curly brackets.
Example
SIML
<Model>
<Pattern>{CONTACT NUMBER}</Pattern>
<Response>+1-000-00-0000</Response>
</Model>
User Input
So what is your contact number?
Bot Output
1-000-00-0000
Explanation
The pattern contains 2 important words contact and number and even if the user adds a word in this case phone the pattern will still hold and a response will be generated.
Asterisk
The * symbol is a wildcard that matches 1 or more words and has the least priority in the evaluation tree. This symbol is the most widely used wildcard symbol in knowledge base development.
Example
SIML
<Model>
<Pattern>ARE YOU A ROBOT</Pattern>
<Response>Maybe I am.</Response>
</Model>
<Model>
<Pattern>ARE YOU * ROBOT</Pattern>
<Response>I am an intelligent entity.</Response>
</Model>
User Input
Are you some robot?
Bot Output
I am an intelligent entity.
Explanation
Since there is no exact pattern for Are you some robot the * wildcard matches the input Are you some robot. The word some is then stored in the Match list which can later be retrieved using the
<Match />
tag.
Behavior of Zero+ wildcards
When zero+ wildcards are used the match value for the wildcard may or may not contain a value. If the length of match is 0 and the <Match>
element or any of its derivative elements are used to retrieve this value. The interpreter checks for the value of the reserved Bot variable Empty-Match
. If a value is specified for the variable then the value is used otherwise an empty string is returned.
Ranged Wildcards
Ranged wildcards allow developers to set a fixed or a variable length capture on any SIML wildcard aforementioned. A ranged wildcard will always maintain its evaluation index based on the symbol used.
Fixed Length
If you wish to capture an exact number of words from user input then add the required number as a suffix to the type of wildcard symbol of your choice.
Example
SIML
<Model>
<Pattern>CALL ME *2</Pattern>
<Response>Nice to meet you, <Match /></Response>
</Model>
<Model>
<Pattern>CALL ME *</Pattern>
<Response>Well, hello there <Match /></Response>
</Model>
User Input
- Call me Sean Gates
- Call me Sean William Gates
Bot Output
- Nice to meet you, Sean Gates
- Well, hello there Sean William Gates
Explanation
The star * wildcard is suffixed with 2 making sure that the wildcard captures exactly 2 words from user input.
Likewise developers can make use of any other SIML wildcard symbol and suffix it with a number to specify the exact number of words it should capture.
Suffixing a Zero+ wildcard with a number forces the wildcard to act as a One+ wildcard that captures the exact number of words specified.
Variable Length
A variable length wildcard can be used to specify the maximum number of words a wildcard may capture. To create a variable length wildcard prefix the number with a tilde.
Example
SIML
<Model>
<Pattern>CALL ME *~2</Pattern>
<Response>It's a pleasure to meet you, <Match /></Response>
</Model>
<Model>
<Pattern>CALL ME *</Pattern>
<Response>Well, hello there <Match /></Response>
</Model>
User Input
- Call me Sean
- Call me Sean Gates
- Call me Sean William Gates
Bot Output
- It’s a please to meet you, Sean
- It’s a pleasure to meet you, Sean Gates
- Well, hello there Sean William Gates
Explanation
The star * wildcard is suffixed with tilde symbol followed by 2 making sure that the wildcard captures a maximum of 2 words from user input.
Priority Index
Every wildcard in SIML is evaluated based on a priority index. The evaluation sequence of a Wildcard symbol is as follows.
- Fixed Length – Example
*2
- Variable Length – Example
*~2
- Atomic Symbol – Example
*