-
Notifications
You must be signed in to change notification settings - Fork 146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Request for Length Wildcard #337
Comments
rivescript uses a subset of regex to make it easier for non technical people to write scripts. there has been some discussion of using full regex syntax but it's never been finalized. most of discussion moved here but there are other related issues eg |
actually there's a PR here where you can use the |
You can run it through an object and parse accordingly to get string length. Basic example, YMMV.
You can get more advanced by referencing and returning from topics to handle these cases. |
This has been asked for a few times and I haven't wanted to try and dig into what the regular expression for this would look like. I know SuperScript.js (a fork of Rivescript) has syntax like described in the OP and I went sleuthing through their code, but didn't find a regexp that I could take from that and add to RiveScript. RiveScript's "simplified regexp" system for triggers ends up creating some rather gnarly raw regular expressions to support all the features RiveScript has. For example the "[optionals]" syntax in RiveScript expands out to a regexp that looks like:
A lot of things are going on with this example: it needs the regexp to either look like "what is your (phone|office|home) number" treating the optionals as a regular alternatives capture group, but also needs to match messages that contain none of those words, so needs the spaces on either side to be optional so you can just say "what is your number" but also require at least one space, so that "what is yournumber" does not match (lack of space where the optionals would go). Additionally, it needs to support the optional being at the beginning or the end of the trigger, and in these cases the extra space characters on either side need to be not required for matching. The word-boundary metacharacter \b helps it anchor on "word boundary (spaces) or start/end of string"... and this brings with it a new set of problems, namely, Unicode symbols have difficulty matching because \b only considers ASCII alphabet to be "word characters" and not umlauts or foreign language symbols. All this to say... extending the regexp engine further to support a "number of words wildcard" while making it compatible with all the existing complexity that RiveScript's triggers currently supports may be a tricky task. If done incorrectly, RiveScript may assemble regular expressions that are invalid and have syntax errors, or that cause matching to fail in certain use cases, and introduce more bugs into the library than it solves. If you want to take a stab at this and figure out a regexp and send me a pull request, feel free! I can then port that change to other editions of RiveScript, too (i.e. Python, Java and Go versions). But I personally haven't felt motivated enough to do this, and everyone who's asked me for this feature doesn't seem willing to try it themselves either. |
I want the length wildcard feature in Rivescript so that I get the option to match user's input text more accurately.
e.g.-
EXACT LENGTH WILDCARD:
Matches
Hello John Doe
Does not match
Hello John
VARIABLE LENGTH WILDCARD:
Matches
Hello!
Matches
Hello John!
Matches
Hello John Doe
Does not match
Hello John George Doe
MIN-MAX WILDCARD:
Matches
Hello John Doe
andHello John Dorian Doe
Does not match
Hello John
The text was updated successfully, but these errors were encountered: