You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by al...@web.de on 2020/11/01 02:11:33 UTC

SHACL validation doesn't show an error

Hey guys,
i created an Issue one weeg ago and you recommended me to validate my schema with jena shacl. I did this, but i still don't get the expected result... 
What do i have to change or what mistake did i do ? (i am not allowed to change the schema by the way).
Maybe you have some example code or another idea how to validate my metadata.rdf ?

The problem:
As you can see, i have a "topic" containing the property "has-component", but my schema just allows (rdfs:domain and rdfs:range) a "component" with the property "has-component". 
The validation report says in both ways, that everything is confirm......

Thanks for you help:)
Greetings from Germany
Alex



My schema is original an .rdf-schema, but i converted it into .ttl in order to use shacl-shapes. It looks like the following:

schema.ttl:

@prefix schema: <http://schema.org/> .
@prefix rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix iirds: <http://iirds.tekom.de/iirds#> .
@prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#> .
iirds:Topic  a             rdfs:Class ;
        rdfs:comment       "A topic is a unit of information covering a single subject."@en ;
        rdfs:label         "Topic"@en , "Topic"@de ;
        rdfs:subClassOf    iirds:InformationUnit ;
        iirds:description  "IRI: required"@en , "The resource of a topic is a file in the iiRDS package."@en .

iirds:has-component  a         rdf:Property ;
        rdfs:comment           "Relates to a component that is part of another component."@en , "Verweist auf eine Kompoente, die Teil einer anderen Komponente ist."@de ;
        rdfs:domain            iirds:Component ;
        rdfs:label             "has component"@en , "hat Komponente"@de ;
        rdfs:range             iirds:Component ;
        rdfs:subPropertyOf     iirds:iirdsRelationConcept ;
        iirds:description      "Cardinality: http://iirds.tekom.de/iirds#Component [0..*]"@en , ""@en ;
        schema:domainIncludes  iirds:Component ;
        schema:rangeIncludes   iirds:Component .

iirds:Component  a         rdfs:Class ;
        rdfs:comment       "Describes a component of the technical system that the documentation refers to."@en ;
        rdfs:label         "Component"@en , "Komponente"@de ;
        rdfs:subClassOf    iirds:ProductMetadata ;
        iirds:description  "IRI: required"@en , "Components may have relations to ot[...] The iirds#Component may also be used as a docking point for external component definitions."@en .





My metadata.rdf converted into metadata.ttl looks like the following:

metadata.ttl:

@prefix pifan: <http://customer.docufy.de/pifan#> .
@prefix rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix iirds: <http://iirds.tekom.de/iirds#> .
@prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#> .
[...]
<http://iirds.docufy.de/topics/05d2c8268b68ff6444a49358ca7fe925/1/de-de>
        a                           iirds:Topic ;
        iirds:dateOfCreation        "2020-08-06T12:24:07.285+02:00"@de-de ;
        iirds:has-component         <http://iirds.docufy.de/metadata/85e7506eb2e33f90c0a802687f559f0c> ;
        iirds:relates-to-component  <http://iirds.docufy.de/metadata/85e7506eb2e33f90c0a802687f559f0c> ;
        iirds:relates-to-product-feature
                <http://iirds.docufy.de/metadata/b63e4b15b2dc2d83c0a8026877f6aa88> , <http://iirds.docufy.de/metadata/10b4c299b2ddae19c0a8026824aa7410> , <http://iirds.docufy.de/metadata/dbbb7334b2e2a9e5c0a8026860d20c17> ;
        iirds:title                 "Kontaktdaten"@de-de .
[...]


My code is the following:

//try with jena shacl
Graph shapesGraph = RDFDataMgr.loadGraph("schema.ttl");
Graph dataGraph = RDFDataMgr.loadGraph("metadata.ttl");	
Shapes shapes = Shapes.parse(shapesGraph);	
ValidationReport report = ShaclValidator.get().validate(shapes, dataGraph);
ShLib.printReport(report);
System.out.println();
RDFDataMgr.write(System.out, report.getModel(), Lang.TTL);

//try with topbraid shacl
Model dataModel = org.topbraid.jenax.util.JenaUtil.createDefaultModel();
dataModel.read("metadata.ttl");
Model shapeModel = org.topbraid.jenax.util.JenaUtil.createDefaultModel();
shapeModel.read("schema.ttl");	
Resource reportResource = ValidationUtil.validateModel(dataModel, shapeModel, true);
File reportFile = new File("report.ttl");







Re: Aw: Re: SHACL validation doesn't show an error

Posted by Thomas Francart <th...@sparna.fr>.
Hello

Le lun. 2 nov. 2020 à 08:52, Lorenz Buehmann <
buehmann@informatik.uni-leipzig.de> a écrit :

> I suggested to use SHACL but I thought it's clear that you need to
> create the corresponding SHACL shapes then - I should be more specific
> in the future.
>
> Regarding your question, no this still won't work. Maybe you didn't
> understand the issue at all, but in OWL you have two things to keep in
> mind:
>
> a) Open World Assumption (OWA)
> b) no Unique Names Assumption (UNA)
>
> the UNA basically means that having entities with different URIs does
> not guarantee that those entities are distinct. With owl:AllDifferent
> you basically avoid this.
>
> But ... this does not solve the OWA behavior. Especially with standard
> reasoning, like rule-based or something like tableau algorithm for full
> OWL DL, you won't get any "violations".
>
> What you need is either something to close the world or you use some
> constraint validation mechanism. In Jena you have out-of-the-box SHACL
> support. There are also other constraint languages like SHeX, Pellet ICV
> (now commercial part of Stardog only), etc.
>
> For OWL there are indeed some approaches to convert (parts of) the
> schema to SHACL shapes, e.g.
> https://www.topquadrant.com/from-owl-to-shacl-in-an-automated-way/
>
>
From that excellent article mentionned above, I have derived simpler
rulesets to convert OWL to SHACL :
https://shacl-play.sparna.fr/play/rules-catalog
The SHACL Play application provides a free owl 2 shacl transformer using
these rules. And also free SHACL validation with human-readable report,
based on TopQuadrant's API.
The rules are not perfect, this is work in progress and the rulesets might
be adjusted in the future, especially regarding inheritance mechanisms and
closed shapes.

Best Regards
Thomas


> So my suggestion, write the SHACL shapes or rethink your infrastructure
> if you don't want to stick to Jena + SHACL
>
>
> On 02.11.20 03:49, alexander.fandre@web.de wrote:
> > Thanks for your answer :) Is there a way to validate the two files (
> data.rdf and schema.rdf ) as .rdf? So without changing the schema... ? I
> tried with the jena reasoner and with adding ALLDifferent to deny the open
> world assumption, but that doesnt help.... ?
> >
> > Alex
> >
> >
> >
> >
> > Gesendet: Sonntag, 01. November 2020 um 12:13 Uhr
> > Von: "Andy Seaborne" <an...@apache.org>
> > An: users@jena.apache.org
> > Betreff: Re: SHACL validation doesn't show an error
> > SHACL uses shapes - not RDFS range and domain
> >
> > "rdfs:range iirds:Component ;" means the range
> > "is of that class" not that there must be that triple because RDFS can
> > be used to infer the fact and add it to the data.
> >
> > See the SHACL spec : https://www.w3.org/TR/shacl/
> > which has lots of examples of shapes.
> >
> > In this case:
> >
> > In schema.ttl:
> >
> > ------------
> > PREFIX iirds: <
> http://iirds.tekom.de/iirds#[http://iirds.tekom.de/iirds#]>
> > PREFIX rdf: <
> http://www.w3.org/1999/02/22-rdf-syntax-ns#[http://www.w3.org/1999/02/22-rdf-syntax-ns#]
> >
> > PREFIX rdfs: <
> http://www.w3.org/2000/01/rdf-schema#[http://www.w3.org/2000/01/rdf-schema#]
> >
> > PREFIX sh: <http://www.w3.org/ns/shacl#[http://www.w3.org/ns/shacl#]>
> > PREFIX xsd: <
> http://www.w3.org/2001/XMLSchema#[http://www.w3.org/2001/XMLSchema#]>
> > PREFIX : <http://example/>
> >
> > :shape1 sh:targetObjectsOf iirds:has-component ;
> > sh:class iirds:Component ;
> > .
> > ------------
> >
> > and you'll get a violation
> >
> > Add the expected triple to metadata.ttl:
> > ----
> > <
> http://iirds.docufy.de/topics/05d2c8268b68ff6444a49358ca7fe925/1/de-de[http://iirds.docufy.de/topics/05d2c8268b68ff6444a49358ca7fe925/1/de-de]
> >
> > rdf:type iirds:Component .
> > ----
> >
> > and the violation goes away.
> >
> > From the commandline (shell scripts):
> >
> > Jena SHACL engine:
> >
> > shacl v -s schema.ttl -d metadata.ttl
> >
> > or see the instructions on
> https://github.com/TopQuadrant/shacl[https://github.com/TopQuadrant/shacl]
> for
> > TopQuadrant TopBraid SHACL API
> >
> > shaclvalidate -shapesfile schema.ttl -datafile metadata.ttl
> >
> > Andy
> >
> > On 01/11/2020 02:11, alexander.fandre@web.de wrote:
> >> Hey guys,
> >> i created an Issue one weeg ago and you recommended me to validate my
> schema with jena shacl. I did this, but i still don't get the expected
> result...
> >> What do i have to change or what mistake did i do ? (i am not allowed
> to change the schema by the way).
> >> Maybe you have some example code or another idea how to validate my
> metadata.rdf ?
> >>
> >> The problem:
> >> As you can see, i have a "topic" containing the property
> "has-component", but my schema just allows (rdfs:domain and rdfs:range) a
> "component" with the property "has-component".
> >> The validation report says in both ways, that everything is
> confirm......
> >>
> >> Thanks for you help:)
> >> Greetings from Germany
> >> Alex
> >>
> >>
> >>
> >> My schema is original an .rdf-schema, but i converted it into .ttl in
> order to use shacl-shapes. It looks like the following:
> >>
> >> schema.ttl:
> >>
> >> @prefix schema: <http://schema.org/[http://schema.org/]> .
> >> @prefix rdf: <
> http://www.w3.org/1999/02/22-rdf-syntax-ns#[http://www.w3.org/1999/02/22-rdf-syntax-ns#]>
> .
> >> @prefix iirds: <
> http://iirds.tekom.de/iirds#[http://iirds.tekom.de/iirds#]> .
> >> @prefix rdfs: <
> http://www.w3.org/2000/01/rdf-schema#[http://www.w3.org/2000/01/rdf-schema#]>
> .
> >> iirds:Topic a rdfs:Class ;
> >> rdfs:comment "A topic is a unit of information covering a single
> subject."@en ;
> >> rdfs:label "Topic"@en , "Topic"@de ;
> >> rdfs:subClassOf iirds:InformationUnit ;
> >> iirds:description "IRI: required"@en , "The resource of a topic is a
> file in the iiRDS package."@en .
> >>
> >> iirds:has-component a rdf:Property ;
> >> rdfs:comment "Relates to a component that is part of another
> component."@en , "Verweist auf eine Kompoente, die Teil einer anderen
> Komponente ist."@de ;
> >> rdfs:domain iirds:Component ;
> >> rdfs:label "has component"@en , "hat Komponente"@de ;
> >> rdfs:range iirds:Component ;
> >> rdfs:subPropertyOf iirds:iirdsRelationConcept ;
> >> iirds:description "Cardinality:
> http://iirds.tekom.de/iirds#Component[http://iirds.tekom.de/iirds#Component]
> [0..*]"@en , ""@en ;
> >> schema:domainIncludes iirds:Component ;
> >> schema:rangeIncludes iirds:Component .
> >>
> >> iirds:Component a rdfs:Class ;
> >> rdfs:comment "Describes a component of the technical system that the
> documentation refers to."@en ;
> >> rdfs:label "Component"@en , "Komponente"@de ;
> >> rdfs:subClassOf iirds:ProductMetadata ;
> >> iirds:description "IRI: required"@en , "Components may have relations
> to ot[...] The iirds#Component may also be used as a docking point for
> external component definitions."@en .
> >>
> >>
> >>
> >>
> >>
> >> My metadata.rdf converted into metadata.ttl looks like the following:
> >>
> >> metadata.ttl:
> >>
> >> @prefix pifan: <
> http://customer.docufy.de/pifan#[http://customer.docufy.de/pifan#]> .
> >> @prefix rdf: <
> http://www.w3.org/1999/02/22-rdf-syntax-ns#[http://www.w3.org/1999/02/22-rdf-syntax-ns#]>
> .
> >> @prefix iirds: <
> http://iirds.tekom.de/iirds#[http://iirds.tekom.de/iirds#]> .
> >> @prefix rdfs: <
> http://www.w3.org/2000/01/rdf-schema#[http://www.w3.org/2000/01/rdf-schema#]>
> .
> >> [...]
> >> <
> http://iirds.docufy.de/topics/05d2c8268b68ff6444a49358ca7fe925/1/de-de[http://iirds.docufy.de/topics/05d2c8268b68ff6444a49358ca7fe925/1/de-de]
> >
> >> a iirds:Topic ;
> >> iirds:dateOfCreation "2020-08-06T12:24:07.285+02:00"@de-de ;
> >> iirds:has-component <
> http://iirds.docufy.de/metadata/85e7506eb2e33f90c0a802687f559f0c[http://iirds.docufy.de/metadata/85e7506eb2e33f90c0a802687f559f0c]>
> ;
> >> iirds:relates-to-component <
> http://iirds.docufy.de/metadata/85e7506eb2e33f90c0a802687f559f0c[http://iirds.docufy.de/metadata/85e7506eb2e33f90c0a802687f559f0c]>
> ;
> >> iirds:relates-to-product-feature
> >> <
> http://iirds.docufy.de/metadata/b63e4b15b2dc2d83c0a8026877f6aa88[http://iirds.docufy.de/metadata/b63e4b15b2dc2d83c0a8026877f6aa88]>
> , <
> http://iirds.docufy.de/metadata/10b4c299b2ddae19c0a8026824aa7410[http://iirds.docufy.de/metadata/10b4c299b2ddae19c0a8026824aa7410]>
> , <
> http://iirds.docufy.de/metadata/dbbb7334b2e2a9e5c0a8026860d20c17[http://iirds.docufy.de/metadata/dbbb7334b2e2a9e5c0a8026860d20c17]>
> ;
> >> iirds:title "Kontaktdaten"@de-de .
> >> [...]
> >>
> >>
> >> My code is the following:
> >>
> >> //try with jena shacl
> >> Graph shapesGraph = RDFDataMgr.loadGraph("schema.ttl");
> >> Graph dataGraph = RDFDataMgr.loadGraph("metadata.ttl");
> >> Shapes shapes = Shapes.parse(shapesGraph);
> >> ValidationReport report = ShaclValidator.get().validate(shapes,
> dataGraph);
> >> ShLib.printReport(report);
> >> System.out.println();
> >> RDFDataMgr.write(System.out, report.getModel(), Lang.TTL);
> >>
> >> //try with topbraid shacl
> >> Model dataModel = org.topbraid.jenax.util.JenaUtil.createDefaultModel();
> >> dataModel.read("metadata.ttl");
> >> Model shapeModel =
> org.topbraid.jenax.util.JenaUtil.createDefaultModel();
> >> shapeModel.read("schema.ttl");
> >> Resource reportResource = ValidationUtil.validateModel(dataModel,
> shapeModel, true);
> >> File reportFile = new File("report.ttl");
> >>
> >>
> >>
> >>
> >>
> >>
>
>

-- 

*Thomas Francart* -* SPARNA*
Web de *données* | Architecture de l'*information* | Accès aux
*connaissances*
blog : blog.sparna.fr, site : sparna.fr, linkedin :
fr.linkedin.com/in/thomasfrancart
tel :  +33 (0)6.71.11.25.97, skype : francartthomas

Re: Aw: Re: SHACL validation doesn't show an error

Posted by Lorenz Buehmann <bu...@informatik.uni-leipzig.de>.
I suggested to use SHACL but I thought it's clear that you need to
create the corresponding SHACL shapes then - I should be more specific
in the future.

Regarding your question, no this still won't work. Maybe you didn't
understand the issue at all, but in OWL you have two things to keep in
mind:

a) Open World Assumption (OWA)
b) no Unique Names Assumption (UNA)

the UNA basically means that having entities with different URIs does
not guarantee that those entities are distinct. With owl:AllDifferent
you basically avoid this.

But ... this does not solve the OWA behavior. Especially with standard
reasoning, like rule-based or something like tableau algorithm for full
OWL DL, you won't get any "violations".

What you need is either something to close the world or you use some
constraint validation mechanism. In Jena you have out-of-the-box SHACL
support. There are also other constraint languages like SHeX, Pellet ICV
(now commercial part of Stardog only), etc.

For OWL there are indeed some approaches to convert (parts of) the
schema to SHACL shapes, e.g.
https://www.topquadrant.com/from-owl-to-shacl-in-an-automated-way/

So my suggestion, write the SHACL shapes or rethink your infrastructure
if you don't want to stick to Jena + SHACL


On 02.11.20 03:49, alexander.fandre@web.de wrote:
> Thanks for your answer :) Is there a way to validate the two files ( data.rdf and schema.rdf ) as .rdf? So without changing the schema... ? I tried with the jena reasoner and with adding ALLDifferent to deny the open world assumption, but that doesnt help.... ? 
>  
> Alex
>  
>  
>  
>
> Gesendet: Sonntag, 01. November 2020 um 12:13 Uhr
> Von: "Andy Seaborne" <an...@apache.org>
> An: users@jena.apache.org
> Betreff: Re: SHACL validation doesn't show an error
> SHACL uses shapes - not RDFS range and domain
>
> "rdfs:range iirds:Component ;" means the range
> "is of that class" not that there must be that triple because RDFS can
> be used to infer the fact and add it to the data.
>
> See the SHACL spec : https://www.w3.org/TR/shacl/
> which has lots of examples of shapes.
>
> In this case:
>
> In schema.ttl:
>
> ------------
> PREFIX iirds: <http://iirds.tekom.de/iirds#[http://iirds.tekom.de/iirds#]>
> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#[http://www.w3.org/1999/02/22-rdf-syntax-ns#]>
> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#[http://www.w3.org/2000/01/rdf-schema#]>
> PREFIX sh: <http://www.w3.org/ns/shacl#[http://www.w3.org/ns/shacl#]>
> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#[http://www.w3.org/2001/XMLSchema#]>
> PREFIX : <http://example/>
>
> :shape1 sh:targetObjectsOf iirds:has-component ;
> sh:class iirds:Component ;
> .
> ------------
>
> and you'll get a violation
>
> Add the expected triple to metadata.ttl:
> ----
> <http://iirds.docufy.de/topics/05d2c8268b68ff6444a49358ca7fe925/1/de-de[http://iirds.docufy.de/topics/05d2c8268b68ff6444a49358ca7fe925/1/de-de]>
> rdf:type iirds:Component .
> ----
>
> and the violation goes away.
>
> From the commandline (shell scripts):
>
> Jena SHACL engine:
>
> shacl v -s schema.ttl -d metadata.ttl
>
> or see the instructions on https://github.com/TopQuadrant/shacl[https://github.com/TopQuadrant/shacl] for
> TopQuadrant TopBraid SHACL API
>
> shaclvalidate -shapesfile schema.ttl -datafile metadata.ttl
>
> Andy
>
> On 01/11/2020 02:11, alexander.fandre@web.de wrote:
>> Hey guys,
>> i created an Issue one weeg ago and you recommended me to validate my schema with jena shacl. I did this, but i still don't get the expected result...
>> What do i have to change or what mistake did i do ? (i am not allowed to change the schema by the way).
>> Maybe you have some example code or another idea how to validate my metadata.rdf ?
>>
>> The problem:
>> As you can see, i have a "topic" containing the property "has-component", but my schema just allows (rdfs:domain and rdfs:range) a "component" with the property "has-component".
>> The validation report says in both ways, that everything is confirm......
>>
>> Thanks for you help:)
>> Greetings from Germany
>> Alex
>>
>>
>>
>> My schema is original an .rdf-schema, but i converted it into .ttl in order to use shacl-shapes. It looks like the following:
>>
>> schema.ttl:
>>
>> @prefix schema: <http://schema.org/[http://schema.org/]> .
>> @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#[http://www.w3.org/1999/02/22-rdf-syntax-ns#]> .
>> @prefix iirds: <http://iirds.tekom.de/iirds#[http://iirds.tekom.de/iirds#]> .
>> @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#[http://www.w3.org/2000/01/rdf-schema#]> .
>> iirds:Topic a rdfs:Class ;
>> rdfs:comment "A topic is a unit of information covering a single subject."@en ;
>> rdfs:label "Topic"@en , "Topic"@de ;
>> rdfs:subClassOf iirds:InformationUnit ;
>> iirds:description "IRI: required"@en , "The resource of a topic is a file in the iiRDS package."@en .
>>
>> iirds:has-component a rdf:Property ;
>> rdfs:comment "Relates to a component that is part of another component."@en , "Verweist auf eine Kompoente, die Teil einer anderen Komponente ist."@de ;
>> rdfs:domain iirds:Component ;
>> rdfs:label "has component"@en , "hat Komponente"@de ;
>> rdfs:range iirds:Component ;
>> rdfs:subPropertyOf iirds:iirdsRelationConcept ;
>> iirds:description "Cardinality: http://iirds.tekom.de/iirds#Component[http://iirds.tekom.de/iirds#Component] [0..*]"@en , ""@en ;
>> schema:domainIncludes iirds:Component ;
>> schema:rangeIncludes iirds:Component .
>>
>> iirds:Component a rdfs:Class ;
>> rdfs:comment "Describes a component of the technical system that the documentation refers to."@en ;
>> rdfs:label "Component"@en , "Komponente"@de ;
>> rdfs:subClassOf iirds:ProductMetadata ;
>> iirds:description "IRI: required"@en , "Components may have relations to ot[...] The iirds#Component may also be used as a docking point for external component definitions."@en .
>>
>>
>>
>>
>>
>> My metadata.rdf converted into metadata.ttl looks like the following:
>>
>> metadata.ttl:
>>
>> @prefix pifan: <http://customer.docufy.de/pifan#[http://customer.docufy.de/pifan#]> .
>> @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#[http://www.w3.org/1999/02/22-rdf-syntax-ns#]> .
>> @prefix iirds: <http://iirds.tekom.de/iirds#[http://iirds.tekom.de/iirds#]> .
>> @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#[http://www.w3.org/2000/01/rdf-schema#]> .
>> [...]
>> <http://iirds.docufy.de/topics/05d2c8268b68ff6444a49358ca7fe925/1/de-de[http://iirds.docufy.de/topics/05d2c8268b68ff6444a49358ca7fe925/1/de-de]>
>> a iirds:Topic ;
>> iirds:dateOfCreation "2020-08-06T12:24:07.285+02:00"@de-de ;
>> iirds:has-component <http://iirds.docufy.de/metadata/85e7506eb2e33f90c0a802687f559f0c[http://iirds.docufy.de/metadata/85e7506eb2e33f90c0a802687f559f0c]> ;
>> iirds:relates-to-component <http://iirds.docufy.de/metadata/85e7506eb2e33f90c0a802687f559f0c[http://iirds.docufy.de/metadata/85e7506eb2e33f90c0a802687f559f0c]> ;
>> iirds:relates-to-product-feature
>> <http://iirds.docufy.de/metadata/b63e4b15b2dc2d83c0a8026877f6aa88[http://iirds.docufy.de/metadata/b63e4b15b2dc2d83c0a8026877f6aa88]> , <http://iirds.docufy.de/metadata/10b4c299b2ddae19c0a8026824aa7410[http://iirds.docufy.de/metadata/10b4c299b2ddae19c0a8026824aa7410]> , <http://iirds.docufy.de/metadata/dbbb7334b2e2a9e5c0a8026860d20c17[http://iirds.docufy.de/metadata/dbbb7334b2e2a9e5c0a8026860d20c17]> ;
>> iirds:title "Kontaktdaten"@de-de .
>> [...]
>>
>>
>> My code is the following:
>>
>> //try with jena shacl
>> Graph shapesGraph = RDFDataMgr.loadGraph("schema.ttl");
>> Graph dataGraph = RDFDataMgr.loadGraph("metadata.ttl");
>> Shapes shapes = Shapes.parse(shapesGraph);
>> ValidationReport report = ShaclValidator.get().validate(shapes, dataGraph);
>> ShLib.printReport(report);
>> System.out.println();
>> RDFDataMgr.write(System.out, report.getModel(), Lang.TTL);
>>
>> //try with topbraid shacl
>> Model dataModel = org.topbraid.jenax.util.JenaUtil.createDefaultModel();
>> dataModel.read("metadata.ttl");
>> Model shapeModel = org.topbraid.jenax.util.JenaUtil.createDefaultModel();
>> shapeModel.read("schema.ttl");
>> Resource reportResource = ValidationUtil.validateModel(dataModel, shapeModel, true);
>> File reportFile = new File("report.ttl");
>>
>>
>>
>>
>>
>>


Aw: Re: SHACL validation doesn't show an error

Posted by al...@web.de.
Thanks for your answer :) Is there a way to validate the two files ( data.rdf and schema.rdf ) as .rdf? So without changing the schema... ? I tried with the jena reasoner and with adding ALLDifferent to deny the open world assumption, but that doesnt help.... ? 
 
Alex
 
 
 

Gesendet: Sonntag, 01. November 2020 um 12:13 Uhr
Von: "Andy Seaborne" <an...@apache.org>
An: users@jena.apache.org
Betreff: Re: SHACL validation doesn't show an error
SHACL uses shapes - not RDFS range and domain

"rdfs:range iirds:Component ;" means the range
"is of that class" not that there must be that triple because RDFS can
be used to infer the fact and add it to the data.

See the SHACL spec : https://www.w3.org/TR/shacl/
which has lots of examples of shapes.

In this case:

In schema.ttl:

------------
PREFIX iirds: <http://iirds.tekom.de/iirds#[http://iirds.tekom.de/iirds#]>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#[http://www.w3.org/1999/02/22-rdf-syntax-ns#]>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#[http://www.w3.org/2000/01/rdf-schema#]>
PREFIX sh: <http://www.w3.org/ns/shacl#[http://www.w3.org/ns/shacl#]>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#[http://www.w3.org/2001/XMLSchema#]>
PREFIX : <http://example/>

:shape1 sh:targetObjectsOf iirds:has-component ;
sh:class iirds:Component ;
.
------------

and you'll get a violation

Add the expected triple to metadata.ttl:
----
<http://iirds.docufy.de/topics/05d2c8268b68ff6444a49358ca7fe925/1/de-de[http://iirds.docufy.de/topics/05d2c8268b68ff6444a49358ca7fe925/1/de-de]>
rdf:type iirds:Component .
----

and the violation goes away.

From the commandline (shell scripts):

Jena SHACL engine:

shacl v -s schema.ttl -d metadata.ttl

or see the instructions on https://github.com/TopQuadrant/shacl[https://github.com/TopQuadrant/shacl] for
TopQuadrant TopBraid SHACL API

shaclvalidate -shapesfile schema.ttl -datafile metadata.ttl

Andy

On 01/11/2020 02:11, alexander.fandre@web.de wrote:
> Hey guys,
> i created an Issue one weeg ago and you recommended me to validate my schema with jena shacl. I did this, but i still don't get the expected result...
> What do i have to change or what mistake did i do ? (i am not allowed to change the schema by the way).
> Maybe you have some example code or another idea how to validate my metadata.rdf ?
>
> The problem:
> As you can see, i have a "topic" containing the property "has-component", but my schema just allows (rdfs:domain and rdfs:range) a "component" with the property "has-component".
> The validation report says in both ways, that everything is confirm......
>
> Thanks for you help:)
> Greetings from Germany
> Alex
>
>
>
> My schema is original an .rdf-schema, but i converted it into .ttl in order to use shacl-shapes. It looks like the following:
>
> schema.ttl:
>
> @prefix schema: <http://schema.org/[http://schema.org/]> .
> @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#[http://www.w3.org/1999/02/22-rdf-syntax-ns#]> .
> @prefix iirds: <http://iirds.tekom.de/iirds#[http://iirds.tekom.de/iirds#]> .
> @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#[http://www.w3.org/2000/01/rdf-schema#]> .
> iirds:Topic a rdfs:Class ;
> rdfs:comment "A topic is a unit of information covering a single subject."@en ;
> rdfs:label "Topic"@en , "Topic"@de ;
> rdfs:subClassOf iirds:InformationUnit ;
> iirds:description "IRI: required"@en , "The resource of a topic is a file in the iiRDS package."@en .
>
> iirds:has-component a rdf:Property ;
> rdfs:comment "Relates to a component that is part of another component."@en , "Verweist auf eine Kompoente, die Teil einer anderen Komponente ist."@de ;
> rdfs:domain iirds:Component ;
> rdfs:label "has component"@en , "hat Komponente"@de ;
> rdfs:range iirds:Component ;
> rdfs:subPropertyOf iirds:iirdsRelationConcept ;
> iirds:description "Cardinality: http://iirds.tekom.de/iirds#Component[http://iirds.tekom.de/iirds#Component] [0..*]"@en , ""@en ;
> schema:domainIncludes iirds:Component ;
> schema:rangeIncludes iirds:Component .
>
> iirds:Component a rdfs:Class ;
> rdfs:comment "Describes a component of the technical system that the documentation refers to."@en ;
> rdfs:label "Component"@en , "Komponente"@de ;
> rdfs:subClassOf iirds:ProductMetadata ;
> iirds:description "IRI: required"@en , "Components may have relations to ot[...] The iirds#Component may also be used as a docking point for external component definitions."@en .
>
>
>
>
>
> My metadata.rdf converted into metadata.ttl looks like the following:
>
> metadata.ttl:
>
> @prefix pifan: <http://customer.docufy.de/pifan#[http://customer.docufy.de/pifan#]> .
> @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#[http://www.w3.org/1999/02/22-rdf-syntax-ns#]> .
> @prefix iirds: <http://iirds.tekom.de/iirds#[http://iirds.tekom.de/iirds#]> .
> @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#[http://www.w3.org/2000/01/rdf-schema#]> .
> [...]
> <http://iirds.docufy.de/topics/05d2c8268b68ff6444a49358ca7fe925/1/de-de[http://iirds.docufy.de/topics/05d2c8268b68ff6444a49358ca7fe925/1/de-de]>
> a iirds:Topic ;
> iirds:dateOfCreation "2020-08-06T12:24:07.285+02:00"@de-de ;
> iirds:has-component <http://iirds.docufy.de/metadata/85e7506eb2e33f90c0a802687f559f0c[http://iirds.docufy.de/metadata/85e7506eb2e33f90c0a802687f559f0c]> ;
> iirds:relates-to-component <http://iirds.docufy.de/metadata/85e7506eb2e33f90c0a802687f559f0c[http://iirds.docufy.de/metadata/85e7506eb2e33f90c0a802687f559f0c]> ;
> iirds:relates-to-product-feature
> <http://iirds.docufy.de/metadata/b63e4b15b2dc2d83c0a8026877f6aa88[http://iirds.docufy.de/metadata/b63e4b15b2dc2d83c0a8026877f6aa88]> , <http://iirds.docufy.de/metadata/10b4c299b2ddae19c0a8026824aa7410[http://iirds.docufy.de/metadata/10b4c299b2ddae19c0a8026824aa7410]> , <http://iirds.docufy.de/metadata/dbbb7334b2e2a9e5c0a8026860d20c17[http://iirds.docufy.de/metadata/dbbb7334b2e2a9e5c0a8026860d20c17]> ;
> iirds:title "Kontaktdaten"@de-de .
> [...]
>
>
> My code is the following:
>
> //try with jena shacl
> Graph shapesGraph = RDFDataMgr.loadGraph("schema.ttl");
> Graph dataGraph = RDFDataMgr.loadGraph("metadata.ttl");
> Shapes shapes = Shapes.parse(shapesGraph);
> ValidationReport report = ShaclValidator.get().validate(shapes, dataGraph);
> ShLib.printReport(report);
> System.out.println();
> RDFDataMgr.write(System.out, report.getModel(), Lang.TTL);
>
> //try with topbraid shacl
> Model dataModel = org.topbraid.jenax.util.JenaUtil.createDefaultModel();
> dataModel.read("metadata.ttl");
> Model shapeModel = org.topbraid.jenax.util.JenaUtil.createDefaultModel();
> shapeModel.read("schema.ttl");
> Resource reportResource = ValidationUtil.validateModel(dataModel, shapeModel, true);
> File reportFile = new File("report.ttl");
>
>
>
>
>
>

Re: SHACL validation doesn't show an error

Posted by Andy Seaborne <an...@apache.org>.
SHACL uses shapes - not RDFS range and domain

"rdfs:range iirds:Component ;" means the range
"is of that class" not that there must be that triple because RDFS can 
be used to infer the fact and add it to the data.

See the SHACL spec : https://www.w3.org/TR/shacl/
which has lots of examples of shapes.

In this case:

In schema.ttl:

------------
PREFIX iirds: <http://iirds.tekom.de/iirds#>
PREFIX rdf:     <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs:    <http://www.w3.org/2000/01/rdf-schema#>
PREFIX sh:      <http://www.w3.org/ns/shacl#>
PREFIX xsd:     <http://www.w3.org/2001/XMLSchema#>
PREFIX :        <http://example/>

:shape1 sh:targetObjectsOf iirds:has-component ;
     sh:class  iirds:Component ;
     .
------------

and you'll get a violation

Add the expected triple to metadata.ttl:
----
<http://iirds.docufy.de/topics/05d2c8268b68ff6444a49358ca7fe925/1/de-de>
     rdf:type  iirds:Component .
----

and the violation goes away.

 From the commandline (shell scripts):

Jena SHACL engine:

  shacl v -s schema.ttl -d metadata.ttl

or see the instructions on https://github.com/TopQuadrant/shacl for 
TopQuadrant TopBraid SHACL API

shaclvalidate  -shapesfile schema.ttl -datafile metadata.ttl

     Andy

On 01/11/2020 02:11, alexander.fandre@web.de wrote:
> Hey guys,
> i created an Issue one weeg ago and you recommended me to validate my schema with jena shacl. I did this, but i still don't get the expected result...
> What do i have to change or what mistake did i do ? (i am not allowed to change the schema by the way).
> Maybe you have some example code or another idea how to validate my metadata.rdf ?
> 
> The problem:
> As you can see, i have a "topic" containing the property "has-component", but my schema just allows (rdfs:domain and rdfs:range) a "component" with the property "has-component".
> The validation report says in both ways, that everything is confirm......
> 
> Thanks for you help:)
> Greetings from Germany
> Alex
> 
> 
> 
> My schema is original an .rdf-schema, but i converted it into .ttl in order to use shacl-shapes. It looks like the following:
> 
> schema.ttl:
> 
> @prefix schema: <http://schema.org/> .
> @prefix rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
> @prefix iirds: <http://iirds.tekom.de/iirds#> .
> @prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#> .
> iirds:Topic  a             rdfs:Class ;
>          rdfs:comment       "A topic is a unit of information covering a single subject."@en ;
>          rdfs:label         "Topic"@en , "Topic"@de ;
>          rdfs:subClassOf    iirds:InformationUnit ;
>          iirds:description  "IRI: required"@en , "The resource of a topic is a file in the iiRDS package."@en .
> 
> iirds:has-component  a         rdf:Property ;
>          rdfs:comment           "Relates to a component that is part of another component."@en , "Verweist auf eine Kompoente, die Teil einer anderen Komponente ist."@de ;
>          rdfs:domain            iirds:Component ;
>          rdfs:label             "has component"@en , "hat Komponente"@de ;
>          rdfs:range             iirds:Component ;
>          rdfs:subPropertyOf     iirds:iirdsRelationConcept ;
>          iirds:description      "Cardinality: http://iirds.tekom.de/iirds#Component [0..*]"@en , ""@en ;
>          schema:domainIncludes  iirds:Component ;
>          schema:rangeIncludes   iirds:Component .
> 
> iirds:Component  a         rdfs:Class ;
>          rdfs:comment       "Describes a component of the technical system that the documentation refers to."@en ;
>          rdfs:label         "Component"@en , "Komponente"@de ;
>          rdfs:subClassOf    iirds:ProductMetadata ;
>          iirds:description  "IRI: required"@en , "Components may have relations to ot[...] The iirds#Component may also be used as a docking point for external component definitions."@en .
> 
> 
> 
> 
> 
> My metadata.rdf converted into metadata.ttl looks like the following:
> 
> metadata.ttl:
> 
> @prefix pifan: <http://customer.docufy.de/pifan#> .
> @prefix rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
> @prefix iirds: <http://iirds.tekom.de/iirds#> .
> @prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#> .
> [...]
> <http://iirds.docufy.de/topics/05d2c8268b68ff6444a49358ca7fe925/1/de-de>
>          a                           iirds:Topic ;
>          iirds:dateOfCreation        "2020-08-06T12:24:07.285+02:00"@de-de ;
>          iirds:has-component         <http://iirds.docufy.de/metadata/85e7506eb2e33f90c0a802687f559f0c> ;
>          iirds:relates-to-component  <http://iirds.docufy.de/metadata/85e7506eb2e33f90c0a802687f559f0c> ;
>          iirds:relates-to-product-feature
>                  <http://iirds.docufy.de/metadata/b63e4b15b2dc2d83c0a8026877f6aa88> , <http://iirds.docufy.de/metadata/10b4c299b2ddae19c0a8026824aa7410> , <http://iirds.docufy.de/metadata/dbbb7334b2e2a9e5c0a8026860d20c17> ;
>          iirds:title                 "Kontaktdaten"@de-de .
> [...]
> 
> 
> My code is the following:
> 
> //try with jena shacl
> Graph shapesGraph = RDFDataMgr.loadGraph("schema.ttl");
> Graph dataGraph = RDFDataMgr.loadGraph("metadata.ttl");	
> Shapes shapes = Shapes.parse(shapesGraph);	
> ValidationReport report = ShaclValidator.get().validate(shapes, dataGraph);
> ShLib.printReport(report);
> System.out.println();
> RDFDataMgr.write(System.out, report.getModel(), Lang.TTL);
> 
> //try with topbraid shacl
> Model dataModel = org.topbraid.jenax.util.JenaUtil.createDefaultModel();
> dataModel.read("metadata.ttl");
> Model shapeModel = org.topbraid.jenax.util.JenaUtil.createDefaultModel();
> shapeModel.read("schema.ttl");	
> Resource reportResource = ValidationUtil.validateModel(dataModel, shapeModel, true);
> File reportFile = new File("report.ttl");
> 
> 
> 
> 
> 
>