Skip to content

Instantly share code, notes, and snippets.

@aniruddha27
Created June 5, 2020 21:41
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 aniruddha27/91ae8334f1f6c304310ddc43c2b746d3 to your computer and use it in GitHub Desktop.
Save aniruddha27/91ae8334f1f6c304310ddc43c2b746d3 to your computer and use it in GitHub Desktop.
# 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:
pat.append(phrase)
return pat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment