writer / replaCy

spaCy match and replace, maintaining conjugation
https://pypi.org/project/replacy/
MIT License
34 stars 8 forks source link

Support multi token inflection and copying #46

Open melisa-writer opened 4 years ago

melisa-writer commented 4 years ago

Currently replaCy assumes token matches and text suggestions are single tokens:

Idea: Single token match enforcement: fail json validation if patterns include FROM_TEMPLATE_ID or PATTERN_REF pointing to a token with OP?

sam-writer commented 4 years ago

I agree with the second two, but is it bad that

PATTERN_REF copies 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]
}

?

sam-writer commented 4 years ago

Also, related to #41 and #33

melisa-writer commented 4 years ago

I agree with the second two, but is it bad that

PATTERN_REF copies 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]
}

?

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.

melisa-writer commented 4 years ago

Another use case:

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.

sam-writer commented 4 years ago

Some of the notes in #47 might also be relevant