-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
1448 lines (1445 loc) · 57.9 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>
<head>
<meta charset='utf-8'>
<link href="./formatting.css" rel="stylesheet" />
<script src="./formatting.js"></script>
<script src='https://www.w3.org/Tools/respec/respec-w3c' async class='remove'></script>
<script class='remove'>
var respecConfig = {
postProcess: [postProcessFormatting],
specStatus: "unofficial",
shortName: "ramp-shapes",
subtitle: "RAMP shapes: declarative RDF ↔ algebraic data type mapping",
edDraftURI: "https://ramp-shapes.github.io/ramp-shapes-spec/",
editors: [{
name: "Alexey Morozov",
url: "https://github.com/AlexeyMz",
company: "ITMO University - ISST Laboratory",
companyURL: "http://isst.ifmo.ru/",
}],
authors: [{
name: "Alexey Morozov",
url: "https://github.com/AlexeyMz",
company: "ITMO University - ISST Laboratory",
companyURL: "http://isst.ifmo.ru/",
}],
otherLinks: [{
key: "Version control",
data: [{
value: "Github Repository",
href: "https://github.com/ramp-shapes/ramp-shapes-spec"
}]
}],
localBiblio: {
"rdfjs": {
title: "RDF/JS: Data model specification",
href: "http://rdf.js.org/data-model-spec/",
status: "CG-DRAFT",
publisher: "W3C",
},
"rdfjs-dataset": {
title: "RDF/JS: Dataset specification 1.0",
href: "https://rdf.js.org/dataset-spec/",
status: "CG-FINAL",
publisher: "W3C",
},
"XSPARQL": {
title: "XSPARQL: Traveling between the XML and RDF worlds–and avoiding the XSLT pilgrimage",
href: "https://link.springer.com/chapter/10.1007/978-3-540-68234-9_33",
},
"SPARQL.js": {
title: "SPARQL.js – A SPARQL 1.1 parser for JavaScript",
href: "https://github.com/RubenVerborgh/SPARQL.js",
},
},
};
</script>
<title>RAMP shapes: declarative RDF ↔ algebraic data type mapping</title>
</head>
<body>
<section id='abstract'>
<p>
RAMP (RDF ADT Mapping) is a type construction language, specification and an
implementation of mapping operations between RDF graphs and structured data types.
</p>
</section>
<section id='sotd'>
<p>
Changes to this document may be tracked at
<a href='https://github.com/ramp-shapes/ramp-shapes.github.io'>
https://github.com/ramp-shapes/ramp-shapes.github.io
</a>.
</p>
<p class="note">This draft is implemented by <code>[email protected]</code> NPM package.</p>
</section>
<section>
<h2>External definitions</h2>
<p>
Commonly used types and values from ECMAScript include
<dfn data-lt='DOMString'>string</dfn>,
<dfn>number</dfn>,
<dfn>boolean</dfn>,
<dfn>null</dfn> (and <dfn data-lt="nullType">null type</dfn>),
<dfn>undefined</dfn>,
<dfn>unknown</dfn>.
</p>
<p>
The specification references [[[WebIDL]]] spec:
<dfn data-cite="WebIDL#Exposed">Exposed</dfn>.
</p>
<p>
The specification references the following RDF types defined in [[!rdfjs]] spec:
<dfn data-cite="rdfjs#dom-term">Term</dfn>,
<dfn data-cite="rdfjs#dom-namednode">NamedNode</dfn>,
<dfn data-cite="rdfjs#dom-blanknode">BlankNode</dfn>,
<dfn data-cite="rdfjs#dom-literal">Literal</dfn>,
<dfn data-cite="rdfjs#dom-quad">Quad</dfn>.
</p>
<p>
The specification references the following types from [[!rdfjs-dataset]]:
<dfn data-cite="rdfjs-dataset#dom-dataset">Dataset</dfn>.
</p>
<p>
The specification references the following types from [[!SPARQL.js]] query AST:
<dfn>ConstructQuery</dfn>.
</p>
<p>
The specification uses the following prefix definitions for examples:
<pre class="ttl">
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
@prefix owl: <http://www.w3.org/2002/07/owl#>.
@prefix dctypes: <http://purl.org/dc/dcmitype/>.
@prefix sc: <http://iiif.io/api/presentation/2#>.
@prefix ramp: <http://ramp-shapes.github.io/schema#>.
@prefix ex: <http://example.com/shapes#>.
</pre>
</p>
</section>
<section data-dfn-for="Shape" data-link-for="Shape">
<h2><dfn>Shape</dfn> type constructors</h2>
The set of defined types forms a type construction language with RDF-based atomic terms and ADTs (Algebraic Data Types).
<pre class="idl">
typedef (
ResourceShape
or LiteralShape
or RecordShape
or AnyOfShape
or OptionalShape
or SetShape
or ListShape
or MapShape
) Shape;
</pre>
<section data-dfn-for="ShapeID" data-link-for="ShapeID">
<h3><dfn>ShapeID</dfn></h3>
<p>Shapes are referenced by <a>ShapeID</a>.</p>
<pre class="idl">
typedef (NamedNode or BlankNode) ShapeID;
</pre>
</section>
<section data-dfn-for="ShapeBase" data-link-for="ShapeBase">
<h3><dfn>ShapeBase</dfn></h3>
<p>Basic shapes properties are <dfn>id</dfn> and <dfn>lenient</dfn>.</p>
<p>
<a>lenient</a> property sets non-strict matching mode for shape.
See <a data-lt='RamOperations.frame()'>frame()</a> for matching mode description.
</p>
<pre class="idl">
[Exposed] interface ShapeBase {
readonly attribute ShapeID id;
readonly attribute boolean? lenient;
};
</pre>
</section>
<section data-dfn-for="ResourceShape" data-link-for="ResourceShape">
<h3><dfn>ResourceShape</dfn> type</h3>
<p>
<a>ResourceShape</a> describes an RDF resource term, which is either an IRI or a blank node:
</p>
<p>
If <dfn>onlyNamed</dfn> flag is set then the shape will only match <a>NamedNode</a> but
not <a>BlankNode</a>.
</p>
<pre class="idl">
[Exposed] interface ResourceShape : ShapeBase {
/** type == "resource" */
readonly attribute string type;
readonly attribute boolean? onlyNamed;
readonly attribute (NamedNode or BlankNode)? value;
readonly attribute Vocabulary? vocabulary;
};
</pre>
<aside class="example" title="IRI only resource shape">
<p>
This shape matches only IRIs, e.g. <code><http://example.com/resource1></code>
but not blank nodes:
</p>
<pre class="ttl">
ex:AnyIri a ramp:Resource;
ramp:onlyNamed true;
</pre>
<table class="ramp-op-result">
<tr>
<td><pre class="ramp-dataset"><http://example.com/alice></pre></td>
<td><pre class="json ramp-framed">"http://example.com/alice"</pre></td>
</tr>
<tr>
<td><pre class="ramp-dataset">_:bob</pre></td>
<td><span class="ramp-no-matches">no matches</span></td>
</tr>
</table>
</aside>
<aside class="example" title="Constant resource shape">
<p>
This shape matches only <code>dctypes:Image</code> term:
</p>
<pre class="ttl">
ex:ConstantIri a ramp:Resource;
ramp:termValue dctypes:Image.
</pre>
<table class="ramp-op-result">
<tr>
<td><pre class="ramp-dataset">dctypes:Image</pre></td>
<td><pre class="json ramp-framed">"http://purl.org/dc/dcmitype/Image"</pre></td>
</tr>
<tr>
<td><pre class="ramp-dataset">dctypes:Sound</pre></td>
<td><span class="ramp-no-matches">no matches</span></td>
</tr>
</table>
</aside>
<section data-dfn-for="Vocabulary" data-link-for="Vocabulary">
<h3><dfn>Vocabulary</dfn> interface</h3>
<p>
<a>Vocabulary</a> describes a mapping between <a>NamedNode</a> terms and <a>string</a> keys.
The mapping allows to refer to RDF resources by short names in
by matching against <dfn>terms</dfn> dictionary.
</p>
<pre class="idl">
[Exposed] interface Vocabulary {
getter record<DOMString, NamedNode> terms();
};
</pre>
<aside class="example" title="Resource shape with vocabulary">
<p>
This shape matches any IRI from the specified vocabulary and frames it as corresponding
key, e.g. <code>dctypes:Sound</code> IRI will be framed as <code>"sound"</code> string:
</p>
<pre class="ttl">
ex:ResourceType a ramp:Resource;
ramp:vocabulary [
ramp:vocabItem
[ ramp:vocabKey "sound"; ramp:termValue dctypes:Sound ],
[ ramp:vocabKey "image"; ramp:termValue dctypes:Image ],
[ ramp:vocabKey "text"; ramp:termValue dctypes:Text ]
].
</pre>
<table class="ramp-op-result">
<tr>
<td><pre class="ramp-dataset">dctypes:Image</pre></td>
<td><pre class="json ramp-framed">"image"</pre></td>
</tr>
<tr>
<td><pre class="ramp-dataset">dctypes:Sound</pre></td>
<td><pre class="json ramp-framed">"sound"</pre></td>
</tr>
<tr>
<td><pre class="ramp-dataset">sc:Manifest</pre></td>
<td><span class="ramp-match-error">error: no entry in vocabulary</span></td>
</tr>
</table>
</aside>
</section>
</section>
<section data-dfn-for="LiteralShape" data-link-for="LiteralShape">
<h3><dfn>LiteralShape</dfn> type</h3>
<p>
<a>LiteralShape</a> describes an RDF literal term with its specified <dfn>datatype</dfn>,
<dfn>language</dfn> (if the <a>datatype</a> is <code>rdf:langString</code>) and
<dfn>value</dfn>:
</p>
<pre class="idl">
[Exposed] interface LiteralShape : ShapeBase {
/** type == "literal" */
readonly attribute string type;
readonly attribute NamedNode? datatype;
readonly attribute string? language;
readonly attribute Literal? value;
};
</pre>
<aside class="example" title="Literal shape with datatype">
<p>
This shape matches only <code>xsd:string</code> literals:
</p>
<pre class="ttl">
ex:PlainString a ramp:Literal;
ramp:termDatatype xsd:string.
</pre>
<table class="ramp-op-result">
<tr>
<td><pre class="ramp-dataset">"Alice"</pre></td>
<td><pre class="json ramp-framed">"Alice"</pre></td>
</tr>
<tr>
<td><pre class="ramp-dataset">"Bob"^^xsd:string</pre></td>
<td><pre class="json ramp-framed">"Bob"</pre></td>
</tr>
<tr>
<td><pre class="ramp-dataset">"42"^^xsd:integer</pre></td>
<td><span class="ramp-no-matches">no matches: different datatype</span></td>
</tr>
</table>
</aside>
<aside class="example" title="Literal shape with language tag">
<p>
This shape matches literals with <code>rdf:langString</code> datatype and
<code>"en"</code> language tag:
</p>
<pre class="ttl">
ex:EnLiteral a ramp:Literal;
ramp:termLanguage "en".
</pre>
<table class="ramp-op-result">
<tr>
<td><pre class="ramp-dataset">"Alice"@en</pre></td>
<td><pre class="json ramp-framed">"Alice"</pre></td>
</tr>
<tr>
<td><pre class="ramp-dataset">"Bob"</pre></td>
<td><span class="ramp-no-matches">no matches: different datatype</span></td>
</tr>
<tr>
<td><pre class="ramp-dataset">"Carol"@fr</pre></td>
<td><span class="ramp-no-matches">no matches: different language tag</span></td>
</tr>
</table>
</aside>
<aside class="example" title="Constant literal shape">
<p>
This shape matches only <code>"JPEG"</code> literals:
</p>
<pre class="ttl">
ex:ConstantLiteral a ramp:Resource;
ramp:termValue "JPEG".
</pre>
<table class="ramp-op-result">
<tr>
<td><pre class="ramp-dataset">"JPEG"</pre></td>
<td><pre class="json ramp-framed">"JPEG"</pre></td>
</tr>
<tr>
<td><pre class="ramp-dataset">"PNG"</pre></td>
<td><span class="ramp-no-matches">no matches: not equal to "JPEG"</span></td>
</tr>
</table>
</aside>
</section>
<section data-dfn-for="RecordShape" data-link-for="RecordShape">
<h3><dfn>RecordShape</dfn> type</h3>
<p>
<a>RecordShape</a> describes a product type of heterogeneous types accessible through
named properties. Both <dfn>typeProperties</dfn> and <dfn>properties</dfn> define
properties for a shape and the difference is when a candidate term must match given
record shape if and only if all <a>typeProperties</a> matches, which allows to produce
better diagnostic reports if <a>typeProperties</a> match but some of the
<a>properties</a> does not.
</p>
<pre class="idl">
[Exposed] interface RecordShape : ShapeBase {
/** type == "record" */
readonly attribute string type;
getter sequence<Property> typeProperties();
getter sequence<Property> properties();
};
</pre>
<aside class="example" title="Simple record shape">
<p>
This shape matches IRI or blank term with two edges <code>ex:xCoord</code> and
<code>ex:yCoord</code> and frames it into object <code>{ x: number; y: number }</code>:
</p>
<pre class="ttl">
ex:PointShape a ramp:Record;
ramp:property [
ramp:name "x";
ramp:path ex:xCoord;
ramp:shape [ a ramp:Literal; ramp:termDatatype xsd:integer ]
].
ramp:property [
ramp:name "y";
ramp:path ex:yCoord;
ramp:shape [ a ramp:Literal; ramp:termDatatype xsd:integer ]
].
</pre>
<table class="ramp-op-result">
<tr>
<td>
<pre class="ttl ramp-dataset">
_:p1 ex:xCoord 10;
ex:yCoord 20.
</pre>
</td>
<td><pre class="json ramp-framed">{ "x": 10, "y": 20 }</pre></td>
</tr>
<tr>
<td><pre class="ttl ramp-dataset">_:p2 ex:xCoord 30.</pre></td>
<td><span class="ramp-no-matches">no matches: missing property "y"</span></td>
</tr>
</table>
</aside>
<aside class="example" title="Record shape with type property">
<p>
This shape matches IRI or blank term with <code>rdf:type</code> equal to <code>ex:Note</code>
and <code>ex:noteContent</code> string. If <code>ex:noteContent</code> is missing or
does not contain <code>xsd:string</code> literal then the <code>"text"</code> property
specifically will be pointed at by diagnostic reporting instead of the
whole <code>ex:NoteShape</code>.
</p>
<pre class="ttl">
ex:NoteShape a ramp:Record;
ramp:typeProperty [
ramp:name "type";
ramp:path rdf:type;
ramp:shape [ a ramp:Resource; ramp:termValue ex:Note ]
];
ramp:property [
ramp:name "text";
ramp:path ex:noteContent;
ramp:shape [ a ramp:Literal; ramp:termDatatype xsd:string ]
].
</pre>
<table class="ramp-op-result">
<tr>
<td>
<pre class="ttl ramp-dataset">
_:note1 rdf:type ex:Note;
ex:noteContent "Remember to buy milk".
</pre>
</td>
<td>
<pre class="json ramp-framed">
{
"type": "http://example.com/shapes#Note",
"text": "Remember to buy milk"
}
</pre>
</td>
</tr>
<tr>
<td>
<pre class="ttl ramp-dataset">
_:note1 ex:noteContent "Remember to buy bread".
</pre>
</td>
<td><span class="ramp-no-matches">no matches: missing property "type"</span></td>
</tr>
<tr>
<td>
<pre class="ttl ramp-dataset">
_:note1 rdf:type ex:Note;
ex:noteContent "Remember to buy eggs".
</pre>
</td>
<td><span class="ramp-no-matches">no matches: missing property "text"</span></td>
</tr>
</table>
</aside>
<section data-dfn-for="Property" data-link-for="Property">
<h3><dfn>Property</dfn> interface</h3>
<p>
<a>Property</a> describes a named property in a record type.
It is specified by its <dfn>name</dfn> string, <dfn data-lt="path">property path</dfn> and
<dfn data-lt="valueShape">value shape</dfn>. A property with zero-length path allows to embed
a different representation of the same subject, e.g. the subject IRI itself.
</p>
<p>
If <dfn>transient</dfn> flag is set then in <a data-link-for="RamOperations">frame()</a>
the framing result will be discarded; in <a data-link-for="RamOperations">flatten()</a>
the value for <a>valueShape</a> will be synthesized or an error will be thrown if it is not possible.
</p>
<pre class="idl">
[Exposed] interface Property {
readonly attribute string name;
readonly attribute PropertyPath path;
readonly attribute ShapeID valueShape;
readonly attribute boolean? transient;
};
</pre>
<aside class="example" title="Self-referencing property">
<p>
This shape matches IRI or blank term value into a property <code>"iri"</code> of itself:
</p>
<pre class="ttl">
ex:ItemShape a ramp:Record;
ramp:property [
ramp:name "iri";
ramp:path ();
ramp:shape [ a ramp:Resource ]
];
ramp:property [
ramp:name "label";
ramp:path rdfs:label;
ramp:shape [ a ramp:Literal; ramp:termDatatype xsd:string ]
].
</pre>
<table class="ramp-op-result">
<tr>
<td><pre class="ttl ramp-dataset"><http://example.com/alice> rdfs:label "Alice".</pre></td>
<td>
<pre class="json ramp-framed">
{
"iri": "http://example.com/alice",
"label": "Alice"
}
</pre>
</td>
</tr>
</table>
<p>
For other kinds of property paths see <a>PropertyPath</a>.
</p>
</aside>
<aside class="example" title="Transient property">
<p>
This shape matches IRI or blank term with <code>rdf:type</code> equal to
<code>sc:Manifest</code> and <code>rdfs:label</code> literal but discards
<code>"type"</code> property in <a data-link-for="RamOperations">frame()</a> and
synthesizes the value <code>sc:Manifest</code> from corresponding shape in
<a data-link-for="RamOperations">flatten()</a>:
</p>
<pre class="ttl">
ex:ManifestShape a ramp:Record;
ramp:typeProperty [
ramp:name "type";
ramp:path rdf:type;
ramp:transient true;
ramp:shape [ a ramp:Resource; ramp:termValue sc:Manifest ]
];
ramp:property [
ramp:name "label";
ramp:path rdfs:label;
ramp:shape [ a ramp:Literal; ramp:termDatatype xsd:string ]
].
</pre>
<table class="ramp-op-result">
<tr>
<td>
<pre class="ttl ramp-dataset">
_:manifest1 rdf:type sc:Manifest;
rdfs:label "Paintings".
</pre>
</td>
<td><pre class="json ramp-framed">{ "label": "Paintings" }</pre></td>
</tr>
</table>
</aside>
</section>
</section>
<section data-dfn-for="AnyOfShape" data-link-for="AnyOfShape">
<h3><dfn>AnyOfShape</dfn> type</h3>
<p>
<a>AnyOfShape</a> describes a sum (coproduct) type of several types.
The <dfn>variants</dfn> are unordered, which means matching operations
may produce results in arbitrary order when the same candidate term
matches multiple variant types.
</p>
<pre class="idl">
[Exposed] interface AnyOfShape : ShapeBase {
/** type == "union" */
readonly attribute string type;
getter sequence<ShapeID> variants();
};
</pre>
<aside class="example" title="Union of different datatypes">
<p>
This shape matches either <code>xsd:integer</code>, <code>xsd:string</code>
or <code>xsd:boolean</code> terms:
</p>
<pre class="ttl">
ex:SimpleLiteral a ramp:AnyOf;
ramp:variant
[ a ramp:Literal; ramp:termDatatype xsd:integer ],
[ a ramp:Literal; ramp:termDatatype xsd:string ],
[ a ramp:Literal; ramp:termDatatype xsd:boolean ].
</pre>
<table class="ramp-op-result">
<tr>
<td><pre class="ramp-dataset">"42"^^xsd:integer</pre></td>
<td><pre class="json ramp-framed">42</pre></td>
</tr>
<tr>
<td><pre class="ramp-dataset">"true"^^xsd:boolean</pre></td>
<td><pre class="json ramp-framed">true</pre></td>
</tr>
<tr>
<td><pre class="ramp-dataset">"3.14"^^xsd:double</pre></td>
<td><span class="ramp-no-matches">no matches</span></td>
</tr>
</table>
</aside>
<aside class="example" title="Union of literal and RDF list">
<p>
This shape matches either a a single string or RDF list of strings:
</p>
<pre class="ttl">
ex:StringOrList a ramp:AnyOf;
ramp:variant
[ a ramp:Literal; ramp:termDatatype xsd:string ],
[ a ramp:List; ramp:item [ a ramp:Literal; ramp:termDatatype xsd:string ] ].
</pre>
<table class="ramp-op-result">
<tr>
<td><pre class="ramp-dataset">"Alice"</pre></td>
<td><pre class="json ramp-framed">"Alice"</pre></td>
</tr>
<tr>
<td><pre class="ramp-dataset">("Alice" "Bob" "Carol")</pre></td>
<td><pre class="json ramp-framed">["Alice", "Bob", "Carol"]</pre></td>
</tr>
<tr>
<td><pre class="ramp-dataset">(1 2 3)</pre></td>
<td>
<span class="ramp-no-matches">
no matches: different datatype for list item <code>xsd:integer</code>
</span>
</td>
</tr>
</table>
</aside>
</section>
<section data-dfn-for="OptionalShape" data-link-for="OptionalShape">
<h3><dfn>OptionalShape</dfn> type</h3>
<p>
<a>OptionalShape</a> describes a sum type of an empty unit type and a single type
<dfn>itemShape</dfn>.
</p>
<p>
Although this type could also be represented as
a <a>AnyOfShape</a> by introducing a <code>Nothing</code> unit type like
<a>null</a> in C-like languages, the optional type more closely resembles
the semantics of programming languages with either no explicit <code>nothing</code>
type or multiple such types instead (e.g. <a>null</a> and <a>undefined</a>
in ECMAScript).
</p>
<pre class="idl">
[Exposed] interface OptionalShape : ShapeBase {
/** type == "optional" */
readonly attribute string type;
readonly attribute ShapeID itemShape;
readonly attribute nullType? emptyValue;
};
</pre>
<aside class="example" title="Optional literal">
<p>
This shape matches either <code>xsd:string</code> only if a value is present
(it matches only and only if a value has <code>xsd:string</code> type and won't
match e.g. <code>xsd:integer</code> literal):
</p>
<pre class="ttl">
ex:MaybeString a ramp:Optional;
ramp:item [ ramp:Literal; ramp:termDatatype xsd:string ].
</pre>
<table class="ramp-op-result">
<tr>
<td><pre class="ramp-dataset">"Bob"</pre></td>
<td><pre class="json ramp-framed">"Bob"</pre></td>
</tr>
<tr>
<td><span class="ramp-empty-dataset">empty dataset</span></td>
<td><pre class="json ramp-framed">null</pre></td>
</tr>
</table>
</aside>
<aside class="example" title="Optional record property">
<p>
This shape matches a record with optional property value:
</p>
<pre class="ttl">
ex:LocationShape a ramp:Record;
ramp:typeProperty [
ramp:name "type";
ramp:path rdf:type;
ramp:shape [ a ramp:Resource; ramp:termValue ex:Location ]
]
ramp:property [
ramp:name "label";
ramp:path rdfs:label;
ramp:shape [
a ramp:Optional;
ramp:item [ ramp:Literal; ramp:termDatatype xsd:string ]
]
].
</pre>
<table class="ramp-op-result">
<tr>
<td>
<pre class="ttl ramp-dataset">
_:loc1 rdf:type ex:Location;
rdfs:label "Paris".
</pre>
</td>
<td>
<pre class="json ramp-framed">
{
"type": "http://example.com/shapes#Location",
"label": "Paris"
}
</pre>
</td>
</tr>
<tr>
<td><pre class="ttl ramp-dataset">_:loc2 rdf:type ex:Location.</pre></td>
<td><pre class="json ramp-framed">{ "type": "http://example.com/shapes#Location" }</pre></td>
</tr>
</table>
</aside>
</section>
<section data-dfn-for="SetShape" data-link-for="SetShape">
<h3><dfn>SetShape</dfn> type</h3>
<p>
<a>SetShape</a> describes an unordered set of a single type <dfn>itemShape</dfn>.
</p>
<p>
If <dfn>minCount</dfn> or <dfn>maxCount</dfn> is specified then the shape will match
only if matching set contains equal or more items than <a>minCount</a> and
equal or less items than <a>maxCount</a>.
</p>
<pre class="idl">
[Exposed] interface SetShape : ShapeBase {
/** type == "set" */
readonly attribute string type;
readonly attribute ShapeID itemShape;
readonly attribute number? minCount;
readonly attribute number? maxCount;
};
</pre>
<aside class="example" title="Set of literals">
<p>
This shape matches a set (unordered array) of <code>xsd:integer</code> literals:
</p>
<pre class="ttl">
ex:IntegerSet a ramp:Set;
ramp:item [ a ramp:Literal; ramp:termDatatype xsd:integer ].
</pre>
<table class="ramp-op-result">
<tr>
<td><pre class="ramp-dataset">1, 2, -3, 4</pre></td>
<td><pre class="json ramp-framed">[1, 2, -3, 4]</pre></td>
</tr>
<tr>
<td><span class="ramp-empty-dataset">empty dataset</span></td>
<td><pre class="json ramp-framed">[]</pre></td>
</tr>
<tr>
<td><pre class="ramp-dataset">10, "carol", 20</pre></td>
<td>
<span class="ramp-no-matches">
no matches: different datatype for item <code>xsd:string</code>
</span>
</td>
</tr>
</table>
</aside>
<aside class="example" title="Set cardinality restrictions">
<p>
This shape matches a set with >= 1 and <= 3 <code>xsd:string</code> items:
</p>
<pre class="ttl">
ex:BoundedSet a ramp:Set;
ramp:item [ a ramp:Literal; ramp:termDatatype xsd:string ]
ramp:minCount 1;
ramp:maxCount 3.
</pre>
<table class="ramp-op-result">
<tr>
<td><pre class="ramp-dataset">"alice", "bob", "carol"</pre></td>
<td><pre class="json ramp-framed">["alice", "bob", "carol"]</pre></td>
</tr>
<tr>
<td><span class="ramp-empty-dataset">empty dataset</span></td>
<td><span class="ramp-no-matches">no matches: should be at least one item</span></td>
</tr>
<tr>
<td><pre class="ramp-dataset">"a", "b", "c", "d"</pre></td>
<td><span class="ramp-no-matches">no matches: too many items</span></td>
</tr>
</table>
</aside>
<aside class="example" title="Record property with multiple values">
<p>
This shape matches a record with multiple property values:
</p>
<pre class="ttl">
ex:LotteryResult a ramp:Record;
ramp:property [
ramp:name "winningNumbers";
ramp:path ex:winningNumber;
ramp:shape [
a ramp:Set;
ramp:item [ ramp:Literal; ramp:termDatatype xsd:integer ]
]
].
</pre>
<table class="ramp-op-result">
<tr>
<td><pre class="ttl ramp-dataset">_:result ex:winningNumber 10, 20, 30.</pre></td>
<td><pre class="json ramp-framed">{ "winningNumbers": [10, 20, 30] }</pre></td>
</tr>
<tr>
<td><pre class="ttl ramp-dataset">_:result rdfs:label "Lottery Result".</pre></td>
<td><pre class="json ramp-framed">{ "winningNumbers": [] }</pre></td>
</tr>
<tr>
<td><pre class="ttl ramp-dataset">_:result ex:winningNumber 10, "alice".</pre></td>
<td>
<span class="ramp-no-matches">
no matches: different datatype for item <code>xsd:string</code>
</span>
</td>
</tr>
</table>
</aside>
</section>
<section data-dfn-for="ListShape" data-link-for="ListShape">
<h3><dfn>ListShape</dfn> type</h3>
<p>
<a>ListShape</a> describes an ordered set (<a data-cite="WebIDL#idl-sequence">sequence</a>)
of a single type <dfn>itemShape</dfn>.
</p>
<p>
By default a <a>ListShape</a> represents RDF list structures, however it is possible to
override <dfn>headPath</dfn>, or <dfn>tailPath</dfn> property paths and <dfn>nil</dfn> term
to describe other kinds of ordered structures.
</p>
<pre class="idl">
[Exposed] interface ListShape : ShapeBase {
/** type == "list" */
readonly attribute string type;
readonly attribute ShapeID itemShape;
/** @default rdf:first */
readonly attribute PropertyPath? headPath;
/** @default rdf:rest */
readonly attribute PropertyPath? tailPath;
/** @default rdf:nil */
readonly attribute NamedNode? nil;
};
</pre>
<aside class="example" title="List shapes">
<p>
This shape matches an RDF list (ordered array) of <code>xsd:integer</code> literals,
e.g. <code>(1 2 3)</code> framed as <code>[1, 2, 3]</code>:
</p>
<pre class="ttl">
ex:IntegerList a ramp:List;
ramp:item [ a ramp:Literal; ramp:termDatatype xsd:integer ].
</pre>
<table class="ramp-op-result">
<tr>
<td><pre class="ramp-dataset">(2 4 8 10)</pre></td>
<td><pre class="json ramp-framed">[2, 4, 8, 10]</pre></td>
</tr>
<tr>
<td><pre class="ttl ramp-dataset">()</pre></td>
<td><pre class="json ramp-framed">[]</pre></td>
</tr>
<tr>
<td><pre class="ttl ramp-dataset">(1 2 "carol")</pre></td>
<td>
<span class="ramp-no-matches">
no matches: different datatype for item <code>xsd:string</code>
</span>
</td>
</tr>
<tr>
<td><span class="ramp-empty-dataset">empty dataset</span></td>
<td>
<span class="ramp-no-matches">
no matches: cannot find list head <code>rdf:first</code>
</span>
</td>
</tr>
<tr>
<td><pre class="ttl ramp-dataset">_:item1 rdf:first 42.</pre></td>
<td>
<span class="ramp-no-matches">
no matches: cannot find list tail <code>rdf:rest</code>
</span>
</td>
</tr>
</table>
</aside>
</section>
<section data-dfn-for="MapShape" data-link-for="MapShape">
<h3><dfn>MapShape</dfn> type</h3>
<p>
<a>MapShape</a> describes an unordered set (<a data-cite="WebIDL#idl-record">record</a>) of items
with type <dfn>itemShape</dfn> indexed by a <dfn>key</dfn> and (optionally) <dfn>value</dfn>.
</p>
<p>
Any nested shape value, datatype or language may be chosen as the key. When <a>MapShape</a> includes
a nested map value with the same <a>key</a>, the key always refers to the innermost map shape.
A <a>key</a> shape may be limited to non-composite types depending on the implementation.
</p>
<pre class="idl">
[Exposed] interface MapShape : ShapeBase {
/** type == "map" */
readonly attribute string type;
readonly attribute ShapeReference key;
readonly attribute ShapeReference? value;
readonly attribute ShapeID itemShape;
};
</pre>
<aside class="example" title="Map shape indexed by property">
<p>
This shape matches an unordered set of records and indexes it by <code>"name"</code> property,
so the framed object looks like <code>{ [propertyName: string]: string | integer | boolean }</code>:
</p>
<pre class="ttl">
ex:PropertyMap a ramp:Map;
ramp:item [
a ramp:Record;
ramp:property [
ramp:name "name";
ramp:path ex:propertyName;
ramp:shape _:propertyNameShape
];
ramp:property [
ramp:name "value";
ramp:path ex:propertyValue;
ramp:shape _:propertyValueShape
]
];
ramp:mapKey [ ramp:shape _:propertyNameShape ];
ramp:mapValue [ ramp:shape _:propertyValueShape ].
_:propertyNameShape a ramp:Literal;
ramp:termDatatype xsd:string.
_:propertyValueShape a ramp:AnyOf;
ramp:variant
[ a ramp:Literal; ramp:termDatatype xsd:string ],
[ a ramp:Literal; ramp:termDatatype xsd:integer ],
[ a ramp:Literal; ramp:termDatatype xsd:boolean ].
</pre>
<table class="ramp-op-result">
<tr>
<td>
<pre class="ttl ramp-dataset">
_:item1 ex:propertyName "homeDirectory";
ex:propertyValue "/home/alice".
_:item2 ex:propertyName "maxHistoryLength";
ex:propertyValue 20.
_:item3 ex:propertyName "disableNotifications";
ex:propertyValue true.
</pre>
</td>
<td>
<pre class="json ramp-framed">
{
"homeDirectory": "/home/alice",
"maxHistoryLength": 20,
"disableNotifications": true
}
</pre>
</td>
</tr>
<tr>
<td><span class="ramp-empty-dataset">empty dataset</span></td>
<td><pre class="json ramp-framed">{}</pre></td>
</tr>
</table>
</aside>
<section data-dfn-for="ShapeReference" data-link-for="ShapeReference">
<h3><dfn>ShapeReference</dfn> interface</h3>
<p>
<a>ShapeReference</a> describes a reference to a candidate term matched by
<dfn>target</dfn> <a>Shape</a>.
A reference may target whole <a>Term</a> value or a specific <dfn>part</dfn> such as
language or datatype of a <a>Literal</a>.
</p>
<pre class="idl">
[Exposed] interface ShapeReference {
readonly attribute ShapeID target;
/** part in ("value" or "datatype" or "language") */
readonly attribute string? part;
};
</pre>
<aside class="example" title="Map shape indexed by language tag">
<p>
This shape matches an unordered set of <code>rdf:langString</code> literals and
indexes it by language tag, so the framed object looks like
<code>{ [languageTag: string]: string }</code>:
</p>
<pre class="ttl">
ex:LocalizedLabels a ramp:Map;
ramp:item labelLiteral;
ramp:mapKey [ ramp:shape _:labelLiteral; ramp:termPart ramp:TermLanguage ];
ramp:mapValue [ ramp:shape _:labelLiteral; ramp:termPart ramp:TermValue ].
_:labelLiteral a ramp:Literal;
ramp:termDatatype rdf:langString.
</pre>
<table class="ramp-op-result">
<tr>
<td>
<pre class="ramp-dataset">
"Apple"@en,
"Apfel"@de,
"Pomme"@fr,
"Яблоко"@ru
</pre>
</td>
<td>
<pre class="json ramp-framed">
{
"en": "Apple",
"de": "Apfel",
"fr": "Pomme",
"ru": "Яблоко"