-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathindex.html
More file actions
6204 lines (5980 loc) · 267 KB
/
index.html
File metadata and controls
6204 lines (5980 loc) · 267 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="color-scheme" content="light dark">
<title>SHACL 1.2 Core</title>
<script src="https://www.w3.org/Tools/respec/respec-w3c" class="remove" defer=""></script>
<script class="remove">
function prepareSyntaxRules() {
document.querySelectorAll("[data-syntax-rule]").forEach(element => {
let ruleId = element.getAttribute("data-syntax-rule");
let tr = document.createElement("tr");
tr.classList.add("syntax-rule-tr");
let td1 = document.createElement("td");
td1.classList.add("syntax-rule-id");
let a = document.createElement("a");
a.classList.add("syntax-rule-id-a");
a.href = "#syntax-rule-" + ruleId;
a.textContent = ruleId;
td1.appendChild(a);
let td2 = document.createElement("td");
td2.innerHTML = element.innerHTML;
tr.appendChild(td1);
tr.appendChild(td2);
// Replace <dfn> elements inside `tr` with <a> elements
tr.querySelectorAll("dfn").forEach(dfn => {
let a = document.createElement("a");
a.textContent = dfn.textContent;
dfn.replaceWith(a);
});
document.getElementById("syntax-rules-table").appendChild(tr);
element.setAttribute("id", "syntax-rule-" + ruleId);
});
}
function prepareValidators() {
document.querySelectorAll("[data-validator]").forEach(element => {
let validatorId = element.getAttribute("data-validator") + "ConstraintComponent";
let tr = document.createElement("tr");
tr.classList.add("validator-tr");
let td = document.createElement("td");
tr.appendChild(td);
let a = document.createElement("a");
a.classList.add("validator-id-a");
a.href = `#validator-${validatorId}`;
a.textContent = `sh:${validatorId}`;
td.appendChild(a);
td.innerHTML += ": " + element.innerHTML;
document.getElementById("validators-table").appendChild(tr);
element.id = "validator-" + validatorId;
});
}
document.addEventListener("DOMContentLoaded", () => {
// Replace code div blocks in shapes, data, and results graph with tabs
for (const graph of document.querySelectorAll(".shapes-graph, .data-graph, .results-graph")) {
const tabs = document.createElement("aside");
tabs.classList.add("ds-selector-tabs");
graph.firstElementChild.classList.add("selected");
for (const child of graph.children) {
child.classList.add("tab");
}
tabs.append(...graph.children);
graph.append(tabs)
}
// Generate buttons for the selection logic
for (const tabs of document.querySelectorAll(".ds-selector-tabs")) {
const selectors = document.createElement("div");
selectors.classList.add("selectors");
// Check if JSON-LD or shaclc div exists in this tab group
const hasJsonld = tabs.querySelector(".jsonld");
const hasShaclc = tabs.querySelector(".shaclc");
selectors.innerHTML = `
<button class="selected" data-selects="turtle">Turtle</button>
${hasJsonld ? '<button data-selects="jsonld">JSON-LD</button>' : ''}
${hasShaclc ? '<button data-selects="shaclc">SHACL-C</button>' : ''}
`
tabs.prepend(selectors);
}
for (const block of document.querySelectorAll('.shaclc')) {
block.innerHTML = `<i>SHACL-C specification is unstable - SHACL-C document fragments in this document are informative</i>${block.innerHTML}`;
}
// Add example button selection logic
for (const button of document.querySelectorAll(".ds-selector-tabs .selectors button")) {
button.onclick = () => {
const ex = button.closest(".ds-selector-tabs");
ex.querySelector("button.selected").classList.remove("selected");
ex.querySelector(".selected").classList.remove("selected");
button.classList.add('selected');
ex.querySelector("." + button.dataset.selects).classList.add("selected");
}
}
});
var respecConfig = {
group: "wg/data-shapes",
github: "w3c/data-shapes",
edDraftURI: "https://w3c.github.io/data-shapes/shacl12-core/",
specStatus: "ED",
preProcess : [ prepareSyntaxRules, prepareValidators ],
shortName: "shacl12-core",
subjectPrefix: "[shacl12-core]",
editors: [
{
name: "Holger Knublauch",
company: "TopQuadrant, Inc.",
companyURL: "https://topquadrant.com/",
mailto: "holger@topquadrant.com",
w3cid: 46500
},
{
name: "Thomas Bergwinkl",
company: "TopQuadrant, Inc.",
companyURL: "https://www.topquadrant.com/",
mailto: "tbergwinkl@topquadrant.com",
w3cid: 47803
},
{
name: "Yousouf Taghzouti",
company: "Inria",
companyURL: "https://www.inria.fr/",
mailto: "yousouf.taghzouti@inria.fr",
w3cid: 143054
},
{
name: "Jesse Wright",
company: "University of Oxford",
companyURL: "https://www.cs.ox.ac.uk",
mailto: "jesse@jeswr.org",
w3cid: 132252
},
],
formerEditors: [
{
name: "Dimitris Kontokostas",
w3cid: 58399
}
],
testSuiteURI: "https://w3c.github.io/data-shapes/data-shapes-test-suite/",
lint: {
"no-unused-dfns": false, // This should be removed near the end of the process
},
previousPublishDate: "2017-07-20",
previousMaturity: "REC",
prevRecShortname: "shacl",
prevRecURI: "https://www.w3.org/TR/2017/REC-shacl-20170720/",
wgPublicList: "public-shacl",
localBiblio: {
"shacl12-overview": {
title: "SHACL 1.2 Overview",
href: "https://w3c.github.io/data-shapes/shacl12-overview/",
status: "ED",
publisher: "W3C",
},
"shacl12-shacl-c": {
title: "SHACL Compact Syntax",
href: "https://w3c.github.io/data-shapes/shacl-compact-syntax/",
status: "ED",
publisher: "W3C",
}
}
};
</script>
<link rel="stylesheet" href="style.css"/>
</head>
<body>
<section id="abstract">
<p>
This document defines the Core of SHACL.
</p>
<p>
SHACL, the Shapes Constraint Language, is a language for describing the structure of RDF graphs.
SHACL can be used to define classes and the properties that instances of these classes can have.
More general than classes and instances, SHACL introduces the notion of shapes
that can formally specify constraints on the structure of RDF nodes and edges.
SHACL shapes are themselves represented in RDF graphs called shapes graphs.
The RDF graphs that are described by a shapes graph are called data graphs.
</p>
<p>
SHACL may be used for a variety of purposes such as
validating, inferencing, modeling domains, generating ontologies to inform other agents,
building user interfaces, generating code, and integrating data.
</p>
</section>
<section id="sotd">
</section>
<section id="specifications" class="introductory" data-include="../shacl12-common/specifications.html"></section>
<section class="introductory">
<h2>Document Outline</h2>
<p>
The introduction includes a <a href="#terminology">Terminology</a> section.
</p>
<p>
Sections 2 and 3 cover SHACL shapes and constraints, as well as property paths.
</p>
<p>
Section 4 introduces node expressions, while section 5 defines validation in SHACL.
</p>
<p>
Section 6 defines the built-in SHACL Core constraint components, and section 7 discusses non-validating properties.
</p>
<p>
The syntax of SHACL is RDF.
The examples in this document use Turtle [[rdf12-turtle]], JSON-LD [[json-ld]], and SHACL-C [[?shacl12-shacl-c]].
Other RDF serializations such as RDF/XML may be used in practice.
The reader should be familiar with basic RDF concepts [[rdf12-concepts]] such as triples.
</p>
</section>
<section id="introduction">
<h2>Introduction</h2>
<p>
This document specifies the Core of SHACL (Shapes Constraint Language), a language for describing and validating RDF graphs.
This section introduces SHACL with an overview of the key terminology and an example to illustrate basic concepts.
</p>
<section id="terminology">
<h3>Terminology</h3>
<p>
Throughout this document, the following terminology is used.
</p>
<p>
Terminology that is linked to portions of RDF 1.2 Concepts and Abstract
Syntax is used in SHACL as defined there. Terminology that is linked to
portions of SPARQL 1.2 Query Language is used in SHACL as defined there. A
single linkage is sufficient to provide a definition for all occurences of a
particular term in this document.
</p>
<p>
Definitions are complete within this document, i.e., if there is no rule to
make some situation true in this document then the situation is false.
</p>
<div class="def" id="rdf-terminology">
<div class="term-def-header">Basic RDF Terminology</div>
<div>
This document uses the terms
<dfn data-cite="rdf12-concepts#dfn-rdf-graph" data-lt="graph|graphs|RDF graphs">RDF graph</dfn>,
<dfn data-cite="rdf12-concepts#dfn-rdf-triple" data-lt="triple|triples">RDF triple</dfn>,
<dfn data-cite="rdf12-concepts#dfn-iri" data-lt="IRI|IRIs">IRI</dfn>,
<dfn data-cite="rdf12-concepts#dfn-rdf-literal" data-lt="literal|literals">literal</dfn>,
<dfn data-cite="rdf12-concepts#dfn-datatype" data-lt="datatype">datatype</dfn>,
<dfn data-cite="rdf12-concepts#dfn-base-direction" data-lt="base direction">base direction</dfn>,
<dfn data-cite="rdf12-concepts#dfn-blank-node" data-lt="blank node|blank nodes">blank node</dfn>,
<dfn data-cite="rdf12-concepts#dfn-triple-term" data-lt="triple term|triple terms">triple term</dfn>,
<dfn data-cite="rdf12-concepts#dfn-reifier" data-lt="reifier">reifier</dfn>,
<dfn data-cite="rdf12-concepts#dfn-rdf-node" data-lt="node|nodes">node</dfn> of an RDF graph,
<dfn data-cite="rdf12-concepts#dfn-rdf-term" data-lt="term|terms">RDF term</dfn>,
<dfn data-cite="rdf12-concepts#dfn-subject" data-lt="subject|subjects">subject</dfn>,
<dfn data-cite="rdf12-concepts#dfn-predicate" data-lt="predicate|predicates">predicate</dfn>, and
<dfn data-cite="rdf12-concepts#dfn-object" data-lt="object|objects">object</dfn> of RDF triples
as defined in RDF 1.2 Concepts and Abstract Syntax [[!rdf12-concepts]].
<dfn data-lt="language tag">Language tags</dfn> are defined as in [[!BCP47]].
</div>
</div>
<div class="def">
<div class="term-def-header">Property Value and Path</div>
<div>
A <dfn data-lt="properties">property</dfn> is an <a>IRI</a>.
An <a>RDF term</a> <code>n</code> has a <dfn data-lt="value|values|property value|property values">value</dfn> <code>v</code>
for property <code>p</code> in an <a>RDF graph</a> if there is an <a>RDF triple</a> in the graph
with <a>subject</a> <code>n</code>, <a>predicate</a> <code>p</code>, and <a>object</a> <code>v</code>.
The phrase "Every value of P in graph G ..." means "Every object of a triple in G with predicate P ...".
(In this document, the verbs <em>specify</em> or <em>declare</em> are sometimes used to express the fact that an RDF term has values for a given predicate in a graph.)
<br>
<dfn data-lt="SPARQL property path">SPARQL property paths</dfn> are defined as in <a data-cite="sparql12-query#pp-language">SPARQL 1.2</a>.
An RDF term <code>n</code> has value <code>v</code> for <a>SPARQL property path</a> expression
<code>p</code> in an RDF graph <code>G</code> if there is a
<a data-cite="sparql12-query#defn_sparqlSolutionMapping">solution mapping</a> in the result of the SPARQL query
<code>SELECT ?s ?o WHERE { ?s p' ?o }</code> on <code>G</code> that binds <code>?s</code> to
<code>n</code> and <code>?o</code> to <code>v</code>, where <code>p'</code> is SPARQL surface syntax for <code>p</code>.
</div>
</div>
<div class="def">
<div class="term-def-header">SHACL Lists</div>
<div>
<span data-syntax-rule="SHACL-list">A <dfn>SHACL list</dfn> in an RDF graph <code>G</code> is an <a>IRI</a> or a <a>blank node</a>
that is either <code>rdf:nil</code> (provided that <code>rdf:nil</code> has no <a>value</a>
for either <code>rdf:first</code> or <code>rdf:rest</code>), or has exactly one <a>value</a>
for the property <code>rdf:first</code> in <code>G</code> and exactly one <a>value</a>
for the property <code>rdf:rest</code> in <code>G</code> that is also a SHACL list in <code>G</code>,
and the list does not have itself as a value of the property path <code>rdf:rest+</code> in <code>G</code>.</span>
<br>
The <dfn data-lt="members|member">members</dfn> of any SHACL list except <code>rdf:nil</code> in an RDF
graph <code>G</code> consist of its value for <code>rdf:first</code> in <code>G</code> followed by
the members in <code>G</code> of its value for <code>rdf:rest</code> in <code>G</code>.
The SHACL list <code>rdf:nil</code> has no members in any RDF graph.
</div>
</div>
<div class="def">
<div class="term-def-header">SHACL Subclass, SHACL Superclass</div>
<div>
A <a>node</a> <code>Sub</code> in an <a>RDF graph</a> is a <dfn data-lt="SHACL subclass|subclass|subclasses">SHACL subclass</dfn> of another <a>node</a> <code>Super</code>
in the <a>graph</a> if there is a sequence of <a>triples</a> in the <a>graph</a> each with predicate <code>rdfs:subClassOf</code> such that the <a>subject</a> of the first <a>triple</a> is <code>Sub</code>,
the <a>object</a> of the last triple is <code>Super</code>, and the <a>object</a> of each <a>triple</a> except the last is the <a>subject</a> of the next.
If <code>Sub</code> is a <a>SHACL subclass</a> of <code>Super</code> in an <a>RDF graph</a> then <code>Super</code>
is a <dfn data-lt="SHACL superclass|superclass|superclasses">SHACL superclass</dfn> of <code>Sub</code> in the <a>graph</a>.
</div>
</div>
<div class="def">
<div class="term-def-header">SHACL Type</div>
<div>
The <dfn data-lt="SHACL type|type|types">SHACL types</dfn> of an <a>RDF term</a> in an <a>RDF graph</a> is the set of its <a>values</a> for <code>rdf:type</code> in the
<a>graph</a> as well as the <a>SHACL superclasses</a> of these <a>values</a> in the <a>graph</a>.
Note that some SHACL implementations can be parameterized so that the <code>rdfs:subClassOf</code> triples
that determine the <a>SHACL subclasses</a> may be queried from the <a>shapes graph</a> in addition to the <a>data graph</a>.
See <a href="#subClassOfInShapesGraph"></a>.
</div>
</div>
<div class="def">
<div class="term-def-header">SHACL Class</div>
<div>
<a>Nodes</a> in an <a>RDF graph</a> that are subclasses, superclasses, or types of <a>nodes</a> in the <a>graph</a> are referred to as <dfn data-lt="class|classes|SHACL classes">SHACL class</dfn>.
</div>
</div>
<div class="def">
<div class="term-def-header">SHACL Class Instance</div>
<div>
A <a>node</a> <code>n</code> in an <a>RDF graph</a> <code>G</code> is a <dfn data-lt="SHACL instance|SHACL instances">SHACL instance</dfn> of a <a>SHACL class</a> <code>C</code> in <code>G</code>
if one of the <a>SHACL types</a> of <code>n</code> in <code>G</code> is <code>C</code>.
</div>
</div>
<div class="def">
<div class="term-def-header">Deep Copy</div>
<div>
For a <a>node</a> <code>n</code> in a <a>graph</a> <code>sourceGraph</code>,
the <dfn data-lt="deep copy">deep copy</dfn> of <code>n</code> in a <a>graph</a> <code>targetGraph</code>
is <code>n</code> in <code>targetGraph</code> plus, if <code>n</code> is a <a>blank node</a>,
any <a>triples</a> from <code>sourceGraph</code> that can be reached by transitively traversing
the <a>blank nodes</a> that appear in the <a>object</a> position of a triple that can be reached
starting with <code>n</code> as the <a>subject</a>. This is similar to
the <a href="https://www.w3.org/submissions/CBD/">Concise Bounded Description</a>, but without reification.
</div>
</div>
</section>
<section id="conventions">
<h3>Document Conventions</h3>
<p>
Within this document, the following namespace prefix definitions are used:
</p>
<table class="term-table">
<thead>
<tr>
<th>Prefix</th>
<th>Namespace</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>owl:</code></td>
<td><code>http://www.w3.org/2002/07/owl#</code></td>
</tr>
<tr>
<td><code>rdf:</code></td>
<td><code>http://www.w3.org/1999/02/22-rdf-syntax-ns#</code></td>
</tr>
<tr>
<td><code>rdfs:</code></td>
<td><code>http://www.w3.org/2000/01/rdf-schema#</code></td>
</tr>
<tr>
<td><code>sh:</code></td>
<td><code><a href="http://www.w3.org/ns/shacl">http://www.w3.org/ns/shacl#</a></code></td>
</tr>
<tr>
<td><code>xsd:</code></td>
<td><code>http://www.w3.org/2001/XMLSchema#</code></td>
</tr>
<tr>
<td><code>ex:</code></td>
<td><code>http://example.com/ns#</code></td>
</tr>
</tbody>
</table>
<p>
Within this document, the following JSON-LD context is used:
</p>
<pre class="jsonld">{
"@context": {
"owl": "http://www.w3.org/2002/07/owl#",
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
"sh": "http://www.w3.org/ns/shacl#",
"xsd": "http://www.w3.org/2001/XMLSchema#",
"ex": "http://example.com/ns#"
}
}</pre>
<p>
Note that the URI of the graph defining the SHACL vocabulary itself is equivalent to
the namespace above, i.e., it includes the <code>#</code>.
References to the SHACL vocabulary, e.g., via <code>owl:imports</code> should include the <code>#</code>.
</p>
<p>
Throughout the document, color-coded boxes containing RDF graphs in Turtle, JSON-LD and SHACL-C will appear.
These fragments of Turtle documents use the prefix bindings given above.
The JSON-LD document fragments use the context given above.
Only the Turtle documents may highlight certain parts.
<i>The SHACL-C specification is unstable - SHACL-C document fragments in this document are informative</i>
</p>
<div class="shapes-graph">
<div class="turtle">
# This box represents an input shapes graph
<s> ex:p <o> .
</div>
<div class="jsonld">
<pre class="text">// This box represents an input shapes graph</pre>
<pre class="jsonld">{
"@id": "s",
"ex:p": {
"@id": "o"
}
}</pre>
</div>
</div>
<div class="data-graph">
<div class="turtle">
# This box represents an input data graph.
# When highlighting is used in the examples:
# Elements highlighted in blue are <a>focus nodes</a>
<span class="focus-node-selected">ex:Bob</span> a ex:Person .
# Elements highlighted in red are focus nodes that fail validation
<span class="focus-node-error">ex:Alice</span> a ex:Person .
</div>
<div class="jsonld">
<pre class="text">// This box represents an input data graph</pre>
<pre class="jsonld">{
"@graph": [
{
"@id": "ex:Alice",
"@type": "ex:Person"
},
{
"@id": "ex:Bob",
"@type": "ex:Person"
}
]
}</pre>
</div>
</div>
<div class="results-graph">
<div class="turtle">
# This box represents an output results graph
</div>
<div class="jsonld">
<pre class="text">// This box represents an output results graph</pre>
<pre class="jsonld">{}</pre>
</div>
</div>
<p class="syntax">
Grey boxes such as this include syntax rules that apply to the <a>shapes graph</a>.
</p>
<p>
<code>true</code> denotes the RDF term <code>"true"^^xsd:boolean</code>.
<code>false</code> denotes the RDF term <code>"false"^^xsd:boolean</code>.
</p>
</section>
<section id="conformance">
<p>
This document defines the <strong>SHACL Core</strong> language, also referred to as just <strong>SHACL</strong>.
This specification describes conformance criteria for:
</p>
<ul>
<li><strong>SHACL Core processors</strong> as processors that support validation with the SHACL Core Language</li>
</ul>
<p>
This document includes syntactic rules that shapes and other nodes need to fulfill in the <a>shapes graph</a>.
These rules are typically of the form <em>A shape must have...</em> or <em>The values of X are literals</em> or <em>All objects of triples with predicate P must be IRIs</em>.
The complete list of these rules can be found in the <a href="#syntax-rules">appendix</a>.
Nodes that violate any of these rules are called <dfn>ill-formed</dfn>.
Nodes that violate none of these rules are called <dfn>well-formed</dfn>.
A <a>shapes graph</a> is ill-formed if it contains at least one ill-formed node.
</p>
</section>
<section id="shacl-rdfs">
<h3>Relationship between SHACL and RDFS inferencing</h3>
<p>
SHACL uses the RDF and RDFS vocabularies, but full RDFS inferencing is not required.
</p>
<p>
However, SHACL processors MAY operate on RDF graphs that include entailments [[!sparql12-entailment]],
whether pre-computed before being submitted to a SHACL processor or performed on the fly as
part of SHACL processing (without modifying either <a>data graph</a> or <a>shapes graph</a>).
To support processing of entailments, SHACL includes the property
<code>sh:entailment</code> to indicate the inferencing that is required
by a given <a>shapes graph</a>.
</p>
<p class="syntax">
<span data-syntax-rule="entailment-nodeKind">The <a>values</a> of the property <code>sh:entailment</code> are IRIs.</span>
Common values for this property are covered by [[!sparql12-entailment]].
</p>
<p>
SHACL implementations MAY, but are not required to, support entailment regimes.
If a <a>shapes graph</a> contains any <a>triple</a> with the <a>predicate</a> <code>sh:entailment</code> and <a>object</a> <code>E</code>
and the SHACL processor does not support <code>E</code> as an entailment regime for the given <a>data graph</a>,
then the processor MUST signal a <a>failure</a>.
Otherwise, the SHACL processor MUST provide the entailments for all of the values of <code>sh:entailment</code> in the <a>shapes graph</a>,
and any inferred triples MUST be returned by all queries against the <a>data graph</a> during the <a>validation</a> process.
</p>
</section>
</section>
<section id="getting-started" class="informative">
<h2>Getting Started with SHACL Core</h2>
<p>
In this section, we will walk you through a simple example that introduces the basics of SHACL Core.
You will learn to describe how your data should look, and how a SHACL processor checks whether your data meets that description.
</p>
<section>
<h3>Use Case</h3>
<p>
Imagine you have a set of entities (Alice, Bob, Calvin) and you want explain to a computer or another human that
</p>
<ol>
<li>
there is a class called <code>ex:Person</code> that is the type of these entities
</li>
<li>
every instance of <code>ex:Person</code> has at most one Social Security Number (SSN), and that SSN needs to be a properly formatted text (like <code>123-45-6789</code>)
</li>
<li>
every instance of <code>ex:Person</code> can work for one or more companies, but those companies must be typed as a <code>ex:Company</code> in your data
</li>
<li>
no other properties are allowed for an <code>ex:Person</code>, other than the SSN (<code></code>ex:ssn</code>), the work affiliation (<code>ex:worksFor</code>), and the mandatory typing (<code>rdf:type</code>)
</li>
</ol>
</section>
<section>
<h3>Our Sample Data (Data Graph)</h3>
<p>
Here is the data we want to describe and validate:
</p>
<aside class="example" title="Sample Instance Data">
<div class="data-graph">
<div class="turtle">
ex:Alice a ex:Person ;
ex:ssn "987-65-432A" . # SSN has a typo or bad format
ex:Bob a ex:Person ;
ex:ssn "123-45-6789", "124-35-6789" . # Two SSNs (too many)
ex:Calvin a ex:Person ;
ex:birthDate "1971-07-07"^^xsd:date ; # Extra birthDate
ex:worksFor ex:UntypedCompany . # Untyped company
</div>
</div>
<p>
<b>What is wrong here?</b>
<ul>
<li>
<b>Alice</b> has an SSN — but it does not match the correct pattern.
</li>
<li>
<b>Bob</b> has two SSNs, but we only allow one.
</li>
<li>
<b>Calvin</b> works for something called <code>ex:UntypedCompany</code>,
but that entity is not labeled as an <code>ex:Company</code>.
Furthermore, Calvin has an <code>ex:birthDate</code>, which we do not allow in our data.
</li>
</ul>
</p>
</aside>
</section>
<section>
<h3>Writing the Shapes and Classes (Shapes Graph)</h3>
<p>
Here is a self-contained example of how to represent our domain of interest.
In SHACL terminology, this is called a <a>shapes graph</a>, but you can also think
of this as a <em>domain model</em> or an <em>ontology</em>.
</p>
<aside class="example" title="Classes and Shapes to describe our domain of interest">
<div class="shapes-graph">
<div class="turtle">
ex:Person
a rdfs:Class ; # or owl:Class
rdfs:subClassOf rdfs:Resource ; # or owl:Thing
rdfs:label "Person" ;
rdfs:comment "A human being." ;
.
ex:PersonShape
a sh:NodeShape ;
rdfs:label "Person shape" ;
rdfs:comment "A shape that applies to all instances of Person." ;
sh:targetClass ex:Person ;
sh:property ex:PersonShape-ssn ;
sh:property ex:PersonShape-worksFor ;
sh:closed true ; # No other properties are allowed
sh:ignoredProperties ( rdf:type ) ; # except for rdf:type
.
ex:PersonShape-ssn
a sh:PropertyShape ;
sh:path ex:ssn ; # The values of ex:ssn are valid if:
sh:maxCount 1 ; # there is at most one SSN
sh:datatype xsd:string ; # the value must be a string
sh:pattern "^\\d{3}-\\d{2}-\\d{4}$" ; # the value must look like "123-45-6789"
sh:name "social security number" ;
sh:description "A person's unique identifier in the US." ;
.
ex:PersonShape-worksFor
a sh:PropertyShape ;
sh:path ex:worksFor ; # The values of ex:worksFor are valid if:
sh:nodeKind sh:IRI ; # they are IRIs (and, e.g., not literals)
sh:class ex:Company ; # they are instances of Company
sh:name "works for" ;
sh:description "The companies that a person works for." ;
.
</div>
</div>
<p>
<b>Let us break that down:</b>
</p>
<ul>
<li>
<code>sh:targetClass ex:Person</code> means "apply this constraint to all people".
</li>
<li>
The first <code>sh:property</code> definition declares that:
<ul>
<li>
SSNs are strings (<code>sh:datatype xsd:string</code>),
</li>
<li>
Only one is allowed (<code>sh:maxCount 1</code>),
</li>
<li>
And it must follow the typical U.S. SSN format (<code>sh:pattern "^\d{3}-\d{2}-\d{4}$"</code>).
</li>
</ul>
</li>
<li>
The second <code>sh:property</code> definition declares that:
<ul>
<li>
If someone has a <code>ex:worksFor</code> property, its value must be an IRI and point to something that's a <code>ex:Company</code>.
</li>
</ul>
</li>
<li>
<code>sh:closed true</code> means no properties beyond those listed are allowed (except any that are explicitly ignored).
</li>
<li>
<code>sh:ignoredProperties ( rdf:type )</code> lets <code>rdf:type</code> slip through even though it's not in the allowed property list.
</li>
</ul>
</aside>
</section>
<section>
<h3>Running the Validation (Validation Report)</h3>
<p>
When we run SHACL validation on our <a>data graph</a> using our <a>shapes graph</a>, the validator checks each Person against the constraints that we wrote.
</p>
<p>
In plain English, here is what it finds:
</p>
<ul>
<li>
<b>Alice</b>: SSN does not match the expected pattern (<code>987-65-432A</code> has a letter where a digit should be).
</li>
<li>
<b>Bob</b>: Has more than one SSN (two values found, but <code>sh:maxCount</code> says only one is allowed).
</li>
<li>
<b>Calvin</b>:
<ul>
<li>
Works for something (<code>ex:UntypedCompany</code>) that is not declared as a <code>ex:Company</code>.
</li>
<li>
Has an extra property <code>ex:birthDate</code> that is not allowed by the shape.
</li>
</ul>
</li>
</ul>
<p>
Here is what a SHACL validation report for this example might look like (simplified for readability):
</p>
<aside class="example" title="Output produced by a SHACL validation engine">
<div class="results-graph">
<div class="turtle">
[ a sh:ValidationReport ;
sh:conforms false ;
sh:result
[ a sh:ValidationResult ;
sh:resultSeverity sh:Violation ;
sh:focusNode ex:Alice ;
sh:resultPath ex:ssn ;
sh:value "987-65-432A" ;
sh:sourceConstraintComponent sh:PatternConstraintComponent ;
sh:sourceShape ex:PersonShape-ssn ;
sh:resultMessage "Value does not match pattern "^\d{3}-\d{2}-\d{4}$"" ;
] ,
[ a sh:ValidationResult ;
sh:resultSeverity sh:Violation ;
sh:focusNode ex:Bob ;
sh:resultPath ex:ssn ;
sh:sourceConstraintComponent sh:MaxCountConstraintComponent ;
sh:sourceShape ex:PersonShape-ssn ;
sh:resultMessage "More than 1 values" ;
] ,
[ a sh:ValidationResult ;
sh:resultSeverity sh:Violation ;
sh:focusNode ex:Calvin ;
sh:resultPath ex:worksFor ;
sh:value ex:UntypedCompany ;
sh:sourceConstraintComponent sh:ClassConstraintComponent ;
sh:sourceShape ex:PersonShape-worksFor ;
sh:resultMessage "Value does not have class ex:Company" ;
] ,
[ a sh:ValidationResult ;
sh:resultSeverity sh:Violation ;
sh:focusNode ex:Calvin ;
sh:resultPath ex:birthDate ;
sh:value "1971-07-07"^^xsd:date ;
sh:sourceConstraintComponent sh:ClosedConstraintComponent ;
sh:sourceShape sh:PersonShape ;
sh:resultMessage "Predicate is not allowed (closed shape)" ;
]
] .
</div>
</div>
</aside>
<p><b>How to read the report:</b></p>
<ul>
<li>
<code>sh:ValidationReport</code> is the overall report, with <code>sh:conforms false</code> meaning that there was at least one violation.
</li>
<li>
Each <code>sh:ValidationResult</code> is one problem found:
<ul>
<li>
<code>sh:resultSeverity</code> — tells you how serious the problem is. In this example, all issues are <code>sh:Violation</code> (the highest and default severity).
</li>
<li>
<code>sh:focusNode</code> — the data node that failed.
</li>
<li>
<code>sh:resultPath</code> — the property involved.
</li>
<li>
<code>sh:value</code> — the actual value that triggered the failure.
</li>
<li>
<code>sh:sourceConstraintComponent</code> — which kind of constraint was broken (max count, pattern, class, etc.).
</li>
<li>
<code>sh:sourceShape</code> — the shape that defined the constraint.
</li>
<li>
<code>sh:resultMessage</code> — a human-readable explanation.
</li>
</ul>
</li>
</ul>
</section>
<section>
<h3>Syntactic Variations of Shapes and Classes</h3>
<p>
While SHACL is primarily designed to represent shapes, it also borrows terms and concepts such as
<code>rdfs:Class</code> and <code>rdfs:subClassOf</code> from the RDF Schema namespace.
Some people prefer to keep those concepts separate, as shown in the original example above
which had separate entities for <code>ex:Person</code> and <code>ex:PersonShape</code>.
However, it is also possible to couple them more closely together, and use <code>sh:ShapeClass</code>
to declare both a class and a shape at the same time.
</p>
<p>
Furthermore, sometimes you will see property shapes declared as <a>blank nodes</a> instead of <a>IRIs</a>.
This is a more compact notation, but it means that the property shape cannot easily be referenced from
the outside; for example, if some other graph wants to reuse a node shape but deactivate a property shape.
</p>
<p>
The following Turtle example shows these two syntactic variations in action.
</p>
<aside class="example" title="A more compact representation of the shapes graph">
<div class="shapes-graph">
<div class="turtle">
ex:Person
a sh:ShapeClass ; # or rdfs:Class, sh:NodeShape
rdfs:subClassOf rdfs:Resource ; # or owl:Thing
rdfs:label "Person" ;
rdfs:comment "A human being." ;
sh:property [
sh:path ex:ssn ; # The values of ex:ssn are valid if:
sh:maxCount 1 ; # there is at most one SSN
sh:datatype xsd:string ; # the value must be a string
sh:pattern "^\\d{3}-\\d{2}-\\d{4}$" ; # the value must look like "123-45-6789"
sh:name "social security number" ;
sh:description "A person's unique identifier in the US." ;
] ;
sh:property [
sh:path ex:worksFor ; # The values of ex:worksFor are valid if:
sh:nodeKind sh:IRI ; # they are IRIs (so, e.g., not literals)
sh:class ex:Company ; # they are instances of Company
sh:name "works for" ;
sh:description "The companies that a person works for." ;
] ;
sh:closed true ; # No other properties are allowed
sh:ignoredProperties ( rdf:type ) ; # except for rdf:type
.
</div>
</div>
</aside>
</section>
<section>
<h3>Introducing some SHACL Terminology</h3>
<p>
We can use the shape declarations above to introduce some of the formal terminology used by SHACL.
This may help you read the remainder of this specification.
</p>
<p>
The <a>target</a> for the <a>shape</a> <code>ex:PersonShape</code> is the set of all <a>SHACL instances</a> of the <a>class</a> <code>ex:Person</code>.
This is specified using the property <code>sh:targetClass</code>.
During the validation, these target nodes become <a>focus nodes</a> for the shape.
The <a>shape</a> <code>ex:PersonShape</code> is a <a>node shape</a>, which means that it applies to the focus nodes.
It declares <a>constraints</a> on the <a>focus nodes</a>, for example using the <a>parameters</a> <code>sh:closed</code> and <code>sh:ignoredProperties</code>.
The <a>node shape</a> also declares two other constraints with the property <code>sh:property</code>,
and each of these is backed by a <a>property shape</a>.
These <a>property shapes</a> declare additional <a>constraints</a> using <a>parameters</a> such as <code>sh:datatype</code> and <code>sh:maxCount</code>.
</p>
<p>
Some of the <a>property shapes</a> specify parameters from multiple <a>constraint components</a> in order to
restrict multiple aspects of the <a>property values</a>.
For example, in the <a>property shape</a> for <code>ex:ssn</code>, parameters from three <a>constraint components</a> are used.
The <a>parameters</a> of these <a>constraint components</a> are <code>sh:datatype</code>, <code>sh:pattern</code> and <code>sh:maxCount</code>.
For each <a>focus node</a> the <a>property values</a> of <code>ex:ssn</code> will be validated against all three components.
</p>
</section>
</section>
<section id="constraints-section">
<h2>Shapes and Constraints</h2>
<p><em>The following introduction is non-normative.</em></p>
<p>
The following informal diagram provides an overview of some of the key classes in the SHACL vocabulary.
Each box represents a class.
The boxes under the class name list a small subset of the frequently used properties
that instances of these classes may have, together with their value types.
The arrows indicate <code>rdfs:subClassOf</code> triples.
</p>
<div>
<div class="diagram-class" style="margin-left: 200px">
<div class="diagram-class-name"><a href="#shapes">sh:Shape</a></div>
<div class="diagram-class-properties">
<div class="diagram-class-properties-start">
<div><a href="#targetClass">sh:targetClass</a> : rdfs:Class</div>
<div><a href="#targetNode">sh:targetNode</a> : any</div>
<div><a href="#targetObjectsOf">sh:targetObjectsOf</a> : rdf:Property</div>
<div><a href="#targetSubjectsOf">sh:targetSubjectsOf</a> : rdf:Property</div>
</div>
<div class="diagram-class-properties-section">
<div><a href="#deactivated">sh:deactivated</a> : xsd:boolean</div>
<div><a href="#message">sh:message</a> : text</div>
<div><a href="#severity">sh:severity</a> : sh:Severity</div>
</div>
</div>
</div>
<div style="height: 71px; margin-left: 230px; margin-top: -12px;">
<img alt="Class Diagram Arrows" src="images/Class-Diagram-Arrows.svg" style="background: unset;">
</div>
<div style="white-space: nowrap; min-width: 1000px">
<div class="diagram-class" style="float: left; margin-right: 15px; width: 300px;">
<div class="diagram-class-name"><a href="#node-shapes">sh:NodeShape</a></div>
<div class="diagram-class-properties">
<div class="diagram-class-properties-start">
<div><b><a href="#constraints">Constraint parameters</a></b>, for example:</div>
<div><a href="#ClosedConstraintComponent">sh:closed</a> : xsd:boolean or sh:ByTypes</div>
<div><a href="#OrConstraintComponent">sh:or</a>, <a href="#AndConstraintComponent">sh:and</a>, <a href="#XoneConstraintComponent">sh:xone</a> : rdf:List</div>
<div><a href="#NotConstraintComponent">sh:not</a> : sh:Shape</div>
<div><a href="#PropertyConstraintComponent">sh:property</a> : sh:PropertyShape</div>
</div>
</div>
</div>
<div class="diagram-class" style="float: left; width: 480px;">
<div class="diagram-class-name"><a href="#property-shapes">sh:PropertyShape</a></div>
<div class="diagram-class-properties">
<div class="diagram-class-properties-start">
<div><b><a href="#constraints">Constraint parameters</a></b>, for example:</div>
<div><a href="#MinCountConstraintComponent">sh:minCount</a>, <a href="#MaxCountConstraintComponent">sh:maxCount</a> : xsd:integer</div>
<div><a href="#MinLengthConstraintComponent">sh:minLength</a>, <a href="#MaxLengthConstraintComponent">sh:maxLength</a> : xsd:integer</div>
<div><a href="#ClassConstraintComponent">sh:class</a>, <a href="#DatatypeConstraintComponent">sh:datatype</a> : rdfs:Resource or rdf:List of rdfs:Resources</div>
<div><a href="#NodeConstraintComponent">sh:node</a> : sh:NodeShape</div>
</div>
<div class="diagram-class-properties-section">
<div><a href="#name">sh:name</a> : xsd:string or rdf:dirLangString or rdf:langString</div>
<div><a href="#description">sh:description</a> : text</div>
<div><a href="#syntax-rule-path-defaultValue">sh:defaultValue</a> : any</div>
<div><a href="#syntax-rule-path-defaultValue">sh:values</a> : any</div>
<div><a href="#group">sh:group</a> : sh:PropertyGroup</div>
</div>
<div class="diagram-class-properties-section">
<div><a href="#property-shapes">sh:path</a> : rdfs:Resource</div>
</div>
</div>
</div>
<div style="clear: both"></div>
</div>
<p>
The <a href="http://www.w3.org/ns/shacl.ttl">Turtle serialization of the SHACL vocabulary</a> contains the complete SHACL vocabulary.
</p>
</div>
<section id="shapes">
<h3>Shapes</h3>
<div class="syntax" data-syntax-rule="shape">
A <dfn data-lt="shape|shapes">shape</dfn> is an <a>IRI</a> or <a>blank node</a> <code>s</code>
that fulfills at least one of the following conditions in the <a>shapes graph</a>:
<ul>
<li>
<code>s</code> is a <a>SHACL instance</a> of <code>sh:NodeShape</code> or <code>sh:PropertyShape</code>.
</li>
<li>
<code>s</code> is <a>subject</a> of a triple that has <code>sh:targetClass</code>, <code>sh:targetNode</code>,
<code>sh:targetObjectsOf</code> or <code>sh:targetSubjectsOf</code> as <a>predicate</a>.
</li>
<li>
<code>s</code> is <a>subject</a> of a triple that has a <a>parameter</a> as <a>predicate</a>.
</li>
<li>
<code>s</code> is a <a>value</a> of a <a>shape-expecting</a>, non-<a>list-taking</a> <a>parameter</a> such as <code>sh:node</code>,
or a <a>member</a> of a <a>SHACL list</a> that is a <a>value</a> of a <a>shape-expecting</a> and <a>list-taking</a> parameter such as <code>sh:or</code>.
</li>
</ul>
</div>
<p>
Note that the definition above does not include all of the syntax rules of <a>well-formed</a> shapes.
Those are found throughout the document and summarized in Appendix <a href="#syntax-rules"></a>.
For example, shapes that have <a>literals</a> as values for <code>sh:targetClass</code> are <a>ill-formed</a>.
</p>
<p>
Informally, a shape determines how to validate a <a>focus node</a> based on the <a>values</a> of properties and other characteristics of the focus node.
For example, shapes can declare the condition that a focus node be an IRI or that a focus node has a particular value for a property and also a minimum number of values for the property.
</p>
<p>
The SHACL Core language defines two types of shapes:
</p>
<ul>
<li>shapes about the <a>focus node</a> itself, called <a>node shapes</a></li>
<li>shapes about the <a>values</a> of a particular property or path for the focus node, called <a>property shapes</a></li>
</ul>
<p>
<code>sh:Shape</code> is the <a>SHACL superclass</a> of those two shape types in the SHACL vocabulary.
Its subclasses <code>sh:NodeShape</code> and <code>sh:PropertyShape</code> can be used as SHACL type of node and property shapes, respectively.
</p>
<section id="constraints">
<h3>Constraints, Parameters and Constraint Components</h3>
<p>
Shapes can declare <a>constraints</a> using the <a>parameters</a> of <a>constraint components</a>.
</p>
<p>
A <dfn data-lt="constraint component|constraint components|components|component">constraint component</dfn> is an <a>IRI</a>.
Each constraint component has one or more <dfn data-lt="mandatory parameter">mandatory parameters</dfn>, each of which is a property.
Each constraint component has zero or more <dfn data-lt="optional parameter">optional parameters</dfn>, each of which is a property.
The <dfn data-lt="parameter">parameters</dfn> of a constraint component are its mandatory parameters plus its optional parameters.
</p>
<p>
For example, the <a>component</a> <code>sh:MinCountConstraintComponent</code> declares the <a>parameter</a> <code>sh:minCount</code> to represent the restriction
that a <a>node</a> has at least a minimum number of <a>values</a> for a particular property.
</p>
<p>
For a <a>constraint component</a> <code>C</code> with <a>mandatory parameters</a> <code>p1</code>, ... <code>pn</code>,
a <a>shape</a> <code>s</code> in a <a>shapes graph</a> <code>SG</code> <em>declares</em> a <dfn>constraint</dfn>
that has <dfn>kind</dfn> <code>C</code> with <a>mandatory parameter</a> <a>values</a> <code><p1,v1></code>, ... <code><pn,vn></code>
in <code>SG</code> when <code>s</code> has <code>vi</code> as a <a>value</a> for <code>pi</code> in <code>SG</code>.
For constraint components with <a>optional parameters</a>, the constraint declaration consists of the <a>values</a> that the shape has for all mandatory and optional parameters of that component.
</p>