Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
# function for rule 2
def rule2(text):
doc = nlp(text)
pat = []
# iterate over tokens
for token in doc:
phrase = ''
# if the word is a subject noun or an object noun
if (token.pos_ == 'NOUN')\
and (token.dep_ in ['dobj','pobj','nsubj','nsubjpass']):
# iterate over the children nodes
for subtoken in token.children:
# if word is an adjective or has a compound dependency
if (subtoken.pos_ == 'ADJ') or (subtoken.dep_ == 'compound'):
phrase += subtoken.text + ' '
if len(phrase)!=0:
phrase += token.text
if len(phrase)!=0:
return pat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment