'How to use custom named enitities dataset in spacy's DependecyMatcher?
Suppose I have created a spacy model or dataset with all named entities, tagged as a PERSON, from a certain text. How can I apply it in DependencyMatcher, if I need to extract pairs "person" - "root verb"? In other words I want DependencyMatcher to use not its custom model of identifying people's names, but my, already made, dataset of names.
import spacy
from spacy.matcher import DependencyMatcher
nlp = spacy.load("en_core_web_lg")
def on_match(matcher, doc, id, matches):
return matches
patterns = [
[#pattern1 (sur)name Jack lived
{
"RIGHT_ID": "person",
"RIGHT_ATTRS": {"ENT_TYPE": "PERSON", "DEP": "nsubj"}
},
{
"LEFT_ID": "person",
"REL_OP": "<",
"RIGHT_ID": "verb",
"RIGHT_ATTRS": {"POS": "VERB"}
}
]
matcher = DependencyMatcher(nlp.vocab)
matcher.add("PERVERB", patterns, on_match=on_match)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
