Skip to content

Instantly share code, notes, and snippets.

@aniruddha27
Created June 5, 2020 22:06
Show Gist options
  • Save aniruddha27/500d3ca599842b0fd164f02c07639382 to your computer and use it in GitHub Desktop.
Save aniruddha27/500d3ca599842b0fd164f02c07639382 to your computer and use it in GitHub Desktop.
# rule 3 function
def rule3_mod(text):
doc = nlp(text)
sent = []
for token in doc:
if token.pos_=='ADP':
phrase = ''
if token.head.pos_=='NOUN':
# appended rule
append = rule0(text, token.head.i)
if len(append)!=0:
phrase += append
else:
phrase += token.head.text
phrase += ' '+token.text
for right_tok in token.rights:
if (right_tok.pos_ in ['NOUN','PROPN']):
right_phrase = ''
# appended rule
append = rule0(text, right_tok.i)
if len(append)!=0:
right_phrase += ' '+append
else:
right_phrase += ' '+right_tok.text
phrase += right_phrase
if len(phrase)>2:
sent.append(phrase)
return sent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment