forked from shexSpec/primer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
3656 lines (3479 loc) · 241 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>
<title>Shape Expressions (ShEx) Primer</title>
<meta charset='utf-8'/>
<!-- <script src='https://www.w3.org/Tools/respec/respec-w3c-common' -->
<!-- async="async" class='remove'></script> -->
<script src='https://www.w3.org/Tools/respec/respec-w3c-common'
async="async" class='remove'></script>
<link rel="stylesheet" href="local.css"/>
<script class='remove'>
var respecConfig = {
localBiblio: {
"shex-semantics": {
"authors": ["Eric Prud'hommeaux", "Iovka Boneva", "Jose Labra Gayo", "Gregg Kellogg"],
"title": "Shape Expressions Language 2.0",
"href": "http://shex.io/shex-semantics/"
}
},
specStatus: "CG-DRAFT",
shortName: "shex-primer",
latestVersion: "http://shex.io/shex-primer/",
thisVersion: "http://shex.io/shex-primer-20170713",
prevVersion: "http://shex.io/shex-primer-20170327",
edDraftURI: "https://shexspec.github.io/primer/",
editors: [
{ name: "Thomas Baker",
company: "Dublin Core Metadata Initiative",
companyURL: "http://dublincore.org/" },
{ name: "Eric Prud′hommeaux",
url: "http://www.w3.org/People/Eric/",
company: "W3C/MIT",
companyURL: "http://www.w3.org/" }
],
wg: "Shape Expressions Community Group",
wgURI: "https://www.w3.org/community/shex/",
wgPublicList: "public-shex"
};
</script>
<script src="jquery.min.js" type= "text/javascript"></script>
<script type="text/javascript"><!--
function prepareHighlight (highlightables, onClass, offClass, slide) {
if (slide === undefined)
slide = $("body .namespace").last();
$.each( highlightables, function( index, value ){
var elts = slide.find( "."+value );
elts
.mouseenter(function() {
elts.removeClass(offClass).addClass(onClass);
})
.mouseleave(function() {
elts.removeClass(onClass).addClass(offClass);
})
.addClass(offClass);
})
}
--> </script>
</head>
<body>
<section id="abstract">
<p>
Shape Expressions (ShEx) is a language for describing RDF graph structures.
A ShEx schema prescribes conditions that RDF data graphs must meet in order to be considered "conformant": which subjects, predicates, and objects may appear in a given graph, in what combinations and with what cardinalities and datatypes.
In the ShEx model, an RDF graph is tested against a ShEx schema to yield a validation result that flags any parts of the data which do not conform.
ShEx schemas are intended for use in validating RDF data, communicating interface parameters and data structures, generating user interfaces, and transforming RDF graphs into other data formats and structures.
This primer introduces ShEx by means of annotated examples.
Readers should already be familiar with the basic concepts of RDF.
The primer is a companion to the full ShEx language specification [[shex-semantics]].
</p>
</section>
<section id="sotd">
<p>This version of the document represents a Candidate Release, with stable features. Comments and implementations are solicited prior to an eventual Final 2.0 Release.</p>
<p>The Shape Expressions language is expected to remain stable with the exception of:</p>
<ul>
<li>addition of a UNIQUE function</li>
</ul>
</section>
<section id="quickStart">
<h2>Quick Start</h2>
<div class="namespace">
<p>
Shape Expressions (ShEx) is a language for describing RDF graph structures.
A <span class="new">ShEx schema</span> prescribes conditions that RDF data graphs must meet in order to be considered "conformant".
In the ShEx model, a <span class="new">shape map</span> specifies which nodes in an RDF graph will be tested against a ShEx schema.
ShEx schemas are intended for use in validating instance data, communicating interface parameters and data structures, generating user interfaces, and transforming RDF graphs into other data formats and structures.
This primer, a companion to the full ShEx language specification [[shex-semantics]], focuses on the common use case of validating instance data.
</p>
<p>
A ShEx schema is built on <span class="new">node constraints</span> and <span class="new">triple constraints</span> that define what it means for a given RDF data graph to conform.
An RDF triple is the three-part data structure of subject, predicate, and object with which all RDF data is expressed, and an RDF node is the piece of data found in the subject or object position of a triple.
(Readers unfamiliar these terms may want to consult an RDF primer.[[rdf11-primer]])
Node constraints and triple constraints are called "constraints" because they define, or "constrain", the set of RDF nodes and data triples that will pass a conformance test.
</p>
<p>
Picture an RDF database (graph) that carries information about enrollees in a school.
Put yourself into the position of a data manager who wants to ensure that every student "record" in this graph reports a valid age and references one or two guardians, identified by IRI.
The ShEx schema for accomplishing this has: one <span class="lookit">node constraint</span>, <span class="shape-name">school:enrolleeAge</span>, for matching data nodes with an integer value between 13 and 20; one <span class="lookit">triple constraint</span>, defined within the shape <span class="shape-name">school:Enrollee</span>, for matching one or two triples having the predicate <span class="predicate"><span class="type">ex:</span><span class="constant">hasGuardian</span></span>, and a second <span class="lookit">node constraint</span> for specifying that the object (value) of the triple is an IRI.
Data that conforms to these constraints will pass validation tests, and data that does not conform will fail.
</p>
<div id="example-school-enrolleeAge" class="example wrapper">
<pre class="nohighlight schema shexc"><span class="keyword">PREFIX</span> <span class="type">school:</span> <span class="fullURL"><http://school.example/#></span>
<span class="keyword">PREFIX</span> <span class="type">xsd:</span> <span class="fullURL"><http://www.w3.org/2001/XMLSchema#></span>
<span class="keyword">PREFIX</span> <span class="type">ex:</span> <span class="fullURL"><http://ex.example/#></span>
<span class="comment"># <span class="object new lookit">Node constraint</span></span>
<span class="shape-name">school:enrolleeAge</span> <span class="object"><span class="type">xsd:</span><span class="constant">integer</span> <span class="keyword">MinInclusive</span> 13 <span class="keyword">MaxInclusive</span> 20</span>
<span class="shape-name">school:Enrollee</span> {
<span class="comment"># <span class="object new lookit">Triple constraint</span> (including <span class="object new lookit">node constraint</span> <span class="keyword">IRI</span>)</span>
<span class="predicate"><span class="type">ex:</span><span class="constant">hasGuardian</span></span> <span class="object"><span class="keyword">IRI</span> {1,2}</span>
}
</pre>
<!-- JSON example -->
<pre class="nohighlight schema json">
{ "@context": "http://www.w3.org/ns/shex.jsonld",
"type": "Schema",
"shapes": [
{ "id": "http://school.example/#enrolleeAge",
"type": "NodeConstraint",
"datatype": "http://www.w3.org/2001/XMLSchema#integer",
"mininclusive": 13, "maxinclusive": 20 },
{ "id": "http://school.example/#Enrollee",
"type": "Shape",
"expression": {
"type": "TripleConstraint", "min": 1, "max": 2,
"predicate": "http://ex.example/#hasGuardian",
"valueExpr": {
"type": "NodeConstraint",
"nodeKind": "iri" } } }
] }
</pre>
<pre class="nohighlight instance turtle pass tryable">
<span class="keyword">PREFIX</span> <span class="type">ex:</span> <span class="fullURL"><http://ex.example/#></span>
<span class="keyword">PREFIX</span> <span class="type">inst:</span> <span class="fullURL"><http://example.com/users/></span>
<span class="fullURL">inst:Student1</span> <span class="predicate"><span class="type">ex:</span><span class="constant">hasGuardian</span></span>
<span class="fullURL object">inst:Person2</span>, <span class="fullURL object">inst:Person3</span> .
<a class="tryit" href="" data-shape-map="inst:Student1@<http://school.example/#Enrollee>">try it</a></pre>
<pre class="nohighlight instance turtle fail tryable">
<span class="keyword">PREFIX</span> <span class="type">ex:</span> <span class="fullURL"><http://ex.example/#></span>
<span class="keyword">PREFIX</span> <span class="type">inst:</span> <span class="fullURL"><http://example.com/users/></span>
<span class="fullURL">inst:Student2</span> <span class="predicate"><span class="type">ex:</span><span class="constant">hasGuardian</span></span>
<span class="fullURL object">inst:Person4</span>, <span class="fullURL object">inst:Person5</span>, <span class="fullURL object">inst:Person6</span> .
<a class="tryit" href="" data-shape-map="inst:Student2@<http://school.example/#Enrollee>">try it</a></pre>
</div>
<p>
The next example adds a triple constraint on the data predicate <span class="predicate"><span class="type">foaf:</span><span class="constant">age</span></span>, which must have a value matching the node constraint <span class="shape-name">school:enrolleeAge</span>, which is cited in the triple constraint by reference, indicated by the '@' symbol.
</p>
<div id="simple-expressions-example-1" class="example wrapper">
<!-- ShExC example -->
<pre class="nohighlight schema shexc" id="school-Enrollee1" style="float:left;">
<span class="keyword">PREFIX</span> <span class="type">ex:</span> <span class="fullURL"><http://ex.example/#></span>
<span class="keyword">PREFIX</span> <span class="type">xsd:</span> <span class="fullURL"><http://www.w3.org/2001/XMLSchema#></span>
<span class="keyword">PREFIX</span> <span class="type">school:</span> <span class="fullURL"><http://school.example/#></span>
<span class="keyword">PREFIX</span> <span class="type">foaf:</span> <span class="fullURL"><http://xmlns.com/foaf/0.1/></span>
<span class="shape-name">school:enrolleeAge</span> <span class="type">xsd:</span><span class="constant">integer</span> <span class="keyword">MinInclusive</span> 13 <span class="keyword">MaxInclusive</span> 20
<span class="shape-name">school:Enrollee</span> {
<span class="predicate"><span class="type">foaf:</span><span class="constant">age</span></span> <span class="object">@<span class="shape-name">school:enrolleeAge</span></span> ;
<span class="predicate"><span class="type">ex:</span><span class="constant">hasGuardian</span></span> <span class="object"><span class="keyword">IRI</span> {1,2}</span>
}
</pre>
<!-- JSON example -->
<pre class="nohighlight schema json">
{ "@context": "http://www.w3.org/ns/shex.jsonld",
"type": "Schema",
"shapes": [
{ "id": "http://school.example/#enrolleeAge",
"type": "NodeConstraint",
"datatype": "http://www.w3.org/2001/XMLSchema#integer",
"mininclusive": 13, "maxinclusive": 20 },
{ "id": "http://school.example/#Enrollee",
"type": "Shape",
"expression": {
"type": "EachOf",
"expressions": [
{ "type": "TripleConstraint",
"predicate": "http://xmlns.com/foaf/0.1/age",
"valueExpr": "http://school.example/#enrolleeAge" },
{ "type": "TripleConstraint", "min": 1, "max": 2,
"predicate": "http://ex.example/#hasGuardian",
"valueExpr": {
"type": "NodeConstraint",
"nodeKind": "iri" } }
] } }
] }
</pre>
<pre class="nohighlight instance turtle pass tryable">
<span class="keyword">PREFIX</span> <span class="type">ex:</span> <span class="fullURL"><http://ex.example/#></span>
<span class="keyword">PREFIX</span> <span class="type">inst:</span> <span class="fullURL"><http://example.com/users/></span>
<span class="keyword">PREFIX</span> <span class="type">school:</span> <span class="fullURL"><http://school.example/#></span>
<span class="keyword">PREFIX</span> <span class="type">foaf:</span> <span class="fullURL"><http://xmlns.com/foaf/0.1/></span>
<span class="alice lowlight1 top"><span class="fullURL">inst:Alice</span> <span class="predicate"><span class="type">foaf:</span><span class="constant">age</span></span> <span class="object">13</span> ; </span>
<span class="alice lowlight1 bot"> <span class="predicate"><span class="type">ex:</span><span class="constant">hasGuardian</span></span> <span class="fullURL object">inst:Person2</span>, <span class="fullURL object">inst:Person3</span> .</span>
<span class="bob lowlight1 top"><span class="fullURL">inst:Bob</span> <span class="predicate"><span class="type">foaf:</span><span class="constant">age</span></span> <span class="object">15</span> ; </span>
<span class="bob lowlight1 bot"> <span class="predicate"><span class="type">ex:</span><span class="constant">hasGuardian</span></span> <span class="fullURL object">inst:Person4</span> . </span>
<a class="tryit" href="" data-shape-map="inst:Alice@<http://school.example/#Enrollee>,inst:Bob@<http://school.example/#Enrollee>">try it</a></pre>
<pre class="nohighlight instance turtle fail tryable">
<span class="keyword">PREFIX</span> <span class="type">ex:</span> <span class="fullURL"><http://ex.example/#></span>
<span class="keyword">PREFIX</span> <span class="type">inst:</span> <span class="fullURL"><http://example.com/users/></span>
<span class="keyword">PREFIX</span> <span class="type">school:</span> <span class="fullURL"><http://school.example/#></span>
<span class="keyword">PREFIX</span> <span class="type">foaf:</span> <span class="fullURL"><http://xmlns.com/foaf/0.1/></span>
<span class="claire lowlight1 top"><span class="fullURL">inst:Claire</span> <span class="predicate"><span class="type">foaf:</span><span class="constant">age</span></span> <span class="object">12</span> ; </span>
<span class="claire lowlight1 bot"> <span class="predicate"><span class="type">ex:</span><span class="constant">hasGuardian</span></span> <span class="fullURL object">inst:Person5</span> . </span>
<span class="don lowlight1 top bot"><span class="fullURL">inst:Don</span> <span class="predicate"><span class="type">foaf:</span><span class="constant">age</span></span> <span class="object">14</span> . </span>
<a class="tryit" href="" data-shape-map="inst:Claire@<http://school.example/#Enrollee>,inst:Don@<http://school.example/#Enrollee>">try it</a></pre>
</div>
<div style="clear:both;"></div>
<p class="leadup">
The four RDF data nodes <span class="fullURL">inst:Alice</span>, <span class="fullURL">inst:Bob</span>, <span class="fullURL">inst:Claire</span>, and <span class="fullURL">inst:Don</span> can be tested against the shape <a href="#schema-school-enrolleeAge" class="shape-name">school:Enrollee</a> by using either a <span class="new">fixed shape map</span>, which selects nodes by simple enumeration, or a <span class="new">query shape map</span>, which selects nodes matching a triple pattern. In the latter, the shape map keyword "<code>FOCUS</code>" identifies the node of the triple to be selected (here, the subject node), and the keyword "<code>_</code>" acts as a placeholder for any object. For readability, the IRIs are rendered here with prefixes.
</p>
<div id="example-school-enrolleeAge" class="example wrapper">
<pre class="nohighlight shapemap fixed" id="school-Enrollee-fixed-shapemap" style="float:left;">
<span class="fullURL">inst:Alice</span> @ <span class="shape-name">school:Enrollee</span>,
<span class="fullURL">inst:Bob</span> @ <span class="shape-name">school:Enrollee</span>,
<span class="fullURL">inst:Claire</span> @ <span class="shape-name">school:Enrollee</span>,
<span class="fullURL">inst:Don</span> @ <span class="shape-name">school:Enrollee</span>
</pre>
</div>
<div id="example-school-enrolleeAge" class="example wrapper" style="vertical-align: top;">
<pre class="nohighlight shapemap query" id="school-Enrollee-query-shapemap" style="float:left;">
<span class="fullURL">{FOCUS foaf:age _}</span> @ <span class="shape-name">school:Enrollee</span>
</pre>
</div>
<p class="followup">
</p>
<p>
This example yields a validation result in the form of a <span class="new">result shape map</span>. A validation result may be presented in different formats and with different levels of verbosity according to implementation requirements.
</p>
<table class="nohighlight example results">
<tbody><tr><th class="data">Node</th><th class="schema">Shape</th><th>Result</th><th>Reason</th></tr>
<tr class="pass alice top lowlight1"><td>inst:Alice </td><td>school:Enrollee</td><td>pass</td><td class="noreason"></td></tr>
<tr class="pass bob lowlight1"><td>inst:Bob </td><td>school:Enrollee</td><td>pass</td><td class="noreason"></td></tr>
<tr class="fail claire lowlight1"><td>inst:Claire</td><td>school:Enrollee</td><td>fail</td><td class="fail"><span class="predicate"><span class="type">foaf:</span><span class="constant">age</span></span> 12 less than 13.</td></tr>
<tr class="fail don bot lowlight1"><td>inst:Don </td><td>school:Enrollee</td><td>fail</td><td class="fail">No <span class="predicate"><span class="type">ex:</span><span class="constant">hasGuardian</span></span> supplied.</td></tr>
</tbody></table>
<script type="text/javascript">
<!--
prepareHighlight(["alice", "bob", "claire", "don"], "highlight1", "lowlight1");
-->
</script>
</div>
</section>
<section id="model-and-terminology">
<h2>ShEx Model and Terminology</h2>
<!--
<section id="conventions" class="introductory">
<h4>Conventions used in this Primer</h4>
<p>
@@@Most sections: ShEx Schema (in ShExC syntax by default), Passing Data, Failing Data, ?Data, Validation Result.
Most examples support highlighting: mousing over elements in a schema or data example highlights corresponding explanatory text.
@@@Use of "try it" buttons - link to rawgit.
</p>
-->
<!-- p class="note">[for editors] current switches:<br/>
(<code>j</code>)son vs. shex(<code>c</code>).
</p>
</section>
<-->
<section id="validation">
<h2>Validating RDF Data</h2>
<p>
In the Shape Expressions model, RDF data is seen from the standpoint of its structural components, or abstract syntax.
An <span class="new">RDF graph</span> is a collection of <span class="new">triples</span>.
A triple is a data structure composed of three <span class="new">RDF terms</span>.
An RDF term may be an <span class="new">IRI</span>, <span class="new">blank node (BNode)</span>, or <span class="new">literal</span>.
In a triple, RDF terms are arranged in a fixed order, or <span class="new">directed arc</span>, from <span class="new">subject</span> to <span class="new">predicate</span> to <span class="new">object</span>.
A node in the subject position has an <span class="new">outgoing arc</span> and a node in the object position has an <span class="new">incoming arc</span>.
RDF data may be serialized in any of several interchangeable concrete syntaxes designed for a variety of application requirements.
</p>
<p>
A <span class="new">ShEx schema</span> is a collection of <span class="new">shape expressions</span> that describe an RDF graph in terms of these abstract-syntactic components.
A shape expression is a logical combination of <span class="new">node constraints</span> and <span class="new">shapes</span>.
Node constraints define the characteristics of matching RDF nodes.
A shape describes a collection of RDF triples touching a given RDF node in terms of <span class="new">triple constraints</span>. Triple constraints specify matching RDF triples in terms of their predicates, direction (whether they are incoming or outgoing arcs with respect to a node), cardinality (how many triples should match), or value (characteristics of its subject or object node).
</p>
<p>
In the <span class="new">ShEx model</span>, a given RDF data graph is tested against a ShEx schema to yield a <span class="new">validation result</span>.
In the <a href="#simple-expressions-example-1">example above</a>, the RDF nodes <span class="fullURL">inst:Alice</span>, <span class="fullURL">inst:Bob</span>, <span class="fullURL">inst:Claire</span> and <span class="fullURL">inst:Don</span> are tested against the ShEx shape <a href="#schema-school-enrolleeAge" class="shape-name">school:Enrollee</a>.
In the validation process, each of four nodes in the RDF data is treated, in turn, as a <span class="new">focus node</span>, and triples involving that node are tested against a triple constraint which, in turn, includes the node constraint <span class="keyword">IRI</span>.
This validation process is controlled by a <span class="new">shape map</span> that specifies how the constructs of a ShEx schema relate to the components of RDF data graphs.
There are many ways to populate a shape map with nodes to be validated: through queries, APIs, protocols, or simple enumeration.
</p>
<p>
ShEx may be serialized using any of three interchangeable concrete syntaxes:
<a href=" https://github.com/shexSpec/grammar/blob/master/ShExDoc.g4">Shape Expressions Compact Syntax</a>
or <span class="new">ShExC</span>, a compact syntax meant for human eyes and fingers;
<span class="new">ShExJ</span>, a JSON-LD [[json-ld]] (Javascript) syntax meant for machine processing; and <span class="new">ShExR</span>, the RDF interpretation of ShExJ expressed in RDF Turtle syntax [[turtle]].
The ShEx schemas in this primer may be viewed in ShExC syntax (by default) or JSON-LD syntax by pressing 'c' or 'j' in the browser or by clicking on the following radio buttons:
</p>
<form id="langOptions" action="#"><label><input type="radio" name="presLang" value="shexc" checked="checked"/>ShExC ('c')</label> <label><input type="radio" name="presLang" value="json"/>JSON ('j')</label> .</form>
</section>
<section id="vocabulary">
<h2>Basic Terminology</h2>
<dl>
<dt id="vocab-schema">ShEx schema</dt><dd>A collection of shape expressions.</dd>
<dt id="vocab-shape-expression">shape expression</dt><dd>Shapes and node constraints, possibly combined with AND, OR, and NOT expressions.</dd>
<dt id="vocab-focus-node">focus node</dt><dd>A RDF data node of interest that is examined during validation.</dd>
<dt id="vocab-shape">shape</dt><dd>A triple expression aginst which a focus node is tested to see of all incoming or outgoing arcs matching predicates in the triple expression have appropriate number (cardinality) and values.</dd>
<dt id="vocab-triple-expression">triple expression</dt><dd>A collection of triple constraints which may be combined in groups or choices.</dd>
<dt id="vocab-triple-constraint">triple constraint</dt><dd>A constraint with a given predicate which is tested against RDF triples with that predicate and the focus node as subject (or object, for <a href="#inverse-properties">inverse triple constraints</a>).</dd>
<dt id="vocab-node-constraint">node constraint</dt><dd>A collection of constraints on a given focus node.</dd>
<dt id="vocab-value-constraint">value constraint</dt><dd>A shape expression used in a triple constraint. "Value constraint" (or "value constraint on a property") is a shorthand way of saying: "node constraint on the RDF node of the object associated in a triple with a given predicate".
For inverse triple constraints, this shorthand is: "node constraint on the RDF node of the subject associated in a triple with a given predicate".</dd>
<dt id="vocab-value-set">value set</dt><dd>A set of values composed of RDF terms and substrings.</dd>
<dt id="vocab-value">value</dt><dd>A shorthand designation for the RDF node at the opposite end of an RDF data triple from a focus node. In typical usage, this is the object of a triple, or for <a href="#inverse-properties">inverse triple constraints</a>, its subject.</dd>
<dt id="vocab-constraint">constraint</dt><dd>A restriction on the set of permissible nodes or triples.</dd>
<dt id="vocab-shapeMap">shape map</dt><dd>A collection of pairs of RDF data nodes and ShEx shapes that is used for invoking validation and reporting results.</dd>
<dt id="vocab-shexc">ShExC</dt><dd>A compact syntax meant for human eyes and fingers.</dd>
<dt id="vocab-shexj">ShExJ</dt><dd>A JSON-LD [[json-ld]] representation meant for machine processing.</dd>
<dt id="vocab-shexr">ShExR</dt><dd>The RDF interpretation of ShExJ expressable in any RDF syntax.</dd>
</dl>
</section>
</section>
<section id="shex-essentials">
<h2>ShEx Essentials</h2>
<p>
This document uses a running example illustrated by the following graph in which an Issue is submitted by some person and may be reproduced by the same person or someone else.
These issues can have a status of <code>unassigned</code> or <code>assigned</code>.
</p>
<svg
preserveAspectRatio="xMinYMin meet"
viewBox="0 0 466 151"
width="866"
height="251"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
fill-opacity="0"
color-rendering="auto"
color-interpolation="auto"
stroke="rgb(0,0,0)"
text-rendering="auto"
stroke-linecap="square"
stroke-miterlimit="10"
stroke-opacity="0"
shape-rendering="auto"
fill="rgb(0,0,0)"
stroke-dasharray="none"
font-weight="normal"
stroke-width="1"
font-family="'Dialog'"
font-style="normal"
stroke-linejoin="miter"
font-size="12"
stroke-dashoffset="0"
image-rendering="auto"
id="svg3351"
version="1.1"
inkscape:version="0.48.4 r9939"
sodipodi:docname="ex1.svg">
<metadata
id="metadata3536">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
</cc:Work>
</rdf:RDF>
</metadata>
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1920"
inkscape:window-height="1058"
id="namedview3534"
showgrid="false"
inkscape:zoom="2.0879376"
inkscape:cx="260.34707"
inkscape:cy="41.69783"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:window-maximized="1"
inkscape:current-layer="layer2" />
<!--Generated by the Batik Graphics2D SVG Generator-->
<defs
id="genericDefs">
<marker
inkscape:stockid="Arrow2Mend"
orient="auto"
refY="0.0"
refX="0.0"
id="Arrow2Mend"
style="overflow:visible;">
<path
id="path4575"
style="fill-rule:evenodd;stroke-width:0.62500000;stroke-linejoin:round;"
d="M 8.7185878,4.0337352 L -2.2072895,0.016013256 L 8.7185884,-4.0017078 C 6.9730900,-1.6296469 6.9831476,1.6157441 8.7185878,4.0337352 z "
transform="scale(0.6) rotate(180) translate(0,0)" />
</marker>
<marker
inkscape:stockid="Arrow1Send"
orient="auto"
refY="0.0"
refX="0.0"
id="Arrow1Send"
style="overflow:visible;">
<path
id="path4563"
d="M 0.0,0.0 L 5.0,-5.0 L -12.5,0.0 L 5.0,5.0 L 0.0,0.0 z "
style="fill-rule:evenodd;stroke:#000000;stroke-width:1.0pt;"
transform="scale(0.2) rotate(180) translate(6,0)" />
</marker>
<marker
inkscape:stockid="Arrow1Lend"
orient="auto"
refY="0.0"
refX="0.0"
id="Arrow1Lend"
style="overflow:visible;">
<path
id="path4551"
d="M 0.0,0.0 L 5.0,-5.0 L -12.5,0.0 L 5.0,5.0 L 0.0,0.0 z "
style="fill-rule:evenodd;stroke:#000000;stroke-width:1.0pt;"
transform="scale(0.8) rotate(180) translate(12.5,0)" />
</marker>
<marker
inkscape:stockid="Arrow1Mend"
orient="auto"
refY="0.0"
refX="0.0"
id="Arrow1Mend"
style="overflow:visible;">
<path
id="path4557"
d="M 0.0,0.0 L 5.0,-5.0 L -12.5,0.0 L 5.0,5.0 L 0.0,0.0 z "
style="fill-rule:evenodd;stroke:#000000;stroke-width:1.0pt;"
transform="scale(0.4) rotate(180) translate(10,0)" />
</marker>
<marker
inkscape:stockid="Arrow2Mend"
orient="auto"
refY="0"
refX="0"
id="Arrow2Mend-7"
style="overflow:visible">
<path
inkscape:connector-curvature="0"
id="path4575-8"
style="fill-rule:evenodd;stroke-width:0.625;stroke-linejoin:round"
d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z"
transform="scale(-0.6,-0.6)" />
</marker>
<marker
inkscape:stockid="Arrow2Mend"
orient="auto"
refY="0"
refX="0"
id="marker7228"
style="overflow:visible">
<path
inkscape:connector-curvature="0"
id="path7230"
style="fill-rule:evenodd;stroke-width:0.625;stroke-linejoin:round"
d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z"
transform="scale(-0.6,-0.6)" />
</marker>
<marker
inkscape:stockid="Arrow1Lend"
orient="auto"
refY="0"
refX="0"
id="Arrow1Lend-9"
style="overflow:visible">
<path
inkscape:connector-curvature="0"
id="path4551-4"
d="M 0,0 5,-5 -12.5,0 5,5 0,0 z"
style="fill-rule:evenodd;stroke:#000000;stroke-width:1pt"
transform="matrix(-0.8,0,0,-0.8,-10,0)" />
</marker>
<marker
inkscape:stockid="Arrow2Mend"
orient="auto"
refY="0"
refX="0"
id="Arrow2Mend-0"
style="overflow:visible">
<path
inkscape:connector-curvature="0"
id="path4575-2"
style="fill-rule:evenodd;stroke-width:0.625;stroke-linejoin:round"
d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z"
transform="scale(-0.6,-0.6)" />
</marker>
<marker
inkscape:stockid="Arrow1Lend"
orient="auto"
refY="0"
refX="0"
id="Arrow1Lend-7"
style="overflow:visible">
<path
inkscape:connector-curvature="0"
id="path4551-8"
d="M 0,0 5,-5 -12.5,0 5,5 0,0 z"
style="fill-rule:evenodd;stroke:#000000;stroke-width:1pt"
transform="matrix(-0.8,0,0,-0.8,-10,0)" />
</marker>
<marker
inkscape:stockid="Arrow1Lend"
orient="auto"
refY="0"
refX="0"
id="Arrow1Lend-91"
style="overflow:visible">
<path
inkscape:connector-curvature="0"
id="path4551-41"
d="M 0,0 5,-5 -12.5,0 5,5 0,0 z"
style="fill-rule:evenodd;stroke:#000000;stroke-width:1pt"
transform="matrix(-0.8,0,0,-0.8,-10,0)" />
</marker>
</defs>
<g
id="g3354">
<defs
id="defs1">
<linearGradient
x1="65"
gradientUnits="userSpaceOnUse"
x2="65"
y1="100"
y2="0"
id="linearGradient1"
spreadMethod="reflect">
<stop
stop-opacity="1"
stop-color="rgb(118,148,200)"
offset="0%"
id="stop3358" />
<stop
stop-opacity="1"
stop-color="rgb(238,243,251)"
offset="100%"
id="stop3360" />
</linearGradient>
<linearGradient
x1="85"
gradientUnits="userSpaceOnUse"
x2="85"
y1="100"
y2="0"
id="linearGradient2"
spreadMethod="reflect">
<stop
stop-opacity="1"
stop-color="rgb(118,148,200)"
offset="0%"
id="stop3363" />
<stop
stop-opacity="1"
stop-color="rgb(238,243,251)"
offset="100%"
id="stop3365" />
</linearGradient>
<clipPath
clipPathUnits="userSpaceOnUse"
id="clipPath1">
<path
d="M-7 -7 L141 -7 L141 111 L-7 111 L-7 -7 Z"
id="path3368" />
</clipPath>
<clipPath
clipPathUnits="userSpaceOnUse"
id="clipPath2">
<path
d="M0 0 L0 85 L130 85 L130 0 Z"
id="path3371" />
</clipPath>
<clipPath
clipPathUnits="userSpaceOnUse"
id="clipPath3">
<path
d="M0 0 L130 0 L130 15 L0 15 L0 0 Z"
id="path3374" />
</clipPath>
<clipPath
clipPathUnits="userSpaceOnUse"
id="clipPath4">
<path
d="M-7 -7 L181 -7 L181 111 L-7 111 L-7 -7 Z"
id="path3377" />
</clipPath>
<clipPath
clipPathUnits="userSpaceOnUse"
id="clipPath5">
<path
d="M0 0 L0 85 L170 85 L170 0 Z"
id="path3380" />
</clipPath>
<clipPath
clipPathUnits="userSpaceOnUse"
id="clipPath6">
<path
d="M0 0 L170 0 L170 15 L0 15 L0 0 Z"
id="path3383" />
</clipPath>
<clipPath
clipPathUnits="userSpaceOnUse"
id="clipPath7">
<path
d="M-7 -7 L48 -7 L48 26 L-7 26 L-7 -7 Z"
id="path3386" />
</clipPath>
<clipPath
clipPathUnits="userSpaceOnUse"
id="clipPath8">
<path
d="M0 0 L37 0 L37 15 L0 15 L0 0 Z"
id="path3389" />
</clipPath>
<clipPath
clipPathUnits="userSpaceOnUse"
id="clipPath9">
<path
d="M-7 -7 L50 -7 L50 26 L-7 26 L-7 -7 Z"
id="path3392" />
</clipPath>
<clipPath
clipPathUnits="userSpaceOnUse"
id="clipPath10">
<path
d="M0 0 L39 0 L39 15 L0 15 L0 0 Z"
id="path3395" />
</clipPath>
<clipPath
clipPathUnits="userSpaceOnUse"
id="clipPath11">
<path
d="M-7 -7 L37 -7 L37 27 L-7 27 L-7 -7 Z"
id="path3398" />
</clipPath>
<clipPath
clipPathUnits="userSpaceOnUse"
id="clipPath12">
<path
d="M0 0 L26 0 L26 16 L0 16 L0 0 Z"
id="path3401" />
</clipPath>
<clipPath
clipPathUnits="userSpaceOnUse"
id="clipPath13">
<path
d="M-7 -7 L47 -7 L47 26 L-7 26 L-7 -7 Z"
id="path3404" />
</clipPath>
<clipPath
clipPathUnits="userSpaceOnUse"
id="clipPath14">
<path
d="M0 0 L36 0 L36 15 L0 15 L0 0 Z"
id="path3407" />
</clipPath>
<clipPath
clipPathUnits="userSpaceOnUse"
id="clipPath15">
<path
d="M-7 -7 L49 -7 L49 26 L-7 26 L-7 -7 Z"
id="path3410" />
</clipPath>
<clipPath
clipPathUnits="userSpaceOnUse"
id="clipPath16">
<path
d="M0 0 L38 0 L38 15 L0 15 L0 0 Z"
id="path3413" />
</clipPath>
<clipPath
clipPathUnits="userSpaceOnUse"
id="clipPath17">
<path
d="M0 0 L171 0 L171 52 L0 52 L0 0 Z"
id="path3416" />
</clipPath>
<clipPath
clipPathUnits="userSpaceOnUse"
id="clipPath18">
<path
d="M0 0 L162 0 L162 112 L0 112 L0 0 Z"
id="path3419" />
</clipPath>
<clipPath
clipPathUnits="userSpaceOnUse"
id="clipPath19">
<path
d="M-77 -15 L154 -15 L154 30 L-77 30 L-77 -15 Z"
id="path3422" />
</clipPath>
<clipPath
clipPathUnits="userSpaceOnUse"
id="clipPath20">
<path
d="M-92 -15 L184 -15 L184 30 L-92 30 L-92 -15 Z"
id="path3425" />
</clipPath>
<clipPath
clipPathUnits="userSpaceOnUse"
id="clipPath21">
<path
d="M-57 -15 L114 -15 L114 30 L-57 30 L-57 -15 Z"
id="path3428" />
</clipPath>
</defs>
</g>
<g
inkscape:groupmode="layer"
id="layer1"
inkscape:label="UML"
style="display:none">
<g
text-rendering="geometricPrecision"
id="g3430"
style="fill:#ffffff;fill-opacity:1;stroke:#ffffff;stroke-opacity:1">
<rect
x="0"
width="466"
height="151"
y="0"
id="rect3432"
style="stroke:none" />
</g>
<g
font-size="11"
transform="translate(332,2)"
text-rendering="geometricPrecision"
font-weight="bold"
id="g3434"
style="font-size:11px;font-weight:bold;fill:url(#linearGradient1);fill-opacity:1;stroke:url(#linearGradient1);stroke-opacity:1;font-family:sans-serif">
<rect
x="0"
width="130"
height="100"
y="0"
clip-path="url(#clipPath1)"
id="rect3436"
style="stroke:none" />
</g>
<g
font-size="11"
transform="translate(332,2)"
text-rendering="geometricPrecision"
font-weight="bold"
stroke-miterlimit="0"
id="g3438"
style="font-size:11px;font-weight:bold;fill:#000000;fill-opacity:1;stroke:#000000;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:0;stroke-opacity:1;font-family:sans-serif">
<rect
x="0"
width="130"
height="100"
y="0"
clip-path="url(#clipPath1)"
id="rect3440"
style="fill:none" />
<line
y2="15"
x1="0"
clip-path="url(#clipPath1)"
x2="130"
y1="15"
id="line3442"
style="fill:none" />
</g>
<g
font-size="11"
transform="translate(332,17)"
text-rendering="geometricPrecision"
id="g3444"
style="font-size:11px;fill:#000000;fill-opacity:1;stroke:#000000;stroke-opacity:1;font-family:sans-serif">
<text
x="2"
xml:space="preserve"
y="14"
clip-path="url(#clipPath2)"
id="text3446"
style="stroke:none"> :name : xsd:string</text>
</g>
<g
font-size="11"
transform="translate(332,17)"
text-rendering="geometricPrecision"
id="g3448"
style="font-size:11px;fill:#000000;fill-opacity:1;stroke:#000000;stroke-opacity:1;font-family:sans-serif">
<!--
<text x="2" xml:space="preserve" y="29" clip-path="url(#clipPath2)" stroke="none"
> :givenName : xsd:string</text
><text x="2" xml:space="preserve" y="44" clip-path="url(#clipPath2)" stroke="none"
> :familyName : xsd:string</text
>
-->
<text
x="2"
xml:space="preserve"
y="59"
clip-path="url(#clipPath2)"
id="text3450"
style="stroke:none"> :mbox : AnyURI</text>
</g>
<g
font-size="11"
transform="translate(332,2)"
text-rendering="geometricPrecision"
font-weight="bold"
id="g3452"
style="font-size:11px;font-weight:bold;fill:#000000;fill-opacity:1;stroke:#000000;stroke-opacity:1;font-family:sans-serif">
<text
x="50"
xml:space="preserve"
y="12"
clip-path="url(#clipPath3)"
id="text3454"
style="stroke:none">:User</text>
</g>
<g
font-size="11"
transform="translate(42,2)"
text-rendering="geometricPrecision"
font-weight="bold"
id="g3456"
style="font-size:11px;font-weight:bold;fill:url(#linearGradient2);fill-opacity:1;stroke:url(#linearGradient2);stroke-opacity:1;font-family:sans-serif">
<rect
x="0"
width="170"
height="100"
y="0"
clip-path="url(#clipPath4)"
id="rect3458"
style="stroke:none" />
</g>
<g
font-size="11"
transform="translate(42,2)"
text-rendering="geometricPrecision"
font-weight="bold"
stroke-miterlimit="0"
id="g3460"
style="font-size:11px;font-weight:bold;fill:#000000;fill-opacity:1;stroke:#000000;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:0;stroke-opacity:1;font-family:sans-serif">
<rect
x="0"
width="170"
height="100"
y="0"
clip-path="url(#clipPath4)"
id="rect3462"
style="fill:none" />
<line
y2="15"
x1="0"
clip-path="url(#clipPath4)"
x2="170"
y1="15"
id="line3464"
style="fill:none" />
</g>
<g
font-size="11"
transform="translate(42,17)"
text-rendering="geometricPrecision"
id="g3466"
style="font-size:11px;fill:#000000;fill-opacity:1;stroke:#000000;stroke-opacity:1;font-family:sans-serif">
<text
x="2"
xml:space="preserve"
y="14"
clip-path="url(#clipPath5)"
id="text3468"
style="stroke:none"> :status = Assigned|Unassigned</text>
</g>
<g
font-size="11"
transform="translate(42,17)"
text-rendering="geometricPrecision"
id="g3470"
style="font-size:11px;fill:#000000;fill-opacity:1;stroke:#000000;stroke-opacity:1;font-family:sans-serif">
<text
x="2"
xml:space="preserve"
y="29"
clip-path="url(#clipPath5)"
id="text3472"
style="stroke:none"> :reportedOn : xsd:dateTime</text>
<!--
<text x="2" xml:space="preserve" y="44" clip-path="url(#clipPath5)" stroke="none"
> :assignedOn : xsd:dateTime?</text
>
-->
</g>
<g
font-size="11"
transform="translate(42,2)"
text-rendering="geometricPrecision"
font-weight="bold"
id="g3474"
style="font-size:11px;font-weight:bold;fill:#000000;fill-opacity:1;stroke:#000000;stroke-opacity:1;font-family:sans-serif">
<text
x="69"
xml:space="preserve"
y="12"
clip-path="url(#clipPath6)"
id="text3476"
style="stroke:none">:Issue</text>
</g>
<g
font-size="11"
transform="translate(212,62)"
text-rendering="geometricPrecision"
id="g3478"
style="font-size:11px;fill:#000000;fill-opacity:1;stroke:#000000;stroke-opacity:1;font-family:sans-serif">
<text
x="10"
xml:space="preserve"
y="12"
clip-path="url(#clipPath8)"
id="text3480"
style="stroke:none">0..*</text>
</g>
<g
font-size="11"
transform="translate(302,62)"
text-rendering="geometricPrecision"
id="g3482"
style="font-size:11px;fill:#000000;fill-opacity:1;stroke:#000000;stroke-opacity:1;font-family:sans-serif">
<text
x="10"
xml:space="preserve"
y="12"
clip-path="url(#clipPath10)"
id="text3484"
style="stroke:none">0..1</text>
</g>
<g
font-size="11"
transform="translate(312,22)"
text-rendering="geometricPrecision"
id="g3486"
style="font-size:11px;fill:#000000;fill-opacity:1;stroke:#000000;stroke-opacity:1;font-family:sans-serif">
<text
x="10"
xml:space="preserve"
y="12"
clip-path="url(#clipPath12)"
id="text3488"
style="stroke:none">1</text>
</g>
<g
font-size="11"
transform="translate(212,22)"
text-rendering="geometricPrecision"
id="g3490"
style="font-size:11px;fill:#000000;fill-opacity:1;stroke:#000000;stroke-opacity:1;font-family:sans-serif">
<text
x="10"
xml:space="preserve"
y="12"
clip-path="url(#clipPath8)"
id="text3492"
style="stroke:none">0..*</text>
</g>
<g
font-size="11"
transform="translate(122,102)"
text-rendering="geometricPrecision"
id="g3494"
style="font-size:11px;fill:#000000;fill-opacity:1;stroke:#000000;stroke-opacity:1;font-family:sans-serif">
<text
x="9"