예제 #1
0
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)))
예제 #2
0
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))))
예제 #3
0
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))))
예제 #4
0
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
예제 #5
0
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
예제 #6
0
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
예제 #7
0
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
예제 #8
0
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)))
예제 #10
0
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
예제 #11
0
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}
예제 #12
0
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
예제 #13
0
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
예제 #14
0
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
    }