【发布时间】:2021-09-28 13:39:13
【问题描述】:
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])
嗨,我正在学习如何使用 Spacy Matcher,我正在做一些测试以找到与名词相关的动词和形容词。 希望得到“包买得漂亮”的结果。 我什么也没得到,我不知道我做错了什么。任何的想法 ?谢谢!
【问题讨论】: