def match_copy_gaps_with_crds(dag: DAG) -> ProofNet:
    proof = set()

    gaps = list(
        filter(
            lambda node: is_copy(dag, node) and is_gap(dag, node, _head_deps),
            dag.nodes))
    gap_types = list(map(lambda node: dag.attribs[node]['type'], gaps))
    gap_colors = list(map(lambda type_: type_.argument.color, gap_types))
    gap_types = list(map(lambda type_: type_.argument.argument, gap_types))
    conjunction_hierarchies = list(
        map(
            lambda node: participating_conjunctions(
                dag, node, exclude_heads=True), gaps))

    proof = merge_proofs(
        proof,
        list(
            map(lambda ch, gt, gc: intra_crd_match(dag, ch, gt, gc),
                conjunction_hierarchies, gap_types, gap_colors)))

    crd_types = list(
        map(lambda ch: get_crd_type(dag, fst(fst(ch))),
            conjunction_hierarchies))
    results = list(map(last_instance_of, crd_types))
    matches = list(map(identify_missing, results, gap_types, gap_colors))
    return reduce(lambda proof_, pair: match(proof_, fst(pair), snd(pair)),
                  zip(gap_types, matches), proof)
def match_copies_with_crds(dag: DAG) -> ProofNet:
    def get_copy_color(copy_: Node) -> str:
        incoming_ = set(map(lambda inc_: inc_.dep, dag.incoming(copy_)))
        assert len(incoming_) == 1
        return fst(list(incoming_))

    proof = set()

    copies = list(
        filter(
            lambda node: is_copy(dag, node) and not is_gap(
                dag, node, _head_deps), dag.nodes))
    copy_colors = list(map(get_copy_color, copies))
    copy_types = list(map(lambda copy: dag.attribs[copy]['type'], copies))

    conjunction_hierarchies: List[List[Tuple[Node, List[Optional[Node]]]]] = \
        list(map(lambda node: participating_conjunctions(dag, node), copies))

    proof = merge_proofs(
        proof,
        list(
            map(lambda ch, ct, cc: intra_crd_match(dag, ch, ct, cc),
                conjunction_hierarchies, copy_types, copy_colors)))

    crd_types = list(
        map(lambda ch: get_crd_type(dag, fst(fst(ch))),
            conjunction_hierarchies))
    results = list(map(last_instance_of, crd_types))
    matches = list(map(identify_missing, results, copy_types, copy_colors))
    return reduce(lambda proof_, pair: match(proof_, fst(pair), snd(pair)),
                  zip(copy_types, matches), proof)
def get_simple_functor(dag: DAG, node: Node) -> WordType:
    type_ = dag.attribs[node]['type']
    if is_gap(dag, node, _head_deps):
        return ColoredType(argument=type_.argument.result,
                           color=type_.color,
                           result=type_.result)
    else:
        return type_
示例#4
0
def get_simple_functor(dag: DAG[Node, Any], node: Node) -> WordType:
    type_: WordType = dag.attribs[node]['type']
    if is_gap(dag, node, HeadDeps):
        if isinstance(type_, DiamondType):
            return DiamondType(argument=type_.argument.result, diamond=type_.diamond, result=type_.result)
        else:
            raise ProofError(f'Gap type {type_} is not a DiamondType')
    return type_
示例#5
0
def get_simple_argument(dag: DAG[Node, Any], node: Node) -> WordType:
    type_: WordType = dag.attribs[node]['type']
    if is_gap(dag, node, HeadDeps):
        if isinstance(type_, DiamondType):
            if isinstance(type_.argument, FunctorType):
                return type_.argument.argument
            else:
                raise ProofError(f'Gap argument {type_.argument} is not a FunctorType')
        else:
            raise ProofError(f'Gap type {type_} is not a DiamondType')
    return type_
示例#6
0
def add_ghost_nodes(dag: DAG[str, Any]) -> None:
    edges = dag.edges
    copy_edges = set(filter(lambda edge: is_copy(dag, edge.target), edges))
    gap_edges = set(filter(lambda edge: is_gap(dag, edge.target, HeadDeps), edges))
    copy_gap_edges = copy_edges.intersection(gap_edges)
    copy_edges = copy_edges - copy_gap_edges

    copy_gap_edges = set(filter(lambda edge: edge.dep not in HeadDeps, copy_gap_edges))

    copies_and_types = list(map(lambda copy: (copy, get_copy_annotation(dag, copy)), copy_edges.union(copy_gap_edges)))
    for c, t in copies_and_types:
        add_edge(dag, c, t)
示例#7
0
def match_copied_gaps_with_crds(dag: DAG[str, str]) -> ProofNet:
    def extract_color(type_: WordType) -> str:
        if isinstance(type_, FunctorType):
            if isinstance(type_.argument, DiamondType):
                return type_.argument.diamond
            if isinstance(type_.argument, BoxType):
                return type_.argument.box
        raise ProofError(f'Expected {type_} to be a higher order functor.')

    def extract_arg(type_: WordType) -> WordType:
        if isinstance(type_, FunctorType):
            if isinstance(type_.argument, DiamondType):
                return type_.argument.argument
            if isinstance(type_.argument, BoxType):
                return type_.argument.argument
        raise ProofError(f'Expected {type_} to be a higher order functor.')

    gaps = list(filter(lambda node:
                       is_copy(dag, node) and is_gap(dag, node, HeadDeps),
                       dag.nodes))
    gap_types: WordTypes = list(map(lambda node: dag.attribs[node]['type'], gaps))

    gap_colors = list(map(lambda gaptype: extract_color(gaptype), gap_types))
    gap_args = list(map(lambda gaptype: extract_arg(gaptype), gap_types))

    conj_hierarchies = list(map(lambda node:
                                participating_conjunctions(dag, node, exclude_heads=True),
                                gaps))

    proofs = list(map(lambda ch, ga, gc:
                      intra_crd_match(dag, ch, ga, gc),
                      conj_hierarchies,
                      gap_args,
                      gap_colors))

    crds = list(map(lambda ch:
                    get_crd_type(dag, fst(fst(ch))),
                    conj_hierarchies))

    results = list(map(lambda crd: last_instance_of(crd), crds))

    matches = list(map(lambda res, ga, gc:
                       identify_missing(res, ga, gc),
                       results,
                       gap_args,
                       gap_colors))

    return reduce(lambda proof_, pair:
                  match(proof_, fst(pair), snd(pair)),
                  zip(gap_args, matches),
                  merge_proofs(proofs))
def add_ghost_nodes(dag: DAG) -> DAG:
    edges = dag.edges
    copies = set(filter(lambda edge: is_copy(dag, edge.target), edges))
    gaps = set(filter(lambda edge: is_gap(dag, edge.target, _head_deps),
                      edges))
    copy_gaps = copies.intersection(gaps)
    copies = list(copies - copy_gaps)

    # todo. assertions

    copy_gaps = set(filter(lambda edge: edge.dep not in _head_deps, copy_gaps))
    copy_gaps = list(copy_gaps)

    copy_types = list(map(lambda copy: get_copy_annotation(dag, copy), copies))
    gap_types = list(
        map(lambda copy: get_copy_annotation(dag, copy), copy_gaps))

    dag = reduce(lambda dag_, pair_: add_edge(dag_, fst(pair_), snd(pair_)),
                 zip(copies, copy_types), dag)
    dag = reduce(lambda dag_, pair_: add_edge(dag_, fst(pair_), snd(pair_)),
                 zip(copy_gaps, gap_types), dag)

    return dag
def get_simple_argument(dag: DAG, node: Node) -> WordType:
    type_ = dag.attribs[node]['type']
    if is_gap(dag, node, _head_deps):
        return type_.argument.argument
    else:
        return type_
 def is_gap_copy_parent(edge_: Edge) -> bool:
     return edge_.dep in _head_deps and is_copy(
         dag, edge_.target) and is_gap(dag, edge_.target, _head_deps)
示例#11
0
 def is_gap_copy_parent(edge_: Edge[str, str]) -> bool:
     return edge_.dep in HeadDeps and is_copy(dag, edge_.target) and is_gap(dag, edge_.target, HeadDeps)