-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathindex.html
5949 lines (5284 loc) · 358 KB
/
index.html
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 lang="en">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width"/>
<title>Shape Expressions Language 2.next</title>
<!-- link rel="stylesheet" href="css/wgio.min.css"/ ask Iovka -->
<link rel="stylesheet" href="local.css"/>
<style>
/* overloads for IEEE */
:is(h2,h3,h4,h5,h6):not(#toch2)+a.self-link {
display: none !important;
}
h1, h2, h3 {
color: #000 !important;
}
</style>
<script src='respec-ieee.js' defer class='remove'></script>
<!-- <script src='../../ericprud/respec-ieee/profiles/ieee.js' type="module" class='remove'></script> -->
<!-- script src='../primer/respec-w3c-common.js' async class='remove'></script -->
<script src="jquery-2.1.4.min.js" type="text/javascript"></script>
<script class='remove'>
var respecConfig = {
"varDesignation": "3330",
"varDraftNumber": "3",
"GorRPorSTD": "RP",
"varTitlePAR": "Standard for Shape Expression Schemas",
"varCommittee": "C/SABSC - Standards Activities Board Standards Committee ",
"varSociety": "The Computer Society",
"varApprovedDate": "12-03-2022",
"scope": "This standard defines the syntax of Shape Expression schemas represented in JavaScript Object Notation (JSON), Resource Description Framework (RDF) and plain text. This standard includes formal semantics for validation of RDF knowledge graphs using Shape Expressions. This validation process includes the definition of ShapeMaps to associate nodes in RDF graphs with labeled Shape Expressions. A test suite covers all aspects of syntax and validation.",
"github": {
"repoURL": "https://github.com/shexSpec/spec/",
"branch": "main",
},
"localBiblio": {
"shex-vocab": {
"authors": [
"Gregg Kellogg"
],
"title": "Shape Expression Vocabulary",
"href": "http://www.w3.org/ns/shex#",
"id": "shex-vocab"
},
"shape-map": {
"authors": [
"Eric Prud'hommeaux",
"Thomas Baker"
],
"title": "ShapeMap Structure and Language",
"href": "http://shex.io/shape-map/",
"id": "shape-map"
}
},
"specStatus": "CG-FINAL",
"shortName": "shex-semantics",
"latestVersion": "http://shex.io/shex-semantics/",
"prevVersion": "http://shex.io/shex-semantics-20170713",
"edDraftURI": "https://shexspec.github.io/spec/",
"previousPublishDate": "2014-06-02",
"previousMaturity": "Member-SUBM",
"testSuiteURI": "https://github.com/shexSpec/shexTest",
"DISABLED_implementationReportURI": "https://shexspec.github.io/shexTest/reports/#ShEx-validation-tests",
"DISABLED_issueBase": "https://github.com/shexSpec/shex/issues",
"editors": [
{
"name": "Eric Prud'hommeaux",
"url": "http://www.w3.org/People/Eric/",
"company": "W3C/MIT",
"companyURL": "http://www.w3.org/"
},
{
"name": "Iovka Boneva",
"url": "http://cristal.univ-lille.fr/~boneva/",
"company": "University of Lille",
"companyURL": "http://www.univ-lille1.fr/"
},
{
"name": "Jose Emilio Labra Gayo",
"url": "http://di002.edv.uniovi.es/~labra/",
"company": "University of Oviedo",
"companyURL": "http://www.uniovi.es/"
},
{
"name": "Katherine Thornton",
"url": "https://github.com/emulatingkat",
},
],
"formerEditors": [
{
"name": "Gregg Kellogg",
"url": "http://greggkellogg.net/",
"company": "Spec-Ops",
"companyURL": "https://spec-ops.io/",
"w3cid": "44770"
},
],
"wg": "Shape Expressions Community Group",
"wgURI": "https://www.w3.org/community/shex/",
"otherLinks": [
{
"key": "ShEx language",
"data": [
{
"value": "Homepage",
"href": "https://shex.io/"
},
{
"value": "Gitter chat",
"href": "https://gitter.im/shapeExpressions/Lobby"
}
]
}
],
"publishISODate": "2019-07-31T00:00:00.000Z",
"generatedSubtitle": "Final Community Group Report 9 August 2019",
specStatus: "ED",
};
</script>
<script src="./shex-parser-browserify.js"></script>
<script type="text/javascript" src="scripts.js"></script>
</head>
<body>
<section id="abstract">
<p>
The Shape Expressions (ShEx) language describes <a>RDF nodes</a> and <a>graph</a> structures.
A <span class="math">node constraint</span> describes an RDF node (<a>IRI</a>, <a>blank node</a> or <a>literal</a>) and a <span class="math">shape</span> describes the <a>triples</a> involving nodes in an <a>RDF graph</a>.
These descriptions identify <a data-lt="predicate">predicates</a> and their associated cardinalities and datatypes.
ShEx shapes can be used to communicate data structures associated with some process or interface, generate or validate data, or drive user interfaces.
</p>
<p>
This document defines the ShEx language.
See the <a href="../primer/index.html">Shape Expressions Primer</a> for a non-normative description of ShEx.
</p>
</section>
<section id="keywords">
<p>
RDF, Schema, Shape Expressions, Structure Definition, Structural Validation
</p>
</section>
<section id="sotd">
<p>
This is an editor's draft of the Shape Expressions specification.
ShEx 2.x differs significantly from the W3C ShEx Submission.
The <a href="http://shex.io/shex-semantics-20170713/">July 2017 publication</a> included a <a href="#validation">definition of validation</a> which implied infinite recursion.
This version explicitly includes recursion checks.
No tests changed as a result of this and no implementations or applications are known to have been affected.
</p>
<p>
If you wish to make comments regarding this document, please raise them as GitHub issues.
There are separate interfaces for <a href="https://github.com/shexSpec/spec/issues">specification</a>, <a href="https://github.com/shexSpec/shex/issues">language</a> and <a href="https://github.com/shexSpec/shexTest/issues">test</a> issues.
Only send comments to <a href="mailto:[email protected]">[email protected]</a> (<a href="mailto:[email protected]?subject=subscribe">subscribe</a>,
<a href="https://lists.w3.org/Archives/Public/public-shex/">archives</a>) if you are unable to raise issues on GitHub. All comments are welcome.
</p>
</section>
<section id="conformance">
<h2>Conformance</h2>
<p>Conformance criteria are relevant to authors and authoring tool implementers. As well
as sections marked as non-normative, all authoring guidelines, diagrams, examples,
and notes in this specification are non-normative. Everything else in this
specification is normative.</p>
<p>
All ShEx documents MUST conform to the <a href="#schema-requirements" class="sectionRef">Schema Requirements</a>.
Additional constraints for the specific types of ShEx documents (<a>ShExC</a>, <a>ShExJ</a>, and <a>ShExR</a>) follow:
</p>
<ul>
<li>A <a>ShExC</a> document is a UTF-8 document which conforms to the grammar described in <a href="#shexc" class="sectionRef"></a> resulting in a valid <a>ShExJ</a> document.</li>
<li>A <a>ShExJ</a> document is a valid JSON-LD document [[!JSON-LD]], and conforms to the <a>ShExJ</a> syntax, as described in <a href="#shexj" class="sectionRef"></a>.</li>
<li>JSON documents can be interpreted as <a>ShExJ</a> by following the normative statements in <a data-cite="JSON-LD#interpreting-json-as-json-ld">Section 4.8 Interpreting JSON as JSON-LD</a> in [[!JSON-LD]].</li>
A <a>ShExR</a> RDF document complies with this specification if it conforms to the schema in <a href="#shexr" class="sectionRef">ShExR.shex</a>.
</ul>
</section>
<section id="introduction">
<h2>Introduction</h2>
<p>
The Shape Expressions (<dfn>ShEx</dfn>) language provides a structural schema for RDF data.
This can be used to document APIs or datasets, aid in development of API-conformant messages, minimize defensive programming, guide user interfaces, or anything else that involves a machine-readable description of data organization and typing requirements.
</p>
<p>
ShEx describes <a>RDF graph</a> [[RDF11-CONCEPTS]] structures as sets of potentially connected <a data-lt="shape">Shapes</a>.
These constrain the <a>triples</a> involving nodes in an <a>RDF graph</a>.
<code>Node Constraints</code> constrain RDF nodes by constraining their node kind (<a>IRI</a>, <a>blank node</a> or <a>Literal</a>), enumerating permissible values in value sets, specifying their datatype, and constraining value ranges of Literals.
Additionally, they constrain lexical forms of <a>Literals</a>, <a>IRIs</a> and <a>labeled blank nodes</a>.
Shape Expressions schemas share blank nodes with the constrained <a>RDF graphs</a> in the same way that graphs in <a data-cite="rdf11-concepts#dfn-rdf-dataset">RDF datasets</a> [[!rdf11-concepts]] share blank nodes.
</p>
<p>
ShEx can be represented in JSON structures (<a>ShExJ</a>) or a compact syntax (<a>ShExC</a>).
The compact syntax is intended for human consumption; the JSON structure for machine processing.
This document defines ShEx in terms of <a>ShExJ</a> and includes a <a href="#shexc">section on the ShEx Compact Syntax (ShEx)</a>.
</p>
</section>
<section id="defn-acro-abbrs">
<h2>Definitions, Acronyms, and Abbreviations</h2>
<section id="definitions">
<h3>Definitions</h3>
<p>Shape expressions are defined using terms from RDF semantics [[!rdf11-mt]]:</p>
<ul>
<li><dfn data-cite="rdf11-concepts#dfn-node" data-lt="nodes|rdf node|rdf nodes">Node</dfn>: one of <dfn data-cite="rdf11-concepts#dfn-iri" data-lt="iris">IRI</dfn>, <dfn data-cite="rdf11-concepts#dfn-blank-node" data-lt="bnodes|blank nodes">blank node</dfn>, <dfn data-cite="rdf11-concepts#dfn-literal" data-lt="literal|literals|RDF Literal|RDF Literals">Literal</dfn></li>
<li><dfn data-cite="rdf11-concepts#dfn-rdf-graph" data-lt="RDF Graph|RDF Graphs">Graph</dfn>: a set of <dfn data-cite="rdf11-concepts#dfn-rdf-triple" data-lt="triple|rdf triple|rdf triples">Triples</dfn> of (<dfn data-cite="rdf11-concepts#dfn-subject">subject</dfn>, <dfn data-cite="rdf11-concepts#dfn-predicate">predicate</dfn>, <dfn data-cite="rdf11-concepts#dfn-object">object</dfn>)</li>
</ul>
<p>
The following functions access the elements of an <a>RDF graph</a> <span class="math">G</span> containing a node <span class="math">n</span>:</p>
<ul>
<li>
<span class="math"><dfn>arcsOut</dfn>(G, n)</span> is the set of <a>triples</a> in a <a>graph</a> <span class="math">G</span> with <a>subject</a> <span class="math">n</span>.
</li>
<li>
<span class="math"><dfn>predicatesOut</dfn>(G, n)</span> is the set of <a data-lt="predicate">predicates</a> in <span class="math"><a>arcsOut</a>(G, n)</span>.
</li>
<li>
<span class="math"><dfn>arcsIn</dfn>(G, n)</span> is the set of <a>triples</a> in a <a>graph</a> <span class="math">G</span> with <a>object</a> <span class="math">n</span>.
</li>
<li>
<span class="math"><dfn>predicatesIn</dfn>(G, n)</span> is the set of <a data-lt="predicate">predicates</a> in <span class="math"><a>arcsIn</a>(G, n)</span>.
</li>
<li>
<span class="math"><dfn>neigh</dfn>(G, n)</span> is the neighbourhood of the <a>node</a> <span class="math">n</span> in the <a>graph</a> <span class="math">G</span>.<br/><span class="math"><a>neigh</a>(G, n) = <a>arcsOut</a>(G, n) ∪ <a>arcsIn</a>(G, n)</span>.
</li>
<li>
<span class="math"><dfn>predicates</dfn>(G, n)</span> is the set of <a data-lt="predicate">predicates</a> in <span class="math"><a>neigh</a>(G, n)</span>.<br/><span class="math"><a>predicates</a>(G, n) = <a>predicatesOut</a>(G, n) ∪ <a>predicatesIn</a>(G, n)</span>.
</li>
<li>
<span class="math"><dfn>def</dfn>(Sch, label)</span> is the <span class="math">decl</span>.<span class="param">shapeExpr</span> where <span class="math">decl</span>.<span class="param">label</span> = <code>label</code>. <code>Sch</code> must have exactly one <code>def(Sch, label)</code>.
</li>
</ul>
<div class="example">
<p>
Consider the <a>RDF graph</a> <span class="math">G</span> represented in Turtle:
</p>
<pre class="data">
PREFIX ex: http://schema.example/#
PREFIX inst: http://inst.example/#
PREFIX foaf: http://xmlns.com/foaf/
PREFIX xsd: http://www.w3.org/2001/XMLSchema#
inst:Issue1
ex:state ex:unassigned ;
ex:reportedBy _:User2 .
_:User2
foaf:name "Bob Smith" ;
foaf:mbox <mailto:[email protected]> .
</pre>
<p>
There are two arcs out of <span class="pre">_:User2</span>; <span class="math"><a>arcsOut</a>(G, <span class="pre">_:User2</span>)</span>:
</p>
<pre class="data">
_:User2 foaf:name "Bob Smith" .
_:User2 foaf:mbox <mailto:[email protected]> .
</pre>
<p>
There is one arc into <span class="pre">_:User2</span>; <span class="math"><a>arcsIn</a>(G, <span class="pre">_:User2</span>)</span>:
</p>
<pre class="data">
inst:Issue1 ex:reportedBy _:User2 .
</pre>
<p>
There are three arcs in the neighbourhood of <span class="pre">_:User2</span> set, <span class="math"><a>neigh</a>(G, <span class="pre">_:User2</span>)</span>:
</p>
<pre class="data">
_:User2 foaf:name "Bob Smith" .
_:User2 foaf:mbox <mailto:[email protected]> .
inst:Issue1 ex:reportedBy _:User2 .
</pre>
</div>
</section>
<section id="Acronyms and abbreviations">
<h3>Acronyms And Abbreviations</h3>
<table id="acronyms" class="bare">
<tbody>
<tr><td>BNF</td> <td>Backus Naur Form</td></tr>
<tr><td>CSS</td> <td>Cascading Stylesheets</td></tr>
<tr><td>IANA</td> <td>Internet Assigned Numbers Authority</td></tr>
<tr><td>IRI</td> <td>Internationalized Resource Identifier</td></tr>
<tr><td>RDF</td> <td>Resource Description Framework</td></tr>
<tr><td>ShEx</td> <td>Shape Expressions RDF schema language</td></tr>
<tr><td>ShExC</td> <td>ShEx Compact syntax</td></tr>
<tr><td>ShExJ</td> <td>ShEx JSON (or JSON-LD) syntax</td></tr>
<tr><td>ShExR</td> <td>ShEx RDF syntax</td></tr>
<tr><td>SPARQL</td> <td>RDF Query Language</td></tr>
<tr><td>URL</td> <td>Uniform Resource Locator</td></tr>
<tr><td>UTF-8</td> <td>Unicode Transformation Format</td></tr>
<tr><td>XML</td> <td>Extensible Markup Language</td></tr>
<tr><td>XPath</td> <td>Path Language for XML</td></tr>
</tbody>
</table>
</section>
</section>
<section id="notation">
<h2>Notation</h2>
<p>
The JSON [[!rfc7159]] Syntax serves as a serializable proxy for an abstract syntax.
</p>
<p>
<a data-cite="rdf11-concepts/#dfn-rdf-term">RDF terms</a> are represented as <a data-cite="json-ld#dfn-node">JSON-LD nodes</a>.
<ul>
<li><a>IRIs</a> are represented as a <a data-cite="rfc7159#section-7">JSON string</a> consisting of the IRI string, e.g. <br/><code class="json">"http://example.org/resource"</code></li>
<li><a>Blank nodes</a> are represented as a JSON string composed of the concatenation of "<code>_:</code>" and a <dfn data-cite="rdf11-concepts#dfn-blank-node-identifier" data-lt="blank node identifiers|labeled blank nodes">blank node identifier</dfn>, e.g. <br/><code class="json">"_:blank3"</code></li>
<li><a>Literals</a> are represented as a <a>JSON object</a>s following the composition rules for <a data-cite="json-ld/#dfn-json-ld-value">JSON-LD values</a>, i.e.
<ul>
<li>literals with the datatype <code>http://www.w3.org/2001/XMLSchema#string</code> are represented with the <span class="param">value</span> property, e.g. <br/><code class="json">{ "value": "abc" }</code>.</li>
<li><a>language-tagged strings</a> are represented with an additional <span class="param">language</span> property, e.g. <br/><code class="json">{ "value": "hello world", "langague": "en-US" }</code></li>
<li>datatyped literals are represented with an additional <span class="param">datatype</span> property, e.g. <br/><code class="json">{ "value": "123", "datatype": "http://www.w3.org/2001/XMLSchema#integer" }</code></li>
</ul></li>
</ul>
</p>
<section id="json-grammar">
<h3>JSON Grammar</h3>
<p>
This specification uses a <dfn>JSON grammar</dfn> to describe the set of JSON documents that can be interpreted as a ShEx schema.
ShEx data structures are represented as <dfn data-cite="rfc7159#section-4" data-lt="json object">JSON objects</dfn> with a member with the name "<code>type</code>" (i.e. an object with a <span class="param">type</span> attribute):
</p>
<div class="json">
<pre class="json nohighlight">{ "type": "typeName", member<sub>0…n</sub> }</pre>
</div>
<p>
These are expressed in JSON grammar as <span class="shexj">typeName { member* }</span>.
<a data-cite="rfc7159#section-2">RFC7159 Section 2</a> provides syntactic constraints for JSON — the grammar constraining those to valid <a>ShExJ</a> constructs is composed of:
</p>
<ul>
<li><code>typeName</code> is the name of the typed data structure.
Types are referenced in the definitions of object members and in the definitions of the semantics for those data structures.</li>
<li><code>member*</code> is a list of zero or more terminals or references to other typeExpressions.</li>
<li>A <code>typeExpression</code> is one of:
<ul>
<li><code>typeName</code> — an object of corresponding type</li>
<li><code>array</code>: <span class="shexj">[ typeExpression+ ]</span>— an array of one or more JSON values matching the typeExpression.</li>
<li><code>choice</code>: <span class="shexj">typeExpression1 | typeExpression2 | …</span>— a choice between two or more typeExressions.</li>
</ul>
</li>
<li>Cardinalities are represented as by the strings <code>?</code>, <code>+</code>, <code>*</code> following the <a data-cite="XML#sec-notation">notation in the XML specification</a>[[!XML]] or <code>{m,}</code> to indicate a that at least <code>m</code> elements are required.</li>
</ul>
<p>
The following examples are excerpts from the definitions below.
In the JSON notation,
</p>
<div class="shexj simupre"><a class="obj">Schema</a> { <a class="param">startActs</a>:[<a class="objref">SemAct</a>+]? <a class="param">start</a>:<a class="nobref">shapeExpr</a>? <a class="param">imports</a>:[<a>IRI</a>+]? <a class="param">shapes</a>:[<a class="nobref">shapeExpr</a>+]? }</div>
<p>
signifies that a <code>Schema</code> has four optional components called <a class="param">startActs</a>, <a class="param">start</a>, <a class="param">imports</a> and <a class="param">shapes</a>:
</p>
<ul>
<li><span class="param">startActs</span> is a list of one or more <a class="objref">SemAct</a>.</li>
<li><span class="param">start</span> is a <a class="objref">shapeExpr</a>.</li>
<li><span class="param">imports</span> is a list of one or more <a class="objref">IRI</a>.</li>
<li><span class="param">shapes</span> is an array of <a class="nobref">shapeExpr</a>.</li>
</ul>
<div class="shexj simupre"><a class="nob">shapeExpr</a> = <a class="objref">ShapeOr</a> | <a class="objref">ShapeAnd</a> | <a class="objref">ShapeNot</a>
| <a class="objref">NodeConstraint</a> | <a class="objref">Shape</a> | <a class="objref">ShapeExternal</a> ;</div>
<p>
signifies that a <a>shapeExpr</a> is one of seven object types: <a class="objref .shexj">ShapeOr</a> | <a class="objref">ShapeAnd</a> | ….
</p>
<div class="shexj simupre"><a class="obj">NodeConstraint</a> { <span class="param">nodeKind</span>:(<span class="literal">"iri"</span> | <span class="literal">"bnode"</span> | <span class="literal">"nonliteral"</span> | <span class="literal">"literal"</span>)? <a class="nobref">xsFacet</a>* }
<a class="nob">xsFacet</a> = <a class="nobref">stringFacet</a> | <a class="nobref">numericFacet</a> ;</div>
<p>
signifies that a <code>NodeConstraint</code> has a <code class="param">nodeKind</code> of one of the four literals followed by any number of <a class="objref .shexj">xsFacet</a> and an <a class="objref .shexj">xsFacet</a> is either a <a class="objref .shexj">stringFacet</a> or a <a class="objref .shexj">numericFacet</a>.
</p>
<p class="note">
The <a href="https://github.com/shexSpec/shexTest/blob/main/doc/ShExJ.jsg#L11">executable JSON grammar for ShExJ</a> specifically disables the requirement for a matching <code>"type"</code> attribute in <code>ObjectLiteral</code> as <code>"type"</code> is instead used for the datatype of a <a href="https://www.w3.org/TR/json-ld11/#dfn-typed-value">JSON-LD typed value</a>.
</p>
</section>
<section id="shex-references">
<h3>References</h3>
<p>
<a>ShExJ</a> is a dialect of JSON-LD [[!JSON-LD]] and the member <dfn class="param">id</dfn> is used as a <a data-cite="JSON-LD#node-identifiers">node identifier</a>.
An ShapeDecl or tripleExpr may be represented inline or referenced by its <span class="param">id</span> which may be either a <a>blank node</a> or an <a>IRI</a>.
</p>
<div class="shexj simupre"><a class="obj">ShapeOr</a> { <a class="param">id</a>:<a class="nobjref">shapeExprLabel</a>? <a class="param">shapeExprs</a>:[<a class="nobjref">shapeExpr</a>{2,}] }
<a class="nob">shapeExprLabel</a> = <a class="nobref">IRIREF</a> | <a class="objref">BNODE</a> ;
<a class="obj">EachOf</a> { <a class="param">id</a>:<a class="nobjref">tripleExprLabel</a>? <a class="param">expressions</a>:[<a class="nobjref">tripleExpr</a>{2,}] ... }
<a class="nob">tripleExprLabel</a> = <a>IRI</a> | <a>BNODE</a> ;</div>
<p>
The JSON structure may include references to <a data-lt="shape">shape expressions</a> and <a>triple expressions</a>:
</p>
<div class="shexj simupre"><a class="obj">shapeExpr</a> = <a class="objref">ShapeOr</a> | ... | <a class="nobjref">shapeExprRef</a> ;
<a class="nob">shapeExprRef</a> = <a class="nobjref">shapeExprLabel</a> ;
<a class="nobjref">tripleExpr</a> = <a class="objref">EachOf</a> | ... | <a class="nobjref">tripleExprRef</a> ;
<a class="nob">tripleExprRef</a> = <a class="objref">tripleExprLabel</a> ;</div>
<p>
An object with a circular reference must be referenced by an <span class="param">id</span>.
This example uses a nested shape reference on a value expression (<a data-lt="TripleConstraint">defined below</a>).
</p>
<div class="json">
<pre class="json nohighlight">{ "type": "Schema", "shapes": [
{ "id": "<span class="lookit">http://schema.example/#IssueShape</span>",
"type": "Shape", "expression": {
"type": "TripleConstraint", "predicate": "http://schema.example/#related",
"valueExpr": "<span class="lookit">http://schema.example/#IssueShape</span>", "min": 0 } } ] }</pre>
</div>
<p>
Not captured in this JSON syntax definition is the rule that every <a class="nobjref">shapeExpr</a> nested in a schema's <a class="param">shapes</a> must have an <span class="param">id</span> and no other <a class="nobjref">shapeExpr</a> may have an <span class="param">id</span>.
The JSON syntax definitition simplifies this by adding <span style="border: thin solid #888888; background-color: #F8F8F0;"><a class="param">id</a>:<a class="nobjref">shapeExprLabel</a>?</span> to every <a class="nobjref">shapeExpr</a>.
This example includes a nested shape. Nested shapes are not permitted to have <span class="param">ids</span>.
</p>
<div class="json">
<pre class="json nohighlight">{ "type": "Schema", "shapes": [
{ "id": "http://schema.example/#IssueShape",
"type": "Shape", "expression": {
"type": "TripleConstraint", "predicate": "http://schema.example/#submittedBy",
"valueExpr": {
"type": "Shape", "expression": {
"type": "TripleConstraint", "predicate": "http://schema.example/#name",
"valueExpr": {
"type": "NodeConstraint", "nodeKind": "literal"
} } } } } ] }</pre>
</div>
</section>
<section id="style">
<h3>Document style</h3>
<p>
JSON examples are rendered in a <span class="json">.json</span> CSS style.
Partial examples include ranges in a <span class="comment">.comment</span> CSS style to indicate text which would be substituted in a complete example.
For example <span class="json">{ "type": "ShapeAnd", "shapeExprs": [ <span class="comment">SE<sub>1</sub></span>, <span class="comment">…</span> ] }</span> indicates that both <span class="comment">SE<sub>1</sub></span> and <span class="comment">…</span> would be substituted in a complete example.
</p>
<p>
In javascript-enabled browsers, schemas with a <button class="show-repchoice">json</button> button can be converted between the JSON representation and the compact syntax by clicking the button.
The button text indicates the currently shown representation.
Selecting the example and pressing "j" or "c" converts the example to the JSON (ShExJ) or compact form (ShExC).
Pressing "shift J" or "shift C" converts all such examples to ShExJ or ShExC.
</p>
<!--div class="issue">
<p id="json-triples">
When stable, consider switching to the rdfjs task force's <a href="https://github.com/rdfjs/representation-task-force/blob/master/interface-spec.md#term">JSON representation</a> i.e.
</p>
<ul>
<li>IRI: <code class="json">{ "termType": "NamedNode", "value": "http://example.org/resource" }</code></li>
<li>blank node: <code class="json">{ "termType": "BlankNode", "value": "blank3" }</code></li>
<li>literal:
<ul>
<li>literal with type <code>http://www.w3.org/2001/XMLSchema#</code>: <code class="json">{ "termType": "Literal", "value": "abc" }</code></li>
<li><a>language-tagged string</a>: <code class="json">{ "termType": "Literal", "value": "hello world", "language": "en-us", "datatype": "http://www.w3.org/1999/02/22-rdf-syntax-ns#langString" }</code></li>
<li>datatyped literal: <code class="json">{ "termType": "Literal", "value": "123", "language": "", "datatype": "http://www.w3.org/1999/02/22-rdf-syntax-ns#integer" }</code></li>
</ul></li>
</ul>
</div-->
</section>
<section id="graphAccess">
<h3>Graph access</h3>
<p>
The validation process defined in this document relies on matching <a>triple patterns</a> in the form <code>(subject, predicate, object)</code> where each position may be supplied by a constant, a previously defined term, or the underscore "<code>_</code>", which represents a previously undefined element or wildcard.
This corresponds to a <dfn data-cite="sparql11-query#defn_TriplePattern" data-lt="triple pattern|triple patterns">SPARQL Triple Pattern</dfn> where each "_" is replaced by a unique <a>blank node</a>.
Matching such a <a>triple pattern</a> against a <a>graph</a> is defined by <a data-cite="sparql11-query#BGPsparql">SPARQL Basic Graph Pattern Matching</a> (BGP) with a BGP containing only that <a>triple pattern</a>.
</p>
</section>
<!-- button id="toggleRDF">Toggle RDF ("r")</button> <button id="toggleExamples">Toggle Examples ("e")</button> <button id="toggleSquished">Render only abstract syntax ("a")</button -->
<section id="namespaces">
<h3>Namespaces</h3>
<p>This specification makes use of the following namespaces:</p>
<dl>
<dt><code>foaf</code>:</dt>
<dd><code>http://xmlns.com/foaf/0.1/</code></dd>
<dt><code>rdf</code>:</dt>
<dd><code>http://www.w3.org/1999/02/22-rdf-syntax-ns#</code></dd>
<dt><code>rdfs</code>:</dt>
<dd><code>http://www.w3.org/2000/01/rdf-schema#</code></dd>
<dt><code>shex</code>:</dt>
<dd><code>http://www.w3.org/ns/shex#</code></dd>
<dt><code>xsd</code>:</dt>
<dd><code>http://www.w3.org/2001/XMLSchema#</code></dd>
</dl>
</section>
<!-- <p> -->
<!-- The following HTML tags and CSS classes are used to highlight the roles of text in this document: -->
<!-- </p> -->
<!-- <ul> -->
<!-- <li><dfn><dfn data-lt="dfn-shacl-defined-term">defined term</dfn><dfn></li> -->
<!-- <li><a class="internalDFN"><a title="SHACL defined term" class="internalDFN">defined term</a></a></li> -->
<!-- <li><sup class="eval">eval</sup> — link to evaluation semantics</li> -->
<!-- </ul> -->
</section>
<section id="shapes-language">
<h2>The Shape Expressions Language</h2>
<p>
A Shape Expressions (ShEx) schema is a collection of labeled <a data-lt="shape">Shapes</a> and <a href="#node-constraints">Node Constraints</a>.
These can be used to describe or test nodes in <a>RDF graphs</a>.
ShEx does not prescribe a language for associating <a>nodes</a> with <a data-lt="shape">shapes</a> but several approaches are <a href="../primer/index.html#associating-nodes-with-shapes">described in the ShEx Primer</a>.
</p>
<section id="shapes-schema">
<h3>Shapes Schema</h3>
<p>
A shapes schema is captured in a <span class="jobjref"><dfn data-lt="shapes schema">Schema</dfn></span> object with a list of <span class="jobjref"><dfn data-lt="ShapeDecl">Shape Declarationss</dfn></span>:
</p>
<div class="shexjTable">
<table class="shexj">
<tr class="obj"><th class="obj"><a>Schema</a></th><td>{</td><td><dfn class="param">imports</dfn>:[<a>IRIREF</a>+]? <dfn class="param">startActs</dfn>:[<a class="objref">SemAct</a>+]? <dfn class="param">start</dfn>:<a class="nobref">shapeExpr</a>? <dfn class="param">shapes</dfn>:[<a class="objref">ShapeDecl</a>+]? }</td></tr>
<tr class="obj"><th class="obj"><a>ShapeDecl</a></th><td>{</td><td> <span class="param">id</span>:<a class="nobref">shapeExprLabel</a> <span class="param">abstract</span>:<a class="nobref">BOOL</a>? <span class="param">shapeExpr</span>:<a class="nobref">shapeExpr</a> | <a class="objref">ShapeExternal</a> }</td></tr>
</table>
</div>
<p>
where <a class="param">shapes</a> is a list of <a>ShapeDecls</a>.
</p>
<div class="repchoice incomplete">
<pre class="json nohighlight">{ "type": "Schema", "shapes": [
{ "id": "http://schema.example/#IssueShape", <span class="comment">…</span> },
{ "id": "_:UserShape", <span class="comment">…</span> },
{ "id": "http://schema.example/#EmployeeShape", <span class="comment">…</span> } ] }</pre>
<pre class="shexc nohighlight">
ex:IssueShape { … }
_:UserShape { … }
ex:EmployeeShape { … }
</pre>
</div>
</section>
<section id="validation">
<h3>Validation Definition</h3>
<p>
For a graph <span class="math">G</span>, a schema <span class="math">Sch</span> and a fixed ShapeMap <span class="math">ism</span>, <code class="function"><dfn>isValid</dfn>(<span class="math">G</span>, <span class="math">Sch</span>, <span class="math">ism</span>)</code> indicates that for every shape association <span class="math">(<span class="param">node</span>: n, <span class="param">shape</span>: sl, <span class="param">exact</span>: exact)</span> in <span class="math">ism</span>, the node <span class="math">n</span> satisfies the shape expression identified by <span class="math">sl</span>.
If <span class="param">exact</span> is true, the result is
<code class="function"><a>satisfies</a>(<span class="math">n</span>, <a>def</a>(<span class="math">s.label</span>), <span class="math">G</span>, <span class="math">Sch</span>, <a>completeTyping</a>(<span class="math">G</span>, <span class="math">Sch</span>), <span class="math">neigh(n)</span>)</code>
, otherwise, the result is
<code class="function"><a>satisfiesDescendant</a>(<span class="math">n</span>, <a>def</a>(<span class="math">s.label</span>), <span class="math">G</span>, <span class="math">Sch</span>, <a>completeTyping</a>(<span class="math">G</span>, <span class="math">Sch</span>)</code>, <span class="math">neigh(n)</span>).
The function <code class="function"><a>satisfies</a></code> is defined for every kind of <a>shape expression</a>.
</p>
<p>
The validation of an RDF graph <span class="math">G</span> against a ShEx schema <span class="math">Sch</span> is based on the existence of <code class="function"><a>completeTyping</a>(<span class="math">G</span>, <span class="math">Sch</span>)</code>.
For an RDF graph <span class="math">G</span> and a shapes schema <span class="math">Sch</span>, a <dfn>typing</dfn> is a set of pairs of the form <span class="math">(n, l)</span> where <span class="math">n</span> is a node in <span class="math">G</span> and <span class="math">l</span> is a shape label that appears in the shape declarations of the schema.
A <dfn label="correct typing">correct typing</dfn> is a <span class="math">typing</span> such that for every RDF node/shape pair <span class="math">(n,l)</span>, satisfies(n, def(l), G, Sch, typing, neigh(n)) holds or satisfiesDescendant(n, def(l), G, Sch, typing, neigh(n)) holds.
A <code class="function"><a>completeTyping</a>(<span class="math">G</span>, <span class="math">Sch</span>)</code> is a unique correct typing that exists for every graph and every ShEx schema that satisfies the <a href="#schema-requirements">schema requirements</a>.
</p>
<p>
The definition of <code class="function"><dfn>completeTyping</dfn>(<span class="math">G</span>, <span class="math">Sch</span>)</code> is based on a <a>stratification</a> of <span class="math">Sch</span>.
The number of <dfn>strata</dfn> of <span class="math">Sch</span> is the number of maximal strongly connected components of the <a>hierarchy and dependency graph</a> of <span class="math">Sch</span>.
A <dfn>stratification</dfn> of a schema <span class="math">Sch</span> with <span class="math">k</span> strata is a function <code class="function">stratum</code> that associates with every shape label from the shape declarations of <span class="math">Sch</span> a natural number between <span class="math">1</span> and <span class="math">k</span> such that:
</p>
<ul>
<li>
If <span class="math">l1</span> and <span class="math">l2</span> belong to the same maximal strongly connected component, then <code class="function">stratum(<span class="math">l1</span>)</code> = <code class="function">stratum(<span class="math">l2</span>)</code>.
</li>
<li>
If there is a <a>reference</a> from <span class="math">l1</span> to <span class="math">l2</span> and <span class="math">l1</span> and <span class="math">l2</span> do not belong to the same maximal strongly connected component, then <code class="function">stratum(<span class="math">s2</span>)</code> < <code class="function">stratum(<span class="math">s1</span>)</code>.
</li>
</ul>
<p>
The existence of a stratification for every schema is guaranteed by the <a href="#negation-requirement">negation requirement</a>.
</p>
<p>
Given a <a>stratification</a> <code class="function">stratum</code> of <span class="math">Sch</span> with <span class="math">k</span> strata, define inductively the series of <span class="math">k</span> typings <code class="function">completeTypingOn(<span class="math">1</span>, <span class="math">G</span>, <span class="math">Sch</span>)</code> … <code class="function">completeTypingOn(<span class="math">k</span>, <span class="math">G</span>, <span class="math">Sch</span>)</code>.
</p>
<ul>
<li>
<code class="function">completeTypingOn(<span class="math">1</span>, <span class="math">G</span>, <span class="math">Sch</span>)</code> is the union of all correct typings that contain only RDF node/shape pairs <span class="math">(n,s)</span> with <code class="function">stratum(<span class="math">s</span>)</code> = <span class="math">1</span>;
</li>
<li>
for every <span class="math">i</span> between <span class="math">2</span> and <span class="math">k</span>, <code class="function">completeTypingOn(<span class="math">i</span>, <span class="math">G</span>, <span class="math">Sch</span>)</code> is the union of all correct typings that:
<ul>
<li> contain only RDF node/shape pairs <span class="math">(n,s)</span> with <code class="function">stratum(<span class="math">s</span>)</code> ≤ <span class="math">i</span>
</li>
<li> are equal to <code class="function">completeTypingOn(<span class="math">i</span>-1, <span class="math">G</span>, <span class="math">Sch</span>)</code> when restricted to their RDF node/shape pairs <span class="math">(n1,s1)</span> for which <code class="function">stratum(<span class="math">s1</span>)</code> < i.
</li>
</ul>
</li>
</ul>
<p>
Then <code class="function">completeTyping(<span class="math">G</span>, <span class="math">Sch</span>)</code> = <code class="function">completeTypingOn(<span class="math">k</span>, <span class="math">G</span>, <span class="math">Sch</span>)</code>.
</p>
<div class="note">
The definition of strongly connected component and maximal strongly connected component of a graph can be found at Wikipedia: <a href="https://en.wikipedia.org/wiki/Strongly_connected_component">https://en.wikipedia.org/wiki/Strongly_connected_component</a>.
</div>
<div class="note">
<p>
The schema <span class="math">Sch</span> might have several different stratifications but <code class="function">completeTyping(<span class="math">G</span>, <span class="math">Sch</span>)</code> is the same for all these stratifications.
This property is reminiscent of the use of stratified negation in Datalog.
</p>
<p>
In order to decide <code class="function"><a>isValid</a>(<span class="math">Sch</span>, <span class="math">G</span>, <span class="math">m</span>)</code>, it is sufficient to compute only a portion of the complete typing using an appropriate algorithm.
</p>
</div>
<div class="note">
<p>
Popular methods for constructing the input fixed ShapeMaps can be found at <a href="https://www.w3.org/2001/sw/wiki/ShEx/ShapeMap">https://www.w3.org/2001/sw/wiki/ShEx/ShapeMap</a>.
</p>
</div>
<!--
<div class="note">
<p>
Validation of a <a>graph</a> <span class="math">G</span> does not necessarily require the construction of a <a>ShapeMap</a> with every node in <span class="math">G</span>.
The validation semantics defined below imply a set of dependencies for validating some node as a shape.
A validation process that tests every <a>node</a> in a <a>graph</a> against every <a>shape</a> in a <a>schema</a> can be considered to have an input <a>ShapeMap</a> associating each node with the set of all shapes in the schema.
</p>
</div>
<p>
Validation of a node against a shape in a schema requires that there is a consistent mapping from node to <!-\- @@set of -\-> shape for every node and shape visited during a validation process.
The remainder of this document uses <span class="math">m</span> to indicate such a mapping.
</p>
-->
</section>
<section id="shape-expressions">
<h3>Shape Expressions</h3>
<p>
A <dfn data-lt="shape expressions">shape expression</dfn> is composed of four kinds of objects combined with the algebraic operators `And`, `Or` and `Not`:
</p>
<ul>
<li>
A node constraint (<span class="jobjref"><a>NodeConstraint</a></span>) defines the set of allowed values of a node.
These include specification of RDF node kind, literal datatype, XML string and numeric facets and enumeration of value sets.
</li>
<li>
A shape constraint (<span class="jobjref"><a>Shape</a></span>) defines a constraint on the allowed neighbourhood of a node, that is, the allowed triples that contain this node as subject or object.
</li>
<li>
An external shape (<span class="jobjref"><a>ShapeExternal</a></span>) is an extension mechanism allowing a <span class="jobjref"><a>ShapeDecl</a></span> to denote an externally defined <span class="jobjref"><a>shapeExpr</a></span>. <span class="note">It can be used to reference e.g. functional shapes or prohibitively large value sets.</span>
</li>
<li>
A shape reference (<span class="jobjref"><a>shapeExprLabel</a></span>) identifies another shape in the schema or an <a href="#import">imported schema</a>.
</li>
</ul>
<section id="shape-expressions-shexj">
<h4>JSON Syntax</h4>
<div class="shexjTable">
<table class="shexj">
<tr class="nob"><th class="nob"><dfn>shapeExpr</dfn></th> <td>=</td> <td><a class="objref">ShapeOr</a> | <a class="objref">ShapeAnd</a> | <a class="objref">ShapeNot</a> | <a class="objref">NodeConstraint</a> | <a class="objref">Shape</a> | <a class="objref">shapeExprRef</a> ;</td></tr>
<tr class="obj"><th class="obj"><dfn>ShapeOr</dfn></th> <td>{</td> <td><dfn class="param">shapeExprs</dfn>:[<a class="nobref">shapeExpr</a>{2,}] }</td></tr>
<tr class="obj"><th class="obj"><dfn>ShapeAnd</dfn></th> <td>{</td> <td><span class="param">shapeExprs</span>:[<a class="nobref">shapeExpr</a>{2,}] }</td></tr>
<tr class="obj"><th class="obj"><dfn>ShapeNot</dfn></th> <td>{</td> <td><span class="param">shapeExpr</span>:<a class="nobref">shapeExpr</a> }</td></tr>
<tr class="obj"><th class="obj"><dfn>ShapeExternal</dfn></th> <td>{</td> <td>}</td></tr>
<tr class="nob"><th class="nob"><dfn>ShapeExprRef</dfn></th> <td>{</td> <td><span class="param">label</span>:<span class="nobref">shapeExprLabel</a> <span class="param">exact</span>:<a>BOOL</a>? }</td></tr>
<tr class="nob"><th class="nob"><dfn>shapeExprLabel</dfn></th> <td>=</td> <td><a>IRIREF</a> | <a>BNODE</a> ;</td></tr>
</table>
</div>
<div class="example">
<p>
Examples of shape expressions:
</p>
<div class="repchoice incomplete">
<pre class="json nohighlight">{ "type": "Shape", <span class="comment">…</span> } </pre>
<pre class="shexc nohighlight">{ <span class="comment">…</span> } </pre>
</div>
<div style="clear:both;"> </div>
<div class="repchoice incomplete">
<pre class="json nohighlight">{ "type": "ShapeAnd", "shapeExprs": [
{ "type": "NodeConstraint", "nodeKind": "iri" },
{ "type": "ShapeOr", "shapeExprs": [
"http://schema.example/#IssueShape",
{ "type": "ShapeNot", "shapeExpr": { "type": "Shape", <span class="comment">…</span> } }
] } ] }</pre>
<pre class="shexc nohighlight">
<span class="keyword">IRI</span> AND
(
@<http://schema.example/#IssueShape>
OR NOT { <span class="comment">…</span> }
)</pre>
</div>
<p>
In this ShapeOr's <span class="param">shapeExprs</span>, "http://schema.example/#IssueShape" is a reference to the <a>shape expression</a> with the id "http://schema.example/#IssueShape".
</p>
</div>
</section>
<section id="shape-expression-semantics">
<h4>Semantics</h4>
<p>
For a node n of the graph G, we define <dfn>neigh</dfn>(n) as the set of triples adjacent to n in the graph; these are the triples that have n either as subject or as object.
</p>
<p>
For a shape expression <span class="var">se</span> we define its set of shapes <dfn>nestedShapes</dfn><span class="math">(<span class="param">se</span>)</span> recursively on the structure of <span class="var">se</span>:
</p>
<ul>
<li>if <span class="var">se</span> is a <span class="jobjref"><a class="obj">NodeConstraint</a></span>, then <span class="math"><a>nestedShapes</a>(<span class="var">se</span>) = emptyset</span></li>
<li>if <span class="var">se</span> is a <span class="jobjref"><a class="obj">Shape</a></span>, then <span class="math"><a>nestedShapes</a>(<span class="var">se</span>) = {se}</span></li>
<li>if <span class="var">se</span> is a <span class="jobjref"><a class="obj">ShapeNot</a></span>, then <span class="math"><a>nestedShapes</a>(<span class="var">se</span>) = shapes(se.shapeExpr)</span></li>
<li>if <span class="var">se</span> is a <span class="jobjref"><a class="obj">ShapeAnd</a></span> or <span class="jobjref"><a class="obj">ShapeOr</a></span>, then <span class="math"><a>nestedShapes</a>(<span class="var">se</span>)</span> is the union of the sets <span class="math"><a>nestedShapes</a>(<span class="var">se2</span>)</span> for all <span class="var">se2</span> in <span class="param">se.shapeExprs</span></li>
<li>if <span class="var">se</span> is a <span class="jobjref"><a class="obj">shapeExprRef</a></span> with label <span class="var">lab</span>, then <span class="math"><a>nestedShapes</a>(<span class="var">se</span>) = <a>nestedShapes</a>(<a>def</a>(<span class="var">L</span>))</span></li>
<li>if <span class="var">se</span> is a <span class="jobjref"><a class="obj">ShapeExternal</a></span>, then <span class="math"><a>nestedShapes</a>(<span class="var">se</span>)</span> is the set of shapes denoted by <span class="var">se</span>. </li>
</ul>
<p>
For shape expression labels <span class="var">label1</span>, <span class="var">label2</span>, we say that <span class="var">label2</span> <dfn>directly extends</dfn> <span class="var">label1</span> if <span class="math"><a>nestedShapes</a>(<a>def</a>(<span class="var">label2</span>))<span class="math"> contains a Shape <span class="var">s</span> such that <span class="param">s.extends</span> contains <span class="var">label2</span>.
The <dfn>extension hierarchy graph</dfn> of a shapes schema is a directed graph whose nodes are the shape expression labels of the schema and that has an edge from <span class="var">label2</span> to <span class="var">label1</span> whenever <span class="var">label2</span> <a>directly extends</a> <span class="var">label1</span>.
</p>
<p>
<dfn>satisfies</dfn>: The expression <code class="function">satisfies(<span class="math">n</span>, <span class="math">se</span>, <span class="math">G</span>, <span class="math">Sch</span>, <span class="math">t</span>, <span class="math">R</span>)</code> indicates that a node <span class="math">n</span>, a subset <span class="math">R</span> of <span class="math">neigh(n)</span>, and a <a>graph</a> <span class="math">G</span> satisfy a <a>shape expression</a> <span class="math">se</span> with <a>typing</a> <span class="math">t</span> for schema <span class="math">Sch</span>.<br/>
<dfn>satisfiesDescendant</dfn>: The expression <code class="function">satisfiesDescendant(<span class="math">n</span>, <span class="var">shapeExprLabel</span>, <span class="math">G</span>, <span class="math">Sch</span>, <span class="math">t</span>, <span class="math">R</span>)</code> indicates that <span class="math">n</span>, a subset <span class="math">R</span> of <span class="math">neigh(n)</span>, and <span class="math">G</span> and some non-abstract <span class="var">child</span> of <span class="var">shapeExprLabel</span> in the <a>extension hierarchy graph</a> <code class="function"><a>satisfies</a>(<span class="math">n</span>, <span class="var">child</span>, <span class="math">G</span>, <span class="math">Sch</span>, <span class="math">t</span>, <span class="math">R</span>)</code>, with the given <a>typing</a> <span class="math">t</span>.
</p>
<p>
<code class="function"><a>satisfies</a>(<span class="math">n</span>, <span class="math">se</span>, <span class="math">G</span>, <span class="math">Sch</span>, <span class="math">t</span>, <span class="math">R</span>)</code> is true if and only if:
</p>
<ul>
<li id="satisfies-NodeConstraint"><span class="math">se</span> is a <span class="jobjref"><a class="obj">NodeConstraint</a></span> and <code class="function"><a href="#satisfies2-NodeConstraint">satisfies2</a>(<span class="math">n</span>, <span class="math">se</span>)</code> as described below in <a href="#node-constraints">Node Constraints</a>.
Note that testing if a node satisfies a node constraint does not require a <a>graph</a> or <a>typing</a>.</li>
<li id="satisfies-Shape-proxy"><span class="math">se</span> is a <span class="jobjref"><a class="obj">Shape</a></span> and <code class="function"><a>matchesShape</a>(<span class="math">n</span>, <span class="math">S</span>, <span class="math">G</span>, <span class="math">Sch</span>, <span class="math">m</span>, <span class="math">R</span>)</code> is true.
</li>
<li id="satisfies-ShapeOr"><span class="math">se</span> is a <span class="jobjref"><a class="obj">ShapeOr</a></span> and there is some <a>shape expression</a> <span class="math">se2</span> in <span class="math">se</span>.<span class="param">shapeExprs</span> such that <code class="function"><a>satisfies</a>(<span class="math">n</span>, <span class="math">se2</span>, <span class="math">G</span>, <span class="math">Sch</span>, <span class="math">t</span>, <span class="math">R</span>)</code>.</li>
<li id="satisfies-ShapeAnd"><span class="math">se</span> is a <span class="jobjref"><a class="obj">ShapeAnd</a></span> and for every <a>shape expression</a> <span class="math">se2</span> in <span class="math">se</span>.<span class="param">shapeExprs</span>, <code class="function"><a>satisfies</a>(<span class="math">n</span>, <span class="math">se2</span>, <span class="math">G</span>, <span class="math">Sch</span>, <span class="math">t</span>, <span class="math">R</span>)</code>.</li>
<li id="satisfies-ShapeNot"><span class="math">se</span> is a <span class="jobjref"><a class="obj">ShapeNot</a></span> and for the <a>shape expression</a> <span class="math">se2</span> at <span class="math">se</span>.<span class="param">shapeExpr</span>, <code class="function"><a>satisfies</a>(<span class="math">n</span>, <span class="math">se2</span>, <span class="math">G</span>, <span class="math">Sch</span>, <span class="math">t</span>, <span class="math">R</span>)</code> is false.</li>
<li id="satisfies-ShapeExternal"><span class="math">se</span> is a <span class="jobjref"><a class="obj">ShapeExternal</a></span> and implementation-specific mechansims not defined in this specification indicate success.</li>
<li id="satisfies-shapeExprRef"><span class="math">se</span> is a <span class="jobjref"><a class="obj">ShapeExprRef</a></span>. If <span class="param">ShapeExprRef.exact</span>, <code class="function"><a>satisfies</a>(<span class="math">n</span>, <a>def</a>(<span class="math">se.label</span>), <span class="math">G</span>, <span class="math">Sch</span>, <span class="math">t</span>, <span class="math">R</span>)</code>, otherwise <code class="function"><a>satisfiesDescendant</a>(<span class="math">n</span>, <span class="math">se.label</span>, <span class="math">G</span>, <span class="math">Sch</span>, <span class="math">t</span>, <span class="math">R</span>)</code>.
</li>
</ul>
<div class="example">
<p>
Given the three shape expressions <span class="math">SE<sub>1</sub></span>, <span class="math">SE<sub>2</sub></span>, <span class="math">SE<sub>3</sub></span> in a <span class="jobjref"><a class="obj">Schema</a></span> <span class="math">Sch</span>, such that:
</p>
<ul>
<li><code class="function"><a>satisfies</a>(<span class="math">n</span>, <span class="math">SE<sub>1</sub></span>, <span class="math">G</span>, <span class="math">Sch</span>, <span class="math">m</span>)</code></li>
<li><code class="function"><a>satisfies</a>(<span class="math">n</span>, <span class="math">SE<sub>2</sub></span>, <span class="math">G</span>, <span class="math">Sch</span>, <span class="math">m</span>)</code></li>
<li>NOT <code class="function"><a>satisfies</a>(<span class="math">n</span>, <span class="math">SE<sub>3</sub></span>, <span class="math">G</span>, <span class="math">Sch</span>, <span class="math">m</span>)</code></li>
</ul>
<p>
the following hold:
</p>
<ul class="codelist">
<li><div><div style="float:left;" class="code function">satisfies(</div><div style="float:left;" class="code"><span class="math">n</span>,<br/><div class="inline json"><pre>{ "type": "ShapeAnd", "shapeExprs": [ <span class="comment">SE<sub>1</sub></span>, <span class="comment">SE<sub>2</sub></span> ] }</pre></div>,<br/> <span class="math">G</span>, <span class="math">Sch</span>, <span class="math">m</span>)</div><div style="clear:both;"></div></div></li>
<li><div><div style="float:left;" class="code function">satisfies(</div><div style="float:left;" class="code"><span class="math">n</span>,<br/><div class="inline json"><pre>{ "type": "ShapeOr", "shapeExprs": [ <span class="comment">SE<sub>1</sub></span>, <span class="comment">SE<sub>2</sub></span>, <span class="comment">SE<sub>3</sub></span> ] }</pre></div>,<br/> <span class="math">G</span>, <span class="math">Sch</span>, <span class="math">m</span>)</div><div style="clear:both;"></div></div></li>
<li><div>NOT <div style="float:left;" class="code function">satisfies(</div><div style="float:left;" class="code"><span class="math">n</span>,<br/><div class="inline json code"><pre>{ "type": "ShapeNot", "shapeExpr": {
{ "type": "ShapeOr", "shapeExprs": [
<span class="comment">SE<sub>1</sub></span>,
{ "type": "ShapeAnd", "shapeExprs": [ <span class="comment">SE<sub>2</sub></span>, <span class="comment">SE<sub>3</sub></span> ] }
] }
} }</pre></div>,<br/> <span class="math">G</span>, <span class="math">Sch</span>, <span class="math">m</span>)</div><div style="clear:both;"></div></div></li>
</ul>
<p>
If <span class="math">Sch</span>'s <a class="param">shapes</a> maps "<code>http://schema.example/#shape1</code>" to <span class="math">SE<sub>1</sub></span> then the following holds:
</p>
<ul class="codelist">
<li><div><div style="float:left;" class="code function">satisfies(</div><div style="float:left;" class="code"><span class="math">n</span>,<br/><div class="inline json"><pre>http://schema.example/#shape1"</pre></div>,<br/> <span class="math">G</span>, <span class="math">Sch</span>, <span class="math">m</span>)</div><div style="clear:both;"></div></div></li>
</ul>
</div>
<div class="example">
<p>
In this example, EmployeeShape <a>directly extends</a> PersonShape and transitively extends EntityShape
</p>
<div class="repchoice">
<pre class="json nohighlight">{"type" : "Schema",
"shapes" : [ {
"id" : "http://schema.example/#EntityShape",
"type" : "Shape",
"expression" : {
"type" : "TripleConstraint",
"predicate" : "http://schema.example/#entityId"
}
}, {
"id" : "http://schema.example/#PersonShape",
"type" : "Shape",
"extends" : [ "http://schema.example/#EntityShape" ],
"expression" : {
"type" : "TripleConstraint",
"predicate" : "http://xmlns.com/foaf/0.1/name"
}
}, {
"id" : "http://schema.example/#EmployeeShape",
"type" : "Shape",
"extends" : [ "http://schema.example/#PersonShape" ],
"expression" : {
"type" : "TripleConstraint",
"predicate" : "http://schema.example/#employeeNumber"
}
} ] }</pre>
<pre class="shexc nohighlight">
ex:EntityShape {
ex:entityId .
}
ex:PersonShape EXTENDS @ex:EntityShape {
foaf:name .
}
ex:EmployeeShape EXTENDS @ex:PersonShape {
ex:employeeNumber .
}
</pre>
</div>
</div>
<div class="example">
<p>
In this example, UserShape <a>directly extends</a> PersonShape, and PersonShape directly references a conjunct which <a>directly extends</a> EntityShape. Through this, UserShape transitively extends EntityShape.
</p>
<div class="repchoice">
<pre class="json nohighlight">{ "type": "Schema",
"shapes": [
{ "id": "http://schema.example/#EntityShape",
"type": "Shape",
"closed": true,
"expression": {
"type": "TripleConstraint",
"predicate": "http://schema.example/#entityId"
} },
{ "id": "http://schema.example/#PersonShape",
"type": "ShapeAnd",
"shapeExprs": [
{ "type": "Shape",
"extends": [ "http://schema.example/#EntityShape" ],
"closed": true,
"expression": {
"type": "TripleConstraint",
"predicate": "http://xmlns.com/foaf/0.1/name"
} },
{ "type": "Shape",
"expression": {
"type": "TripleConstraint",
"predicate": "http://schema.example/#entityId",
"valueExpr": {
"type": "NodeConstraint",
"datatype": "http://www.w3.org/2001/XMLSchema#integer"
} } }
] },
{ "id": "http://schema.example/#UserShape",
"type": "Shape",
"extends": [ "http://schema.example/#PersonShape" ],
"expression": {
"type": "TripleConstraint",
"predicate": "http://schema.example/#userId"
} }
] }</pre>
<pre class="shexc nohighlight">
<#EntityShape> CLOSED {
:entityId .
}
<#PersonShape> EXTENDS @<#EntityShape> CLOSED {
foaf:name .
} AND {
:entityId
xsd:integer
}
<#UserShape> EXTENDS @<PersonShape>{
:userId .
}
</pre>
</div>
</div>
</section>
</section>
<section id="node-constraints">
<h3>Node Constraints</h3>
<div class="shexjTable">
<table class="shexj">
<tr class="obj"><th class="obj"><dfn>NodeConstraint</dfn></th> <td>{</td><td><span class="param">nodeKind</span>:(<span class="literal">"iri"</span> | <span class="literal">"bnode"</span> | <span class="literal">"nonliteral"</span> | <span class="literal">"literal"</span>)? <span class="param">datatype</span>:<a>IRIREF</a>? <a class="nobref">xsFacet</a>* <span class="param">values</span>:[<a class="nobref">valueSetValue</a>+]? }</td></tr>
<tr class="nob"><th class="nob"><dfn>xsFacet</dfn></th> <td>=</td><td><a class="nobref">stringFacet</a> | <a class="nobref">numericFacet</a> ;</td></tr>
<tr class="nob"><th class="nob"><dfn>stringFacet</dfn></th> <td>=</td><td>(<span class="param">length</span>|<span class="param">minlength</span>|<span class="param">maxlength</span>):<a>INTEGER</a> | <span class="param">pattern</span>:<a>STRING</a> <span class="param">flags</span>:<a>STRING</a>? ;</td></tr>
<tr class="nob"><th class="nob"><dfn>numericFacet</dfn></th> <td>=</td><td>(<span class="param">mininclusive</span>|<span class="param">minexclusive</span>|<span class="param">maxinclusive</span>|<span class="param">maxexclusive</span>):<a class="nobref">numericLiteral</a> </td></tr>
<tr><th></th><td>|</td><td>(<span class="param">totaldigits</span>|<span class="param">fractiondigits</span>):<a>INTEGER</a> ;</td></tr>
<tr class="nob"><th class="nob"><dfn>numericLiteral</dfn></th> <td>=</td><td><a>INTEGER</a> | <a>DECIMAL</a> | <a>DOUBLE</a> ;</td></tr>
<tr class="nob"><th class="nob"><dfn>valueSetValue</dfn></th><td>=</td><td><a class="nobref">objectValue</a> | <a class="objref">IriStem</a> | <a class="objref">IriStemRange</a> | <a class="objref">LiteralStem</a> | <a class="objref">LiteralStemRange</a> | <a class="objref">Language</a> | <a class="objref">LanguageStem</a> | <a class="objref">LanguageStemRange</a> ;</td></tr>
<tr class="nob"><th class="nob"><dfn>objectValue</dfn></th><td>=</td><td><a>IRIREF</a> | <a class="objref">ObjectLiteral</a> ;</td></tr>
<tr class="nob"><th class="nob"><dfn>ObjectLiteral</dfn></th><td>{</td><td><span class="param">value</span>:<a>STRING</a> <span class="param">language</span>:<a>STRING</a>? <span class="param">type</span>:<a>STRING</a>? }</td></tr>
<tr class="obj"><th class="obj"><dfn>IriStem</dfn></th><td>{</td><td><span class="param">stem</span>:<a>IRIREF</a> }</td></tr>
<tr class="obj"><th class="obj"><dfn>IriStemRange</dfn></th><td>{</td><td><span class="param">stem</span>:(<a>IRIREF</a> | <a class="objref">Wildcard</a>) <span class="param">exclusions</span>:[<a class="nobref">IRIREF</a>|<a class="objref">IriStem</a>+]? }</td></tr>
<tr class="obj"><th class="obj"><dfn>LiteralStem</dfn></th><td>{</td><td><span class="param">stem</span>:<a>STRING</a> }</td></tr>
<tr class="obj"><th class="obj"><dfn>LiteralStemRange</dfn></th><td>{</td><td><span class="param">stem</span>:(<a class="nobref">STRING</a> | <a class="objref">Wildcard</a>) <span class="param">exclusions</span>:[<a class="nobref">STRING</a>|<a class="objref">LiteralStem</a>+]? }</td></tr>
<tr class="obj"><th class="obj"><dfn>Language</dfn></th><td>{</td><td><span class="param">languageTag</span>:<a>LANGTAG</a> }</td></tr>
<tr class="obj"><th class="obj"><dfn>LanguageStem</dfn></th><td>{</td><td><span class="param">stem</span>:<a>LANGTAG</a> }</td></tr>
<tr class="obj"><th class="obj"><dfn>LanguageStemRange</dfn></th><td>{</td><td><span class="param">stem</span>:(<a>LANGTAG</a> | <a class="objref">Wildcard</a>) <span class="param">exclusions</span>:[<a class="nobref">LANGTAG</a>|<a class="objref">LanguageStem</a>+]? }</td></tr>
<tr class="obj"><th class="obj"><dfn>Wildcard</dfn></th> <td>{</td><td><span class="comment">/* empty */</span> }</td></tr>
</table>
</div>
<section id="node-constraint-semantics">
<h4>Semantics</h4>
<p id="satisfies2-NodeConstraint">
For a node <span class="param">n</span> and constraint <span class="param">nc</span>, <code class="function">satisfies2(<span class="math">n</span>, <span class="math">nc</span>)</code> if and only if for every <span class="param">nodeKind</span>, <span class="param">datatype</span>, <span class="param">xsFacet</span> and <span class="param">values</span> constraint value <span class="math">v</span> present in <span class="param">nc</span> <code class="function">nodeSatisfies(<span class="math">n</span>, <span class="math">v</span>)</code>.
The following sections define <code class="function">nodeSatisfies</code> for each of these types of constraints:
</p>
<ul>
<li><a href="#nodeKind">Node Kind Constraints</a></li>
<li><a href="#datatype">Datatype Constraints</a></li>
<li><a href="#xs-string">XML Schema String Facet Constraints</a></li>
<li><a href="#xs-numeric">XML Schema Numeric Facet Constraints</a></li>
<li><a href="#values">Values Constraints</a></li>
</ul>
</section>
<section id="nodeKind">
<h4>Node Kind Constraints</h4>
<p id="nodeSatisfies-nodeKind">
For a node <span class="math">n</span> and constraint value <span class="math">v</span>, <code class="function">nodeSatisfies(<span class="math">n</span>, <span class="math">v</span>)</code> if:
</p>
<ul>
<li><span class="math">v</span> = "iri" and <span class="math">n</span> is an <a>IRI</a>.</li>
<li><span class="math">v</span> = "bnode" and <span class="math">n</span> is a <a>blank node</a>.</li>
<li><span class="math">v</span> = "literal" and <span class="math">n</span> is a <a>Literal</a>.</li>
<li><span class="math">v</span> = "nonliteral" and <span class="math">n</span> is an <a>IRI</a> or <a>blank node</a>.</li>
</ul>
<div class="example">
<div class="example-title marker"><span>Node Kind example 1</span></div>
<p>
The following examples use a <span class="jobjref"><a>TripleConstraint</a></span> object described later in the document.
The
</p>
<div class="repchoice">
<pre class="json nohighlight">{ "type": "Schema", "shapes": [
{ "id": "http://schema.example/#IssueShape",
"type": "Shape", "expression": {
"type": "TripleConstraint", "predicate": "http://schema.example/#state",
"valueExpr": { "type": "NodeConstraint", "nodeKind": "iri" } } } ] }</pre>
<pre class="shexc nohighlight">
ex:IssueShape {
ex:state IRI
}
</pre>
</div>
<pre class="data">
<issue1> ex:state ex:HunkyDory .
<issue2> <span style="border-bottom: thin solid red;">ex:taste</span> ex:GoodEnough .
<span class="fail"><issue3> ex:state "just fine" .</span></pre>
<table>
<tr><th class="data">node</th><th class="schema">shape</th><th>result</th><th>reason</th></tr>
<tr class="pass"><td><issue1></td><td><IssueShape></td><td>pass</td><td class="noreason"></td></tr>
<tr class="fail"><td><issue2></td><td><IssueShape></td><td>fail</td><td class="fail">expected 1 <code>ex:state</code> property.</td></tr>
<tr class="fail"><td><issue3></td><td><IssueShape></td><td>fail</td><td class="fail"><code>ex:state</code> expected to be an IRI, literal found.</td></tr>
</table>
<p>
Note that <issue2> <span class="fail">fails</span> not because of a nodeKind violation but instead because of a <a href="#matches-cardinality">Cardinality</a> violation described below.
</p>
</div>
</section>
<section id="datatype">
<h4>Datatype Constraints</h4>
<p id="nodeSatisfies-datatype">
For a node <span class="math">n</span> and constraint value <span class="math">v</span>, <code class="function">nodeSatisfies(<span class="math">n</span>, <span class="math">v</span>)</code> if <span class="math">n</span> is a Literal with the datatype <span class="math">v</span> and, if <span class="math">v</span> is in the set of <a data-cite="sparql11-query#operandDataTypes">SPARQL operand data types</a>[[!sparql11-query]], an XML schema string with a value of the lexical form of <span class="math">n</span> can be cast to the target type <span class="math">v</span> per <a data-cite="xpath-functions-31#casting">XPath Functions 3.1 section 19 Casting</a>[[!xpath-functions]].
The lexical form and numeric value (where applicable) of all datatypes required by <a data-cite="sparql11-query#FunctionMapping">SPARQL XPath Constructor Functions</a> MUST be tested for conformance with the corresponding XML Schema form.
ShEx extensions MAY add support for other datatypes.
</p>
<div class="example">
<div class="example-title marker"><span>Datatype example 1</span></div>