Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Example of spaCy object Labeling Function
from spacy.matcher import Matcher
matcher = Matcher(nlp.vocab)
pattern = [{'POS': 'VERB'}, {'POS': 'ADP'}, {'POS': 'PROPN'}]
matcher.add("VERB_ADP_PROPN", None, pattern)
def lf_verb_in_noun(x):
"""Return positive if the pattern"""
sp = x['spacy']
matches = matcher(sp)
found = False
for match_id, start, end in matches:
if start == x['start'] - 2:
if sp[start].text in ['work', 'written', 'wrote']:
if sp[start + 1].text in ['in']:
return ABSTAIN
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.