SeedVault / rhizome

conversational bot engine created by Botanic/SEED team
https://seedtoken.io
Other
7 stars 2 forks source link

Add basic functionality for .Flow v2 instruction $aimlMatch #8

Open nicolasbotanic opened 5 years ago

nicolasbotanic commented 5 years ago

This will provide basic pattern matching compatible with AIML 2.0 tag with wildcards * _ ^ #

For more information on AIML 2 see https://pandorabots.github.io/tutorials/wildcards/ and https://gist.github.com/onlurking/f6431e672cfa202c09a7c7cf92ac8a8b

For more information on .Flow v2 pattern matching instructions see https://github.com/SeedVault/flow#intent-matching-instructions

Same as .Flow v2 instruction $regexMatch it should support a 3rd argument with a list of variables to be set with values provided by the wildcards (see code on /engines/dotflow2/core_functions.py method df2_regexMatch ... also see code on /engines/dotflow2/extensions/chatscript_match.py )

Ex:

{"$aimlMatch": [
    "MY NAME IS * AND I AM * YEARS OLD", 
    "MY NAME IS NICOLÁS AND I AM 40 YEARS OLD", 
    ["name", "age"]
}

This instruction should return True and store in variable "name" the value "NICOLÁS" and in variable "age" with value "40"

Add the code in a new file /engines/dotflow2/extensions/aiml_match.py and add an entry for it into the config file /instance/config_development_example.yml

Do not include any AIML preprocessing or parse any tag inside the pattern tag (like \<regex> or any other) (Note in the example I've provided an input text in uppercase and avoiding to use "I'm" to do an exact match)

You can easily test .Flow v2 instructions using the provided console:

BBOT_ENV=development python -m channels.console.app joe testbot 1 nodebug

This will enter to the provided demo bot's console as userid "joe" You can run any .Flow instruction with the command df2:

Expected result with $aimlMatch:

You: :reset all
Testbot: All user session data erased.
You: :df2 aimlMatch('MY NAME IS * AND I AM * YEARS OLD', 'MY NAME IS NICOLÁS AND I AM 40 YEARS OLD', ['name', 'age'])
Testbot: True
You: :df2 get('name')
Testbot: NICOLÁS
You: :df2 get('age')
Testbot: 40
You: :df2 text('Your are $name and you are $age years old')
Testbot: {'text': 'Your are NICOLÁS and you are 40 years old''}