-
Notifications
You must be signed in to change notification settings - Fork 54
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
adding support for shortest choice #28
base: master
Are you sure you want to change the base?
Conversation
Hi. Thanks for the contribution. |
if result is not None: | ||
result = [result] | ||
result_str = "".join([x.flat_str() for x in flatten(result)]) | ||
if (not shortest_result) or (len(shortest_result_str) > len(result_str)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be done more optimal. Flattening and converting to string of all resulting subtrees is slow.
It is enough to use position and track in which branch you have smaller advance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will make a patch for this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make a unit test also if you can. I am trying to keep test coverage as high as possible. Thanks.
I had to use this while building a pretty complex grammar for tagging parts of a school name It's an equivalent of the non greedy version of regexp operations say if you have grammar x and y given input 'ab', ShortestChoice([x, y]) will match 'a' while OrderedChoice([x, y]) will match 'ab' In my case, I did not know upfront which of x y matches a shorter input, therefore something like ShortestChoice has to be used. |
I see. I think that a similar variant |
Hi,
Hopefully this is useful for someone (A ShortestChoice variant of OrderedChoice)