Skip to content

Commit 1cc898b

Browse files
committed
Add @embed: @first and use as default.
Depends on #42. Fixes #43.
1 parent 8f754cc commit 1cc898b

File tree

2 files changed

+88
-70
lines changed

2 files changed

+88
-70
lines changed

index.html

Lines changed: 80 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -628,13 +628,13 @@ <h4>Object Embed Flag</h4>
628628
The initial value for the <a>object embed flag</a> is set using the
629629
<a data-link-for="JsonLdOptions">embed</a> option.
630630
Consider the following frame
631-
based on the default <code>@last</code> value of the <a>object embed flag</a>:</p>
631+
based on the default <code>@first</code> value of the <a>object embed flag</a>:</p>
632632

633-
<pre id="sample-library-frame-with-explicit-embed-set-to-last"
633+
<pre id="sample-library-frame-with-explicit-embed-set-to-first"
634634
class="example frame" data-transform="updateExample"
635635
data-content-type="application/ld+json;profile=http://www.w3.org/ns/json-ld#framed"
636636
data-frame-for="Flattened library objects"
637-
title="Sample library frame with implicit @embed set to @last">
637+
title="Sample library frame with implicit @embed set to @first">
638638
<!--
639639
{
640640
"@context": {"@vocab": "http://example.org/"},
@@ -644,15 +644,15 @@ <h4>Object Embed Flag</h4>
644644
</pre>
645645

646646
<aside class="example ds-selector-tabs"
647-
title="Framed library objects with @embed set to @last">
647+
title="Framed library objects with @embed set to @first">
648648
<div class="selectors">
649649
<a class="playground"
650650
data-result-for="#flattened-library-objects"
651-
data-frame="#sample-library-frame-with-explicit-embed-set-to-last"
651+
data-frame="#sample-library-frame-with-explicit-embed-set-to-first"
652652
target="_blank"></a>
653653
</div>
654654
<pre class="selected original nohighlight" data-transform="updateExample"
655-
data-frame="Sample library frame with implicit @embed set to @last"
655+
data-frame="Sample library frame with implicit @embed set to @first"
656656
data-result-for="Flattened library objects">
657657
<!--
658658
{
@@ -678,7 +678,7 @@ <h4>Object Embed Flag</h4>
678678
</pre>
679679
</aside>
680680

681-
<p>Because, the default for the <a>object embed flag</a> is <code>@last</code>
681+
<p>Because, the default for the <a>object embed flag</a> is <code>@first</code>
682682
(in addition to the <a>explicit inclusion flag</a> being <code>false</code>),
683683
non-listed properties are added to the output, and implicitly embedded
684684
using a default empty frame. As a result, the same output used in the
@@ -1293,12 +1293,16 @@ <h2>Syntax Tokens and Keywords</h2>
12931293
Always embed <a>node objects</a> as property values, unless this would
12941294
cause a circular reference.
12951295
</dd>
1296-
<dt><code>@last</code></dt><dd>
1297-
Only the last value within a given <a>node object</a> should be embedded,
1298-
previous values of other properties use a <a>node reference</a>. This is the
1296+
<dt class="changed"><code>@first</code></dt><dd class="changed">
1297+
Only the first value within a given <a>node object</a> should be embedded,
1298+
subsequent values of other properties use a <a>node reference</a>. This is the
12991299
default value if neither <code>@embed</code> nor <a>object embed flag</a>
13001300
is not specified.
13011301
</dd>
1302+
<dt><code>@last</code></dt><dd>
1303+
Only the last value within a given <a>node object</a> should be embedded,
1304+
previous values of other properties use a <a>node reference</a>.
1305+
</dd>
13021306
<dt><code>@never</code></dt><dd>
13031307
Always use a <a>node reference</a> when serializing matching values.
13041308
</dd>
@@ -1441,77 +1445,79 @@ <h3>Framing Algorithm</h3>
14411445
circular reference would be created by an embed,
14421446
add <var>output</var> to <var>parent</var>
14431447
and do not perform additional processing for this <var>node</var>.</li>
1448+
<li class="changed">Otherwise, if <var>embed</var> is <code>@first</code>
1449+
and parent has an existing embedded node in <var>parent</var> associated with
1450+
<var>graph name</var> and <var>id</var> in <var>state</var>,
1451+
add <var>output</var> to <var>parent</var>
1452+
and do not perform additional processing for this <var>node</var>.
1453+
<span class="ednote">Requires sorting of subjects.</span></li>
14441454
<li>Otherwise, if <var>embed</var> is <code>@last</code>,
1445-
remove any existing embedded node from <var>parent</var> associate with
1446-
<var>graph name</var> in <var>state</var>.
1455+
remove any existing embedded node from <var>parent</var> associated with
1456+
<var>graph name</var> and <var>id</var> in <var>state</var>.
14471457
<span class="ednote">Requires sorting of subjects. We could consider <code>@sample</code>, to embed
14481458
just the first matched node. With sorting, we could also consider <code>@first</code>.</span></li>
1449-
<li>If <var>embed</var> is <code>@last</code> or <code>@always</code>
1459+
<li class="changed">If <var>graph map</var> in <var>state</var> has an entry for <var>id</var>:
14501460
<ol>
1451-
<li class="changed">If <var>graph map</var> in <var>state</var> has an entry for <var>id</var>:
1461+
<li>If <var>frame</var> does not have a <code>@graph</code> <a>member</a>,
1462+
set <var>recurse</var> to <code>true</code>, unless <var>graph name</var> in <var>state</var> is <code>@merged</code>
1463+
and set <var>subframe</var> to a new empty <a>dictionary</a>.</li>
1464+
<li>Otherwise, set <var>subframe</var> to the first entry for <code>@graph</code> in <var>frame</var>,
1465+
or a new empty <a>dictionary</a>, if it does not exist, and
1466+
set <var>recurse</var> to <code>true</code>, unless <var>id</var>
1467+
is <code>@merged</code> or <code>@default</code>.</li>
1468+
<li>If <var>recurse</var> is <code>true</code>:
14521469
<ol>
1453-
<li>If <var>frame</var> does not have a <code>@graph</code> <a>member</a>,
1454-
set <var>recurse</var> to <code>true</code>, unless <var>graph name</var> in <var>state</var> is <code>@merged</code>
1455-
and set <var>subframe</var> to a new empty <a>dictionary</a>.</li>
1456-
<li>Otherwise, set <var>subframe</var> to the first entry for <code>@graph</code> in <var>frame</var>,
1457-
or a new empty <a>dictionary</a>, if it does not exist, and
1458-
set <var>recurse</var> to <code>true</code>, unless <var>id</var>
1459-
is <code>@merged</code> or <code>@default</code>.</li>
1460-
<li>If <var>recurse</var> is <code>true</code>:
1461-
<ol>
1462-
<li>Push <var>graph name</var> from <var>state</var> onto <var>graph stack</var>
1463-
in <var>state</var>.</li>
1464-
<li>Set the value of <var>graph name</var> in <var>state</var> to <var>id</var>.</li>
1465-
<li>Invoke the recursive algorithm using <var>state</var>,
1466-
the keys from the <var>graph map</var> in <var>state</var> associated with id as <var>subjects</var>,
1467-
<var>subframe</var> as <var>frame</var>,
1468-
<var>output</var> as <var>parent</var>, and <code>@graph</code> as <var>active property</var>.
1469-
<li>Pop the value from <var>graph stack</var> in <var>state</var> and set <var>graph name</var> in <var>state</var>
1470-
back to that value.</li>
1471-
</ol>
1472-
</li>
1470+
<li>Push <var>graph name</var> from <var>state</var> onto <var>graph stack</var>
1471+
in <var>state</var>.</li>
1472+
<li>Set the value of <var>graph name</var> in <var>state</var> to <var>id</var>.</li>
1473+
<li>Invoke the recursive algorithm using <var>state</var>,
1474+
the keys from the <var>graph map</var> in <var>state</var> associated with id as <var>subjects</var>,
1475+
<var>subframe</var> as <var>frame</var>,
1476+
<var>output</var> as <var>parent</var>, and <code>@graph</code> as <var>active property</var>.
1477+
<li>Pop the value from <var>graph stack</var> in <var>state</var> and set <var>graph name</var> in <var>state</var>
1478+
back to that value.</li>
14731479
</ol>
14741480
</li>
1475-
<li>For each <var>property</var> and <var>objects</var> in <var>node</var>, ordered lexicographically by <var>property</var>
1476-
<span class="changed">if the optional <a data-link-for="JsonLdOptions">ordered</a> flag is <code>true</code></span>:
1481+
</ol>
1482+
</li>
1483+
<li>For each <var>property</var> and <var>objects</var> in <var>node</var>, ordered lexicographically by <var>property</var>
1484+
<span class="changed">if the optional <a data-link-for="JsonLdOptions">ordered</a> flag is <code>true</code></span>:
1485+
<ol>
1486+
<li>If <var>property</var> is a <a>keyword</a>, add <var>property</var> and <var>objects</var>
1487+
to <var>output</var>.</li>
1488+
<li>Otherwise, if <var>property</var> is not in <var>frame</var>, and <var>explicit</var> is <code>true</code>,
1489+
<a>processors</a> MUST NOT add any values for <var>property</var> to <var>output</var>, and the following
1490+
steps are skipped.</li>
1491+
<li>For each <var>item</var> in <var>objects</var>:
14771492
<ol>
1478-
<li>If <var>property</var> is a <a>keyword</a>, add <var>property</var> and <var>objects</var>
1479-
to <var>output</var>.</li>
1480-
<li>Otherwise, if <var>property</var> is not in <var>frame</var>, and <var>explicit</var> is <code>true</code>,
1481-
<a>processors</a> MUST NOT add any values for <var>property</var> to <var>output</var>, and the following
1482-
steps are skipped.</li>
1483-
<li>For each <var>item</var> in <var>objects</var>:
1493+
<li>If <var>item</var> is a <a>dictionary</a> with the property <code>@list</code>, then each
1494+
<var>listitem</var> in the list is processed in sequence and added to a new list <a>dictionary</a>
1495+
in output:
14841496
<ol>
1485-
<li>If <var>item</var> is a <a>dictionary</a> with the property <code>@list</code>, then each
1486-
<var>listitem</var> in the list is processed in sequence and added to a new list <a>dictionary</a>
1487-
in output:
1488-
<ol>
1489-
<li>If <var>listitem</var> is a <a>node reference</a>,
1490-
invoke the recursive algorithm using <var>state</var>,
1491-
the value of <code>@id</code> from <var>listitem</var>
1492-
as the sole item in a new <var>subjects</var> <a>array</a>,
1493-
the first value from <code>@list</code> in <var>frame</var> as <var>frame</var>,
1494-
<var>list</var> as <var>parent</var>, and <code>@list</code> as <var>active property</var>.
1495-
If <var>frame</var> does not exist, create a new <var>frame</var> using a new <a>dictionary</a>
1496-
with properties for <code>@embed</code>, <code>@explicit</code> and <code>@requireAll</code>
1497-
taken from <var>embed</var>, <var>explicit</var> and <var>requireAll</var>.
1498-
<span class="ednote">Could this use the <var>list</var> <a>array</a>, and <code>null</code> for <var>active property</var>?</span></li>
1499-
<li>Otherwise, append a copy of <var>listitem</var> to <code>@list</code> in <var>list</var>.</li>
1500-
</ol>
1501-
</li>
1502-
<li>If <var>item</var> is a <a>node reference</a>,
1497+
<li>If <var>listitem</var> is a <a>node reference</a>,
15031498
invoke the recursive algorithm using <var>state</var>,
1504-
the value of <code>@id</code> from <var>item</var>
1499+
the value of <code>@id</code> from <var>listitem</var>
15051500
as the sole item in a new <var>subjects</var> <a>array</a>,
1506-
the first value from <var>property</var> in <var>frame</var> as <var>frame</var>,
1507-
<var>output</var> as <var>parent</var>, and <var>property</var> as <var>active property</var>.
1501+
the first value from <code>@list</code> in <var>frame</var> as <var>frame</var>,
1502+
<var>list</var> as <var>parent</var>, and <code>@list</code> as <var>active property</var>.
15081503
If <var>frame</var> does not exist, create a new <var>frame</var> using a new <a>dictionary</a>
15091504
with properties for <code>@embed</code>, <code>@explicit</code> and <code>@requireAll</code>
1510-
taken from <var>embed</var>, <var>explicit</var> and <var>requireAll</var>.</li>
1511-
<li>Otherwise, append a copy of <var>item</var> to <a>active property</a> in
1512-
<var>output</var>.</li>
1505+
taken from <var>embed</var>, <var>explicit</var> and <var>requireAll</var>.
1506+
<span class="ednote">Could this use the <var>list</var> <a>array</a>, and <code>null</code> for <var>active property</var>?</span></li>
1507+
<li>Otherwise, append a copy of <var>listitem</var> to <code>@list</code> in <var>list</var>.</li>
15131508
</ol>
15141509
</li>
1510+
<li>If <var>item</var> is a <a>node reference</a>,
1511+
invoke the recursive algorithm using <var>state</var>,
1512+
the value of <code>@id</code> from <var>item</var>
1513+
as the sole item in a new <var>subjects</var> <a>array</a>,
1514+
the first value from <var>property</var> in <var>frame</var> as <var>frame</var>,
1515+
<var>output</var> as <var>parent</var>, and <var>property</var> as <var>active property</var>.
1516+
If <var>frame</var> does not exist, create a new <var>frame</var> using a new <a>dictionary</a>
1517+
with properties for <code>@embed</code>, <code>@explicit</code> and <code>@requireAll</code>
1518+
taken from <var>embed</var>, <var>explicit</var> and <var>requireAll</var>.</li>
1519+
<li>Otherwise, append a copy of <var>item</var> to <a>active property</a> in
1520+
<var>output</var>.</li>
15151521
</ol>
15161522
</li>
15171523

@@ -1844,7 +1850,7 @@ <h3>JsonLdOptions</h3>
18441850

18451851
<pre class="idl" data-transform="unComment"><!--
18461852
dictionary JsonLdOptions {
1847-
(JsonLdEmbed or boolean) embed = "@last";
1853+
(JsonLdEmbed or boolean) embed = "@first";
18481854
boolean explicit = false;
18491855
boolean omitDefault = false;
18501856
boolean omitGraph;
@@ -1855,6 +1861,7 @@ <h3>JsonLdOptions</h3>
18551861
18561862
enum JsonLdEmbed {
18571863
"@always",
1864+
"@first",
18581865
"@last",
18591866
"@never"
18601867
};
@@ -1899,11 +1906,14 @@ <h3>JsonLdOptions</h3>
18991906
<dt><dfn data-dfn-for="JsonLdEmbed">@always</dfn></dt><dd>
19001907
Always embed <a>node objects</a> as property values, unless this would
19011908
cause a circular reference.</dd>
1902-
<dt><dfn data-dfn-for="JsonLdEmbed">@last</dfn></dt><dd>
1903-
Only the last value within a given <a>node object</a> should be embedded,
1904-
previous values of other properties use a <a>node reference</a>. This is the
1909+
<dt><dfn data-dfn-for="JsonLdEmbed">@first</dfn></dt><dd>
1910+
Only the first value within a given <a>node object</a> should be embedded,
1911+
subsequent values of other properties use a <a>node reference</a>. This is the
19051912
default value if neither <code>@embed</code> nor <a>object embed flag</a>
19061913
is not specified.</dd>
1914+
<dt><dfn data-dfn-for="JsonLdEmbed">@last</dfn></dt><dd>
1915+
Only the last value within a given <a>node object</a> should be embedded,
1916+
previous values of other properties use a <a>node reference</a>.</dd>
19071917
<dt class="changed"><dfn data-dfn-for="JsonLdEmbed">@never</dfn></dt><dd class="changed">
19081918
Always use a <a>node reference</a> when serializing matching values.</dd>
19091919
</dl>

tests/frame-manifest.jsonld

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,14 @@
515515
"input": "frame/0059-in.jsonld",
516516
"frame": "frame/0059-frame.jsonld",
517517
"expect": "frame/0059-out.jsonld"
518+
}, {
519+
"@id": "#t0060",
520+
"@type": ["jld:PositiveEvaluationTest", "jld:FrameTest"],
521+
"name": "@embed: @first only embeds first value with node reference",
522+
"purpose": "Verify that within a matched node and @embed: @first, by only the first reference will be embedded.",
523+
"input": "frame/0060-in.jsonld",
524+
"frame": "frame/0060-frame.jsonld",
525+
"expect": "frame/0060-out.jsonld"
518526
}, {
519527
"@id": "#tg001",
520528
"@type": ["jld:PositiveEvaluationTest", "jld:FrameTest"],

0 commit comments

Comments
 (0)