Skip to content

Instantly share code, notes, and snippets.

@aniruddha27
Last active June 28, 2020 17:55
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/ed39b4de3e5bd4ba1d2af92f3dcceeed to your computer and use it in GitHub Desktop.
Save aniruddha27/ed39b4de3e5bd4ba1d2af92f3dcceeed to your computer and use it in GitHub Desktop.
# rule 3 function
def rule3(text):
doc = nlp(text)
sent = []
for token in doc:
# look for prepositions
if token.pos_=='ADP':
phrase = ''
# if its head word is a noun
if token.head.pos_=='NOUN':
# append noun and preposition to phrase
phrase += token.head.text
phrase += ' '+token.text
# check the nodes to the right of the preposition
for right_tok in token.rights:
# append if it is a noun or proper noun
if (right_tok.pos_ in ['NOUN','PROPN']):
phrase += ' '+right_tok.text
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