Skip to content

Instantly share code, notes, and snippets.

@aniruddha27
Created June 5, 2020 22:06
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
# 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