示例#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
    }