-
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
How to write optional word with empty support? #262
Comments
For #256, it only show usage " My question is near #254 but i am not talking about char detection for Japanese words, I want to used " Currently i workaround it by changing brian.coffee line 623. Which changed "
|
Wildcards, JavaScript and Unicode don't get along very well, as you can see from all the other issues linked above. The This is actually the first request I've seen for an optional wildcard between Unicode words, but the same problems apply... unfortunately though the If you want to do some experimenting, an idea to resolve this may be to further improve the My idea is to have it search out any
One trigger will end up with a lot of variations but these can be calculated on the fly. Not sure how efficient the solution is though. 😃 |
I'm not quite sure what the initial simplified regexes worked kind of OK for content people but I'm not sure having some other variation for more complex UTF8 phrases, vs real regexes with all their tooling, is going to be a win. for example you can use |
So the Here's the part of code that handles optionals. Optionals have the strange requirement that: the user's message can either provide the word(s) from the optional, in which case it must be surrounded by spaces (or word boundaries, in the case that the optional is at the beginning or end of the trigger), or the optional must be entirely missing, but there has to be at least a space or word boundary in its place. For the trigger The problem then is that the Since it was a really common use case to want "keyword triggers" like So I played with the idea of allowing users to provide raw regular expressions without any of the magic or simplified syntax that RiveScript's triggers support: aichaos/rivescript-wd#6 It became hard though to handle the sorting of the regexps. With RiveScript's trigger system, it's able to count the number of normal words, wildcards, optionals, alternative sets and so-on and organize the triggers in a "most specific first" ordering, so that the longest trigger with the most words and fewest wildcards will be tested first when looking up a reply, so that less specific triggers don't overshadow more specific ones and make matching a nightmare. (For a quick example of ordering triggers, if you were writing a completely custom bot doing regexp tests yourself you might have code like this:) # forgive the Perl but it's fast to write
if ($message =~ /^who is (.+?)$/) {
# trigger: who is *
$reply = "I've never heard of $1 before.";
}
elsif ($message =~ /^who is linus torvalds$/) {
$reply = "He is the father of Linux.";
} Here a less specific trigger of Allowing users to write raw regular expressions though complicates the sorting -- regexps tend to be shorter and more concise than full sentences in some cases. Since you can't easily count the words and wildcards in a raw regexp it's hard to rank them in the same way as the normal triggers; you can either sort them by pure character length (in which case many of them will appear much further down the sort list than you'd want) or try and come up with something more complicated. So the |
if the sorting is the only problem, then let the regexps match just in the order that the user provides them in the script? That seems an easy solution. if you could add a weight option to regexp too then for example with matches across different files we could control the ordering. |
I am used rivescript in chinese chatbot. But i found difficult to use "
*
" for some char is optional. For example, red chair, in chinese it will be "紅色的椅子". But normally "的" is optional, which it is same meaning even you said "紅色椅子". Is there any simple way to support optional "*"?If i wrote this, it only support 紅色的椅子 but not 紅色椅子
I try to add nothing or "
*
" but not success.This one is working, but it is too hard to keep maintain if i need to help thousand of word i need to put into this style.
Rivescript sample:
https://play.rivescript.com/s/QFFb1zVd8b
The text was updated successfully, but these errors were encountered: