【发布时间】:2021-12-30 17:22:58
【问题描述】:
我正在尝试匹配一个特定的模式:任何以 s、t 或 l 结尾的名词的动词。 例如。: 像猫一样, 吃饭, 制作香料
我该怎么做?
我知道我在这样做:
nlp =spacy.load("en_core_web_sm")
matcher = Matcher(nlp.vocable)
pattern = [{"POS": "VERB"}, {"POS": "NOUN"}]
matcher.add("mypattern", [pattern])
doc = nlp(Verbwithnoun)
matches = matcher(doc)
for match_id, start, end in matches:
string_id = nlp.vocab.strings[match_id]
print(doc[start:end)
但这会打印所有带有名词的动词,而不是以 t,l 或 s 结尾的名词。如何让 spacy 只匹配以 t、l 或 s 结尾的特定名词?
【问题讨论】:
标签: python python-3.x spacy spacy-3