Skip to content

Commit f52c3a5

Browse files
committed
Replace @first and @last with @once. Some pre-existing tests marked json-ld-1.0 and new tests added. The ordered` option is added to these tests to guarantee predictable results.
Fixes #43.
1 parent d72bc11 commit f52c3a5

10 files changed

+134
-110
lines changed

index.html

Lines changed: 38 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -624,13 +624,13 @@ <h4>Object Embed Flag</h4>
624624
The initial value for the <a>object embed flag</a> is set using the
625625
<a data-link-for="JsonLdOptions">embed</a> option.
626626
Consider the following frame
627-
based on the default <code>@first</code> value of the <a>object embed flag</a>:</p>
627+
based on the default <code>@once</code> value of the <a>object embed flag</a>:</p>
628628

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

642642
<aside class="example ds-selector-tabs"
643-
title="Framed library objects with @embed set to @first">
643+
title="Framed library objects with @embed set to @once">
644644
<div class="selectors">
645645
<a class="playground"
646646
data-result-for="#flattened-library-objects"
647-
data-frame="#sample-library-frame-with-implicit-embed-set-to-first"
647+
data-frame="#sample-library-frame-with-implicit-embed-set-to-once"
648648
target="_blank"></a>
649649
</div>
650650
<pre class="selected original nohighlight" data-transform="updateExample"
651-
data-frame="Sample library frame with implicit @embed set to @first"
651+
data-frame="Sample library frame with implicit @embed set to @once"
652652
data-result-for="Flattened library objects">
653653
<!--
654654
{
@@ -674,11 +674,12 @@ <h4>Object Embed Flag</h4>
674674
</pre>
675675
</aside>
676676

677-
<p>Because, the default for the <a>object embed flag</a> is <code>@first</code>
677+
<p>Because, the default for the <a>object embed flag</a> is <code>@once</code>
678678
(in addition to the <a>explicit inclusion flag</a> being <code>false</code>),
679679
non-listed properties are added to the output, and implicitly embedded
680680
using a default empty frame. As a result, the same output used in the
681-
<a href="#lib-example-output">Framed library objects</a> above is generated.</p>
681+
<a href="#lib-example-output">Framed library objects</a> above is generated,
682+
assuming that the <a data-link-for="JsonLdOptions">ordered</a> flag is <code>true</code>.</p>
682683

683684
<p>However, if the <code>@embed</code> property is added explicitly with a
684685
value of <code>@never</code>, the values for <em>Book</em> and <em>Chapter</em> will be excluded.</p>
@@ -726,7 +727,7 @@ <h4>Object Embed Flag</h4>
726727
</pre>
727728
</aside>
728729

729-
<p>To illustrate the case where <code>@first</code> does not expand values,
730+
<p>To illustrate the case where <code>@once</code> does not expand values,
730731
consider an alternate library example where books are doubly indexed.</p>
731732

732733
<pre id="flattened-library-objects-with-double-index"
@@ -765,11 +766,11 @@ <h4>Object Embed Flag</h4>
765766
<div class="selectors">
766767
<a class="playground"
767768
data-result-for="#flattened-library-objects-with-double-index"
768-
data-frame="#sample-library-frame-with-implicit-embed-set-to-first"
769+
data-frame="#sample-library-frame-with-implicit-embed-set-to-once"
769770
target="_blank"></a>
770771
</div>
771772
<pre class="selected original nohighlight" data-transform="updateExample"
772-
data-frame="Sample library frame with implicit @embed set to @first"
773+
data-frame="Sample library frame with implicit @embed set to @once"
773774
data-result-for="Flattened library objects with double index">
774775
<!--
775776
{
@@ -796,60 +797,10 @@ <h4>Object Embed Flag</h4>
796797
</pre>
797798
</aside>
798799

799-
<p>When framed using the same frame with the default <code>@embed</code> of <code>@first</code>,
800-
only the <em>"books"</em> property will have content, and the <em>"contains"</em> property will use a reference.</p>
801-
802-
<p>If we use a frame using <code>"@embed": "@last"</code>,
803-
only the "contains" property will use a reference.</p>
804-
805-
<pre id="sample-library-frame-with-explicit-embed-set-to-last"
806-
class="example frame nohighlight" data-transform="updateExample"
807-
data-content-type="application/ld+json;profile=http://www.w3.org/ns/json-ld#framed"
808-
data-frame-for="Flattened library objects with double index"
809-
title="Sample library frame with explicit @embed set to @last">
810-
<!--
811-
{
812-
"@context": {"@vocab": "http://example.org/"},
813-
"@type": "Library",
814-
****"@embed": "@last"****
815-
}
816-
-->
817-
</pre>
818-
<aside class="example ds-selector-tabs"
819-
title="Framed library objects with double index and @last">
820-
<div class="selectors">
821-
<a class="playground"
822-
data-result-for="#flattened-library-objects-with-double-index"
823-
data-frame="#sample-library-frame-with-explicit-embed-set-to-last"
824-
target="_blank"></a>
825-
</div>
826-
<pre class="selected original nohighlight" data-transform="updateExample"
827-
data-frame="Sample library frame with explicit @embed set to @last"
828-
data-result-for="Flattened library objects with double index">
829-
<!--
830-
{
831-
"@context": {"@vocab": "http://example.org/"},
832-
"@graph": [{
833-
"@id": "http://example.org/library",
834-
"@type": "Library",
835-
****"books": {"@id": "http://example.org/library/the-republic"},****
836-
****"contains": {
837-
"@id": "http://example.org/library/the-republic",
838-
"@type": "Book",
839-
"contains": {
840-
"@id": "http://example.org/library/the-republic#introduction",
841-
"@type": "Chapter",
842-
"description": "An introductory chapter on The Republic.",
843-
"title": "The Introduction"
844-
},
845-
"creator": "Plato",
846-
"title": "The Republic"
847-
}****
848-
}]
849-
}
850-
-->
851-
</pre>
852-
</aside>
800+
<p>When framed using the same frame with the default <code>@embed</code> of <code>@once</code>,
801+
only the <em>"books"</em> property will have content,
802+
if the <a data-link-for="JsonLdOptions">ordered</a> flag is <code>true</code>,
803+
and the <em>"contains"</em> property will use a reference.</p>
853804

854805
<p>If we use a frame using <code>"@embed": "@always"</code>,
855806
both properties will include expanded values.</p>
@@ -1431,15 +1382,15 @@ <h2>Syntax Tokens and Keywords</h2>
14311382
Always embed <a>node objects</a> as property values, unless this would
14321383
cause a circular reference.
14331384
</dd>
1434-
<dt class="changed"><code>@first</code></dt><dd class="changed">
1435-
Only the first value within a given <a>node object</a> should be embedded,
1436-
subsequent values of other properties use a <a>node reference</a>. This is the
1385+
<dt class="changed"><code>@once</code></dt><dd class="changed">
1386+
Juse a single value within a given <a>node object</a> should be embedded,
1387+
other values of other properties use a <a>node reference</a>. This is the
14371388
default value if neither <code>@embed</code> nor <a>object embed flag</a>
14381389
is not specified.
1439-
</dd>
1440-
<dt><code>@last</code></dt><dd>
1441-
Only the last value within a given <a>node object</a> should be embedded,
1442-
previous values of other properties use a <a>node reference</a>.
1390+
<div class="note">The specific <a>node object</a> chosen to embed depends on
1391+
ordering. if the <a data-link-for="JsonLdOptions">ordered</a> flag is <code>true</code>,
1392+
this will be the first <a>node object</a> encountered,
1393+
otherwise, it may be any node object.</div>
14431394
</dd>
14441395
<dt><code>@never</code></dt><dd>
14451396
Always use a <a>node reference</a> when serializing matching values.
@@ -1536,7 +1487,7 @@ <h3>Framing Algorithm</h3>
15361487

15371488
<p>The recursive algorithm operates with a <a>framing state</a> (<var>state</var>),
15381489
created initially using
1539-
the <a>object embed flag</a> set to <code>@first</code>,
1490+
the <a>object embed flag</a> set to <code>@once</code>,
15401491
the <a>explicit inclusion flag</a> set to <code>false</code>,
15411492
the <a>require all flag</a> set to <code>true</code>,
15421493
the <a>omit default flag</a> set to <code>false</code>,
@@ -1583,18 +1534,11 @@ <h3>Framing Algorithm</h3>
15831534
circular reference would be created by an embed,
15841535
add <var>output</var> to <var>parent</var>
15851536
and do not perform additional processing for this <var>node</var>.</li>
1586-
<li class="changed">Otherwise, if <var>embed</var> is <code>@first</code>
1537+
<li class="changed">Otherwise, if <var>embed</var> is <code>@once</code>
15871538
and parent has an existing embedded node in <var>parent</var> associated with
15881539
<var>graph name</var> and <var>id</var> in <var>state</var>,
15891540
add <var>output</var> to <var>parent</var>
1590-
and do not perform additional processing for this <var>node</var>.
1591-
<span class="ednote">Requires sorting of subjects.
1592-
We could consider <code>@sample</code>, to embed in a property, rather than the lexicographically first.</span></li>
1593-
<li>Otherwise, if <var>embed</var> is <code>@last</code>,
1594-
remove any existing embedded node from <var>parent</var> associated with
1595-
<var>graph name</var> and <var>id</var> in <var>state</var>.
1596-
<span class="ednote">Requires sorting of subjects.
1597-
We could consider <code>@sample</code>, to embed in a property, rather than the lexicographically last.</span></li>
1541+
and do not perform additional processing for this <var>node</var>.</li>
15981542
<li class="changed">If <var>graph map</var> in <var>state</var> has an entry for <var>id</var>:
15991543
<ol>
16001544
<li>If <var>frame</var> does not have a <code>@graph</code> <a>member</a>,
@@ -1989,19 +1933,18 @@ <h3>JsonLdOptions</h3>
19891933

19901934
<pre class="idl" data-transform="unComment"><!--
19911935
dictionary JsonLdOptions {
1992-
(JsonLdEmbed or boolean) embed = "@first";
1993-
boolean explicit = false;
1994-
boolean omitDefault = false;
1936+
(JsonLdEmbed or boolean) embed = "@once";
1937+
boolean explicit = false;
1938+
boolean omitDefault = false;
19951939
boolean omitGraph;
1996-
boolean requireAll = false;
1940+
boolean requireAll = false;
19971941
boolean frameDefault = false;
1998-
boolean ordered = false;
1942+
boolean ordered = false;
19991943
};
20001944
20011945
enum JsonLdEmbed {
20021946
"@always",
2003-
"@first",
2004-
"@last",
1947+
"@once",
20051948
"@never"
20061949
};
20071950
-->
@@ -2015,7 +1958,7 @@ <h3>JsonLdOptions</h3>
20151958
<dd>Sets the value <a>object embed flag</a> used in the
20161959
<a href="#framing-algorithm">Framing Algorithm</a>.
20171960
A boolean value of <code>true</code> sets the flag to
2018-
<code>@last</code>, while an value of <code>false</code> sets the flag
1961+
<code>@once</code>, while an value of <code>false</code> sets the flag
20191962
to <code>@never</code>.</dd>
20201963
<dt><dfn data-dfn-for="JsonLdOptions">explicit</dfn></dt>
20211964
<dd>Sets the value <a>explicit inclusion flag</a> used in the
@@ -2045,14 +1988,11 @@ <h3>JsonLdOptions</h3>
20451988
<dt><dfn data-dfn-for="JsonLdEmbed">@always</dfn></dt><dd>
20461989
Always embed <a>node objects</a> as property values, unless this would
20471990
cause a circular reference.</dd>
2048-
<dt><dfn data-dfn-for="JsonLdEmbed">@first</dfn></dt><dd>
2049-
Only the first value within a given <a>node object</a> should be embedded,
2050-
subsequent values of other properties use a <a>node reference</a>. This is the
1991+
<dt><dfn data-dfn-for="JsonLdEmbed">@once</dfn></dt><dd>
1992+
Only a single value within a given <a>node object</a> should be embedded,
1993+
other values of other properties use a <a>node reference</a>. This is the
20511994
default value if neither <code>@embed</code> nor <a>object embed flag</a>
20521995
is not specified.</dd>
2053-
<dt><dfn data-dfn-for="JsonLdEmbed">@last</dfn></dt><dd>
2054-
Only the last value within a given <a>node object</a> should be embedded,
2055-
previous values of other properties use a <a>node reference</a>.</dd>
20561996
<dt class="changed"><dfn data-dfn-for="JsonLdEmbed">@never</dfn></dt><dd class="changed">
20571997
Always use a <a>node reference</a> when serializing matching values.</dd>
20581998
</dl>
@@ -2241,6 +2181,8 @@ <h2>Changes since JSON-LD Community Group Final Report</h2>
22412181
evaluating test results have been updated accordingly.</li>
22422182
<li>The IANA registration is changed from <code>application/ld-frame+json</code> to
22432183
<code>application/ld+json</code> with a required <code>profile</code> parameter.</li>
2184+
<li>Removed <code>@first</code> and <code>@last</code> values for the
2185+
<a>object embed flag</a> in favor of <code>@once</code>.</li>
22442186
</ul>
22452187
</section>
22462188

tests/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Implementations create their own infrastructure for running the test suite. In p
3535

3636
* Some algorithms, may not preserve the order of statements listed in the input document, and provision should be taken for performing unordered array comparison, for arrays other than values of `@list`. (This may be difficult for compacted results, where array value ordering is dependent on the associated term definition).
3737
* Some implementations may choose an alternative Blank Node Label algorithm, the comparison between documents containing blank node labels should take this into consideration. (One way to do this may be to reduce both results and _expected_ to datsets to extract a bijective mapping of blank node labels between the two datasets as described in [RDF Dataset Isomorphism](https://www.w3.org/TR/rdf11-concepts/#dfn-dataset-isomorphism)).
38+
* Note that the `"@embed": "@once"` test behavior requires that the `ordered` option be set to `true` for repeatability.
3839

3940
# Contributing
4041

0 commit comments

Comments
 (0)