/
index.html
1599 lines (1442 loc) · 74.5 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>JSON-LD 1.1 Framing</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<script type="text/javascript" src="https://www.w3.org/Tools/respec/respec-w3c-common" class="remove"></script>
<script type="text/javascript" src="../common/common.js" class="remove"></script>
<script type="text/javascript" class="remove">
//<![CDATA[
var respecConfig = {
// extend the bibliography entries
localBiblio: jsonld.localBiblio,
// specification status (e.g. WD, LCWD, NOTE, etc.). If in doubt use ED.
specStatus: "CG-DRAFT",
// if you wish the publication date to be other than today, set this
//publishDate: "2012-08-30",
copyrightStart: "2010",
// the specification's short name, as in http://www.w3.org/TR/short-name/
shortName: "json-ld11cg-framing",
subtitle: "An Application Programming Interface for the JSON-LD Syntax",
// if there is a previously published draft, uncomment this and set its YYYY-MM-DD date
// and its maturity status
prevVersion: "https://json-ld.org/spec/ED/json-ld-framing/20120830/",
previousPublishDate: "2012-08-30",
previousMaturity: "CG-DRAFT",
// if there a publicly available Editor's Draft, this is the link
edDraftURI: "https://json-ld.org/spec/latest/json-ld-framing/",
testSuiteURI: "https://json-ld.org/test-suite/",
// if this is a LCWD, uncomment and set the end of its review period
// lcEnd: "2009-08-05",
// if you want to have extra CSS, append them to this list
// it is recommended that the respec.css stylesheet be kept
// extraCSS: [],
includePermalinks: true,
noRecTrack: true,
doJsonLd: true,
highlightVars: true,
postProcess: [internalizeTermListReferences],
// editors, add as many as you like
// only "name" is required
editors: [
{ name: "Gregg Kellogg",
url: "http://greggkellogg.net/",
company: "Spec-Ops",
companyURL: "https://spec-ops.io/",
w3cid: "44770" }
],
formerEditors: [
{ name: "Manu Sporny", url: "http://manu.sporny.org/",
company: "Digital Bazaar", companyURL: "https://digitalbazaar.com/" },
{ name: "Dave Longley", url: "https://digitalbazaar.com/",
company: "Digital Bazaar", companyURL: "https://digitalbazaar.com/"},
{ name: "Markus Lanthaler", url: "http://www.markus-lanthaler.com/",
company: "Graz University of Technology", companyURL: "http://www.tugraz.at/" }
],
// authors, add as many as you like.
// This is optional, uncomment if you have authors as well as editors.
// only "name" is required. Same format as editors.
authors: [
{ name: "Dave Longley",
url: "https://digitalbazaar.com/",
company: "Digital Bazaar",
companyURL: "https://digitalbazaar.com/",
note: "v1.0" },
{ name: "Manu Sporny",
url: "http://manu.sporny.org/",
company: "Digital Bazaar",
companyURL: "https://digitalbazaar.com/",
note: "v1.0" },
{ name: "Gregg Kellogg",
url: "http://greggkellogg.net/",
company: "Spec-Ops",
companyURL: "https://spec-ops.io/",
w3cid: "44770",
note: "v1.0 and v1.1" },
{ name: "Markus Lanthaler",
url: "http://www.markus-lanthaler.com/",
company: "Graz University of Technology",
companyURL: "http://www.tugraz.at/",
note: "v1.0" },
{ name: "Niklas Lindström",
url: "http://neverspace.net/",
note: "v1.0" }
],
github: "https://github.com/json-ld/json-ld.org",
// name of the WG
wg: "Linking Data in JSON Community Group",
// URI of the public WG page
wgURI: "https://json-ld.org/",
// name (with the @w3c.org) of the public mailing to which comments are due
wgPublicList: "public-linked-json",
// URI of the patent status for this WG, for Rec-track documents
// !!!! IMPORTANT !!!!
// This is important for Rec-track documents, do not copy a patent URI from a random
// document unless you know what you're doing. If in doubt ask your friendly neighbourhood
// Team Contact.
//wgPatentURI: "",
maxTocLevel: 4
///alternateFormats: [ {uri: "diff-20120830.html", label: "diff to previous version"} ],
};
//]]>
</script>
<style type="text/css">
div.example .highlight .hljs-string {
font-weight: bold;
}
div.example .comment .hljs-string {
color: #999;
text-decoration: line-through;
}
.diff { font-weight:bold; color:#0a3; }
.error a {
color: #ff4500;
border-bottom: 1px dotted #ff4500;
text-decoration: none;
}
.algorithm ol {
counter-reset: numsection;
list-style-type: none;
}
.algorithm li {
margin: 0.5em 0;
}
.algorithm li:before {
font-weight: bold;
counter-increment: numsection;
content: counters(numsection, ".") ") ";
}
.hl-bold {
font-weight: bold;
color: #0a3;
}
.comment {
color: #999;
}
.changed {
background-color: rgb(215, 238, 197);
}
.changed:hover {
color: green;
background-color: inherit;
}
</style>
</head>
<body>
<section id="abstract">
<p>JSON-LD Framing allows developers to query by example and
force a specific tree layout to a JSON-LD document.</p>
</section>
<section id='sotd'>
<p>This document has been developed by the
<a href="https://www.w3.org/community/json-ld/">JSON for Linking Data W3C Community Group</a>.
The specification has undergone
significant development, review, and changes during the course of several years.</p>
<p>There are several independent
<a href="https://json-ld.org/test-suite/reports/">interoperable implementations</a> of
this specification, a test suite [[JSON-LD-TESTS]] and a
<a href="https://json-ld.org/playground/">live JSON-LD playground</a> that is capable
of demonstrating the features described in this document.</p>
<section>
<h2>Set of Documents</h2>
<p>This document is one of three JSON-LD 1.1 Recommendations produced by the
<a href="https://www.w3.org/community/json-ld/">JSON for Linking Data W3C Community Group</a>:</p>
<ul>
<li><a data-cite="JSON-LD11CG">JSON-LD 1.1</a></li>
<li><a data-cite="JSON-LD11CG-API">JSON-LD 1.1 Processing Algorithms and API</a></li>
<li><a data-cite="JSON-LD11CG-FRAMING">JSON-LD 1.1 Framing</a></li>
</ul>
</section>
</section>
<section id='introduction'>
<h1>Introduction</h1>
<p>A JSON-LD document is a representation of a directed graph. A single
directed graph can have many different serializations, each expressing
exactly the same information. Developers typically work with trees, represented as
<a>JSON objects</a>. While mapping a graph to
a tree can be done, the layout of the end result must be specified in advance.
A <a>Frame</a> can be used by a developer on a JSON-LD document to
specify a deterministic layout for a graph.</p>
<section>
<h2>How to Read this Document</h2>
<p>
This document is a detailed specification for a serialization of Linked
Data in JSON. The document is primarily intended for the following audiences:
</p>
<ul>
<li>Authors who want to query JSON-LD documents to create representations
more appropriate for a given use case.</li>
<li>Software developers that want to implement <a>processors</a> and APIs for
JSON-LD.</li>
</ul>
<p>
To understand the basics in this specification you must first be familiar with
<a data-cite="RFC7159">JSON</a>, which is detailed in [[!RFC7159]]. You must also understand the
JSON-LD 1.1 Syntax specification [[!JSON-LD11CG]], which is the base syntax used by all of the
algorithms in this document,
and the JSON-LD 1.1 API [[!JSON-LD11CG-API]]. To understand the API and how it is
intended to operate in a programming environment, it is useful to have working
knowledge of the JavaScript programming language [[ECMASCRIPT-6.0]] and
WebIDL [[!WEBIDL]]. To understand how JSON-LD maps to RDF, it is helpful to be
familiar with the basic RDF concepts [[!RDF-CONCEPTS]].</p>
</section>
<section>
<h2>Contributing</h2>
<p>There are a number of ways that one may participate in the development of
this specification:</p>
<ul>
<li>Technical discussion typically occurs on the public mailing list:
<a href="https://lists.w3.org/Archives/Public/public-linked-json/">public-linked-json@w3.org</a></li>
<!--<li><a href="https://json-ld.org/minutes/">Public teleconferences</a> are held
on Tuesdays at 1500UTC on the second and fourth week of each month.</li> -->
<li>The <a href="https://webchat.freenode.net/?channels=json-ld">#json-ld</a>
IRC channel is available for real-time discussion on irc.freenode.net.</li>
</ul>
</section>
<section>
<h2>Terminology</h2>
<p>This document uses the following terms as defined in JSON [[!RFC7159]]. Refer
to the <a data-cite="RFC7159#section-2">JSON Grammar section</a> in [[!RFC7159]] for formal definitions.</p>
<div data-include="../common/terms.html"
data-oninclude="restrictReferences">
</div>
<section>
<h4>Algorithm Terms</h4>
<p>The Following terms are used within specific algorithms.</p>
<div data-include="../common/algorithm-terms.html"
data-oninclude="restrictReferences">
</div>
</section>
</section>
<section>
<h2>Typographical conventions</h2>
<div data-include="../common/typographical-conventions.html"></div>
</section>
</section>
<section class="informative">
<h2>Features</h2>
<section class="informative">
<h3>Framing</h3>
<p><dfn>Framing</dfn> is used to shape the data in a <a>JSON-LD document</a>,
using an example <a>frame</a> document which is used to both match the
<a data-cite="JSON-LD11CG-API#dfn-flattened">flattened</a>
data and show an example of how the resulting data should be shaped.
Matching is performed by using <a>properties</a> present in in the <a>frame</a>
to find objects in the data that share common values. Matching can be done
either using all properties present in the frame, or any property in the frame.
By chaining together objects using matched property values, objects can be embedded
within one another.</p>
<p>A <a>frame</a> also includes a <a>context</a>, which is used for compacting the resulting
framed output.</p>
<p>For example, assume the following JSON-LD frame:</p>
<pre class="example nohighlight" data-transform="updateExample"
title="Sample library frame">
<!--
{
"@context": {"@vocab": "http://example.org/"},
"@type": "Library",
"contains": {
"@type": "Book",
"contains": {
"@type": "Chapter"
}
}
}
-->
</pre>
<p>This <a>frame</a> document describes an embedding structure that would place
objects with type <code>ex:Library</code> at the top, with objects of
type <code>ex:Book</code> that were linked to the library object using
the <code>ex:contains</code> property embedded as property values. It also
places objects of type <code>ex:Chapter</code> within the referencing ex:Book object
as embedded values of the book object.</p>
<p>When using a flattened set of objects that match the frame components:</p>
<pre class="example nohighlight" data-transform="updateExample"
title="Flattened library objects">
<!--
{
"@context": {
"@vocab": "http://example.org/",
"contains": {"@type": "@id"}
},
"@graph": [{
"@id": "http://example.org/library",
"@type": "Library",
"contains": "http://example.org/library/the-republic"
}, {
"@id": "http://example.org/library/the-republic",
"@type": "Book",
"creator": "Plato",
"title": "The Republic",
"contains": "http://example.org/library/the-republic#introduction"
}, {
"@id": "http://example.org/library/the-republic#introduction",
"@type": "Chapter",
"description": "An introductory chapter on The Republic.",
"title": "The Introduction"
}]
}
-->
</pre>
<p>The Frame Algorithm can create a new document which follows the structure
of the frame:</p>
<pre class="example nohighlight" data-transform="updateExample"
title="Framed library objects">
<!--
{
"@context": {"@vocab": "http://example.org/"},
"@graph": [{
"@id": "http://example.org/library",
"@type": "Library",
"contains": {
"@id": "http://example.org/library/the-republic",
"@type": "Book",
"contains": {
"@id": "http://example.org/library/the-republic#introduction",
"@type": "Chapter",
"description": "An introductory chapter on The Republic.",
"title": "The Introduction"
},
"creator": "Plato",
"title": "The Republic"
}
}]
}
-->
</pre>
<p>If <a>processing mode</a> is <code>json-ld-1.1</code>, or the <a>omit graph flag</a> is <code>true</code>,
the top-level <code>@graph</code> member may be omitted.</p>
<pre class="example nohighlight" data-transform="updateExample"
title="Framed library objects with omitGraph set to false">
<!--
{
"@context": {"@vocab": "http://example.org/"},
"@id": "http://example.org/library",
"@type": "Library",
"contains": {
"@id": "http://example.org/library/the-republic",
"@type": "Book",
"contains": {
"@id": "http://example.org/library/the-republic#introduction",
"@type": "Chapter",
"description": "An introductory chapter on The Republic.",
"title": "The Introduction"
},
"creator": "Plato",
"title": "The Republic"
}
}
-->
</pre>
<p>The <a href="#framing-algorithm">Framing Algorithm</a> does this by
first expanding both the input frame and document. It then creates
a <a>map of flattened subjects</a>. The outer-most <a>node object</a> within the frame
is used to match objects in the map, in this case looking for <a>node objects</a>
which have an <code>@type</code> of <code>Library</code>, and a
<code>contains</code> property with another
frame used to match values of that property. The input document contains
exactly one such <a>node object</a>. The value of contains also has
a <a>node object</a>, which is then treated as a frame to match the set of <a>subjects</a>
which are <code>contains</code> values of the <code>Library</code> object, and so forth.</p>
</section>
<section>
<h3>Default content</h3>
<p>A frame may specify properties that don't exist in an input file. If the
<a>explicit inclusion flag</a> is <code>false</code>, the framing algorithm
will add a property and value to the result. The <code>@default</code> property
in a <a>node object</a> or <a>value object</a> provides a default value to use in the resulting
output document. If there is no <code>@default</code> value, the property will be output
with a <code>null</code> value. (See <a href="#omit-default-flag" class="sectionRef"></a>
for ways to avoid this).</p>
<p class="note">The value of the property in the frame is not otherwise
used in the output document. It's purpose is for frame matching and
finding default values. Note the <em>description</em> value for <em>Library</em> in the following example.</p>
<pre class="example nohighlight" data-transform="updateExample"
title="Sample library frame with @default value">
<!--
{
"@context": {"@vocab": "http://example.org/"},
"@type": "Library",
****"description": "A great Library.",****
"contains": {
"@type": "Book",
****"description": {"@default": "A great book."},****
"contains": {
"@type": "Chapter"
}
}
}
-->
</pre>
<pre class="example nohighlight" data-transform="updateExample"
title="Sample library output with @default value">
<!--
{
"@context": {"@vocab": "http://example.org/"},
"@graph": [{
"@id": "http://example.org/library",
"@type": "Library",
"contains": {
"@id": "http://example.org/library/the-republic",
"@type": "Book",
"contains": {
"@id": "http://example.org/library/the-republic#introduction",
"@type": "Chapter",
"description": "An introductory chapter on The Republic.",
"title": "The Introduction"
},
"creator": "Plato",
****"description": "A great book.",****
"title": "The Republic"
},
****"description": null****
}]
}
-->
</pre>
</section>
<section>
<h3>Framing Flags</h3>
<p>Framing can be controlled using <a data-lt="JsonLdOptions">API options</a>,
or by adding framing <a>keywords</a> within the <a>frame</a> as
described in <a href="#framing-keywords" class="sectionRef"></a>.</p>
<p class="note">Framing flags set using keywords have effect only for the
frame in which they appear, and for implicit frames which are created
for objects where no frame object exists.</p>
<section>
<h4>Object Embed Flag</h4>
<p>The <a>object embed flag</a> determines if a referenced
<a>node object</a> is embedded as a property value of a referencing
object, or kept as a <a>node reference</a>.
The initial value for the <a>object embed flag</a> is set using the
<a data-link-for="JsonLdOptions">embed</a> option.
Consider the following frame
based on the default <code>@last</code> value of the <a>object embed flag</a>:</p>
<pre class="example nohighlight" data-transform="updateExample"
title="Sample library frame with implicit @embed set to @last">
<!--
{
"@context": {"@vocab": "http://example.org/"},
"@type": "Library"
}
-->
</pre>
<p>Because, the default for the <a>object embed flag</a> is <code>@last</code>
(in addition to the <a>explicit inclusion flag</a> being <code>false</code>),
non-listed properties are added two the output, and implicitly embedded
using a default empty frame. As a result, the same output used in the
<a href="#lib-example-output">Framed library objects</a> above is generated.</p>
<p>However, if the <code>@embed</code> property is added explicitly with a
value of <code>@never</code>, the values for <em>Book</em> and <em>Chapter</em> will be excluded.</p>
<pre class="example nohighlight" data-transform="updateExample"
title="Sample library frame with explicit @embed set to @never">
<!--
{
"@context": {"@vocab": "http://example.org/"},
"@type": "Library",
"contains": {
"@type": "Book",
****"@embed": "@never"****
}
}
-->
</pre>
<pre class="example nohighlight" data-transform="updateExample"
title="Framed library objects with @embed set to @never">
<!--
{
"@context": {"@vocab": "http://example.org/"},
"@graph": [{
"@id": "http://example.org/library",
"@type": "Library",
"contains": {
****"@id": "http://example.org/library/the-republic"****
}
}]
}
-->
</pre>
</section>
<section>
<h4>Explicit inclusion flag</h4>
<p>The <a>explicit inclusion flag</a> used to determine
properties which will be included in the output document.
The default value is <code>false</code>, which means that properties
present in an input <a>node object</a> that are not in the associated frame will be
included in the output object.
The initial value for the <a>explicit inclusion flag</a> is set using the
<a data-link-for="JsonLdOptions">explicit</a> option.
If <code>true</code>, only properties present in
the input frame will be placed into the output.</p>
<p>For example, take an expanded version of the library frame which include
some properties from the input, but omit others.</p>
<pre class="example nohighlight" data-transform="updateExample"
title="Sample library frame with @explicit set to true">
<!--
{
"@context": {"@vocab": "http://example.org/"},
"@type": "Library",
"description": {},
"contains": {
"@type": "Book",
****"@explicit": true,****
****"title": {},****
"contains": {
"@type": "Chapter"
}
}
}
-->
</pre>
<p>The resulting output will exclude properties for Book which are not explicitly
listed in the <a>frame object</a>:</p>
<pre id="lib-example-output" class="example" data-transform="updateExample"
title="Framed library objects with @explicit set to true">
<!--
{
"@context": {"@vocab": "http://example.org/"},
"@graph": [{
"@id": "http://example.org/library",
"@type": "Library",
"contains": {
"@id": "http://example.org/library/the-republic",
"@type": "Book",
"contains": {
"@id": "http://example.org/library/the-republic#introduction",
"@type": "Chapter",
"description": "An introductory chapter on The Republic.",
"title": "The Introduction"
},
****"creator": "Plato"****,
"title": "The Republic"
}
}]
}
-->
</pre>
</section>
<section>
<h4>Omit default flag</h4>
<p>The <a>omit default flag</a> changes the way framing generates output when a property
described in the frame is not present in the input document.
The initial value for the <a>omit default flag</a> is set using the
<a data-link-for="JsonLdOptions">omitDefault</a> option.
See <a href="#default-content" class="sectionRef"></a> for a further discussion.</p>
</section>
<section class="changed">
<h4>Omit graph flag</h4>
<p>The <a>omit graph flag</a> determines if framed output containing a single
<a>node object</a> is contained within <code>@graph</code>, or not.
The initial value for the <a>omit graph flag</a> is set using the
<a data-link-for="JsonLdOptions">omitGraph</a> option, or based on
the <a>processing mode</a>; if <a>processing mode</a> is <code>json-ld-1.0</code>, the output
always includes a <code>@graph</code> member, otherwise, the <code>@graph</code> member is used only
to describe multiple <a>node objects</a>, consistent with compaction.
See <a href="#framing-algorithm" class="sectionRef"></a> for a further discussion.</p>
</section>
<section>
<h4>Require all flag</h4>
<p>The <a>require all flag</a> is used in frame matching to determine when a
<a>node object</a> from an input document matches a frame. When
matching, an object may include <code>@type</code> and other
properties, a match is made when <em>any</em> property value in the
object matches the <a>node pattern</a> in the <a>frame object</a> if
the value of the <a>require all flag</a> is <code>false</code> (the
default). If the flag value is <code>true</code>, then <em>all</em>
properties in the <a>frame object</a> must be present in the <a>node
object</a> for the node to match.</p>
</section>
</section>
<section>
<h3>Reverse Framing</h3>
<p>A frame may include @reverse, or a value of a term defined using @reverse
to invert the relationships in the output object. For example, the
Library example can be inverted using the following frame:</p>
<pre class="example nohighlight" data-transform="updateExample"
title="Inverted library frame">
<!--
{
"@context": {
"@vocab": "http://example.org/",
****"within": {"@reverse": "contains"}****
},
****"@type": "Chapter",
"within": {
"@type": "Book",
"within": {
"@type": "Library"
}
}****
}
-->
</pre>
<p>Using the flattened library example above, results in the following:</p>
<pre class="example nohighlight" data-transform="updateExample"
title="Inverted library output">
<!--
{
"@context": {
"@vocab": "http://example.org/",
"within": {"@reverse": "contains"}
},
"@graph": [{
"@id": "http://example.org/library/the-republic#introduction",
"@type": "Chapter",
"description": "An introductory chapter on The Republic.",
"title": "The Introduction",
"within": {
"@id": "http://example.org/library/the-republic",
"@type": "Book",
"contains": {"@id": "http://example.org/library/the-republic#introduction"},
"creator": "Plato",
"title": "The Republic",
"within": {
"@id": "http://example.org/library",
"@type": "Library",
"contains": {"@id": "http://example.org/library/the-republic"}
}
}
}]
}
-->
</pre>
</section>
<section class="changed">
<h3>Framing Named Graphs</h3>
<p>Frames can include <code>@graph</code>, which allows information from <a>named graphs</a>
contained within a <a>JSON-LD document</a> to be exposed within it's proper
graph context. By default, framing uses a <var>merged graph</var>, composed of all
the <a>node objects</a> across all graphs within the input. By using <code>@graph</code>
within a frame, the output document can include information specifically
from <a>named graphs</a> contained within the input document.</p>
<p>The following example uses a variation on our library theme where information
is split between the <a>default graph</a>, and a graph named <code>http://example.org/graphs/books</code>:</p>
<pre class="example nohighlight" data-transform="updateExample"
title="Frame with named graphs">
<!--
{
"@context": {"@vocab": "http://example.org/"},
"@type": "Library",
"contains": {
"@id": "http://example.org/graphs/books",
****"@graph": {
"@type": "Book"
}****
}
}
-->
</pre>
<pre class="example nohighlight" data-transform="updateExample"
title="Flattened Input with named graphs">
<!--
[{
"@context": {"@vocab": "http://example.org/"},
"@id": "http://example.org/graphs/books",
"@graph": [{
"@id": "http://example.org/library/the-republic",
"@type": "http://example.org/Book",
"http://example.org/contains": {
"@id": "http://example.org/library/the-republic#introduction"
},
"http://example.org/creator": "Plato",
"http://example.org/title": "The Republic"
}, {
"@id": "http://example.org/library/the-republic#introduction",
"@type": "http://example.org/Chapter",
"http://example.org/description": "An introductory chapter on The Republic.",
"http://example.org/title": "The Introduction"
}]
}, {
"@context": {"@vocab": "http://example.org/"},
"@id": "http://example.org/library",
"@type": "http://example.org/Library",
"http://example.org/contains": {"@id": "http://example.org/graphs/books"},
"http://example.org/name": "Library"
}]
-->
</pre>
<pre class="example nohighlight" data-transform="updateExample"
title="Framed output with named graphs">
<!--
{
"@context": {"@vocab": "http://example.org/"},
"@graph": [{
"@id": "http://example.org/library",
"@type": "Library",
"name": "Library",
"contains": {
****"@id": "http://example.org/graphs/books",
"@graph": [{****
"@id": "http://example.org/library/the-republic",
"@type": "Book",
"creator": "Plato",
"title": "The Republic",
"contains": {
"@id": "http://example.org/library/the-republic#introduction",
"@type": "Chapter",
"description": "An introductory chapter on The Republic.",
"title": "The Introduction"
}
****}]****
}
}]
}
-->
</pre>
</section>
</section>
<section id="conformance">
<p>There is one class of products that can claim conformance to this
specification: <a>JSON-LD Processors</a>.</p>
<p>A conforming <a>JSON-LD Processor</a> is a system which can perform the
<a href="#framing-algorithm">Framing</a> operation in a manner consistent with
the algorithms defined in this specification.</p>
<p><a>JSON-LD Processors</a> MUST NOT
attempt to correct malformed <a>IRIs</a> or language tags;
however, they MAY issue validation warnings. IRIs are not modified other
than conversion between <a data-lt="relative IRI">relative</a> and
<a>absolute IRIs</a>.</p>
<p>The algorithms in this specification are generally written with more concern for clarity
than efficiency. Thus, <a>JSON-LD Processors</a> MAY
implement the algorithms given in this specification in any way desired,
so long as the end result is indistinguishable from the result that would
be obtained by the specification's algorithms.</p>
<p class="note">Implementers can partially check their level of conformance to
this specification by successfully passing the test cases of the JSON-LD test
suite [[JSON-LD-TESTS]]. Note, however, that passing all the tests in the test
suite does not imply complete conformance to this specification. It only implies
that the implementation conforms to aspects tested by the test suite.</p>
</section> <!-- end of Conformance section -->
<section>
<h2>Framing Algorithms</h2>
<p>All algorithms described in this section are intended to operate on
language-native data structures. That is, the serialization to a text-based
JSON document isn't required as input or output to any of these algorithms.</p>
<p>Reference to JSON data structures are interpreted using their <em>internal representation</em> for the purpose
of describing algorithms.</p>
<section id="framing-keywords">
<h2>Syntax Tokens and Keywords</h2>
<p>This specification adds a number of <a>keywords</a> (<dfn>framing keywords</dfn>) to
the ones defined in the JSON-LD 1.1 Syntax specification [[!JSON-LD11CG]]:</p>
<dl data-sort>
<dt><code>@default</code></dt>
<dd>Used in <a href="#framing">Framing</a> to set the default value for
an output property when the framed <a>node object</a> does not include such a property.</dd>
<dt><code>@embed</code></dt>
<dd>Used in <a href="#framing">Framing</a> to override the
value of <a>object embed flag</a> within a specific frame. Valid values for
<code>@embed</code> as the following:
<dl data-sort>
<dt><code>@always</code></dt><dd>
Always embed <a>node objects</a> as property values, unless this would
cause a circular reference.
</dd>
<dt><code>@last</code></dt><dd>
Only the last value within a given <a>node object</a> should be embedded,
previous values of other properties use a <a>node reference</a>. This is the
default value if neither <code>@embed</code> nor <a>object embed flag</a>
is not specified.
</dd>
<dt><code>@never</code></dt><dd>
Always use a <a>node reference</a> when serializing matching values.
</dd>
<dt><code>true</code></dt><dd>(equivalent to <code>@last</code>).</dd>
<dt><code>false</code></dt><dd>(equivalent to <code>@never</code>).</dd>
</dl>
<p>Any other value for <code>@embed</code> is invalid and indicates that an
<a data-link-for="JsonLdFramingErrorCode">invalid @embed value</a>
error has been detected and processing is aborted.</p>
</dd>
<dt><code>@explicit</code></dt>
<dd>Used in <a href="#framing">Framing</a> to override the
value of <a>explicit inclusion flag</a> within a specific frame.</dd>
<dt><code>@null</code></dt>
<dd>Used in <a href="#framing">Framing</a> when a value of <code>null</code>
should be returned, which would otherwise be removed when
<a data-cite="JSON-LD11CG-API#compaction">Compacting</a>.</dd>
<dt><code>@omitDefault</code></dt>
<dd>Used in <a href="#framing">Framing</a> to override the
value of <a>omit default flag</a> within a specific frame.
<div class="issue">Is this flag really useful? Easier to simply not have a default value,
if it shouldn't match.</div>
</dd>
<dt class="changed"><code>@requireAll</code></dt>
<dd class="changed">Used in <a href="#framing">Framing</a> to override the
value of <a>require all flag</a> within a specific frame.</dd>
</dl>
<p>All JSON-LD tokens and keywords are case-sensitive.</p>
</section>
<section>
<h2>Framing</h2>
<p>Framing is the process of taking a JSON-LD document, which expresses a
graph of information, and applying a specific graph layout
(called a <a>Frame</a>).</p>
<p>Framing makes use of the <a data-cite="JSON-LD11CG-API#node-map-generation">Node Map Generation</a> algorithm
to place each object defined in the JSON-LD document into a <a>map of flattened subjects</a>, allowing
them to be operated upon by the <a href="#framing-algorithm">Framing algorithm</a>.</p>
<section>
<h3>Framing Requirements</h3>
<p>A valid <a>JSON-LD Frame</a> is a superset of a valid <a>JSON-LD document</a>,
allowing additional content, which is preserved through expansion.
The <a data-cite="JSON-LD11CG#json-ld-grammar">Grammar</a> defined in the JSON-LD 1.1 Syntax specification [[JSON-LD11CG]]
is extended as follows:</p>
<ul>
<li>Framing adds <a>framing keywords</a> which may be used as keys of a <a>node object</a>, which MUST be preserved when expanding.
<li>Values of keys in a <a>frame object</a> that are not <a>keyword</a> MAY also include a <a>default object</a>.
Values of <code>@default</code> MAY include the value <code>@null</code>,
or an <a>array</a> containing only <code>@null</code>, in addition to other values
allowed in the grammar for values of keys expanding to <a>absolute IRIs</a>.
<a>Processors</a> MUST preserve this value when expanding. All other key/value pairs of
a <a>default object</a> MUST be ignored.</li>
<li>The values of <code>@id</code> and <code>@type</code> may also be an empty <a>dictionary</a>, or an <a>array</a>
containing only an empty <a>dictionary</a>.
<a>Processors</a> MUST preserve this value when expanding.</li>
<li>Framing either operates on the merged node definitions contained in
the input document, or on the <a>default graph</a> depending on if the
input frame contains the <code>@graph</code> key at the top level.
Nodes with a <a>subject</a> that is also a <a>named graph</a>, where
the <a>frame object</a> contains <code>@graph</code>, extend framing
to <a>node objects</a> from the associated <a>named graph</a>.</li>
</ul>
</section>
<section class="algorithm">
<h3>Framing Algorithm</h3>
<p>The framing algorithm takes an <a>JSON-LD input</a> (<var>expanded input</var>),
which MUST be a <a>JSON-LD document</a> in
<a data-cite="JSON-LD11CG-API#dfn-expanded-form">expanded form</a>,
an <a>input frame</a> (<var>expanded frame</var>),
which MUST be a <a>JSON-LD frame</a> in
<a data-cite="JSON-LD11CG-API#dfn-expanded-form">expanded form</a>,
a <a>context</a> (<var>context</var>),
and a number of <a data-lt="JsonLdProcessor-frame-options">options</a> and produces <a>JSON-LD output</a>.</p>
<p>If an error is detected in the <var>expanded frame</var>, a <a data-link-for="JsonLdFramingErrorCode">invalid frame</a>
error has been detected and processing is aborted.
<span class="ednote">Need more specifics as to what constitutes a valid frame.</span></p>
<p class="changed">Set <var>graph map</var> to the result of performing the
<a data-cite="JSON-LD11CG-API#node-map-generation">Node Map Generation</a> algorithm on
<var>expanded input</var>.</p>
<p class="changed">If the <a data-link-for="JsonLdOptions">frameDefault</a> option
is present with the value <code>true</code>, set <var>graph name</var> to <code>@default</code>.
Otherwise, create <var>merged node map</var> using the <a data-cite="JSON-LD11CG-API#merge-node-maps">Merge Node Maps</a> algorithm
with <var>graph map</var> and add <var>merged node map</var> as the value of <code>@merged</code>
in <var>graph map</var> and set <var>graph name</var> to <code>@merged</code>.</p>
<p>The recursive algorithm operates with a <a>framing state</a> (<var>state</var>),
created initially using
the <a>object embed flag</a> set to <code>true</code>,
the <a>explicit inclusion flag</a> set to <code>false</code>,
the <a>require all flag</a> set to <code>true</code>,
the <a>omit default flag</a> set to <code>false</code>,
<var>graph map</var>, <var>graph name</var>,
along with <a>map of flattened subjects</a>
set to the property associated with <var>graph name</var> in <var>graph map</var>, and
<var>graph stack</var> set to an empty <a>array</a>. The initial values of the
<a>object embed flag</a>, <a>require all flag</a>, and <a>omit default flag</a>
MUST be overridden by values set in <a data-lt="JsonLdProcessor-frame-options">options</a>.
Also initialize <var>results</var> as an empty <a>array</a>.</p>
<p class="note"><a>Processors</a> MAY use other runtime options to set different <a>framing state</a> defaults
for values of <var>state</var>.</p>
<p>Invoke the recursive algorithm using <a>framing state</a> (<var>state</var>),
the keys from the <a>map of flattened subjects</a> as <var>subjects</var>,
<var>expanded frame</var> (<var>frame</var>), <var>result</var> as <var>parent</var>, and
<code>null</code> as <var>active property</var>.</p>
<p>The recursive algorithm adds elements to <var>parent</var> either by appending
the element to <var>parent</var>, if it is an <a>array</a>, or by appending it
to an array associated with <var>active property</var> in <var>parent</var>, if it is a <a>dictionary</a>.
Note that if <var>parent</var> is an <a>array</a>, <var>active property</var> MUST be <code>null</code>,
and if it is a <a>dictionary</a>, it MUST NOT be <code>null</code>.</p>
<p>The following series of steps is the recursive
portion of the framing algorithm:</p>
<ol>
<li>If <var>frame</var> is an <a>array</a>, set <var>frame</var> to the first member of the <a>array</a>, which MUST be a valid <a>frame</a>.</li>
<li>Initialize flags <var>embed</var>, <var>explicit</var>, and <var>requireAll</var> from
<a>object embed flag</a>, <a>explicit inclusion flag</a>, and
<a>require all flag</a> in <var>state</var> overriding from any property values
for <code>@embed</code>, <code>@explicit</code>, and <code>@requireAll</code> in <var>frame</var>.</li>
<li>Create a list of matched subjects by filtering <var>subjects</var> against <var>frame</var>
using the <a href="#frame-matching">Frame Matching algorithm</a>
with <var>state</var>, <var>subjects</var>, <var>frame</var>, and <var>requireAll</var>.</li>
<li>For each <var>id</var> and associated <a>node object</a> <var>node</var>
from the set of matched subjects, ordered by <var>id</var>:
<p class="ednote">Can we remove sorting, or make it subject to a processing
flag? In general, sorting is a performance problem for JSON-LD, and
inhibits stream processing.</p>
<ol>
<li>Initialize <var>output</var> to a new <a>dictionary</a> with <code>@id</code> and <var>id</var>.</li>
<li>Otherwise, if <var>embed</var> is <code>@never</code> or if a
circular reference would be created by an embed,
add <var>output</var> to <var>parent</var>
and do not perform additional processing for this <var>node</var>.</li>
<li>Otherwise, if <var>embed</var> is <code>@last</code>,
remove any existing embedded node from <var>parent</var> associate with
<var>graph name</var> in <var>state</var>.
<span class="ednote">Requires sorting of subjects. We could consider <code>@sample</code>, to embed
just the first matched node. With sorting, we could also consider <code>@first</code>.</span></li>
<li>If <var>embed</var> is <code>@last</code> or <code>@always</code>