Skip to content

Instantly share code, notes, and snippets.

@aniruddha27
Last active June 28, 2020 17:50
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/d796631e54d8b49c906aa03bfc5640e5 to your computer and use it in GitHub Desktop.
Save aniruddha27/d796631e54d8b49c906aa03bfc5640e5 to your computer and use it in GitHub Desktop.
# rule 1 modified function
def rule1_mod(text):
doc = nlp(text)
sent = []
for token in doc:
# root word
if (token.pos_=='VERB'):
phrase =''
# only extract noun or pronoun subjects
for sub_tok in token.lefts:
if (sub_tok.dep_ in ['nsubj','nsubjpass']) and (sub_tok.pos_ in ['NOUN','PROPN','PRON']):
# look for subject modifier
adj = rule2_mod(text,sub_tok.i)
phrase += adj + ' ' + sub_tok.text
# save the root word of the word
phrase += ' '+token.lemma_
# check for noun or pronoun direct objects
for sub_tok in token.rights:
if (sub_tok.dep_ in ['dobj']) and (sub_tok.pos_ in ['NOUN','PROPN']):
# look for object modifier
adj = rule2_mod(text,sub_tok.i)
phrase += adj+' '+sub_tok.text
sent.append(phrase)
return sent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment