Skip to content

Commit a87357d

Browse files
committed
Add the ordered option for controlling elements of the framing algorithm.
For w3c/json-ld-api#8. (cherry picked from commit 42b1aae)
1 parent ef30fa4 commit a87357d

File tree

2 files changed

+50
-15
lines changed

2 files changed

+50
-15
lines changed

index.html

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,10 +1015,8 @@ <h3>Framing Algorithm</h3>
10151015
using the <a href="#frame-matching">Frame Matching algorithm</a>
10161016
with <var>state</var>, <var>subjects</var>, <var>frame</var>, and <var>requireAll</var>.</li>
10171017
<li>For each <var>id</var> and associated <a>node object</a> <var>node</var>
1018-
from the set of matched subjects, ordered by <var>id</var>:
1019-
<p class="ednote">Can we remove sorting, or make it subject to a processing
1020-
flag? In general, sorting is a performance problem for JSON-LD, and
1021-
inhibits stream processing.</p>
1018+
from the set of matched subjects, ordered lexographically by <var>id</var>
1019+
<span class="changed">if the optional <a data-link-for="JsonLdOptions">ordered</a> flag is <code>true</code></span>:
10221020
<ol>
10231021
<li>Initialize <var>output</var> to a new <a>dictionary</a> with <code>@id</code> and <var>id</var>.</li>
10241022
<li>Otherwise, if <var>embed</var> is <code>@never</code> or if a
@@ -1056,7 +1054,8 @@ <h3>Framing Algorithm</h3>
10561054
</li>
10571055
</ol>
10581056
</li>
1059-
<li>For each <var>property</var> and <var>objects</var> in <var>node</var>, ordered by <var>property</var>:
1057+
<li>For each <var>property</var> and <var>objects</var> in <var>node</var>, ordered lexographically by <var>property</var>
1058+
<span class="changed">if the optional <a data-link-for="JsonLdOptions">ordered</a> flag is <code>true</code></span>:
10601059
<ol>
10611060
<li>If <var>property</var> is a <a>keyword</a>, add <var>property</var> and <var>objects</var>
10621061
to <var>output</var>.</li>
@@ -1322,14 +1321,16 @@ <h3>JsonLdProcessor</h3>
13221321
following steps are then executed asynchronously.</li>
13231322
<li>Set <var>expanded input</var> to the result of using the
13241323
<a data-cite="JSON-LD11-API#dom-jsonldprocessor-expand">expand</a>
1325-
method using <a data-lt="JsonLdProcessor-frame-input">input</a> and <a data-lt="JsonLdProcessor-frame-options">options</a>.
1324+
method using <a data-lt="JsonLdProcessor-frame-input">input</a> and <a data-lt="JsonLdProcessor-frame-options">options</a>
1325+
<span class="changed">with <a data-link-for="JsonldOptions">ordered</a> set to <code>false</code></span>.
13261326
<li>Set <var>expanded frame</var> to the result of using the
13271327
<code class="idlMemberName"><a data-cite="JSON-LD11-API#dom-jsonldprocessor-expand">expand</a></code>
13281328
method using
13291329
<a data-lt="JsonLdProcessor-frame-frame">frame</a> and
13301330
<a data-lt="JsonLdProcessor-frame-options">options</a> with
1331-
<code class="idlMemberName"><a data-cite="JSON-LD11-API#dom-jsonldoptions-expandcontext">expandContext</a></code> set to <code>null</code>
1332-
and the <a data-cite="JSON-LD11-API#dom-jsonldoptions-frameexpansion">frameExpansion</a> option set to <code>true</code>.
1331+
<code class="idlMemberName"><a data-cite="JSON-LD11-API#dom-jsonldoptions-expandcontext">expandContext</a></code> set to <code>null</code>,
1332+
the <a data-cite="JSON-LD11-API#dom-jsonldoptions-frameexpansion">frameExpansion</a> option set to <code>true</code>,
1333+
<span class="changed">and the <a data-link-for="JsonldOptions">ordered</a> option set to <code>false</code></span>.
13331334
<li>Set <var>context</var> to the value of <code>@context</code>
13341335
from <a data-lt="JsonLdProcessor-frame-frame">frame</a>, if it exists, or to
13351336
a new empty <a>context</a>, otherwise.</li>
@@ -1426,11 +1427,12 @@ <h3>JsonLdOptions</h3>
14261427
<pre class="idl" data-transform="unComment"><!--
14271428
dictionary JsonLdOptions {
14281429
(JsonLdEmbed or boolean) embed = "@last";
1429-
boolean explicit = false;
1430-
boolean omitDefault = false;
1431-
boolean omitGraph;
1432-
boolean requireAll = false;
1433-
boolean frameDefault = false;
1430+
boolean explicit = false;
1431+
boolean omitDefault = false;
1432+
boolean omitGraph;
1433+
boolean requireAll = false;
1434+
boolean frameDefault = false;
1435+
boolean ordered = false;
14341436
};
14351437
14361438
enum JsonLdEmbed {
@@ -1467,6 +1469,11 @@ <h3>JsonLdOptions</h3>
14671469
<a href="#framing-algorithm">Framing Algorithm</a>.</dd>
14681470
<dt><dfn data-dfn-for="JsonLdOptions">frameDefault</dfn></dt>
14691471
<dd>Instead of framing a <var>merged graph</var>, frame only the <a>default graph</a>.</dd>
1472+
<dt class="changed"><dfn data-dfn-for="JsonLdOptions">ordered</dfn></dt>
1473+
<dd class="changed">If set to <code>true</code>, certain algorithm
1474+
processing steps where indicated are ordered lexicographically.
1475+
If <code>false</code>, order
1476+
is not considered in processing.</dd>
14701477
</dl>
14711478

14721479
<p><dfn>JsonLdEmbed</dfn> enumerates the values of the <a data-link-for="JsonLdOptions">embed</a> option:</p>
@@ -1603,12 +1610,23 @@ <h2>Changes since 1.0 Draft of 30 August 2012</h2>
16031610
<li>Added the <a>omit default flag</a>, controled via the
16041611
<a data-link-for="JsonLdOptions">omitDefault</a> API option and/or
16051612
the current <a>processing mode</a>.</li>
1613+
<li>The API now adds an <a data-link-for="JsonLdOptions">ordered</a>
1614+
option, defaulting to <code>false</code> This is used in algorithms to
1615+
control interation of <a>dictionary member</a> keys. Previously, the
1616+
algorithms always required such an order. The instructions for
1617+
evaluating test results have been updated accordingly.</li>
16061618
</ul>
16071619
</section>
16081620

16091621
<section class="appendix informative" id="changes-from-cg">
16101622
<h2>Changes since JSON-LD Community Group Final Report</h2>
1611-
<p>None.</p>
1623+
<ul>
1624+
<li>The API now adds an <a data-link-for="JsonLdOptions">ordered</a>
1625+
option, defaulting to <code>false</code> This is used in algorithms to
1626+
control interation of <a>dictionary member</a> keys. Previously, the
1627+
algorithms always required such an order. The instructions for
1628+
evaluating test results have been updated accordingly.</li>
1629+
</ul>
16121630
</section>
16131631

16141632
<section class="appendix informative">

tests/README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,34 @@ comprehensive JSON-LD testing solution for developers creating JSON-LD Processor
88
# Design
99

1010
Tests are for _framing_:
11-
* _frame_ tests have _input_, _frame_ and _expected_ documents. The _expected_ results can be compared using JSON object comparison with the processor output. For *NegativeEvaluationTests*, the result is a string associated with the expected error code.
11+
12+
* _frame_ tests have _input_, _frame_ and _expected_ documents. The _expected_ results can be compared using [JSON-LD object comparison](#json-ld-object-comparison) with the processor output. Additionally, if the `ordered` option is not set, result should be expanded and compared with the expanded _expected_ document also using [JSON-LD object comparison](#json-ld-object-comparison).
13+
14+
For *NegativeEvaluationTests*, the result is a string associated with the expected error code.
1215

1316
Unless `processingMode` is set explicitly in a test entry, `processingMode` is compatible with both `json-ld-1.0` and `json-ld-1.1`.
1417

1518
Test results that include a context input presume that the context is provided locally, and not from the referenced location, thus the results will include the content of the context file, rather than a reference.
1619

20+
## JSON-LD Object comparison
21+
22+
If algorithms are invoked with the `ordered` flag set to `true`, simple JSON Object comparison may be used, as the order of all arrays will be preserved (except for _fromRdf_, unless the input quads are also ordered). If `ordered` is `false`, then the following algorithm will ensure arrays other than values of `@list` are compared without regard to order.
23+
24+
JSON-LD Object comparison compares JSON objects, arrays, and values recursively for equality.
25+
26+
* JSON objects are compared member by member without regard to the ordering of members within the object. Each member must have a corresponding member in the object being compared to. Values are compared recursively.
27+
* JSON arrays are generally compared without regard to order (the lone exception being if the referencing key is `@list`). Each item within the array must be equivalent to an item in the array being compared to by using the comparison algorithm recursively. For values of `@list`, the order of these items is significant.
28+
* JSON values are compared using strict equality.
29+
30+
Note that some tests require re-expansion and comparison, as list values may exist as values of properties that have `@container: @list` and the comparison algorithm will not consider ordering significant.
31+
1732
# Running tests
33+
1834
Implementations create their own infrastructure for running the test suite. In particular, the following should be considered:
1935

2036
* 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).
2137
* 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+
2239
# Contributing
2340

2441
If you would like to contribute a new test or a fix to an existing test,

0 commit comments

Comments
 (0)