All Tutorials / Jlucben / Synbot Plugin Tutorial - interface to Syn Bot Software

Synbot Plugin Tutorial - interface to Syn Bot Software

Step 11 : Pattern Reductions

Using Pattern reductions

In the Pattern Reductions SIML file , you can specify patterns which will be evaluate first for every User Input to the Bot.
Look at the example file delivered in which pattern reduction is used to specify several common syntax forms for a request.
COULD YOU TELL ME - CAN YOU GIVE US - I WOULD LIKE YOU TO GIVE - I JUST WANT YOU TELL ME - I WANT TO KNOW - COULD I KNOW - GIVE US - TELL ME - .....

User Input I WANT TO KNOW WHAT IS YOUR NAME will in this case switch to the evaluation of Pattern WHAT IS YOUR NAME due to the Goto tag
Variables values can be set in the Pattern Reductions Models in ordered to be tested in the switched Pattern Model.
Personnal framework example include automatic setting of some SIML variables Flags Typego1 to Typego15 , depending on the verb used.

Code:

[Map Name="Peux_Tu_en"]
[MapItem Content="can you" Value="T" /]
[MapItem Content="could you" Value="T" /]
[/Map]
[Map Name="Pourrai_je_en"]
[MapItem Content="can I" Value="T" /]
[MapItem Content="could I" Value="T" /]
[MapItem Content="can we" Value="T" /]
[MapItem Content="could we" Value="T" /]
[/Map]
[Map Name="Aimerai_voudrai_je_en"]
[MapItem Content="I would like" Value="T" /]
[MapItem Content="I wish" Value="T" /]
[MapItem Content="I just wish" Value="T" /]
[MapItem Content="I want" Value="T" /]
[MapItem Content="I just want" Value="T" /]
[/Map]


Different User input structures are taken into account in the example models :
. For kind of verbs configured in map CURRENT_VERB_1_EN
Phrase structure of type : can you give me , could you tell us , can you give , could you tell , I would like you give , I just want you tell , we wish you give
I would like you give me , I just want you tell us , we wish you give us , give me , tell us , give , tell
. For kind of verbs configured in map CURRENT_VERB_2_EN and Conjugate form im map CURRENT_VERB_2_FORM2_EN
Phrase structure of type : can I know , could we have , I would like to know , we wish to have , do you have , do you know
. For kind of verbs configured in map CURRENT_VERB_3_EN
Phrase structure of type : can you learn that , I would like you learn that, I just want you learn that , we wish you learn that , learn that.

Code:

[Map Name="current_verb_2_en"]
[MapItem Content="know" Value="%" /]
[MapItem Content="have" Value="%" /]
[/Map]
[Map Name="current_verb_2_form2_en"]
[MapItem Content="have you" Value="have" /]
[MapItem Content="do you have" Value="have" /]
[MapItem Content="do you know" Value="know" /]
[/Map]

Note than content value for conjugate form maps links to the key entry in the verb map.

Same kind of Maps (but suffixed with fr) are existing to configure french verbs : current_verb_1_fr , current_verb_1_form1_fr , current_verb_1_form_fr , current_verb_2_fr , current_verb_2_form2_fr
current_verb_3_fr , current_verb_3_form1_fr , current_verb_3_form2_fr

In the pattern reductions example files you find also recognition in user input phrases of some greetings and politness formulas configured in map greetins and politness and combined with bot name.

Code:

[Map Name="greetings"]
[MapItem Content="Hi" Value="en" /]
[MapItem Content="Hello" Value="0" /]
[MapItem Content="Bonjour" Value="fr" /]
[/Map]
[Map Name="politeness"]
[MapItem Content="S'il te plait" Value="fr" /]
[MapItem Content="S'il vous plait" Value="fr" /]
[MapItem Content="Please" Value="en" /]
[/Map]



For example Input phrase : "Hi Maya could you give me your voltage please" would be redirected to the "XXXXXFROMPATTERNREDUCTION Your voltage" Pattern Model.
Note the XXXXXFROMPATTERNREDUCTION prefix indicating that a verb pattern reduction interpretation has bee done in the user input phrase.
Other Pattern reductions for EZ Commands verbs are included in EZ Robot request SIML File.

Using Pattern reductions - setting of some SIML variables Flags Typego1 to 15

Map autho_numflag_verb is used to configure flags TypeGoxx setting depending on the verb found in input pattern

Code:

[MapItem Content="1|dire" Value="%" /]
[MapItem Content="1|tell" Value="%" /]
[MapItem Content="1|say" Value="%" /]
[MapItem Content="1|savoir" Value="%" /]
[MapItem Content="1|connaƮtre" Value="%" /]
[MapItem Content="1|connaitre" Value="%" /]
[MapItem Content="1|know" Value="%" /]
[MapItem Content="2|donner" Value="%" /]
[MapItem Content="2|connaƮtre" Value="%" /]
[MapItem Content="2|connaitre" Value="%" /]
[MapItem Content="2|tell" Value="%" /]
[MapItem Content="2|give" Value="%" /]


Entry key is flag index|verb keyword , for example if we found the verb tell in input pattern , variable flag Typego1 will be set to 1.
Verbs are limited to verbs configured in pattern reduction example (maps CURRENT_VERB_1_EN , CURRENT_VERB_2_EN , CURRENT_VERB_3_EN and same suffixed by fr for french language)
Variable flag Typego is also Set to 1 if a verb pattern reduction is applied.

For example , For input "Give me your voltage" - Pattern activated will be "XXXXXFROMPATTERNREDUCTION1 your voltage" with Typego and Typego2 set to 1.
For Input "talk us your voltage" , pattern activated will be the same with Typego2 set to empty string.
In the "XXXXXFROMPATTERNREDUCTION1 your voltage" pattern model, we can so test typego2 variable and reject the incorrect input phrase "talk us your voltage"

Code:

[Model]
[Pattern]
[Item]XXXXXFROMPATTERNREDUCTION1 [MAP:DIRECT_QUESTION_OBJECT_EN] $[/Item]
[/Pattern]
[Response xml:space="preserve"]
[Think]
[If Var="Typego2" Value="1"]
[Var Set="temp1"][Map Get="direct_question_object_en"][Match /][/Map][/Var]
[Var Set="keyobject"][Text WordAt="2"][Var Get="temp1" /][/Text][/Var]
[Var Set="Compattribute"][Match At="2" /][/Var]
[Goto xml:space="preserve"]XXXXXQUERYEZ [Var Get="keyobject" /][/Goto]
[/If]
[ElseIf Var="Typego11" Value="1"][Goto xml:space="preserve"]XXXXXFROMPATTERNREDUCTION2 [Match /] [Match At="2" /][/Goto][/ElseIf]
[/Think]
[/Response]
[/Model]
[Map Name="direct_question_object_en"]
[MapItem Content="your current voltage" Value="%M VOLTAGE" /]
[MapItem Content="your voltage" Value="%M VOLTAGE" /]
[MapItem Content="your temperature" Value="%F PROCESSORTEMPERATURE" /]
[MapItem Content="your processor temperature" Value="%F PROCESSORTEMPERATURE" /]
[/Map]

Example can be found in EZ Robot Request - Queries SIML File.
Note The test included for Typego11 - in order to redirect to correct pattern because entries in the 2 maps VARIABLE_VALUE_EN and direct_question_object_en can be the same.
and for this entries pattern [Item]XXXXXFROMPATTERNREDUCTION1 [MAP:VARIABLE_VALUE_EN] * TO *[/Item] will never be activated.

Code:

[Model]
[Pattern]
[Item]XXXXXFROMPATTERNREDUCTION1 [MAP:VARIABLE_VALUE_EN] * TO *[/Item]
[Item]XXXXXFROMPATTERNREDUCTION1 [MAP:VARIABLE_VALUE_EN] * ON *[/Item]
[Item]XXXXXFROMPATTERNREDUCTION2 [MAP:VARIABLE_VALUE_EN] * TO *[/Item]
[Item]XXXXXFROMPATTERNREDUCTION2 [MAP:VARIABLE_VALUE_EN] * ON *[/Item]
[/Pattern]
[Response xml:space="preserve"]
[Think]
[If Var="Typego11" Value="1"]
[Var Set="Temp"][Match At="2" /][/Var]
[Var Set="Temp2"][x:EZvar Get="{Bind Var:Temp}" /][/Var]
[x:EZvar Set="{Bind Var:Temp}" Value="{Bind Match:3}" /]
[User Think:Set="bot_event_response"]Value of variable [Var Get="Temp" /] has been set to [Match At="3" /][/User]
[/If]
[/Think]
[/Response]
[/Model]

Steps