Пример #1
0
def produce_existential_arc(restriction_bnode, g):
    """
    Memoized on `restriction` of type `BNode` production of existential arcs

    """
    # there can only be one restriction_bnode on one property
    # here we collect, source, label of the arc, and the target
    source_cls = next(g.subjects(RDFS.subClassOf, restriction_bnode))
    obj_property = next(g.objects(restriction_bnode, OWL.onProperty))
    r_successor = next(g.objects(restriction_bnode, OWL.someValuesFrom))

    # we assume only atomic concepts in the filler of the restriction
    if isinstance(r_successor, BNode):
        return None

    source_id = str(source_cls)
    target_id = str(r_successor)

    arc_label = entity_mapper.compute_short_name(obj_property, g)
    arc_uri = str(obj_property)
    arc_type = str(OWL.someValuesFrom)

    arc_data = {'label': arc_label, 'arc_uri': arc_uri, 'arc_type': arc_type}

    arc = (source_id, target_id, arc_data)

    return arc
Пример #2
0
def test_existential_arcs():
    arc_label = entity_mapper.compute_short_name(
        positively_regulates.identifier, g)
    arc_type = str(OWL.someValuesFrom)
    arc_uri = str(positively_regulates.identifier)
    source = str(chondro_anabolism.identifier)
    targets = [
        str(collagen_production.identifier),
        str(proteoglycan_production.identifier)
    ]

    arc_data = {'label': arc_label, 'arc_type': arc_type, 'arc_uri': arc_uri}

    # find bnodes of the restrictions
    restriction_bnodes = [
        o for o in g.objects(chondro_anabolism.identifier, RDFS.subClassOf)
        if isinstance(o, BNode) and (o, RDF.type, OWL.Restriction)
    ]

    arcs = [
        produce_arcs.produce_existential_arc(restriction_bnode, g)
        for restriction_bnode in restriction_bnodes
    ]

    for target in targets:
        arc = (source, target, arc_data)
        assert graph_utils.is_edge_in_edges(arc, arcs)
Пример #3
0
def test_produce_nodes():
    node_id = str(con.identifier)
    node_label = entity_mapper.compute_short_name(con.identifier, g)
    node_uri = node_id

    node_data = {'label': node_label, 'node_uri': node_uri}

    node = (node_id, node_data)
    produced_node = produce_nodes.produce_node(con.identifier, g)

    assert graph_utils.are_same_nodes(node, produced_node)
Пример #4
0
def produce_node(owl_class_uri, g):
    if isinstance(owl_class_uri, BNode):
        return None

    node_id = str(owl_class_uri)
    node_label = entity_mapper.compute_short_name(owl_class_uri, g)
    node_uri = node_id

    node_data = {
            'label': node_label,
            'node_uri': node_uri
        }

    return (node_id, node_data)
Пример #5
0
def make_is_a_arc():
    source    = str(tnf_alpha.identifier)
    target    = str(con.identifier)
    arc_label = entity_mapper.compute_short_name(RDFS.subClassOf, g)
    arc_uri   = str(RDFS.subClassOf)
    arc_type  = str(RDFS.subClassOf)

    arc_data = {
        'arc_label': arc_label,
        'arc_type': arc_type,
        'arc_uri': arc_uri
    }

    arc = (source, target, arc_data)

    return arc
Пример #6
0
def make_existential_arc():
    source    = str(chondro_anabolism.identifier)
    target    = str(collagen_production.identifier)
    arc_label = entity_mapper.compute_short_name(
            positively_regulates.identifier, g)
    arc_uri   = str(positively_regulates.identifier)
    arc_type  = str(OWL.someValuesFrom)

    arc_data = {
        'arc_label': arc_label,
        'arc_type': arc_type,
        'arc_uri': arc_uri
    }

    arc = (source, target, arc_data)

    return arc
Пример #7
0
def produce_is_a_arc(triple, g):
    """
    Memoized on `triple` for the production of is-a arcs

    """
    s, p, o = triple
    # here we collect, source, label of the arc, and the target
    source_id = str(s)
    target_id = str(o)

    arc_label = entity_mapper.compute_short_name(p, g)
    arc_uri = str(p)
    arc_type = str(p)

    arc_data = {'label': arc_label, 'arc_uri': arc_uri, 'arc_type': arc_type}

    arc = (source_id, target_id, arc_data)

    return arc
Пример #8
0
def test_is_a_arcs():
    arc_label = entity_mapper.compute_short_name(RDFS.subClassOf, g)
    arc_uri = str(RDFS.subClassOf)
    arc_type = str(RDFS.subClassOf)

    source = str(tnf_alpha.identifier)
    targets = [str(con.identifier)]

    arc_data = {'label': arc_label, 'arc_type': arc_type, 'arc_uri': arc_uri}

    # find is-a axioms
    is_a_axioms = list(axiom_iterators.is_a_axioms(g))

    arcs = [
        produce_arcs.produce_is_a_arc(is_a_axiom, g)
        for is_a_axiom in is_a_axioms
    ]

    for target in targets:
        arc = (source, target, arc_data)
        assert graph_utils.is_edge_in_edges(arc, arcs)
Пример #9
0
def test_compute_shortname():
    con_matched = entity_mapper.match_entity('continuant', g)
    assert entity_mapper.compute_short_name(con_matched, g) == 'Continuant'

    occ_matched = entity_mapper.match_entity('Occurrent', g)
    assert entity_mapper.compute_short_name(occ_matched, g) == 'Occurent'