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.
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.
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)