Skip to content

Instantly share code, notes, and snippets.

@prateekjoshi565
Last active September 24, 2019 06:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prateekjoshi565/23bdd8f96c997d05ea0d009bb751b207 to your computer and use it in GitHub Desktop.
Save prateekjoshi565/23bdd8f96c997d05ea0d009bb751b207 to your computer and use it in GitHub Desktop.
def subtree_matcher(doc):
x = ''
y = ''
# iterate through all the tokens in the input sentence
for i,tok in enumerate(doc):
# extract subject
if tok.dep_.find("subjpass") == True:
y = tok.text
# extract object
if tok.dep_.endswith("obj") == True:
x = tok.text
return x,y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment