📅  最后修改于: 2022-03-11 14:46:19.103000             🧑  作者: Mango
import spacy
from spacy.matcher import Matcher
nlp = spacy.load('en-core-web-us')
matcher = Matcher(nlp.vocab)
patterns =[[{'LOWER':'hello'}, {'LOWER':'potato'}], [{'LOWER':'hello'}, {'LOWER':'yam'}], [{'LOWER':'hello'}, {'LOWER':'stupid'}]]
matcher.add('a', patterns, on_match=None)
document = nlp(u'hello potato i am hello yam you are hello stupid')
matcher(document)