Skip to content

Commit

Permalink
Merge pull request #199 from zazuko/error-margin-validation
Browse files Browse the repository at this point in the history
Dimension relation validations
  • Loading branch information
tpluscode authored Sep 30, 2024
2 parents d5e56b1 + 7cb9da8 commit 2a93676
Show file tree
Hide file tree
Showing 8 changed files with 319 additions and 10 deletions.
8 changes: 8 additions & 0 deletions .changeset/lucky-doors-brush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"cube-link": patch
---

Improve validation of `meta:dimensionRelation`:

1. Check that upper/lower bound has at most one `dcterms:type`
2. Check that `meta:relatesTo` is actually a dimension
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
PREFIX dcterms: <http://purl.org/dc/terms/>
@prefix relation: <https://cube.link/relation/> .
@prefix meta: <https://cube.link/meta/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix cube: <https://cube.link/> .
@prefix observation: <https://environment.ld.admin.ch/foen/nfi/observation/max_min_undefined> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix schema: <http://schema.org/> .
@base <https://example.org/> .

<cube> a cube:Cube ;
cube:observationConstraint <shape> ;
cube:observationSet <observationSet> .

<observationSet> cube:observation <observationA>, <observationB>, <observationC> .

<observationA> a cube:Observation ;
cube:observedBy <observer> ;
<dimension> 4.9 ;
<upperConfidence> 0.1 ;
.

<shape> a cube:Constraint ;
sh:targetClass cube:Observation ;
sh:closed true ;
sh:property
[
sh:path rdf:type ;
sh:nodeKind sh:IRI ;
sh:minCount 1 ;
sh:maxCount 1
] ;
sh:property
[
sh:path cube:observedBy ; ;
sh:nodeKind sh:IRI ;
sh:minCount 1 ;
sh:maxCount 1
] ;
sh:property
[
a cube:MeasureDimension ;
sh:datatype xsd:decimal ;
sh:path <dimension> ;
schema:name "dimension" ;
sh:minCount 1 ;
sh:maxCount 1 ;
],
[
sh:datatype xsd:decimal ;
sh:path <upperConfidence> ;
schema:name "upper confidence" ;
sh:minCount 1 ;
sh:maxCount 1 ;
meta:dimensionRelation
[
a relation:ConfidenceUpperBound ;
dcterms:type "Confidence interval", "bogus" ;
meta:relatesTo <dimension> ;
] ;
];
.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix schema: <http://schema.org/> .
@prefix cube: <https://cube.link/> .

_:report a sh:ValidationReport ;
sh:result [
rdf:type sh:ValidationResult ;
sh:resultSeverity sh:Violation ;
sh:sourceConstraintComponent sh:MaxCountConstraintComponent ;
sh:sourceShape [
sh:path <http://purl.org/dc/terms/type> ;
sh:maxCount 1 ;
] ;
sh:focusNode _:b5 ;
sh:resultPath <http://purl.org/dc/terms/type> ;
sh:resultMessage "More than 1 values" ;
] ;
sh:conforms false .
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
@prefix dcterms: <http://purl.org/dc/terms/> .
@prefix relation: <https://cube.link/relation/> .
@prefix meta: <https://cube.link/meta/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix cube: <https://cube.link/> .
@prefix observation: <https://environment.ld.admin.ch/foen/nfi/observation/max_min_undefined> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix schema: <http://schema.org/> .
@base <https://example.org/> .

<cube> a cube:Cube ;
cube:observationConstraint <shape> ;
cube:observationSet <observationSet> .

<observationSet> cube:observation <observationA>, <observationB>, <observationC> .

<observationA> a cube:Observation ;
cube:observedBy <observer> ;
<dimension> 4.9 ;
<upperConfidence> 0.1 ;
.

<shape> a cube:Constraint ;
sh:targetClass cube:Observation ;
sh:closed true ;
sh:property
[
sh:path rdf:type ;
sh:nodeKind sh:IRI ;
sh:minCount 1 ;
sh:maxCount 1
] ;
sh:property
[
sh:path cube:observedBy ; ;
sh:nodeKind sh:IRI ;
sh:minCount 1 ;
sh:maxCount 1
] ;
sh:property
[
sh:datatype xsd:decimal ;
sh:path <dimension> ;
schema:name "dimension" ;
sh:minCount 1 ;
sh:maxCount 1 ;
],
[
sh:datatype xsd:decimal ;
sh:path <upperConfidence> ;
schema:name "upper confidence" ;
sh:minCount 1 ;
sh:maxCount 1 ;
meta:dimensionRelation
[
a relation:ConfidenceUpperBound ;
dcterms:type "Confidence interval" ;
meta:relatesTo <non-dimension> ;
] ;
];
.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix schema: <http://schema.org/> .
@prefix cube: <https://cube.link/> .

_:report a sh:ValidationReport ;
sh:result [
rdf:type sh:ValidationResult ;
sh:resultSeverity sh:Violation ;
sh:sourceConstraintComponent sh:NodeConstraintComponent ;
sh:sourceShape [
sh:path sh:property ;
sh:node <https://cube.link/shape/standalone-constraint-constraint#DimensionRelation> ;
] ;
sh:focusNode <https://example.org/shape> ;
sh:resultPath sh:property ;
sh:resultMessage "Value does not have shape <https://cube.link/shape/standalone-constraint-constraint#DimensionRelation>" ;
sh:detail [
rdf:type sh:ValidationResult ;
sh:resultSeverity sh:Violation ;
sh:sourceConstraintComponent sh:MinCountConstraintComponent ;
sh:sourceShape [
sh:path _:b675 ;
sh:class cube:Constraint ;
sh:minCount 1 ;
sh:message "value of meta:relatesTo must be a cube dimension" ;
] ;
sh:focusNode _:b5 ;
sh:resultPath _:b675 ;
sh:resultMessage "value of meta:relatesTo must be a cube dimension" ;
] ;
sh:value _:b4 ;
] ;
sh:conforms false .

_:b675 rdf:first <https://cube.link/meta/relatesTo> ;
rdf:rest (
[
sh:inversePath sh:path ;
]
[
sh:inversePath sh:property ;
]
) .
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ _:report a sh:ValidationReport ;
rdf:type sh:ValidationResult ;
sh:resultSeverity sh:Violation ;
sh:sourceConstraintComponent sh:MinCountConstraintComponent ;
sh:sourceShape _:b679 ;
sh:sourceShape _:b690 ;
sh:focusNode _:b6 ;
sh:resultPath rdf:rest ;
sh:resultMessage "list node needs exactly one rdf:rest" ;
Expand Down Expand Up @@ -41,7 +41,7 @@ _:report a sh:ValidationReport ;
rdf:type sh:ValidationResult ;
sh:resultSeverity sh:Violation ;
sh:sourceConstraintComponent sh:MinCountConstraintComponent ;
sh:sourceShape _:b679 ;
sh:sourceShape _:b690 ;
sh:focusNode _:b6 ;
sh:resultPath rdf:rest ;
sh:resultMessage "list node needs exactly one rdf:rest" ;
Expand All @@ -60,7 +60,7 @@ _:report a sh:ValidationReport ;
] ;
sh:conforms false .

_:b679 sh:path rdf:rest ;
_:b690 sh:path rdf:rest ;
sh:maxCount 1 ;
sh:minCount 1 ;
sh:message "list node needs exactly one rdf:rest" .
77 changes: 77 additions & 0 deletions test/standalone-constraint-constraint/valid.dimensionRelation.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
PREFIX dcterms: <http://purl.org/dc/terms/>
@prefix relation: <https://cube.link/relation/> .
@prefix meta: <https://cube.link/meta/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix cube: <https://cube.link/> .
@prefix observation: <https://environment.ld.admin.ch/foen/nfi/observation/max_min_undefined> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix schema: <http://schema.org/> .
@base <https://example.org/> .

<cube> a cube:Cube ;
cube:observationConstraint <shape> ;
cube:observationSet <observationSet> .

<observationSet> cube:observation <observationA>, <observationB>, <observationC> .

<observationA> a cube:Observation ;
cube:observedBy <observer> ;
<dimension> 4.9 ;
<upperConfidence> 0.1 ;
<lowerConfidence> 0.15 ;
.

<shape> a cube:Constraint ;
sh:targetClass cube:Observation ;
sh:closed true ;
sh:property
[
sh:path rdf:type ;
sh:nodeKind sh:IRI ;
sh:minCount 1 ;
sh:maxCount 1
] ;
sh:property
[
sh:path cube:observedBy ; ;
sh:nodeKind sh:IRI ;
sh:minCount 1 ;
sh:maxCount 1
] ;
sh:property
[
a cube:MeasureDimension ;
sh:datatype xsd:decimal ;
sh:path <dimension> ;
schema:name "dimension" ;
sh:minCount 1 ;
sh:maxCount 1 ;
],
[
sh:datatype xsd:decimal ;
sh:path <upperConfidence> ;
schema:name "upper confidence" ;
sh:minCount 1 ;
sh:maxCount 1 ;
meta:dimensionRelation
[
a relation:ConfidenceUpperBound ;
dcterms:type "Confidence interval" ;
meta:relatesTo <dimension> ;
] ;
],
[
sh:datatype xsd:decimal ;
sh:path <lowerConfidence> ;
schema:name "lower confidence" ;
sh:minCount 1 ;
sh:maxCount 1 ;
meta:dimensionRelation
[
a relation:ConfidenceLowerBound ;
dcterms:type "Confidence interval" ;
meta:relatesTo <dimension> ;
] ;
] ;
.
46 changes: 39 additions & 7 deletions validation/standalone-constraint-constraint.ttl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@prefix dcterms: <http://purl.org/dc/terms/> .
@prefix : <https://cube.link/shape/standalone-constraint-constraint#> .
@prefix dash: <http://datashapes.org/dash#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
Expand All @@ -8,6 +9,7 @@
@prefix cube: <https://cube.link/> .
@prefix meta: <https://cube.link/meta/> .
@prefix qudt: <http://qudt.org/schema/qudt/> .
@prefix relation: <https://cube.link/relation/> .

#
# This is the bare minimal SHACL shape for validating a Cube Constraint.
Expand Down Expand Up @@ -179,17 +181,47 @@
.

:DimensionRelation a sh:NodeShape ;
sh:property [
sh:property
[
sh:path meta:dimensionRelation;
sh:property [
sh:path meta:relatesTo;
sh:nodeKind sh:IRI ;
sh:minCount 1;
sh:message "meta:dimensionRelation requires at least one meta:relatesTo";
] ;
sh:property
[
sh:path meta:relatesTo ;
sh:nodeKind sh:IRI ;
sh:minCount 1 ;
sh:message "meta:dimensionRelation requires at least one meta:relatesTo" ;
],
[
sh:path
(
meta:relatesTo
[ sh:inversePath sh:path ]
[ sh:inversePath sh:property ]
) ;
sh:minCount 1 ;
sh:class cube:Constraint ;
sh:message "value of meta:relatesTo must be a cube dimension" ;
],
[
sh:path
(
meta:relatesTo
[ sh:inversePath sh:path ]
) ;
sh:class cube:MeasureDimension ;
sh:message "value of meta:relatesTo must point to measure dimension " ;
] ;
] ;
.

:Confidence a sh:NodeShape ;
sh:targetClass relation:ConfidenceLowerBound, relation:ConfidenceUpperBound ;
sh:property
[
sh:path dcterms:type ;
sh:maxCount 1 ;
] ;
.

# Testing proper rdf:list construction

Expand Down

0 comments on commit 2a93676

Please sign in to comment.