예제 #1
0
def number_per_unit(dep_graph: DependencyGraph):
    """

    :param dep_graph:
    :param oia_graph:
    :return:
    """

    units = []
    for node in dep_graph.nodes(filter=lambda n: n.UPOS == "SYM"):

        previous_node = dep_graph.get_node_by_loc(node.LOC - 1)
        post_node = dep_graph.get_node_by_loc(node.LOC + 1)

        if not previous_node or not post_node:
            continue

        if previous_node.UPOS == "NUM" and post_node.UPOS == "NOUN":
            units.append((previous_node, node, post_node))

    for unit in units:
        unit_node = merge_dep_nodes(unit,
                                    UPOS="NUM",
                                    LOC=unit[-1].LOC
                                    )

        dep_graph.replace_nodes(unit, unit_node)
def process_head_conj(dep_graph: DependencyGraph):
    """

    :param dep_graph:
    :return:
    """
    first_word = dep_graph.get_node_by_loc(0)
    if first_word and first_word.LEMMA in {"and", "but"}:
        cc_parents = [n for n, l in dep_graph.parents(first_word) if l == "cc"]
        for p in cc_parents:
            dep_graph.remove_dependency(p, first_word)
            dep_graph.add_dependency(first_word, p, "arg_conj:1")
예제 #3
0
def aux_not(dep_graph: DependencyGraph):
    """

    :param dep_graph:
    :return:
    """

    aux_not = []
    for node in dep_graph.nodes(filter=lambda n: n.UPOS == "AUX"):

        next_node = dep_graph.get_node_by_loc(node.LOC + 1)

        if not next_node:
            continue

        if next_node.UPOS == "PART" and next_node.FORM == "n't":
            aux_not.append((node, next_node))

    for aux_node, not_node in aux_not:
        new_node = merge_dep_nodes([aux_node, not_node], UPOS=aux_node.UPOS, LOC=aux_node.LOC)

        dep_graph.replace_nodes([aux_node, not_node], new_node)