Last active
June 28, 2020 17:55
-
-
Save aniruddha27/ed39b4de3e5bd4ba1d2af92f3dcceeed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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