Skip to content

Commit 99c0df2

Browse files
committed
Update framing algorithm to use embedded flag in _framing state_, defaulting to false, and set to true when recursing into node objects. Add tests to not add node at top level if embedded is false and it has already been serialized, and also use the check on @embed: @never to make that happen only when in an embedded node object.
Update test g010 to not use `@type` in framing. For #27.
1 parent 1aff7e8 commit 99c0df2

File tree

3 files changed

+34
-18
lines changed

3 files changed

+34
-18
lines changed

common/algorithm-terms.html

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@
1313
A flag specifying that for <a>properties</a> to be included in the output,
1414
they MUST be explicitly declared in the matching <a>frame</a>.</dd>
1515
<dt><dfn data-cite="JSON-LD11-FRAMING#dfn-framing-state">framing state</dfn></dt><dd>
16-
A <a>map</a> containing values for the
17-
<a>object embed flag</a>, the
18-
<a>require all flag</a>, the
19-
<a>explicit inclusion flag</a>, and the
20-
<a>omit default flag</a>.</dd>
16+
A <a>map</a> containing values for
17+
the <a>object embed flag</a>,
18+
the <a>require all flag</a>,
19+
<span class="changed">the <a>embedded flag</a>,
20+
used internally to help determine if object embedding is appropriate,</span>
21+
the <a>explicit inclusion flag</a>,
22+
and the <a>omit default flag</a>.</dd>
2123
<dt><dfn data-cite="JSON-LD11-FRAMING#dfn-input-frame">input frame</dfn></dt><dd>
2224
The initial <a>Frame</a> provided to the framing algorithm.</dd>
2325
<dt><dfn data-cite="JSON-LD11-API#dfn-json-ld-input">JSON-LD input</dfn></dt><dd>

index.html

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,6 +1500,7 @@ <h3>Framing Algorithm</h3>
15001500
<p>The recursive algorithm operates with a <a>framing state</a> (<var>state</var>),
15011501
created initially using
15021502
the <a>object embed flag</a> set to <code>@once</code>,
1503+
<span class="changed">the <dfn>embedded flag</dfn>, set to `false`,</span>
15031504
the <a>explicit inclusion flag</a> set to <code>false</code>,
15041505
the <a>require all flag</a> set to <code>true</code>,
15051506
the <a>omit default flag</a> set to <code>false</code>,
@@ -1542,12 +1543,19 @@ <h3>Framing Algorithm</h3>
15421543
<span class="changed">if the optional <a data-link-for="JsonLdOptions">ordered</a> flag is <code>true</code></span>:
15431544
<ol>
15441545
<li>Initialize <var>output</var> to a new <a>map</a> with <code>@id</code> and <var>id</var>.</li>
1545-
<li>Otherwise, if <var>embed</var> is <code>@never</code> or if a
1546+
<li class="changed">If the <a>embedded flag</a> in <var>state</var> is `false`
1547+
and there is an existing embedded node in <var>parent</var> associated with
1548+
<var>graph name</var> and <var>id</var> in <var>state</var>,
1549+
do not perform additional processing for this <var>node</var>.
1550+
</li>
1551+
<li class="changed">Otherwise, if the <a>embedded flag</a> in <var>state</var> is `true`
1552+
and either <var>embed</var> is <code>@never</code> or if a
15461553
circular reference would be created by an embed,
15471554
add <var>output</var> to <var>parent</var>
15481555
and do not perform additional processing for this <var>node</var>.</li>
1549-
<li class="changed">Otherwise, if <var>embed</var> is <code>@once</code>
1550-
and parent has an existing embedded node in <var>parent</var> associated with
1556+
<li class="changed">Otherwise, if the <a>embedded flag</a> in <var>state</var> is `true`,
1557+
<var>embed</var> is <code>@once</code>,
1558+
and there is an existing embedded node in <var>parent</var> associated with
15511559
<var>graph name</var> and <var>id</var> in <var>state</var>,
15521560
add <var>output</var> to <var>parent</var>
15531561
and do not perform additional processing for this <var>node</var>.</li>
@@ -1565,19 +1573,24 @@ <h3>Framing Algorithm</h3>
15651573
<li>Push <var>graph name</var> from <var>state</var> onto <var>graph stack</var>
15661574
in <var>state</var>.</li>
15671575
<li>Set the value of <var>graph name</var> in <var>state</var> to <var>id</var>.</li>
1568-
<li>Invoke the recursive algorithm using <var>state</var>,
1576+
<li>Set the value of <a>embedded flag</a> in <var>state</var> to `false`.</li>
1577+
<li>Invoke the recursive algorithm
1578+
using a copy of <var>state</var>
1579+
with the value of <var>graph name</var> set to <var>id</var>
1580+
and the value of <a>embedded flag</a> set to `false`,
15691581
the keys from the <var>graph map</var> in <var>state</var> associated with id as <var>subjects</var>,
15701582
<var>subframe</var> as <var>frame</var>,
15711583
<var>output</var> as <var>parent</var>, and <code>@graph</code> as <var>active property</var>.
1572-
<li>Pop the value from <var>graph stack</var> in <var>state</var> and set <var>graph name</var> in <var>state</var>
1573-
back to that value.</li>
1584+
<li>Pop the value from <var>graph stack</var> in <var>state</var>.</li>
15741585
</ol>
15751586
</li>
15761587
</ol>
15771588
</li>
15781589
<li class="changed">
15791590
If <var>frame</var> has an `@included` <a>entry</a>,
1580-
invoke the recursive algorithm using <var>state</var>, <var>subjects</var>, <var>frame</var>,
1591+
invoke the recursive algorithm
1592+
using a copy of <var>state</var> with the value of <a>embedded flag</a> set to `true`,
1593+
<var>subjects</var>, <var>frame</var>,
15811594
<var>output</var> as <var>parent</var>, and `@included` as <var>active property</var>.
15821595
</li>
15831596
<li>For each <var>property</var> and <var>objects</var> in <var>node</var>, ordered lexicographically by <var>property</var>
@@ -1595,7 +1608,8 @@ <h3>Framing Algorithm</h3>
15951608
in output:
15961609
<ol>
15971610
<li>If <var>listitem</var> is a <a>node reference</a>,
1598-
invoke the recursive algorithm using <var>state</var>,
1611+
invoke the recursive algorithm
1612+
<span class="changed">using a copy of <var>state</var> with the value of <a>embedded flag</a> set to `true`</span>,
15991613
the value of <code>@id</code> from <var>listitem</var>
16001614
as the sole item in a new <var>subjects</var> <a>array</a>,
16011615
the first value from <code>@list</code> in <var>frame</var> as <var>frame</var>,
@@ -1608,7 +1622,8 @@ <h3>Framing Algorithm</h3>
16081622
</ol>
16091623
</li>
16101624
<li>If <var>item</var> is a <a>node reference</a>,
1611-
invoke the recursive algorithm using <var>state</var>,
1625+
invoke the recursive algorithm
1626+
<span class="changed">using a copy of <var>state</var> with the value of <a>embedded flag</a> set to `true`</span>,
16121627
the value of <code>@id</code> from <var>item</var>
16131628
as the sole item in a new <var>subjects</var> <a>array</a>,
16141629
the first value from <var>property</var> in <var>frame</var> as <var>frame</var>,
@@ -1646,7 +1661,8 @@ <h3>Framing Algorithm</h3>
16461661
<var>reverse property</var> containing a <a>node reference</a> with an <code>@id</code> of <var>id</var>:
16471662
<ol>
16481663
<li>Add <var>reverse property</var> to <var>reverse dict</var> with a new empty <a>array</a> as its value.</li>
1649-
<li>Invoke the recursive algorithm using <var>state</var>,
1664+
<li>Invoke the recursive algorithm
1665+
<span class="changed">using a copy of <var>state</var> with the value of <a>embedded flag</a> set to `true`</span>,
16501666
the <var>reverse id</var>
16511667
as the sole item in a new <var>subjects</var> <a>array</a>,
16521668
<var>sub frame</var> as <var>frame</var>,

tests/frame/g010-frame.jsonld

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
},
66
"@graph": {
77
"subject": {},
8-
"proof": {
9-
"@type": "ex:Proof"
10-
}
8+
"proof": {}
119
}
1210
}

0 commit comments

Comments
 (0)