5.5 advanced patterns
Keyword Phrases : Just put them in quotes. E.g.
cocept: ~remove ( "take away" remove )
?: ( do you take away cheese )
Implied concept Sets : This allows the system to find the soonest match of any of them. otherwise [] and {} take each element in turn and try to find a match, which may be later in the sentence than a later element in the set would match.
Dictionary Keyword sets : In ChatScript, WordNet ontologies are invoked by naming the word, a ~, and the index of the meaning you want.
concept: ~buildings [ shelter~1 living_accomodations~1 building~3 ]
Similarly you can invoke parts of speech classes on words. By default you get all of them. If you write :
concept: ~beings [ snake mother ]
then a sentence like "I like mothering my baby" would trigger this concept, as would "He snaked his way through the grass". But the engine has a dictionary and a part-of-speech tagger, so it often knows what part of speech a word in the sentence is.
You can use that to help prevent false matches to concepts by adding ~n ~v ~a or ~b (adverb) after a word.
concept: ~beings [ snake~n mother~n ]
System Functions : ^query --- to see if some fact data could be found. Many functions make no sense to call, because they are only useful on output and their behavior on the pattern side is unpredictable.
Macros : Just as you can use sets to "share" data across rules, you can also write macros to share code.
Pattern macros : a top-level declaration that declares a name, arguments that can be passed, and a set of script to be executed "as though the script code were in place of the original call".
Macro names can be ordinary names or have a ^ in front of them. The arguments must always begin with ^ .
The definition ends with the start of a new top-level declaration or end of file. E.g.
patternmacro: ^ISHAIRCOLOR(^who)
![not never]
[
( << be ^who [blonde brunette redhead blond ] >> )
( << what ^who hair color >> )
]
?: ( ^ISHAIRCOLOR(I) ) How would I know your hair color ?
Dual macros : it means can be used in both pattern and output contexts.
Literal Next \ :
Question and exclamation - ? ! : In rejoinders rule, you need to use the ? keyword. It doesn't change the match position.
t: Do you like germs?
a: ( ? ) Why are you asking ...
a: ( !? ) I appreciate your statement.
More comparison test - & ? : You can use the logical and bit-relation to test numbers. Any non-zero value passes.
s: ( _~number _0&1 ) Your number is odd
Comparison with C++ #define in dictionarySystem.h : You can name a constant from that file as the right hand side of a comparison test by prefixing its name with #. E.g.
s: ( _~number _0=#NOUN )
Current Topic ~ : If the topic is currently on the pending list, then the system will match the ~ . E.g .
u: ( chocolate ~ ) I love chocolate ice cream
A useful idiom is [~topicname ~]. This allows you to match if either the user gave keywords of the topic OR you are already in the topic. So :
u: ( << chocolate [~ice_cream ~] >> )
would match if you only said chocolate while inside the topic, or if you said chocolate ice cream while outside the topic.
Prefix Wildcard Spelling and Postfix Wildcard Spelling : like Sagittarius
u: ( Sag* ) # This matches "Sagittarius" in a variety of misspellings.
Indirect pattern elements :
Setting Match Position - @_3+ @_3- @_3 :
Backward Wildcards :
Gory details about strings :
Generalizing a pattern word :
The deep view of patterns :
Interesting thing about match variables :
Precautionary note about [ ] and pattern matching retries :