Пример #1
0
def main():
    if args.ontology:
        print("IF  args.ontology: ")
        g = schema(args.graph)
        kwargs = {'serial': 'turtle'}
        if args.serialization:
            kwargs['serial'] = args.serialization
        if args.namespace:
            kwargs['namespace'] = args.namespace
        g.gen_graph(**kwargs)
    else:
        print("Else rdf graph....")
        kwargs = {'serial': 'turtle'}
        print("Starting to load graph ....")
        g = data_graph(args.graph)
        print("Graph is parsed....  g = data_graph(args.graph)")
        #        if args.nested:
        #            kwargs['graph_format'] = 'nf'
        #        elif args.extended:
        #            kwargs['graph_format'] = 'ef'
        if args.serialization:
            kwargs['serial'] = args.serialization
        if args.namespace:
            kwargs['namespace'] = args.namespace
        print('## shape file generated by SHACLGEN')
        g.gen_graph(**kwargs)
Пример #2
0
def test_namespace():
    source_graph = Graph()

    data = """
    <urn:test:resource> a <urn:test:Class> .
    """

    source_graph.parse(data=data, format="turtle")

    extraction_graph = data_graph(source_graph)
    shacl_graph = extraction_graph.gen_graph(
        namespace=("http://custom.namespace.org/", "custom"))

    assertAskQuery(
        shacl_graph,
        """
    prefix sh: <http://www.w3.org/ns/shacl#>
    prefix xsd: <http://www.w3.org/2001/XMLSchema#>
    ask {
        ?nodeShape a sh:NodeShape .

        filter regex(str(?nodeShape), "^http://custom.namespace.org/")
    }
    """,
    )
Пример #3
0
def test_object_blank_node():
    source_graph = Graph()

    data = """
    <urn:test:resource> a <urn:test:Class> ;
    <urn:test:obj_property> [] .
    """

    source_graph.parse(data=data, format="turtle")

    extraction_graph = data_graph(source_graph)
    shacl_graph = extraction_graph.gen_graph()

    assertAskQuery(
        shacl_graph,
        """
    prefix sh: <http://www.w3.org/ns/shacl#>
    prefix xsd: <http://www.w3.org/2001/XMLSchema#>
    ask {
        ?nodeShapeA a sh:NodeShape ;
            sh:nodeKind sh:BlankNodeOrIRI ;
            sh:property ?property ;
            sh:targetClass <urn:test:Class> .

        ?property a sh:PropertyShape ;
            sh:nodeKind sh:BlankNode ;
            sh:path <urn:test:obj_property> .
    }
    """,
    )
Пример #4
0
def test_two_classes():
    source_graph = Graph()

    data = """
    <urn:test:resource> a <urn:test:Class> .
    <urn:test:resource_2> a <urn:test:Class> .
    <urn:test:other_resource> a <urn:test:OtherClass> .
    """

    source_graph.parse(data=data, format="turtle")

    extraction_graph = data_graph(source_graph)
    shacl_graph = extraction_graph.gen_graph()

    assertAskQuery(
        shacl_graph,
        """
    prefix sh: <http://www.w3.org/ns/shacl#>
    prefix xsd: <http://www.w3.org/2001/XMLSchema#>
    ask {
        ?nodeShapeA a sh:NodeShape ;
            sh:nodeKind sh:BlankNodeOrIRI ;
            sh:targetClass <urn:test:Class> .

        ?nodeShapeB a sh:NodeShape ;
            sh:nodeKind sh:BlankNodeOrIRI ;
            sh:targetClass <urn:test:OtherClass> .
    }
    """,
    )
Пример #5
0
def test_two_object_classes_are_sorted():
    source_graph = Graph()

    data = """
    <urn:test:resource> a <urn:test:Class> ;
    <urn:test:obj_property> <urn:test:other_resource> .
    <urn:test:other_resource> a <urn:test:OtherClass>, <urn:test:OtherClass2> .
    """

    source_graph.parse(data=data, format="turtle")

    extraction_graph = data_graph(source_graph)
    shacl_graph = extraction_graph.gen_graph()

    assertAskQuery(
        shacl_graph,
        """
    prefix sh: <http://www.w3.org/ns/shacl#>
    prefix xsd: <http://www.w3.org/2001/XMLSchema#>
    ask {
        ?nodeShapeA a sh:NodeShape ;
            sh:nodeKind sh:BlankNodeOrIRI ;
            sh:property ?property ;
            sh:targetClass <urn:test:Class> .

        ?nodeShapeB a sh:NodeShape ;
            sh:nodeKind sh:BlankNodeOrIRI ;
            sh:targetClass <urn:test:OtherClass> .

        ?nodeShapeC a sh:NodeShape ;
            sh:nodeKind sh:BlankNodeOrIRI ;
            sh:targetClass <urn:test:OtherClass2> .

        ?property a sh:PropertyShape ;
            sh:nodeKind sh:IRI ;
            sh:or/rdf:first/sh:class <urn:test:OtherClass> ;
            sh:or/rdf:rest/rdf:first/sh:class <urn:test:OtherClass2> ;
            sh:path <urn:test:obj_property> .
    }
    """,
    )
Пример #6
0
def test_create_shape_http_iri_slash():
    source_graph = Graph()

    data = """
    @prefix ext: <http://example.org/test/> .
    @prefix extv: <http://example.org/test/vocab/> .
    ext:resource a extv:Class ;
        extv:lit_property "String" ;
        extv:obj_property ext:other_resource .
    """

    source_graph.parse(data=data, format="turtle")

    extraction_graph = data_graph(source_graph)
    shacl_graph = extraction_graph.gen_graph()

    assertAskQuery(
        shacl_graph,
        """
    prefix sh: <http://www.w3.org/ns/shacl#>
    prefix xsd: <http://www.w3.org/2001/XMLSchema#>
    ask {
        ?nodeShape a sh:NodeShape ;
            sh:nodeKind sh:BlankNodeOrIRI ;
            sh:targetClass <http://example.org/test/vocab/Class> ;
            sh:property ?propA, ?propB .

        ?propA a sh:PropertyShape ;
            sh:datatype xsd:string ;
            sh:nodeKind sh:Literal ;
            sh:path <http://example.org/test/vocab/lit_property> .
            ?ropB a sh:PropertyShape ;

            sh:nodeKind sh:IRI ;
            sh:path <http://example.org/test/vocab/obj_property> .
    }
    """,
    )
Пример #7
0
def test_create_shape_urn():
    source_graph = Graph()

    data = """
    <urn:test:resource> a <urn:test:Class> ;
    <urn:test:lit_property> "String" ;
    <urn:test:obj_property> <urn:test:other_resource> .
    """

    source_graph.parse(data=data, format="turtle")

    extraction_graph = data_graph(source_graph)
    shacl_graph = extraction_graph.gen_graph()

    assertAskQuery(
        shacl_graph,
        """
    prefix sh: <http://www.w3.org/ns/shacl#>
    prefix xsd: <http://www.w3.org/2001/XMLSchema#>
    ask {
        ?nodeShape a sh:NodeShape ;
            sh:nodeKind sh:BlankNodeOrIRI ;
            sh:targetClass <urn:test:Class> ;
            sh:property ?propA, ?propB .

        ?propA a sh:PropertyShape ;
            sh:datatype xsd:string ;
            sh:nodeKind sh:Literal ;
            sh:path <urn:test:lit_property> .
            ?ropB a sh:PropertyShape ;

            sh:nodeKind sh:IRI ;
            sh:path <urn:test:obj_property> .
    }
    """,
    )