Created
June 5, 2020 22:06
-
-
Save aniruddha27/500d3ca599842b0fd164f02c07639382 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_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