When I apply negspacy to my sentence, I want negspacy to consider specific phrase as a single entity and give me the output for it.
import en_core_sci_lg
from negspacy.negation import Negex
nlp = en_core_sci_lg.load()
negex = Negex(nlp, language = "en_clinical_sensitive")
nlp.add_pipe(negex, last=True)
doc = nlp(""" patient has no signs of shortness of breath. """)
for word in doc.ents:
print(word, word._.negex)
The output is -
patient False
shortness True
I want the output to be -
patient False
shortness of breath True
How can I consider phrases like "shortness of breath", "sore throat", "respiratory distress" as a single entity.
I have tried -
import en_core_sci_lg
from negspacy.negation import Negex
nlp = en_core_sci_lg.load()
from spacy.pipeline import EntityRuler
ruler = EntityRuler(nlp)
patterns = [{"label": "ENTITY", "pattern": [{"LOWER": "shortness"}, {"LOWER": "of"}, {"LOWER": "breath"}]}]
ruler.add_patterns(patterns)
nlp.add_pipe(ruler)
negex = Negex(nlp, language = "en_clinical")
nlp.add_pipe(negex, last=True)
doc = nlp("""patient has no signs of shortness of breath. """)
for word in doc.ents:
print(word, word._.negex)
The output is still coming -
patient False
shortness True
What can I do to solve this problem