Hello, I'm trying to figure out with rule based matching whhere ENT_TYPE is supported, it seems as though it doesn't work on PhraseMatcher or Entity Ruler. I have an example where this does not work. Is this not supported or am I doing it wrong?
import spacy
from spacy import displacy
nlp = spacy.load('en_core_web_md')
ruler = nlp.add_pipe("entity_ruler")
patterns = [
{"label": "VEHICLE", "pattern": "bike"},
{"label": "PART", "pattern": "handlebars"},
{"label": "COMPOUND", "pattern":[{"LOWER": "my"}, {"ENT_TYPE": "VEHICLE"}]}
]
ruler.add_patterns(patterns)
doc = nlp("I can ride my bike with no handlebars today.")
displacy.render(doc, style='ent')
Needs to have a VEHICLE entity around in order to work, which means that it needs to be available in a step before the entity ruler. Adding a second ruler indeed seems a sensible solution.
Thank you for your reply. Is there an alternative way to do it in the same pipeline? The way this is setup right now it would be much better for me to do it in the same pipeline.
The alternative would be to make a spaCy component that handles everything with custom Python code that wraps around the spaCy matcher object. But that feels like a lot of effort and also less performant/elegant to what you have here.