Support multi token inflection and copying
Currently replaCy assumes token matches and text suggestions are single tokens:
-
PATTERN_REFcopies only the first matched token: https://github.com/Qordobacode/replaCy/blob/bd7df64e2e5b875aaa9fecff31b1d898650219b4/replacy/init.py#L166 suggested fix: change the above line, enforceINFLECTIONonly if one token is matched -
TEXTconsists of a single word only: https://github.com/Qordobacode/replaCy/blob/bd7df64e2e5b875aaa9fecff31b1d898650219b4/replacy/init.py#L163 suggested fix: json validation to enforce single tokens asTEXTex. instead of{"TEXT": "blah blah"}use{"TEXT": "blah"}, {"TEXT": "blah"} -
FROM_TEMPLATE_ID: assumes single token match, from which we transfer the inflection https://github.com/Qordobacode/replaCy/blob/bd7df64e2e5b875aaa9fecff31b1d898650219b4/replacy/init.py#L178 suggested fix: enforceTEMPLATE_IDmatch being single token
Idea:
Single token match enforcement: fail json validation if patterns include FROM_TEMPLATE_ID or PATTERN_REF pointing to a token with OP?
I agree with the second two, but is it bad that
PATTERN_REFcopies only the first matched token
? That was intentional. I guess I can see use cases for removing this restriction though... what would the API be, also support a dict with start and end? Something like
{
"PATTERN_REF": {"start": 1, "end": 4}
}
or a list?
{
"PATTERN_REF": [0, 3, 7]
}
?
Also, related to #41 and #33
I agree with the second two, but is it bad that
PATTERN_REFcopies only the first matched token? That was intentional. I guess I can see use cases for removing this restriction though... what would the API be, also support a dict with
startandend? Something like{ "PATTERN_REF": {"start": 1, "end": 4} }or a list?
{ "PATTERN_REF": [0, 3, 7] }?
Haha, actually I don't need the second and third, I just need the first one ie. PATTERN_REF.
The use case:
imagine you want to match : to (very) quickly go
and turn it into: (very) quickly going
So you would want to copy stuff between TO and infinitive, which in general can be even a few words long.
Of course here one can do it manually and play with indices after finding the match (remove first and second, move middle stuff), but then you need to separately use pyinflect/lemminflect/replaCy wrapper to make the gerund (so at this point you don't need replaCy at all since you are making it fully manually, you could just use the spaCy matcher).
(A few days ago spent 2h trying to confirm its a spaCy matcher bug, then discovered this in replaCy. :disappointed: The second and the third added for design consistency. )
Copy stuff you matched seems more natural than copy the first token from the phrase you matched
By default would assume we always copy everything.
Another use case:
- matching a token and moving it to the end of the sentence. If you can't copy more than one token - this won't work.
It's more difficult to imagine a use case when the pattern would be multi-token, but we would want to copy just the first one imo.
Some of the notes in #47 might also be relevant