import spacy
from spacy.matcher import DependencyMatcher
nlp = spacy.load("en_core_web_sm")
pattern = [
{
"RIGHT_ID": "target",
"RIGHT_ATTRS": {"POS": "NOUN"}
},
{
"LEFT_ID": "target",
"REL_OP": ">",
"RIGHT_ID": "verb",
"RIGHT_ATTRS": {"POS": {"IN": ["VERB"]}}
},
{
"LEFT_ID": "target",
"REL_OP": ">",
"RIGHT_ID": "adj",
"RIGHT_ATTRS": {"POS": {"IN": ["ADJ"]}}
}
]
matcher = DependencyMatcher(nlp.vocab)
matcher.add("FOUNDED", [pattern])
text = "the bag that I bought is really beautiful"
doc = nlp(text)
for match_id, (target, verb, adj) in matcher(doc):
print(doc[target], doc[verb], doc[adj])
Hi I'm learning how to use Spacy Matcher, I'm doing some test to find the verb and the adj related to the noun. Hoping to get "bag bought beautiful" as a result. I don't get anything and I don't know what I have done wrong. Any idea ? Thank you !