def process_pp_when_be_is_root(relations, index, context, engine, info, subjs): """TODO: Docstring for process_pp_when_be_is_root.""" prep_indices = Relation.get_children_with_dep('prep', relations, index) if not prep_indices: return [] if subjs['return_list'][0].lower() == 'it': prep_index = prep_indices[0] pobj_children = Relation.get_children_with_dep('pobj', relations, prep_index) if pobj_children: pobj_index = pobj_children[0] else: return [] pobj_return_value = engine.analyze(relations, pobj_index, context + [index, prep_index]) return_list = [] for noun in pobj_return_value['return_list']: return_list.append(relations[prep_index].word + ' ' + noun) engine.mark_processed(relations, prep_index) return return_list else: for prep_index in prep_indices: engine.analyze(relations, prep_index, context + [index]) return []
def process_conjs(relations, index, context, engine, info, subjs, auxs, prop_ids): conj_indices = Relation.get_children_with_dep('conj', relations, index) if conj_indices != []: cc_indices = Relation.get_children_with_dep('cc', relations, index) if cc_indices: conjunction = engine.analyze(relations, cc_indices[0], context + [index]) else: conjunction = None preconj_indices = Relation.get_children_with_dep( 'preconj', relations, index) if preconj_indices != []: preconj = engine.analyze(relations, preconj_indices[0], context + [index]) conjunction = preconj + '_' + conjunction for i in conj_indices: ret = engine.analyze(relations, i, context + [index], info={ 'class': 'VP', 'subj': subjs, 'aux': auxs }) prop_ids.extend(ret['prop_ids']) if conjunction: conj_prop = tuple([conjunction] + prop_ids) engine.emit(conj_prop, 'C')
def process_conjs(relations, index, context, engine): """TODO: Docstring for process_conjs.""" # Composite NP with conjunction conj_indices = Relation.get_children_with_dep('conj', relations, index) if conj_indices != []: # Consume the cc. cc_indices = Relation.get_children_with_dep('cc', relations, index) for i in cc_indices: engine.analyze(relations, i, context + [index]) # Get the conjs. conjs = [engine.analyze(relations, i, context + [index], info={'class': 'NP'}) for i in conj_indices] # TODO: check if this makes sense. conjs = [c[0] for c in conjs] else: conjs = [] conjs = [relations[index].word] + conjs return conjs
def process_conjs(relations, index, context, engine, info={}): """Process composite NP with conjunction (e.g., John and Mary).""" conj_indices = Relation.get_children_with_dep('conj', relations, index) if conj_indices != []: # Consume the cc. cc_indices = Relation.get_children_with_dep('cc', relations, index) for i in cc_indices: engine.analyze(relations, i, context + [index]) # Get the conjs. conjs = [ engine.analyze(relations, i, context + [index], info={'class': 'NP'}) for i in conj_indices ] # TODO: check if this makes sense. conjs = [c[0] for c in conjs] else: conjs = [] conjs = [relations[index].word] + conjs return conjs
def transform(self, relations): for index, relation in enumerate(relations): if relation.rel in ('null', 'root', 'xcomp', 'rcmod')\ and relation.tag in ('VBZ', 'VBD', 'VBP', 'VB')\ and relation.word in self.verb_forms: xcomp_indices = Relation.get_children_with_dep( 'xcomp', relations, index) if xcomp_indices == []: continue else: xcomp_index = xcomp_indices[0] if relations[xcomp_index].tag == 'VB': aux_indices = Relation.get_children_with_dep( 'aux', relations, xcomp_index) to_index = [ index for index in aux_indices if relations[index].tag == 'TO' ][0] # Append 'to' and the xcomp head to main verb. relations[index].word += ' to ' + \ relations[xcomp_index].word # Remove 'aux' and 'xcomp' relations. delete_indices(relations, [to_index, xcomp_index]) # Change head of relations pointing to xcomp to point to # the main verb. for i, rel in enumerate(relations): if rel.head == xcomp_index - 2: rel.head = index relations[index].deps.append(i) relations[index].deps.sort()
def process_conjs(relations, index, context, engine, info, subjs, auxs, prop_ids): """Process cc/conj.""" conj_indices = Relation.get_children_with_dep('conj', relations, index) if conj_indices != []: cc_indices = Relation.get_children_with_dep('cc', relations, index) if cc_indices: conjunction = engine.analyze(relations, cc_indices[0], context + [index]) else: conjunction = None preconj_indices = Relation.get_children_with_dep('preconj', relations, index) if preconj_indices != []: preconj = engine.analyze(relations, preconj_indices[0], context + [index]) conjunction = preconj + '_' + conjunction for i in conj_indices: ret = engine.analyze(relations, i, context + [index], info={'class': 'VP', 'subj': subjs, 'aux': auxs}) prop_ids.extend(ret['prop_ids']) if conjunction: conj_prop = tuple([conjunction] + prop_ids) engine.emit(conj_prop, 'C')
def transform(self, relations): for i in range(len(relations)): cc_indices = Relation.get_children_with_dep('cc', relations, i) conj_indices = Relation.get_children_with_dep('conj', relations, i) if cc_indices and not conj_indices: relations[cc_indices[0]].rel = 'preconj'
def process_pp_when_be_is_root(relations, index, context, engine, info, subjs): # TODO: Maybe unnecessary. """Process prepositional phrases when be is root.""" prep_indices = Relation.get_children_with_dep('adpmod', relations, index) if prep_indices == []: return [] if subjs['return_list'][0].lower() == 'it': prep_index = prep_indices[0] pobj_index = Relation.get_children_with_dep('adpobj', relations, prep_index)[0] pobj_return_value = engine.analyze(relations, pobj_index, context + [index, prep_index]) return_list = [] for noun in pobj_return_value['return_list']: return_list.append(relations[prep_index].word + ' ' + noun) engine.mark_processed(relations, prep_index) return return_list else: for prep_index in prep_indices: engine.analyze(relations, prep_index, context + [index]) return []
def extract(self, relations, index, context, engine, info={}): """extract(relations, index, context, engine, info) -> str | list(str) An nn can be a single word or multiple words connected by cc/conj. Examples: * Oil prices nn(prices, Oil) -> return "Oil" * East and West Germany nn(Germany, East) cc(East, and) conj(East, West) -> return ["East", "West"] """ conj_indices = Relation.get_children_with_dep('conj', relations, index) if conj_indices != []: # Consume the conjunction. cc_indices = Relation.get_children_with_dep('cc', relations, index) for i in cc_indices: engine.analyze(relations, cc_indices[0], context + [index]) conjs = [ engine.analyze(relations, i, context + [index], info={'class': 'NP'}) for i in conj_indices ] conjs = [c[0] for c in conjs] # TODO: check if this makes sense. return [relations[index].word] + conjs else: return relations[index].word
def extract(self, relations, index, context, engine, info={}): """extract(relations, index, context, engine, info) -> str | list(str) An nn can be a single word or multiple words connected by cc/conj. Examples: * Oil prices nn(prices, Oil) -> return "Oil" * East and West Germany nn(Germany, East) cc(East, and) conj(East, West) -> return ["East", "West"] """ conj_indices = Relation.get_children_with_dep('conj', relations, index) if conj_indices != []: # Consume the conjunction. cc_indices = Relation.get_children_with_dep('cc', relations, index) for i in cc_indices: engine.analyze(relations, cc_indices[0], context + [index]) conjs = [engine.analyze(relations, i, context + [index], info={'class': 'NP'}) for i in conj_indices] conjs = [c[0] for c in conjs] # TODO: check if this makes sense. return [relations[index].word] + conjs else: return relations[index].word
def process_comps(relations, index, context, engine, info): """Process complements (direct objects, open clausal complements, adjectival complements, and subject predicates).""" dobj_index = Relation.get_children_with_dep('dobj', relations, index) xcomp_index = Relation.get_children_with_dep('xcomp', relations, index) acomp_index = Relation.get_children_with_dep('acomp', relations, index) attr_index = Relation.get_children_with_dep('attr', relations, index) comps_indices = sorted(dobj_index + xcomp_index + acomp_index + attr_index) _comps = [ engine.analyze(relations, i, context + [index], info) for i in comps_indices ] comps = [] for comp in _comps: if isinstance(comp, dict): if 'return_value' in comp: # xcomp comp = comp['return_value'] else: # attr comp = comp['return_list'] if isinstance(comp, list): comps.extend(comp) else: if comp is not None: comps.append(comp) return comps
def transform(self, relations): for index, relation in enumerate(relations): if relation.rel in ('null', 'root', 'xcomp', 'rcmod')\ and relation.tag in ('VBZ', 'VBD', 'VBP', 'VB')\ and relation.word in self.verb_forms: xcomp_indices = Relation.get_children_with_dep('xcomp', relations, index) if not xcomp_indices: continue else: xcomp_index = xcomp_indices[0] if relations[xcomp_index].tag == 'VB': aux_indices = Relation.get_children_with_dep('aux', relations, xcomp_index) aux_indices_with_to = [index for index in aux_indices if relations[index].tag == 'TO'] if aux_indices_with_to: to_index = aux_indices_with_to[0] else: continue # Append 'to' and the xcomp head to main verb. relations[index].word += ' to ' + \ relations[xcomp_index].word # Remove 'aux' and 'xcomp' relations. delete_indices(relations, [to_index, xcomp_index]) # Change head of relations pointing to xcomp to point to # the main verb. for i, rel in enumerate(relations): if rel.head == xcomp_index - 2: rel.head = index relations[index].deps.append(i) relations[index].deps.sort()
def process_pp_when_be_is_root(relations, index, context, engine, info, subjs): """TODO: Docstring for process_pp_when_be_is_root.""" prep_indices = Relation.get_children_with_dep('prep', relations, index) if prep_indices == []: return [] if subjs['return_list'][0].lower() == 'it': prep_index = prep_indices[0] pobj_index = Relation.get_children_with_dep( 'pobj', relations, prep_index)[0] pobj_return_value = engine.analyze(relations, pobj_index, context + [index, prep_index]) return_list = [] for noun in pobj_return_value['return_list']: return_list.append(relations[prep_index].word + ' ' + noun) engine.mark_processed(relations, prep_index) return return_list else: for prep_index in prep_indices: engine.analyze(relations, prep_index, context + [index]) return []
def process_comps(relations, index, context, engine, info): """TODO: Docstring for process_comps.""" dobj_index = Relation.get_children_with_dep('dobj', relations, index) xcomp_index = Relation.get_children_with_dep('xcomp', relations, index) acomp_index = Relation.get_children_with_dep('acomp', relations, index) comps_indices = sorted(dobj_index + xcomp_index + acomp_index) _comps = [ engine.analyze(relations, i, context + [index], info) for i in comps_indices ] comps = [] for comp in _comps: if isinstance(comp, dict): comp = comp['return_value'] if isinstance(comp, list): comps.extend(comp) else: if comp is not None: comps.append(comp) return comps
def process_pp_when_be_is_root(relations, index, context, engine, info, subjs): # TODO: Maybe unnecessary. """Process prepositional phrases when be is root.""" prep_indices = Relation.get_children_with_dep('adpmod', relations, index) if prep_indices == []: return [] if subjs['return_list'][0].lower() == 'it': prep_index = prep_indices[0] pobj_index = Relation.get_children_with_dep( 'adpobj', relations, prep_index)[0] pobj_return_value = engine.analyze(relations, pobj_index, context + [index, prep_index]) return_list = [] for noun in pobj_return_value['return_list']: return_list.append(relations[prep_index].word + ' ' + noun) engine.mark_processed(relations, prep_index) return return_list else: for prep_index in prep_indices: engine.analyze(relations, prep_index, context + [index]) return []
def process_comps(relations, index, context, engine, info): """Process complements (direct objects, open clausal complements, adjectival complements, and subject predicates).""" dobj_index = Relation.get_children_with_dep('dobj', relations, index) xcomp_index = Relation.get_children_with_dep('xcomp', relations, index) acomp_index = Relation.get_children_with_dep('acomp', relations, index) attr_index = Relation.get_children_with_dep('attr', relations, index) comps_indices = sorted(dobj_index + xcomp_index + acomp_index + attr_index) _comps = [engine.analyze(relations, i, context + [index], info) for i in comps_indices] comps = [] for comp in _comps: if isinstance(comp, dict): if 'return_value' in comp: # xcomp comp = comp['return_value'] else: # attr comp = comp['return_list'] if isinstance(comp, list): comps.extend(comp) else: if comp is not None: comps.append(comp) return comps
def process_iobj(relations, index, context, engine, info): """TODO: Docstring for process_iobj.""" # prep + pobj prep_indices = Relation.get_children_with_dep('prep', relations, index) for prep_index in prep_indices: engine.analyze(relations, prep_index, context + [index]) # iobj iobj_index = Relation.get_children_with_dep('iobj', relations, index) if iobj_index != []: engine.analyze(relations, iobj_index[0], context + [index])
def process_iobj(relations, index, context, engine, info): """Process the indirect object.""" # adpmod + adpobj prep_indices = Relation.get_children_with_dep('adpmod', relations, index) for prep_index in prep_indices: engine.analyze(relations, prep_index, context + [index]) # iobj iobj_index = Relation.get_children_with_dep('iobj', relations, index) if iobj_index != []: engine.analyze(relations, iobj_index[0], context + [index])
def extract(self, relations, index, context, engine, info={}): """extract(relations, index, context, engine, info) -> None Prepositional phrases always generate new propositions, according to Chand et al.'s manual. Examples: * to the city pobj(to, city) det(city, the) -> emit((to the city,)) * to both East and West Germany pobj(to, Germany) preconj(Germany, both) nn(Germany, East) cc(East, and) conj(East, West) -> emit((to East Germany, )) # Proposition x -> emit((to West Germany, )) # Proposition y -> emit((both, x, y)) * TODO: insert example with PCOMP. """ # pobj pobj_index = Relation.get_children_with_dep('pobj', relations, index) if pobj_index != []: pobjs = engine.analyze(relations, pobj_index[0], context + [index]) emitted_prop_ids = [] for pobj in pobjs['return_list']: prop_id = engine.emit((relations[index].word + ' ' + pobj, ), 'M') emitted_prop_ids.append(prop_id) if pobjs['ids_for_preconj'] != []: indices = [ j for i, j in enumerate(emitted_prop_ids) if i in pobjs['ids_for_preconj'] ] proposition = tuple([pobjs['preconj']] + indices) engine.emit(proposition, 'C') # pcomp pcomp_index = Relation.get_children_with_dep('pcomp', relations, index) if pcomp_index != []: pcomp = engine.analyze(relations, pcomp_index[0], context + [index])['return_value'] if pcomp is not None: engine.emit((relations[index].word + ' ' + pcomp, ), 'M')
def extract(self, relations, index, context, engine, info={}): """extract(relations, index, context, engine, info) -> None Prepositional phrases always generate new propositions, according to Chand et al.'s manual. Examples: * to the city pobj(to, city) det(city, the) -> emit((to the city,)) * to both East and West Germany pobj(to, Germany) preconj(Germany, both) nn(Germany, East) cc(East, and) conj(East, West) -> emit((to East Germany, )) # Proposition x -> emit((to West Germany, )) # Proposition y -> emit((both, x, y)) * TODO: insert example with PCOMP. """ # adpobj pobj_index = Relation.get_children_with_dep('adpobj', relations, index) if pobj_index != []: pobjs = engine.analyze(relations, pobj_index[0], context + [index]) emitted_prop_ids = [] for pobj in pobjs['return_list']: prop_id = engine.emit((relations[index].word + ' ' + pobj,), 'M') emitted_prop_ids.append(prop_id) if pobjs['ids_for_preconj'] != []: indices = [j for i, j in enumerate(emitted_prop_ids) if i in pobjs['ids_for_preconj']] proposition = tuple([pobjs['preconj']] + indices) engine.emit(proposition, 'C') # adpcomp pcomp_index = Relation.get_children_with_dep('adpcomp', relations, index) if pcomp_index != []: pcomp = engine.analyze(relations, pcomp_index[0], context + [index])['return_value'] if pcomp is not None: engine.emit((relations[index].word + ' ' + pcomp,), 'M')
def extract(self, relations, index, context, engine, info={}): """extract(relations, index, context, engine, info) -> str Nummerical modifiers are treated in the same way as adjectives. This ruleset assembles and returns the number, and it's up to the calling NounPhraseRuleset to emit the propositions. This ruleset also emits propositions for quantifier phrase modifiers. Examples: * About 200 people num(people, 200) quantmod(200, About) -> emit((200, about)) # by calling QuantmodRuleset -> return "200" """ number_indices = Relation.get_children_with_dep( 'number', relations, index) cc_indices = Relation.get_children_with_dep('cc', relations, index) conj_indices = Relation.get_children_with_dep('conj', relations, index) indices = sorted([index] + number_indices + cc_indices + conj_indices) words = [] for n in indices: if n != index: word = engine.analyze(relations, n, context + [index], info={'class': 'NP'}) else: word = relations[index].word if isinstance(word, str): words.append(word) elif isinstance(word, list): words += word this_number = ' '.join(words) # Process quantmods quantmod_indices = Relation.get_children_with_dep( 'quantmod', relations, index) for q in quantmod_indices: engine.analyze(relations, q, context + [index], {'num': this_number}) return this_number
def extract(self, relations, index, context, engine, info={}): """extract(relations, index, context, engine, info) -> str Nummerical modifiers are treated in the same way as adjectives. This ruleset assembles and returns the number, and it's up to the calling NounPhraseRuleset to emit the propositions. This ruleset also emits propositions for quantifier phrase modifiers. Examples: * About 200 people num(people, 200) quantmod(200, About) -> emit((200, about)) # by calling QuantmodRuleset -> return "200" """ number_indices = Relation.get_children_with_dep('number', relations, index) cc_indices = Relation.get_children_with_dep('cc', relations, index) conj_indices = Relation.get_children_with_dep('conj', relations, index) indices = sorted([index] + number_indices + cc_indices + conj_indices) words = [] for n in indices: if n != index: word = engine.analyze(relations, n, context + [index], info={'class': 'NP'}) else: word = relations[index].word if isinstance(word, str): words.append(word) elif isinstance(word, list): words += word this_number = ' '.join(words) # Process quantmods quantmod_indices = Relation.get_children_with_dep('quantmod', relations, index) for q in quantmod_indices: engine.analyze(relations, q, context + [index], {'num': this_number}) return this_number
def extract(self, relations, index, context, engine, info={}): cc_indices = Relation.get_children_with_dep('cc', relations, index) if cc_indices != []: engine.analyze(relations, cc_indices[0], context + [index]) conj_indices = Relation.get_children_with_dep('conj', relations, index) conjs = [engine.analyze(relations, i, context + [index], info={'class': 'NP'}) for i in conj_indices] conjs = [c[0] for c in conjs] # TODO: check if this makes sense. return [relations[index].word] + conjs else: return [relations[index].word]
def process_auxs(relations, index, context, engine, info): """Process auxiliaries and modals.""" aux_index = Relation.get_children_with_dep('aux', relations, index) auxpass_index = Relation.get_children_with_dep('auxpass', relations, index) auxs_index = sorted(aux_index + auxpass_index) auxs = [ engine.analyze(relations, i, context + [index]) for i in auxs_index ] if auxs == [] and 'aux' in info: auxs = info['aux'] return auxs
def process_ignorables(relations, index, context, engine, info): """Process elements that can be ignored (complm - DEPRECATED, and mark).""" # complm complm_indices = Relation.get_children_with_dep( 'complm', relations, index) for i in complm_indices: engine.analyze(relations, i, context + [index]) # TODO: check if this makes sense. # mark mark_indices = Relation.get_children_with_dep('mark', relations, index) for i in mark_indices: engine.analyze(relations, i, context + [index])
def process_auxs(relations, index, context, engine, info): """Process auxiliaries and modals.""" aux_index = Relation.get_children_with_dep('aux', relations, index) auxpass_index = Relation.get_children_with_dep('auxpass', relations, index) auxs_index = sorted(aux_index + auxpass_index) auxs = [engine.analyze(relations, i, context + [index]) for i in auxs_index] if auxs == [] and 'aux' in info: auxs = info['aux'] return auxs
def process_preps(relations, index, context, engine, info): """TODO: Docstring for process_preps.""" prep_indices = Relation.get_children_with_dep("prep", relations, index) for prep_index in prep_indices: engine.analyze(relations, prep_index, context + [index])
def process_negs(relations, index, context, engine, info): """Process negations.""" neg_indices = Relation.get_children_with_dep('neg', relations, index) for i in neg_indices: engine.analyze(relations, i, context + [index])
def process_ccomp(relations, index, context, engine, info): """Process clausal complements.""" ccomp_index = Relation.get_children_with_dep('ccomp', relations, index) if ccomp_index != []: engine.analyze(relations, ccomp_index[0], context + [index], info)
def process_ignorables(relations, index, context, engine, info): """Process elements that can be ignored (complm - DEPRECATED, and mark).""" # complm complm_indices = Relation.get_children_with_dep('complm', relations, index) for i in complm_indices: engine.analyze(relations, i, context + [index]) # TODO: check if this makes sense. # mark mark_indices = Relation.get_children_with_dep('mark', relations, index) for i in mark_indices: engine.analyze(relations, i, context + [index])
def process_auxs(relations, index, context, engine, info): """TODO: Docstring for process_auxs.""" # TODO: add support for multiple auxiliaries. aux_index = Relation.get_children_with_dep('aux', relations, index) auxpass_index = Relation.get_children_with_dep('auxpass', relations, index) auxs_index = sorted(aux_index + auxpass_index) auxs = [ engine.analyze(relations, i, context + [index]) for i in auxs_index ] if auxs == [] and 'aux' in info: auxs = info['aux'] return auxs
def process_vmods(relations, index, context, engine, info): """Processes reduced non-finite verbal modifiers.""" vmod_indices = Relation.get_children_with_dep('vmod', relations, index) for i in vmod_indices: engine.analyze(relations, i, context + [index], info)
def process_adpmods(relations, index, context, engine, info): """Process adpositional modifiers (e.g., angry with you).""" prep_indices = Relation.get_children_with_dep('adpmod', relations, index) for prep_index in prep_indices: engine.analyze(relations, prep_index, context + [index])
def handle_cop_with_np(self, relations, index, context, engine, info): """Handle copular verbs with NP complements.""" subjs = self.process_subj(relations, index, context, engine, info) cop_index = Relation.get_children_with_dep('cop', relations, index)[0] cop = engine.analyze(relations, cop_index, context + [index]) auxs = self.process_auxs(relations, index, context, engine, info) verb = ' '.join([word for word in auxs + [cop] if word is not None]) self.process_ignorables(relations, index, context, engine, info) this = NounPhraseRuleset.extract(self, relations, index, context, engine, info) # TODO: handle cc/conj and preconj. complms = this['return_list'] prop_ids = [] for subj in subjs['return_list']: for compl in complms: # engine.emit((verb, subj, relations[index].word)) prop_id = engine.emit((verb, subj, compl), 'P') prop_ids.append(prop_id) self.subjs = subjs self.auxs = auxs return {'return_value': None, 'prop_ids': prop_ids, 'this': this}
def process_auxs(relations, index, context, engine, info): """TODO: Docstring for process_auxs.""" # TODO: add support for multiple auxiliaries. aux_index = Relation.get_children_with_dep('aux', relations, index) auxpass_index = Relation.get_children_with_dep('auxpass', relations, index) auxs_index = sorted(aux_index + auxpass_index) auxs = [engine.analyze(relations, i, context + [index]) for i in auxs_index] if auxs == [] and 'aux' in info: auxs = info['aux'] return auxs
def process_appos(relations, index, context, engine, info): """Process appositional modifiers (e.g., John, my brother, is here).""" appos_indices = Relation.get_children_with_dep('appos', relations, index) for i in appos_indices: engine.analyze(relations, i, context + [index], info)
def handle_cop_with_adjp(self, relations, index, context, engine, info): """Handle copular verbs with AdjP complements.""" subjs = self.process_subj(relations, index, context, engine, info) cop_index = Relation.get_children_with_dep('cop', relations, index)[0] cop = engine.analyze(relations, cop_index, context + [index]) auxs = self.process_auxs(relations, index, context, engine, info) verb = ' '.join([word for word in auxs + [cop] if word is not None]) self.process_ignorables(relations, index, context, engine, info) self.process_nmods(relations, index, context, engine, info) this = AdjectivalPhraseRuleset.extract(self, relations, index, context, engine, info) prop_ids = [] for subj in subjs['return_list']: for word in this: prop_id = engine.emit((verb, subj, word), 'P') prop_ids.append(prop_id) self.subjs = subjs self.auxs = auxs return {'return_value': None, 'prop_ids': prop_ids}
def process_adpmods(relations, index, context, engine, info={}): """Process adpositional modifiers (e.g., result of the action).""" prep_indices = Relation.get_children_with_dep('adpmod', relations, index) for i in prep_indices: engine.analyze(relations, i, context + [index])
def handle_cop_with_adjp(self, relations, index, context, engine, info): """Handle copular verbs with ADJP complements.""" subjs = self.process_subj(relations, index, context, engine, info) cop_index = Relation.get_children_with_dep('cop', relations, index)[0] cop = engine.analyze(relations, cop_index, context + [index]) auxs = self.process_auxs(relations, index, context, engine, info) verb = ' '.join([word for word in auxs + [cop] if word is not None]) self.process_ignorables(relations, index, context, engine, info) self.process_npadvmod(relations, index, context, engine, info) this = AdjectivalPhraseRuleset.extract(self, relations, index, context, engine, info) prop_ids = [] for subj in subjs['return_list']: for word in this: prop_id = engine.emit((verb, subj, word), 'P') prop_ids.append(prop_id) self.subjs = subjs self.auxs = auxs return {'return_value': None, 'prop_ids': prop_ids}
def process_ccomp(relations, index, context, engine, info): """TODO: Docstring for process_ccomp.""" ccomp_index = Relation.get_children_with_dep('ccomp', relations, index) if ccomp_index != []: engine.analyze(relations, ccomp_index[0], context + [index], info)
def process_vmods(relations, index, context, engine, info): """Processes children with label 'vmod'.""" vmod_indices = Relation.get_children_with_dep('vmod', relations, index) for i in vmod_indices: engine.analyze(relations, i, context + [index], info)
def process_graphs(graphs): engine = Engine(idd3.all_rulesets, idd3.all_transformations) stats = defaultdict(int) for index in range(len(graphs)): print('-' * int(columns)) relations = [] for relation in graphs[index].nodes.values(): relations.append(Relation(**relation)) print(colored('Sentence %d:' % (index + 1), 'white', attrs=['bold'])) print('\t' + get_sentence(graphs[index])) print(colored('Propositions:', 'white', attrs=['bold'])) try: engine.analyze(relations) for i, prop in enumerate(engine.props): print(str(i + 1) + ' ' + str(prop)) stats[prop.kind] += 1 except Exception as e: logger.error('{0} in engine.analyze: {1}'.format( e.__class__.__name__, e)) print('-' * int(columns)) return stats
def process_whats(relations, index, context, engine, info): """Processes children with label 'what'.""" what_indices = Relation.get_children_with_dep('what', relations, index) for i in what_indices: engine.analyze(relations, i, context + [index], info)
def process_npadvmod(relations, index, context, engine, info={}): """TODO: Docstring for process_npadvmod.""" npadvmod_indices = Relation.get_children_with_dep("npadvmod", relations, index) if npadvmod_indices != []: npadvmod = engine.analyze(relations, npadvmod_indices[0], context + [index]) engine.emit((relations[index].word, npadvmod), "M")
def process_discourse_markers(relations, index, context, engine, info): """TODO: Docstring for process_discourse_markers.""" discourse_indices = Relation.get_children_with_dep( 'discourse', relations, index) for i in discourse_indices: engine.analyze(relations, i, context + [index])
def process_appos(relations, index, context, engine, info): """TODO: Docstring for process_appos.""" appos_indices = Relation.get_children_with_dep('appos', relations, index) for i in appos_indices: engine.analyze(relations, i, context + [index], info)
def process_ignorables(relations, index, context, engine, info): """TODO: Docstring for process_ignorables.""" # complm complm_indices = Relation.get_children_with_dep( 'complm', relations, index) for i in complm_indices: engine.analyze(relations, i, context + [index])
def process_preps(relations, index, context, engine, info={}): """TODO: Docstring for process_preps.""" # VP modifiers prep_indices = Relation.get_children_with_dep('prep', relations, index) for i in prep_indices: engine.analyze(relations, i, context + [index])
def process_advmods(relations, index, context, engine, info={}): """TODO: Docstring for process_advmods.""" advmod_indices = Relation.get_children_with_dep("advmod", relations, index) advmods = [engine.analyze(relations, i, context + [index], {"no_emit": True}) for i in advmod_indices] return advmods
def process_negs(relations, index, context, engine, info): """TODO: Docstring for process_negs.""" # neg neg_indices = Relation.get_children_with_dep('neg', relations, index) for i in neg_indices: engine.analyze(relations, i, context + [index])
def process_preps(relations, index, context, engine): """TODO: Docstring for process_preps.""" # VP modifiers prep_indices = Relation.get_children_with_dep('prep', relations, index) for i in prep_indices: engine.analyze(relations, i, context + [index])
def process_advmods(relations, index, context, engine, info={}): """TODO: Docstring for process_advmods.""" advmod_indices = Relation.get_children_with_dep("advmod", relations, index) for i in advmod_indices: advmod = engine.analyze(relations, i, context + [index], {"no_emit": True}) engine.emit((relations[index].word, advmod), "M")