jenojp / negspacy

spaCy pipeline object for negating concepts in text
MIT License
274 stars 36 forks source link

Make spacy extension name ("negex") variable #20

Closed lcreteig closed 4 years ago

lcreteig commented 4 years ago

Currently it is not possible to add a second instance of NegEx to a spaCy pipeline, as this would simply overwrite the registered "negex" extension from the first instance:

Span.set_extension("negex", default=False, force=True)

This PR makes it possible to set the name of the extension (while keeping the default of "negex"). This solution was proposed here: https://github.com/jenojp/negspacy/issues/17#issuecomment-661018290.

My use case is similar: I also wanted to detect other context-based modifiers (e.g. speculations), while keeping them separate from the detected negations. This works now for my use case, and the default behavior is unchanged. But I'm not sure this is exactly what you had in mind, or whether you'd like to add this to negspacy at all, so please feel free to disregard or (request me to) make further changes.

jenojp commented 4 years ago

I love this solution, let me dig in when I get a sec

jenojp commented 4 years ago

Yeah this looks good, exactly what I was hoping for. I'll merge it in and release it with a few other changes soon.

jenojp commented 4 years ago

Thanks again!!!