You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Kyle Lawlor-Bagcal <ky...@regen.network.INVALID> on 2022/09/08 21:11:22 UTC

Is it possible to get more info out of the shacl validation messages?

Hello,

I've got the following scenario. Upon running the shacl CLI tool, I'm 
seeing this as output:

[ rdf:type     sh:ValidationReport ;
   sh:conforms  false ;
   sh:result    [ rdf:type                      sh:ValidationResult ;
                  sh:focusNode                  _:b0 ;
                  sh:resultMessage 
"Node[<http://regen.network/ProjectBaseFieldsShape>] at focusNode 
_:Bfdf188221d60ec452edfe2e7c7c855b1" ;
                  sh:resultSeverity             sh:Violation ;
                  sh:sourceConstraintComponent sh:NodeConstraintComponent ;
                  sh:sourceShape regen:C02-ProjectShape ;
                  sh:value                      _:b0
                ]
] .

Where the relevant pieces of the shacl graph are:

@prefix schema: <http://schema.org/> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix regen: <http://regen.network/> .
@prefix qudt: <http://qudt.org/schema/qudt/> .
@prefix unit: <http://qudt.org/vocab/unit/> .
@prefix geojson: <https://purl.org/geojson/vocab#> .
@prefix dash: <http://datashapes.org/dash#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .

regen:C02-ProjectShape a sh:NodeShape ;
   sh:targetClass regen:C02-Project ;
   sh:node regen:ProjectBaseFieldsShape ;
.

regen:ProjectTypeFieldShape a sh:NodeShape ;
   sh:property [
     sh:path regen:projectType ;
     sh:minCount 1 ;
     sh:maxCount 1 ;
     sh:minLength 1 ;
     sh:datatype xsd:string ;
     sh:group regen:ProjectPageMetadataGroup ;
   ] ;
.

regen:ProjectBaseFieldsShape a sh:NodeShape ;
   sh:node regen:NameFieldShape ;
   sh:node regen:DescriptionFieldShape ;
   sh:node regen:LocationFieldShape ;
   sh:node regen:ProjectSizeFieldShape ;
   sh:node regen:ProjectActivityFieldShape ;
   sh:node regen:ProjectStartDateFieldShape ;
   sh:node regen:ProjectEndDateFieldShape ;
   sh:node regen:ProjectTypeFieldShape ;
.

And the relevant pieces of the data graph (json-ld) under validation are:

{
   "@context": {
     "schema": "http://schema.org/",
     "regen": "http://regen.network/",
     "qudt": "http://qudt.org/schema/qudt/",
     "unit": "http://qudt.org/vocab/unit/",
     "xsd": "http://www.w3.org/2001/XMLSchema#",
   },
   "@type": "regen:C02-Project",
   "regen:projectType": ""
}

So the failure is clearly due to the "sh:minLength" constraint. But in 
the validation error report, that's not so clear. Is there a way to have 
the fact that the "sh:minLength" constraint was violated here?

Thank you,

Kyle


Re: Is it possible to get more info out of the shacl validation messages?

Posted by Florian Kleedorfer <fl...@austria.fm>.
You can use the ValidationListener to get more detailed information, as described here: https://jena.apache.org/documentation/shacl/index.html

...if executing the SHACL validation in a Java program is an option for you.

Best,
Florian 

Am 9. September 2022 07:59:33 MESZ schrieb "Bögershausen, Merlin" <me...@rwth-aachen.de>:
>Hi Kyle,
>sh:message worked for use in a similar situation.
>https://www.w3.org/TR/shacl/#message
>
>Best Merlin
>________________________________
>Von: Kyle Lawlor-Bagcal <ky...@regen.network.INVALID>
>Gesendet: Thursday, September 8, 2022 11:11:22 PM
>An: users@jena.apache.org <us...@jena.apache.org>
>Betreff: Is it possible to get more info out of the shacl validation messages?
>
>Hello,
>
>I've got the following scenario. Upon running the shacl CLI tool, I'm
>seeing this as output:
>
>[ rdf:type     sh:ValidationReport ;
>   sh:conforms  false ;
>   sh:result    [ rdf:type                      sh:ValidationResult ;
>                  sh:focusNode                  _:b0 ;
>                  sh:resultMessage
>"Node[<http://regen.network/ProjectBaseFieldsShape>] at focusNode
>_:Bfdf188221d60ec452edfe2e7c7c855b1" ;
>                  sh:resultSeverity             sh:Violation ;
>                  sh:sourceConstraintComponent sh:NodeConstraintComponent ;
>                  sh:sourceShape regen:C02-ProjectShape ;
>                  sh:value                      _:b0
>                ]
>] .
>
>Where the relevant pieces of the shacl graph are:
>
>@prefix schema: <http://schema.org/> .
>@prefix sh: <http://www.w3.org/ns/shacl#> .
>@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
>@prefix regen: <http://regen.network/> .
>@prefix qudt: <http://qudt.org/schema/qudt/> .
>@prefix unit: <http://qudt.org/vocab/unit/> .
>@prefix geojson: <https://purl.org/geojson/vocab#> .
>@prefix dash: <http://datashapes.org/dash#> .
>@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
>@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
>
>regen:C02-ProjectShape a sh:NodeShape ;
>   sh:targetClass regen:C02-Project ;
>   sh:node regen:ProjectBaseFieldsShape ;
>.
>
>regen:ProjectTypeFieldShape a sh:NodeShape ;
>   sh:property [
>     sh:path regen:projectType ;
>     sh:minCount 1 ;
>     sh:maxCount 1 ;
>     sh:minLength 1 ;
>     sh:datatype xsd:string ;
>     sh:group regen:ProjectPageMetadataGroup ;
>   ] ;
>.
>
>regen:ProjectBaseFieldsShape a sh:NodeShape ;
>   sh:node regen:NameFieldShape ;
>   sh:node regen:DescriptionFieldShape ;
>   sh:node regen:LocationFieldShape ;
>   sh:node regen:ProjectSizeFieldShape ;
>   sh:node regen:ProjectActivityFieldShape ;
>   sh:node regen:ProjectStartDateFieldShape ;
>   sh:node regen:ProjectEndDateFieldShape ;
>   sh:node regen:ProjectTypeFieldShape ;
>.
>
>And the relevant pieces of the data graph (json-ld) under validation are:
>
>{
>   "@context": {
>     "schema": "http://schema.org/",
>     "regen": "http://regen.network/",
>     "qudt": "http://qudt.org/schema/qudt/",
>     "unit": "http://qudt.org/vocab/unit/",
>     "xsd": "http://www.w3.org/2001/XMLSchema#",
>   },
>   "@type": "regen:C02-Project",
>   "regen:projectType": ""
>}
>
>So the failure is clearly due to the "sh:minLength" constraint. But in
>the validation error report, that's not so clear. Is there a way to have
>the fact that the "sh:minLength" constraint was violated here?
>
>Thank you,
>
>Kyle
>

-- 
Diese Nachricht wurde von meinem Android-Gerät mit K-9 Mail gesendet.

Re: Is it possible to get more info out of the shacl validation messages?

Posted by "Bögershausen, Merlin" <me...@rwth-aachen.de>.
Hi Kyle,
sh:message worked for use in a similar situation.
https://www.w3.org/TR/shacl/#message

Best Merlin
________________________________
Von: Kyle Lawlor-Bagcal <ky...@regen.network.INVALID>
Gesendet: Thursday, September 8, 2022 11:11:22 PM
An: users@jena.apache.org <us...@jena.apache.org>
Betreff: Is it possible to get more info out of the shacl validation messages?

Hello,

I've got the following scenario. Upon running the shacl CLI tool, I'm
seeing this as output:

[ rdf:type     sh:ValidationReport ;
   sh:conforms  false ;
   sh:result    [ rdf:type                      sh:ValidationResult ;
                  sh:focusNode                  _:b0 ;
                  sh:resultMessage
"Node[<http://regen.network/ProjectBaseFieldsShape>] at focusNode
_:Bfdf188221d60ec452edfe2e7c7c855b1" ;
                  sh:resultSeverity             sh:Violation ;
                  sh:sourceConstraintComponent sh:NodeConstraintComponent ;
                  sh:sourceShape regen:C02-ProjectShape ;
                  sh:value                      _:b0
                ]
] .

Where the relevant pieces of the shacl graph are:

@prefix schema: <http://schema.org/> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix regen: <http://regen.network/> .
@prefix qudt: <http://qudt.org/schema/qudt/> .
@prefix unit: <http://qudt.org/vocab/unit/> .
@prefix geojson: <https://purl.org/geojson/vocab#> .
@prefix dash: <http://datashapes.org/dash#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .

regen:C02-ProjectShape a sh:NodeShape ;
   sh:targetClass regen:C02-Project ;
   sh:node regen:ProjectBaseFieldsShape ;
.

regen:ProjectTypeFieldShape a sh:NodeShape ;
   sh:property [
     sh:path regen:projectType ;
     sh:minCount 1 ;
     sh:maxCount 1 ;
     sh:minLength 1 ;
     sh:datatype xsd:string ;
     sh:group regen:ProjectPageMetadataGroup ;
   ] ;
.

regen:ProjectBaseFieldsShape a sh:NodeShape ;
   sh:node regen:NameFieldShape ;
   sh:node regen:DescriptionFieldShape ;
   sh:node regen:LocationFieldShape ;
   sh:node regen:ProjectSizeFieldShape ;
   sh:node regen:ProjectActivityFieldShape ;
   sh:node regen:ProjectStartDateFieldShape ;
   sh:node regen:ProjectEndDateFieldShape ;
   sh:node regen:ProjectTypeFieldShape ;
.

And the relevant pieces of the data graph (json-ld) under validation are:

{
   "@context": {
     "schema": "http://schema.org/",
     "regen": "http://regen.network/",
     "qudt": "http://qudt.org/schema/qudt/",
     "unit": "http://qudt.org/vocab/unit/",
     "xsd": "http://www.w3.org/2001/XMLSchema#",
   },
   "@type": "regen:C02-Project",
   "regen:projectType": ""
}

So the failure is clearly due to the "sh:minLength" constraint. But in
the validation error report, that's not so clear. Is there a way to have
the fact that the "sh:minLength" constraint was violated here?

Thank you,

Kyle


Re: Is it possible to get more info out of the shacl validation messages?

Posted by Kyle Lawlor-Bagcal <ky...@regen.network.INVALID>.
Thanks to all for your replies, I very much appreciate it.

> You could write and be able to reuse share if written as a property 
> shape referred to directly:
>
> """
> regen:C02-ProjectShapeX a sh:NodeShape ;
>   sh:targetClass regen:C02-Project ;
>   sh:property regen:ProjectTypePropertyShape
> .
>
> # Property shapes can have URIs!
> regen:ProjectTypePropertyShape
>     # rdf:type not necessary
>     rdf:type a sh:PropertyShape ;
>     sh:path regen:projectType ;
>     sh:minCount 1 ;
>     sh:maxCount 1 ;
>     sh:minLength 1 ;
>     sh:datatype xsd:string ;
>     sh:group regen:ProjectPageMetadataGroup ;
> .
> """
>
> will give
>
> "MinLengthConstraint[1]: String too short: "
>
> If written this way, all the violations of 
> regen:ProjectTypePropertyShape will generate messages so you can get 
> one for minLength and one for maxCount, say, if they both fail.

This set me down a path that is working quite well for me. I did have to 
make some adjustments, but I'm quite happy with where I ended up.

Indeed, having property shapes with URI's is also a nicety that I think 
is a benefit for our schema as well. Thanks for pointing that out. This 
info adds some (https://book.validatingrdf.com/bookHtml011.html#sec125).

For posterity, I've end up with this as my schema (a little simplified):

> @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
> @prefix regen: <http://regen.network/> .
> @prefix qudt: <http://qudt.org/schema/qudt/> .
> @prefix unit: <http://qudt.org/vocab/unit/> .
> @prefix geojson: <https://purl.org/geojson/vocab#> .
> @prefix dash: <http://datashapes.org/dash#> .
> @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
> @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
>
> regen:C02-ProjectShape a sh:NodeShape ;
>   sh:targetClass regen:C02-Project ;
>   sh:property regen:NamePropertyShape ;
>   sh:property regen:DescriptionPropertyShape ;
> .
>
> regen:NamePropertyShape sh:path schema:name ;
>   sh:minCount 1 ;
>   sh:maxCount 1 ;
>   sh:minLength 1 ;
>   sh:datatype xsd:string ;
>   sh:group regen:ProjectPageBasicInfoGroup ;
> .
>
> regen:DescriptionPropertyShape sh:path schema:description ;
>   sh:maxLength 1400 ;
>   sh:datatype xsd:string ;
>   sh:group regen:ProjectPageDescriptionGroup ;
> . 

This satisfies my needs nicely by providing a way to dedupe particular 
fields.


Re: Is it possible to get more info out of the shacl validation messages?

Posted by Andy Seaborne <an...@apache.org>.
 > So the failure is clearly due to the "sh:minLength" constraint.

Not so clear :-)

The message is coming from the sh:node because that is the validating 
constraint.

sh:node can refer to a large and complex collection of constraints.

A sh:node generates a violation only once even for multiple violations 
of the referred to shape happen.

You could write and be able to reuse share if written as a property 
shape referred to directly:

"""
regen:C02-ProjectShapeX a sh:NodeShape ;
   sh:targetClass regen:C02-Project ;
   sh:property regen:ProjectTypePropertyShape
.

# Property shapes can have URIs!
regen:ProjectTypePropertyShape
     # rdf:type not necessary
     rdf:type a sh:PropertyShape ;
     sh:path regen:projectType ;
     sh:minCount 1 ;
     sh:maxCount 1 ;
     sh:minLength 1 ;
     sh:datatype xsd:string ;
     sh:group regen:ProjectPageMetadataGroup ;
.
"""

will give

"MinLengthConstraint[1]: String too short: "

If written this way, all the violations of 
regen:ProjectTypePropertyShape will generate messages so you can get one 
for minLength and one for maxCount, say, if they both fail.

     Andy

On 08/09/2022 22:11, Kyle Lawlor-Bagcal wrote:
> Hello,
> 
> I've got the following scenario. Upon running the shacl CLI tool, I'm 
> seeing this as output:
> 
> [ rdf:type     sh:ValidationReport ;
>    sh:conforms  false ;
>    sh:result    [ rdf:type                      sh:ValidationResult ;
>                   sh:focusNode                  _:b0 ;
>                   sh:resultMessage 
> "Node[<http://regen.network/ProjectBaseFieldsShape>] at focusNode 
> _:Bfdf188221d60ec452edfe2e7c7c855b1" ;
>                   sh:resultSeverity             sh:Violation ;
>                   sh:sourceConstraintComponent sh:NodeConstraintComponent ;
>                   sh:sourceShape regen:C02-ProjectShape ;
>                   sh:value                      _:b0
>                 ]
> ] .
> 
> Where the relevant pieces of the shacl graph are:
> 
> @prefix schema: <http://schema.org/> .
> @prefix sh: <http://www.w3.org/ns/shacl#> .
> @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
> @prefix regen: <http://regen.network/> .
> @prefix qudt: <http://qudt.org/schema/qudt/> .
> @prefix unit: <http://qudt.org/vocab/unit/> .
> @prefix geojson: <https://purl.org/geojson/vocab#> .
> @prefix dash: <http://datashapes.org/dash#> .
> @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
> @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
> 
> regen:C02-ProjectShape a sh:NodeShape ;
>    sh:targetClass regen:C02-Project ;
>    sh:node regen:ProjectBaseFieldsShape ;
> .
> 
> regen:ProjectTypeFieldShape a sh:NodeShape ;
>    sh:property [
>      sh:path regen:projectType ;
>      sh:minCount 1 ;
>      sh:maxCount 1 ;
>      sh:minLength 1 ;
>      sh:datatype xsd:string ;
>      sh:group regen:ProjectPageMetadataGroup ;
>    ] ;
> .
> 
> regen:ProjectBaseFieldsShape a sh:NodeShape ;
>    sh:node regen:NameFieldShape ;
>    sh:node regen:DescriptionFieldShape ;
>    sh:node regen:LocationFieldShape ;
>    sh:node regen:ProjectSizeFieldShape ;
>    sh:node regen:ProjectActivityFieldShape ;
>    sh:node regen:ProjectStartDateFieldShape ;
>    sh:node regen:ProjectEndDateFieldShape ;
>    sh:node regen:ProjectTypeFieldShape ;
> .
> 
> And the relevant pieces of the data graph (json-ld) under validation are:
> 
> {
>    "@context": {
>      "schema": "http://schema.org/",
>      "regen": "http://regen.network/",
>      "qudt": "http://qudt.org/schema/qudt/",
>      "unit": "http://qudt.org/vocab/unit/",
>      "xsd": "http://www.w3.org/2001/XMLSchema#",
>    },
>    "@type": "regen:C02-Project",
>    "regen:projectType": ""
> }
> 
> So the failure is clearly due to the "sh:minLength" constraint. But in 
> the validation error report, that's not so clear. Is there a way to have 
> the fact that the "sh:minLength" constraint was violated here?
> 
> Thank you,
> 
> Kyle
>