keiffster / program-y

Python 3.x based AIML 2.0 Chatbot interpreter, framework, related programs and knowledge files
https://keiffster.github.io/program-y/
Other
348 stars 138 forks source link

How to match optional set of words? #231

Closed dilyararimovna closed 4 years ago

dilyararimovna commented 4 years ago

Hello!

I would like to learn how to match patterns like the following example (non-working example, of course):

<pattern><regex pattern="(ALICE|BOB)" /> <regex pattern="(PLEASE|COULD YOU|COULD YOU PLEASE)?" /> DO * </pattern>

to match such patterns like "Alice, please, do it", "Alice, could you, please, do it", "Bob, do it". The last example is the most important as I succeeded to use regex to match one of the given words (Alice or Bob) but I do not understand how to optionally (!) match one of the given words.

Thank you in advance!

keiffster commented 4 years ago

AIML matches at the word rather than the phrase level, so it will only match one word at a time. Some of your phrases are multiple words which breaks AIML and theuse of the regex matcher.

It will match ALICE or BOB in the first pattern, but will not match 'COULD YOU' or 'COULD YOU PLEASE'

But this is the wrong way to go about AIML pattern matching, you should use multiple patterns if you want specifics or use of sets and * pattern matching.

For example you could create

<pattern>BOB * DO *</pattern>
<pattern>ALICE * DO *</pattern>

Or you can use a set of names

<pattern><set name="people" /> * DO *</pattern>

Where the set people.txt contains the names you want to match such as

BOB
ALICE

The former would be better if you only ever match BOB or ALICE, the latter if you want more names

dilyararimovna commented 4 years ago

Thank you!