def convert_passage(passage, report_writer): for rule in RULES: for terminal in passage.layer(layer0.LAYER_ID).all: parent = fparent(terminal) if len(parent.children) == 1 and rule(terminal, parent): report_writer.writerow( (rule.__name__, passage.ID, terminal.ID, parent, fparent(terminal)))
def convert_passage(passage, report_writer): for rule in RULES: for terminal in passage.layer(layer0.LAYER_ID).all: parent = fparent(terminal) grandparent = fparent(parent) grandparent_str = str(grandparent) if len(parent.children) == 1 and rule(terminal, parent, grandparent): report_writer.writerow((rule.__name__, passage.ID, terminal.ID, get_annotation(terminal, Attr.POS), grandparent_str, fparent(fparent(terminal))))
def convert_passage(passage, report_writer): for rule in RULES: for terminal in passage.layer(layer0.LAYER_ID).all: parent = fparent(terminal) grandparent = fparent(parent) grandparent_str = str(grandparent) if len(parent.children) == 1 and rule(terminal, parent, grandparent): report_writer.writerow( (rule.__name__, passage.ID, terminal.ID, get_annotation(terminal, Attr.POS), grandparent_str, fparent(fparent(terminal))))
def extract_ground(terminal, parent, grandparent): if get_annotation(terminal, Attr.LEMMA) in GROUND: if is_main_relation( grandparent) and parent.ftag == layer1.EdgeTags.Elaborator: move_node(parent, fparent(grandparent), tag=layer1.EdgeTags.Ground) return True return False
def extract_modal(terminal, parent, grandparent): if (get_annotation(terminal, Attr.LEMMA) in MODALS or get_annotation(terminal, Attr.POS) in {"VERB", "ADV"} and get_annotation(terminal, Attr.DEP) not in {"aux", "auxpass"}) and \ is_main_relation(grandparent) and parent.ftag == layer1.EdgeTags.Elaborator: move_node(parent, fparent(grandparent), tag=layer1.EdgeTags.Adverbial) return True return False
def extract_aux(terminal, parent, grandparent): if get_annotation(terminal, Attr.LEMMA) in AUX and is_main_relation(grandparent) and ( parent.ftag == layer1.EdgeTags.Function or parent.ftag in {layer1.EdgeTags.Elaborator, layer1.EdgeTags.Relator} and get_annotation(terminal, Attr.DEP) in {"aux", "auxpass"}): move_node(parent, fparent(grandparent), tag=layer1.EdgeTags.Function) return True return False
def extract_aux(terminal, parent, grandparent): if get_annotation( terminal, Attr.LEMMA) in AUX and is_main_relation(grandparent) and ( parent.ftag == layer1.EdgeTags.Function or parent.ftag in {layer1.EdgeTags.Elaborator, layer1.EdgeTags.Relator} and get_annotation(terminal, Attr.DEP) in {"aux", "auxpass"}): move_node(parent, fparent(grandparent), tag=layer1.EdgeTags.Function) return True return False
def convert_passage(passage, lang, report_writer): for rule in RULES: for terminal in passage.layer(layer0.LAYER_ID).all: parent = fparent(terminal) if len(parent.children) == 1 and rule(terminal, parent, lang): report_writer.writerow((rule.__name__, passage.ID, terminal.ID, parent, fparent(terminal)))
def move_node(node, new_parent, tag=None): for edge in node.incoming: if edge.parent == fparent(edge): copy_edge(edge, parent=new_parent, tag=tag) remove(edge.parent, edge) break
def is_main_relation(node): while node is not None and node.ftag == layer1.EdgeTags.Center: node = fparent(node) return node is not None and node.ftag in {layer1.EdgeTags.Process, layer1.EdgeTags.State}
def extract_ground(terminal, parent, grandparent): if get_annotation(terminal, Attr.LEMMA) in GROUND: if is_main_relation(grandparent) and parent.ftag == layer1.EdgeTags.Elaborator: move_node(parent, fparent(grandparent), tag=layer1.EdgeTags.Ground) return True return False
def is_main_relation(node): while node is not None and node.ftag == layer1.EdgeTags.Center: node = fparent(node) return node is not None and node.ftag in { layer1.EdgeTags.Process, layer1.EdgeTags.State }