Created
June 5, 2020 21:41
-
-
Save aniruddha27/91ae8334f1f6c304310ddc43c2b746d3 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
# function for rule 2 | |
def rule2(text): | |
doc = nlp(text) | |
pat = [] | |
# iterate over tokens | |
for token in doc: | |
phrase = '' | |
# if the word is a subject noun or an object noun | |
if (token.pos_ == 'NOUN')\ | |
and (token.dep_ in ['dobj','pobj','nsubj','nsubjpass']): | |
# iterate over the children nodes | |
for subtoken in token.children: | |
# if word is an adjective or has a compound dependency | |
if (subtoken.pos_ == 'ADJ') or (subtoken.dep_ == 'compound'): | |
phrase += subtoken.text + ' ' | |
if len(phrase)!=0: | |
phrase += token.text | |
if len(phrase)!=0: | |
pat.append(phrase) | |
return pat |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment