From 07592de2c8f9fb7bec6515daf6a8784bcd894382 Mon Sep 17 00:00:00 2001 From: Holger Knublauch Date: Tue, 18 Mar 2025 09:21:17 +0100 Subject: [PATCH 1/7] #327: Added section on Annotations --- shacl12-sparql/index.html | 109 +++++++++++++++++++++++++++++++++++++- 1 file changed, 108 insertions(+), 1 deletion(-) diff --git a/shacl12-sparql/index.html b/shacl12-sparql/index.html index 9531a4d6..d10edd48 100644 --- a/shacl12-sparql/index.html +++ b/shacl12-sparql/index.html @@ -1211,7 +1211,113 @@

Validation with SPARQL-based Constraint Components

- + +
+

Annotation Properties

+

+ This section extends the general mechanism + to produce validation results using of SPARQL-based constraints or + constraint components. +

+

+ Implementations that support this feature make it possible to inject so-called annotation properties + into the validation result nodes created for each solution produced by the SELECT queries of a + SPARQL-based constraint or constraint component. + Any such annotation property needs to be declared via a value of sh:resultAnnotation at + the subject of the sh:select or sh:ask triple. +

+

+ The values of sh:resultAnnotation are + called result annotations and are either IRIs or blank nodes. +

+

+ Result annotations have the following properties: +

+ + + + + + + + + + + + + + + + + +
PropertySummary and Syntax Rules
sh:annotationProperty + The property that shall be set. + Each result annotation has exactly one value + for the property sh:annotationProperty and this value is an IRI. +
sh:annotationVarName + The name of the SPARQL variable to take the annotation values from. + Each result annotation has at most 1 value + for the property sh:annotationVarName and this value is literal with + datatype xsd:string. +
sh:annotationValue + Constant RDF terms that shall be used as default values. +
+

+ For each solution of a SELECT result set, a SHACL processor that supports annotations + walks through the declared result annotations. + The mapping from result annotations to SPARQL variables uses the following rules: +

+
    +
  1. Use the value of the property sh:annotationVarName
  2. +
  3. If no such value exists, use the local name of the value of sh:annotationProperty + as the variable name
  4. +
+

+ If a variable name could be determined, then the SHACL processor copies the binding for the given variable + as a value for the property specified using sh:annotationProperty + into the validation result that is being produced for the current solution. + If the variable has no binding in the result set solution, + then the values of sh:annotationValue is used, if present. +

+

+ Here is an example illustrating the use of result annotations. +

+
+ex:AnnotationExample
+	a sh:NodeShape ;
+	sh:targetNode ex:ExampleResource ;
+	sh:sparql [   # _:b1
+		sh:resultAnnotation [
+			sh:annotationProperty ex:time ;
+			sh:annotationVarName "time" ;
+		] ;
+		sh:select """
+			SELECT $this ?message ?time
+			WHERE {
+				BIND (CONCAT("The ", "message.") AS ?message) .
+				BIND (NOW() AS ?time) .
+			}
+			""" ;
+	] .
+

+ Validation produces the following validation report: +

+
+[	a sh:ValidationReport ;
+	sh:conforms false ;
+	sh:result [
+		a sh:ValidationResult ;
+		sh:focusNode ex:ExampleResource ;
+		sh:resultMessage "The message." ;
+		sh:resultSeverity sh:Violation ;
+		sh:sourceConstraint _:b1 ;
+		sh:sourceConstraintComponent sh:SPARQLConstraintComponent ;
+		sh:sourceShape ex:AnnotationExample ;
+		ex:time "2015-03-27T10:58:00"^^xsd:dateTime ;  # Example
+	]
+] .
+
+

SPARQL-based Node Expressions

@@ -1659,6 +1765,7 @@

Revision History

Changes between SHACL 1.0 SPARQL and SHACL 1.2 SPARQL Extensions

From 932c1ab22330088c281f3391f20eece82521cc79 Mon Sep 17 00:00:00 2001 From: Holger Knublauch Date: Wed, 19 Mar 2025 08:41:13 +0100 Subject: [PATCH 2/7] Apply suggestions from code review Co-authored-by: Ted Thibodeau Jr --- shacl12-sparql/index.html | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/shacl12-sparql/index.html b/shacl12-sparql/index.html index d10edd48..de22ceea 100644 --- a/shacl12-sparql/index.html +++ b/shacl12-sparql/index.html @@ -1216,12 +1216,12 @@

Validation with SPARQL-based Constraint Components

Annotation Properties

This section extends the general mechanism - to produce validation results using of SPARQL-based constraints or + to produce validation results using SPARQL-based constraints or constraint components.

- Implementations that support this feature make it possible to inject so-called annotation properties - into the validation result nodes created for each solution produced by the SELECT queries of a + Implementations that support this feature make it possible to inject annotation properties + into the validation result nodes created for each solution produced by the SELECT queries of a SPARQL-based constraint or constraint component. Any such annotation property needs to be declared via a value of sh:resultAnnotation at the subject of the sh:select or sh:ask triple. @@ -1263,14 +1263,14 @@

Annotation Properties

- For each solution of a SELECT result set, a SHACL processor that supports annotations + For each solution of a SELECT result set, a SHACL processor that supports annotations walks through the declared result annotations. The mapping from result annotations to SPARQL variables uses the following rules:

  1. Use the value of the property sh:annotationVarName
  2. If no such value exists, use the local name of the value of sh:annotationProperty - as the variable name
  3. + as the variable name.

If a variable name could be determined, then the SHACL processor copies the binding for the given variable From 4af55fe7db87f449532794daaea7cd492892377b Mon Sep 17 00:00:00 2001 From: Holger Knublauch Date: Mon, 12 May 2025 09:01:57 +0200 Subject: [PATCH 3/7] #327: Fixed trivial grammar error --- shacl12-sparql/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shacl12-sparql/index.html b/shacl12-sparql/index.html index 825dc33b..826bd282 100644 --- a/shacl12-sparql/index.html +++ b/shacl12-sparql/index.html @@ -1272,7 +1272,7 @@

Annotation Properties

as a value for the property specified using sh:annotationProperty into the validation result that is being produced for the current solution. If the variable has no binding in the result set solution, - then the values of sh:annotationValue is used, if present. + then the values of sh:annotationValue are used, if present.

Here is an example illustrating the use of result annotations. From d75cfee192b551049ac7ef43095cfab5d335f501 Mon Sep 17 00:00:00 2001 From: Alex Nelson Date: Mon, 12 May 2025 06:17:37 -0400 Subject: [PATCH 4/7] #327: SHACL-SHACL for SHACL-SPARQL ASK, SELECT, and Annotations Signed-off-by: Alex Nelson --- shacl12-vocabularies/shacl-shacl.ttl | 43 ++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/shacl12-vocabularies/shacl-shacl.ttl b/shacl12-vocabularies/shacl-shacl.ttl index dc0f2c72..512d100d 100644 --- a/shacl12-vocabularies/shacl-shacl.ttl +++ b/shacl12-vocabularies/shacl-shacl.ttl @@ -409,3 +409,46 @@ shsh:EntailmentShape a sh:NodeShape ; sh:targetObjectsOf sh:entailment ; sh:nodeKind sh:IRI . # entailment-nodeKind + + +shsh:SPARQLAskExecutableShape + a sh:NodeShape ; + sh:targetSubjectsOf sh:ask , sh:resultAnnotation ; + sh:property [ + sh:path sh:ask ; + sh:minCount 1 ; # ask-count + sh:maxCount 1 ; # ask-count + sh:datatype xsd:string ; # ask-datatype + ] . + +shsh:SPARQLSelectExecutableShape + a sh:NodeShape ; + sh:targetSubjectsOf sh:select , sh:resultAnnotation ; + sh:property [ + sh:path sh:select ; + sh:minCount 1 ; # SPARQLConstraint-select-count + sh:maxCount 1 ; # SPARQLConstraint-select-count + sh:datatype xsd:string ; # SPARQLConstraint-select-datatype + ] . + +shsh:ResultAnnotationShape + a sh:NodeShape ; + sh:targetObjectsOf sh:resultAnnotation ; # sparql-constraints-annotations + sh:nodeKind sh:BlankNodeOrIRI ; # resultAnnotation-nodeKind + sh:property + [ + sh:path sh:annotationProperty ; # annotationProperty + sh:minCount 1 ; + sh:maxCount 1 ; + sh:nodeKind sh:IRI ; + ] , + [ + sh:path sh:annotationVarName ; # annotationVarName + sh:datatype xsd:string ; + sh:maxCount 1 ; + sh:nodeKind sh:Literal ; + ] , + [ + sh:path sh:annotationValue ; # annotationValue + sh:nodeKind sh:IRI ; + ] . From e68d239e2e35644fef71429dfcd5e460f66fc0c0 Mon Sep 17 00:00:00 2001 From: Alex Nelson Date: Mon, 12 May 2025 06:52:27 -0400 Subject: [PATCH 5/7] #327: Add data syntax rule span for annotationValue Signed-off-by: Alex Nelson --- shacl12-sparql/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shacl12-sparql/index.html b/shacl12-sparql/index.html index 826bd282..462f5760 100644 --- a/shacl12-sparql/index.html +++ b/shacl12-sparql/index.html @@ -1253,7 +1253,7 @@

Annotation Properties

sh:annotationValue - Constant RDF terms that shall be used as default values. + Constant RDF terms that shall be used as default values. From e5d86de9aa4dea7b2b2b2962485638a8be2e35f6 Mon Sep 17 00:00:00 2001 From: Alex Nelson Date: Tue, 13 May 2025 08:39:47 -0400 Subject: [PATCH 6/7] Start SPARQLExecutableShape to review sh:prefixes Targeting of `shsh:SPARQLExecutableShape` derived from: ```turtle sh:prefixes rdfs:domain sh:SPARQLExecutable . ``` Signed-off-by: Alex Nelson --- shacl12-vocabularies/shacl-shacl.ttl | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/shacl12-vocabularies/shacl-shacl.ttl b/shacl12-vocabularies/shacl-shacl.ttl index 512d100d..faf34e93 100644 --- a/shacl12-vocabularies/shacl-shacl.ttl +++ b/shacl12-vocabularies/shacl-shacl.ttl @@ -410,6 +410,14 @@ shsh:EntailmentShape sh:targetObjectsOf sh:entailment ; sh:nodeKind sh:IRI . # entailment-nodeKind +shsh:SPARQLExecutableShape + a sh:NodeShape ; + sh:targetClass sh:SPARQLExecutable ; + sh:targetSubjectsOf sh:prefixes ; + sh:property [ + sh:path sh:prefixes ; + sh:nodeKind sh:BlankNodeOrIRI ; + ] . shsh:SPARQLAskExecutableShape a sh:NodeShape ; From c53fe245828aad2fe1a7c9ea61e189c2444bb2dc Mon Sep 17 00:00:00 2001 From: Alex Nelson Date: Tue, 13 May 2025 08:42:07 -0400 Subject: [PATCH 7/7] Note syntax rule Signed-off-by: Alex Nelson --- shacl12-vocabularies/shacl-shacl.ttl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shacl12-vocabularies/shacl-shacl.ttl b/shacl12-vocabularies/shacl-shacl.ttl index faf34e93..31b563fb 100644 --- a/shacl12-vocabularies/shacl-shacl.ttl +++ b/shacl12-vocabularies/shacl-shacl.ttl @@ -416,7 +416,7 @@ shsh:SPARQLExecutableShape sh:targetSubjectsOf sh:prefixes ; sh:property [ sh:path sh:prefixes ; - sh:nodeKind sh:BlankNodeOrIRI ; + sh:nodeKind sh:BlankNodeOrIRI ; # prefixes-nodeKind ] . shsh:SPARQLAskExecutableShape