@@ -1206,7 +1206,113 @@ <h3>Validation with SPARQL-based Constraint Components</h3>
1206
1206
</ p >
1207
1207
</ section >
1208
1208
</ section >
1209
-
1209
+
1210
+ < section id ="sparql-constraints-annotations ">
1211
+ < h2 > Annotation Properties</ h2 >
1212
+ < p >
1213
+ This section extends the general < a href ="#sparql-constraints-variables "> mechanism</ a >
1214
+ to produce validation results using < a href ="sparql-constraints "> SPARQL-based constraints</ a > or
1215
+ < a href ="sparql-constraint-components "> constraint components</ a > .
1216
+ </ p >
1217
+ < p >
1218
+ Implementations that support this feature make it possible to inject < dfn > annotation properties</ dfn >
1219
+ into the validation result nodes created for each < a > solution</ a > produced by the < code > SELECT</ code > queries of a
1220
+ SPARQL-based < a > constraint</ a > or < a > constraint component</ a > .
1221
+ Any such annotation property needs to be declared via a < a > value</ a > of < code > sh:resultAnnotation</ code > at
1222
+ the < a > subject</ a > of the < code > sh:select</ code > or < code > sh:ask</ code > < a > triple</ a > .
1223
+ </ p >
1224
+ < p class ="syntax ">
1225
+ < span data-syntax-rule ="resultAnnotation-nodeKind "> The < a > values</ a > of < code > sh:resultAnnotation</ code > are
1226
+ called < dfn data-lt ="result annotation "> result annotations</ dfn > and are either < a > IRIs</ a > or < a > blank nodes</ a > </ span > .
1227
+ </ p >
1228
+ < p >
1229
+ < a > Result annotations</ a > have the following properties:
1230
+ </ p >
1231
+ < table class ="term-table ">
1232
+ < tr >
1233
+ < th > Property</ th >
1234
+ < th > Summary and Syntax Rules</ th >
1235
+ </ tr >
1236
+ < tr >
1237
+ < td > < code > sh:annotationProperty</ code > </ td >
1238
+ < td >
1239
+ The property that shall be set.
1240
+ < span data-syntax-rule ="annotationProperty "> Each < a > result annotation</ a > has exactly one < a > value</ a >
1241
+ for the property < code > sh:annotationProperty</ code > and this value is an < a > IRI</ a > .</ span >
1242
+ </ td >
1243
+ </ tr >
1244
+ < tr >
1245
+ < td > < code > sh:annotationVarName</ code > </ td >
1246
+ < td >
1247
+ The name of the SPARQL variable to take the annotation values from.
1248
+ < span data-syntax-rule ="annotationVarName "> Each < a > result annotation</ a > has at most 1 < a > value</ a >
1249
+ for the property < code > sh:annotationVarName</ code > and this < a > value</ a > is < a > literal</ a > with
1250
+ < a > datatype</ a > < code > xsd:string</ code > .</ span >
1251
+ </ td >
1252
+ </ tr >
1253
+ < tr >
1254
+ < td > < code > sh:annotationValue</ code > </ td >
1255
+ < td >
1256
+ Constant < a > RDF terms</ a > that shall be used as default values.
1257
+ </ td >
1258
+ </ tr >
1259
+ </ table >
1260
+ < p >
1261
+ For each < a > solution</ a > of a < code > SELECT</ code > result set, a SHACL processor that supports annotations
1262
+ walks through the declared result annotations.
1263
+ The mapping from result annotations to SPARQL variables uses the following rules:
1264
+ </ p >
1265
+ < ol >
1266
+ < li > Use the < a > value</ a > of the property < code > sh:annotationVarName</ code > </ li >
1267
+ < li > If no such < a > value</ a > exists, use the < a > local name</ a > of the < a > value</ a > of < code > sh:annotationProperty</ code >
1268
+ as the variable name.</ li >
1269
+ </ ol >
1270
+ < p >
1271
+ If a variable name could be determined, then the SHACL processor copies the < a > binding</ a > for the given variable
1272
+ as a value for the property specified using < code > sh:annotationProperty</ code >
1273
+ into the validation result that is being produced for the current < a > solution</ a > .
1274
+ If the variable has no < a > binding</ a > in the result set < a > solution</ a > ,
1275
+ then the < a > values</ a > of < code > sh:annotationValue</ code > are used, if present.
1276
+ </ p >
1277
+ < p >
1278
+ Here is an example illustrating the use of result annotations.
1279
+ </ p >
1280
+ < pre class ="example-shapes ">
1281
+ ex:AnnotationExample
1282
+ a sh:NodeShape ;
1283
+ sh:targetNode ex:ExampleResource ;
1284
+ sh:sparql [ # _:b1
1285
+ sh:resultAnnotation [
1286
+ sh:annotationProperty ex:time ;
1287
+ sh:annotationVarName "time" ;
1288
+ ] ;
1289
+ sh:select """
1290
+ SELECT $this ?message ?time
1291
+ WHERE {
1292
+ BIND (CONCAT("The ", "message.") AS ?message) .
1293
+ BIND (NOW() AS ?time) .
1294
+ }
1295
+ """ ;
1296
+ ] .</ pre >
1297
+ < p >
1298
+ Validation produces the following validation report:
1299
+ </ p >
1300
+ < pre class ="example-results ">
1301
+ [ a sh:ValidationReport ;
1302
+ sh:conforms false ;
1303
+ sh:result [
1304
+ a sh:ValidationResult ;
1305
+ sh:focusNode ex:ExampleResource ;
1306
+ sh:resultMessage "The message." ;
1307
+ sh:resultSeverity sh:Violation ;
1308
+ sh:sourceConstraint _:b1 ;
1309
+ sh:sourceConstraintComponent sh:SPARQLConstraintComponent ;
1310
+ sh:sourceShape ex:AnnotationExample ;
1311
+ ex:time "2015-03-27T10:58:00"^^xsd:dateTime ; # Example
1312
+ ]
1313
+ ] .</ pre >
1314
+ </ section >
1315
+
1210
1316
< section id ="sparql-node-expressions ">
1211
1317
< h2 > SPARQL-based Node Expressions</ h2 >
1212
1318
< p >
@@ -1734,6 +1840,7 @@ <h2>Revision History</h2>
1734
1840
< h2 > Changes between SHACL 1.0 SPARQL and SHACL 1.2 SPARQL Extensions</ h2 >
1735
1841
< ul >
1736
1842
< li > Added the < a > node expression function</ a > < a href ="#SelectExpression "> < code > sh:SelectExpression</ code > </ a > , see < a href ="https://github.com/w3c/data-shapes/issues/288 "> Issue 288</ a > </ li >
1843
+ < li > Added support for < a > annotation properties</ a > , see < a href ="https://github.com/w3c/data-shapes/issues/327 "> Issue 327</ a > </ li >
1737
1844
< li > Added the < a > node expression function</ a > < a href ="#SPARQLExprExpression "> < code > sh:SPARQLExprExpression</ code > </ a > , see < a href ="https://github.com/w3c/data-shapes/issues/315 "> Issue 315</ a > </ li >
1738
1845
</ ul >
1739
1846
</ section >
0 commit comments