def get_means_phrases(self, story, found_mv_phrase, assume=True): if assume: for np in story.means.text.noun_chunks: if story.means.main_object.main in np: story.means.main_object.phrase = np if story.means.main_object.phrase: m = story.means.main_object.main if m.i > 0 and NLPUtility.is_compound( m.nbor(-1)) and m.nbor(-1).head == m: story.means.main_object.compound = [m.nbor(-1), m] else: for token in story.means.main_object.phrase: if NLPUtility.is_compound( token ) and token.head == story.means.main_object.main: story.means.main_object.compound = [ token, story.means.main_object.main ] if not found_mv_phrase: pv = MinerUtility.get_phrasal_verb(story, story.means.main_verb.main, 'means.text') story.means.main_verb.phrase = MinerUtility.get_span( story, pv[0], 'means.text') story.means.main_verb.type = pv[1] return story
def get_ends_phrases(self, story, found_mv_phrase, assume=True): if assume: for np in story.ends.text.noun_chunks: if story.ends.main_object.main in np: story.ends.main_object.phrase = np if story.ends.main_object.phrase: m = story.ends.main_object.main if m.i > 0 and NLPUtility.is_compound(m.nbor(-1)) and m.nbor(-1).head == m: story.ends.main_object.compound = [m.nbor(-1), m] else: for token in story.ends.main_object.phrase: if NLPUtility.is_compound(token) and token.head == story.ends.main_object.main: story.ends.main_object.compound = [token, story.ends.main_object.main] ends_subj = story.ends.subject.main if str.lower(story.ends.subject.main.text) != '' and str.lower(story.ends.subject.main.text) != 'i': for np in story.ends.text.noun_chunks: if story.ends.subject.main in np: story.ends.subject.phrase = np if story.ends.subject.phrase: for token in story.ends.subject.phrase: if NLPUtility.is_compound(token) and token.head == story.ends.subject.main: story.ends.subject.compound = [token, story.ends.subject.main] if not found_mv_phrase: pv = MinerUtility.get_phrasal_verb(story, story.ends.main_verb.main, 'ends.text') story.ends.main_verb.phrase = MinerUtility.get_span(story, pv[0], 'ends.text') story.ends.main_verb.type = pv[1] return story
def get_functional_role(self, story): potential_without_with = [] with_i = -1 for token in story.role.text: if MinerUtility.lower(token.text) == 'with' or MinerUtility.lower( token.text) == 'w/': with_i = token.i if with_i > 0: potential_without_with = story.role.text[0:with_i] else: potential_without_with = story.role.text # If there is just one word if len(story.role.text) == 1: story.role.functional_role.main = story.role.text[0] else: compound = [] for token in potential_without_with: if NLPUtility.is_compound(token): compound.append([token, token.head]) if len(compound) == 1 and type(compound[0]) is list: compound = compound[0] # pick rightmost elif len(compound) > 1 and type(compound[-1]) is list: compound = compound[-1] story.role.functional_role.compound = compound # If it is a compound if story.role.functional_role.compound: story.role.functional_role.main = story.role.functional_role.compound[ -1] # Get head of tree else: for token in story.role.text: if token is token.head: story.role.functional_role.main = token return story
def get_compound_nouns(story, span): compounds = [] nouns = MinerUtility.get_nouns(story, span) for token in nouns: for child in token.children: if NLPUtility.is_compound(child): # Replace to take rightmost child if child.idx < token.idx: for compound in compounds: if child in compound or token in compound: compounds.remove(compound) compounds.append([child, token]) for c in compounds: c = MinerUtility.get_span(story, c) if compounds and type(compounds[0]) is list: compounds = compounds[0] return compounds
def get_functional_role(self, story): potential_without_with = [] with_i = -1 for token in story.role.text: if MinerUtility.lower(token.text) == 'with' or MinerUtility.lower(token.text) == 'w/': with_i = token.i if with_i > 0: potential_without_with = story.role.text[0:with_i] else: potential_without_with = story.role.text # If there is just one word if len(story.role.text) == 1: story.role.functional_role.main = story.role.text[0] else: compound = [] for token in potential_without_with: if NLPUtility.is_compound(token): compound.append([token, token.head]) if len(compound) == 1 and type(compound[0]) is list: compound = compound[0] # pick rightmost elif len(compound) > 1 and type(compound[-1]) is list: compound = compound[-1] story.role.functional_role.compound = compound # If it is a compound if story.role.functional_role.compound: story.role.functional_role.main = story.role.functional_role.compound[-1] # Get head of tree else: for token in story.role.text: if token is token.head: story.role.functional_role.main = token return story