示例#1
0
def generate_langnotlang_literal_po_map(RML_graph, map_name, predicate,
                                        property_number):
    map_name = URIRef(f"http://example.org/entity/{map_name}Map")
    predicate = convert_string_to_IRI(predicate)
    # lang
    po_map_lang = BNode()
    object_map_lang = BNode()
    language_map = BNode()
    property_number_lang = Literal(
        f'{property_number}[not(@rdf:resource)][@xml:lang]')
    language_map_reference = Literal(f'{property_number}/@xml:lang')

    RML_graph.add((map_name, rr.predicateObjectMap, po_map_lang))
    RML_graph.add((po_map_lang, rr.predicate, predicate))
    RML_graph.add((po_map_lang, rr.objectMap, object_map_lang))
    RML_graph.add((object_map_lang, rml.reference, property_number_lang))
    RML_graph.add((object_map_lang, rr.termType, rr.Literal))
    RML_graph.add((object_map_lang, rml.languageMap, language_map))
    RML_graph.add((language_map, rml.reference, language_map_reference))

    # not lang
    po_map_not_lang = BNode()
    object_map_not_lang = BNode()
    property_number_not_lang = Literal(
        f'{property_number}[not(@rdf:resource) and not(@xml:lang)]')

    RML_graph.add((map_name, rr.predicateObjectMap, po_map_not_lang))
    RML_graph.add((po_map_not_lang, rr.predicate, predicate))
    RML_graph.add((po_map_not_lang, rr.objectMap, object_map_not_lang))
    RML_graph.add(
        (object_map_not_lang, rml.reference, property_number_not_lang))
    RML_graph.add((object_map_not_lang, rr.termType, rr.Literal))

    return RML_graph
示例#2
0
def generate_lang_literal_split_po_map(RML_graph, map_name, predicate,
                                       RDA_prop):
    if RDA_prop in classification_props:
        generate_not_lang_literal_split_po_map(RML_graph, map_name, predicate,
                                               RDA_prop)
    else:
        RDA_prop = RDA_prop[0].split(":")[-1]
        map_name = URIRef(f"http://example.org/entity/{map_name}Map")
        predicate = convert_string_to_IRI(predicate)

        po_map = BNode()
        object_map = BNode()
        language_map = BNode()

        reference_value = Literal('.')
        lang_map_value = Literal('@xml:lang')

        RML_graph.add((map_name, rr.predicateObjectMap, po_map))
        RML_graph.add((po_map, rr.predicate, predicate))
        RML_graph.add((po_map, rr.objectMap, object_map))
        RML_graph.add((object_map, rml.reference, reference_value))
        RML_graph.add((object_map, rr.termType, rr.Literal))
        RML_graph.add((object_map, rml.languageMap, language_map))
        RML_graph.add((language_map, rml.reference, lang_map_value))

        return RML_graph
示例#3
0
def generate_bnode_subject_map(RML_graph, map_name, class_name):
    bnode_subject_map = BNode()
    map_name = URIRef(f"http://example.org/entity/{map_name}Map")
    class_property = URIRef('http://www.w3.org/ns/r2rml#class'
                            )  # throws an error when you just enter rr.class
    class_name = convert_string_to_IRI(class_name)

    RML_graph.add((map_name, rr.subjectMap, bnode_subject_map))
    RML_graph.add((bnode_subject_map, rr.termType, rr.BlankNode))
    RML_graph.add((bnode_subject_map, class_property, class_name))

    return RML_graph
示例#4
0
def generate_bnode_po_map(RML_graph, map_name, bnode_map_name, predicate):
    bnode_po_map = BNode()
    object_map = BNode()
    map_name = URIRef(f"http://example.org/entity/{map_name}Map")
    bnode_map_name = URIRef(f"http://example.org/entity/{bnode_map_name}Map")
    predicate = convert_string_to_IRI(predicate)

    RML_graph.add((map_name, rr.predicateObjectMap, bnode_po_map))
    RML_graph.add((bnode_po_map, rr.predicate, predicate))
    RML_graph.add((bnode_po_map, rr.objectMap, object_map))
    RML_graph.add((object_map, rr.parentTriplesMap, bnode_map_name))

    return RML_graph
示例#5
0
def generate_neutral_literal_split_po_map(RML_graph, map_name, predicate):
    map_name = URIRef(f"http://example.org/entity/{map_name}Map")
    predicate = convert_string_to_IRI(predicate)

    po_map = BNode()
    object_map = BNode()

    RML_graph.add((map_name, rr.predicateObjectMap, po_map))
    RML_graph.add((po_map, rr.predicate, predicate))
    RML_graph.add((po_map, rr.objectMap, object_map))
    RML_graph.add((object_map, rml.reference, Literal('.')))
    RML_graph.add((object_map, rr.termType, rr.Literal))

    return RML_graph
示例#6
0
def generate_neutral_literal_po_map(RML_graph, map_name, predicate,
                                    property_number):
    map_name = URIRef(f"http://example.org/entity/{map_name}Map")
    predicate = convert_string_to_IRI(predicate)
    property_number = Literal(f'{property_number}[not(@rdf:resource)]')

    po_map = BNode()
    object_map = BNode()

    RML_graph.add((map_name, rr.predicateObjectMap, po_map))
    RML_graph.add((po_map, rr.predicate, predicate))
    RML_graph.add((po_map, rr.objectMap, object_map))
    RML_graph.add((object_map, rml.reference, property_number))
    RML_graph.add((object_map, rr.termType, rr.Literal))

    return RML_graph
示例#7
0
def generate_IRI_split_po_map(RML_graph, map_name, predicate):
    map_name = URIRef(f"http://example.org/entity/{map_name}Map")
    if "*" not in predicate:
        print(f"{predicate} -- are you sure this takes an IRI?")
        quit()
    else:
        predicate = predicate.strip('*')
        predicate = convert_string_to_IRI(predicate)

    po_map = BNode()
    object_map = BNode()

    RML_graph.add((map_name, rr.predicateObjectMap, po_map))
    RML_graph.add((po_map, rr.predicate, predicate))
    RML_graph.add((po_map, rr.objectMap, object_map))
    RML_graph.add((object_map, rml.reference, Literal('self::node()')))
    RML_graph.add((object_map, rr.termType, rr.IRI))

    return RML_graph