Skip to content

Fix compacting property-based indexes. #528

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 20 additions & 16 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ <h2>Expansion</h2>
<button data-selects="expanded">Expanded (Result)</button>
<button data-selects="statements">Statements</button>
<button data-selects="turtle">Turtle</button>
<a class="playground" target="_blank" href="#">PG</a>
<a class="playground" target="_blank" href="">PG</a>
</div>
<pre class="compacted selected" data-transform="updateExample">
<!--
Expand Down Expand Up @@ -599,7 +599,7 @@ <h2>Expansion</h2>
<button data-selects="expanded">Expanded (Result)</button>
<button data-selects="statements">Statements</button>
<button data-selects="turtle">Turtle</button>
<a class="playground" target="_blank" href="#">PG</a>
<a class="playground" target="_blank" href="">PG</a>
</div>
<pre class="compacted input selected nohighlight" data-transform="updateExample">
<!--
Expand Down Expand Up @@ -774,7 +774,7 @@ <h2>Compaction</h2>
data-context="#sample-document-context"
data-compact
target="_blank"
href="#">PG</a>
href="">PG</a>
</div>
<pre class="result compacted selected nohighlight" data-transform="updateExample"
data-result-for="Expanded sample document"
Expand Down Expand Up @@ -857,7 +857,7 @@ <h2>Flattening</h2>
data-result-for="#json-ld-document-in-compact-form"
data-flatten
target="_blank"
href="#">PG</a>
href="">PG</a>
</div>
<pre class="original result selected nohighlight" data-transform="updateExample"
data-result-for="JSON-LD document in compact form"
Expand Down Expand Up @@ -903,7 +903,7 @@ <h2>Flattening</h2>
data-context="#json-ld-document-in-compact-form"
data-flatten
target="_blank"
href="#">PG</a>
href="">PG</a>
</div>
<pre class="result selected nohighlight" data-transform="updateExample"
data-result-for="JSON-LD document in compact form"
Expand Down Expand Up @@ -1281,7 +1281,7 @@ <h3>Algorithm</h3>
to the {{RemoteDocument}} obtained
by dereferencing <var>context</var> using
the <a>LoadDocumentCallback</a>, passing <var>context</var>
for <a data-link-for="LoadDocumentCallback">url</a>,
for {{LoadDocumentCallback/url}},
and <code>http://www.w3.org/ns/json-ld#context</code> for <a data-link-for="LoadDocumentOptions">profile</a>
and for <a data-link-for="LoadDocumentOptions">requestProfile</a>.
<ol>
Expand Down Expand Up @@ -1350,7 +1350,7 @@ <h3>Algorithm</h3>
<var>base URL</var>.</li>
<li>Dereference <var>import</var> using
the <a>LoadDocumentCallback</a>, passing <var>import</var>
for <a data-link-for="LoadDocumentCallback">url</a>,
for {{LoadDocumentCallback/url}},
and <code>http://www.w3.org/ns/json-ld#context</code> for <a data-link-for="LoadDocumentOptions">profile</a>
and for <a data-link-for="LoadDocumentOptions">requestProfile</a>.</li>
<li>If <var>import</var> cannot be dereferenced,
Expand Down Expand Up @@ -3861,8 +3861,8 @@ <h3>Algorithm</h3>
<li id="alg-compact-12_8_9_6" class="changed">Otherwise, if <var>container</var> includes <code>@index</code>
and <var>index key</var> is not <code>@index</code>:
<ol>
<li>Reinitialize <var>container key</var> by <a>IRI compacting</a>
<var>index key</var>.</li>
<li id="alg-compact-12_8_9_6_1">Reinitialize <var>container key</var> by <a>IRI compacting</a>
<var>index key</var> after first <a>IRI expanding</a> it.</li>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative to consider, which is probably more correct, would be to do the expansion of the @index value when the context is processed, as the value may expand differently than it would when compacting. It would still be a localized change, but not to the Compaction algorithm.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did try this, but remembering the original compacted term is necessary for expansion. The most correct solution would be to save the expanded version of this in the term definition, and use that in the Compaction algorithm instead of the original version, but that would be more disruptive to the rest of the document. This solution will solve any issues other than those specifically constructed to defeat it.

<li>Set <var>map key</var> to the first value of <var>container key</var> in <var>compacted item</var>, if any.</li>
<li id="alg-compact-12_8_9_6_3">If there are remaining values in <var>compacted item</var>
for <var>container key</var>, use <a>add value</a> to
Expand Down Expand Up @@ -5737,7 +5737,7 @@ <h3>Algorithm</h3>
<li>Otherwise, if the provided <a data-lt="jsonldprocessor-compact-input">input</a>
is a <a>string</a> representing the <a>IRI</a> of a remote document, await and dereference it as <var>remote document</var>
using <a>LoadDocumentCallback</a>, passing <a data-lt="jsonldprocessor-compact-input">input</a>
for <a data-link-for="LoadDocumentCallback">url</a>,
for {{LoadDocumentCallback/url}},
and the {{JsonLdOptions/extractAllScripts}} option from <a data-lt="jsonldprocessor-compact-options">options</a>
for <a data-link-for="LoadDocumentOptions">extractAllScripts</a>.</li>
<li>Set <var>expanded input</var> to the result of
Expand Down Expand Up @@ -5822,7 +5822,7 @@ <h3>Algorithm</h3>
<li>Otherwise, if the provided <a data-lt="jsonldprocessor-expand-input">input</a>
is a <a>string</a> representing the <a>IRI</a> of a remote document, await and dereference it as <var>remote document</var>
using <a>LoadDocumentCallback</a>, passing <a data-lt="jsonldprocessor-expand-input">input</a>
for <a data-link-for="LoadDocumentCallback">url</a>,
for {{LoadDocumentCallback/url}},
the {{JsonLdOptions/extractAllScripts}} option from <a data-lt="jsonldprocessor-expand-options">options</a>
for <a data-link-for="LoadDocumentOptions">extractAllScripts</a>.</li>
<li class="changed">If {{RemoteDocument/document}}
Expand Down Expand Up @@ -5903,7 +5903,7 @@ <h3>Algorithm</h3>
<li>Otherwise, if the provided <a data-lt="jsonldprocessor-flatten-input">input</a>
is a <a>string</a> representing the <a>IRI</a> of a remote document, await and dereference it as <var>remote document</var>
using <a>LoadDocumentCallback</a>, passing <a data-lt="jsonldprocessor-flatten-input">input</a>
for <a data-link-for="LoadDocumentCallback">url</a>,
for {{LoadDocumentCallback/url}},
and the {{JsonLdOptions/extractAllScripts}} option from <a data-lt="jsonldprocessor-flatten-options">options</a>
for <a data-link-for="LoadDocumentOptions">extractAllScripts</a>.
</li>
Expand Down Expand Up @@ -6355,8 +6355,8 @@ <h3>LoadDocumentCallback</h3>
<li>Create a new {{Promise}} <var>promise</var> and return it.
The following steps are then deferred.</li>
<li id="LoadDocumentCallback-step-2">Set <var>document</var> to the body retrieved from
the resource identified by <a data-link-for="LoadDocumentCallback">url</a>,
or by otherwise locating a resource associated with <a data-link-for="LoadDocumentCallback">url</a>.
the resource identified by {{LoadDocumentCallback/url}},
or by otherwise locating a resource associated with {{LoadDocumentCallback/url}}.
When requesting remote documents the request MUST prefer <a>Content-Type</a> <code>application/ld+json</code>
followed by <code>application/json</code>.

Expand Down Expand Up @@ -6502,10 +6502,10 @@ <h3>RemoteDocument</h3>
or <code>application/xhtml+xml</code>:</p>
<ol>
<li>Set <var>documentUrl</var> to the <a data-cite="HTML/urls-and-fetching.html#document-base-url">Document Base URL</a>
of <a data-link-for="LoadDocumentCallback">url</a>, as defined in [[HTML]],
of {{LoadDocumentCallback/url}}, as defined in [[HTML]],
using the existing <var>documentUrl</var> as the document's URL.
</li>
<li>If the <a data-link-for="LoadDocumentCallback">url</a> parameter
<li>If the {{LoadDocumentCallback/url}} parameter
contains a <a data-cite="RFC3986#section-3.5">fragment identifier</a>,
set <var>source</var> to the <a data-cite="DOM#dom-node-textcontent">textContent</a>
of the <a data-cite="HTML/scripting.html#the-script-element">script element</a> in <var>document</var>
Expand Down Expand Up @@ -7105,6 +7105,10 @@ <h2>Changes since Recommendation of 16 July 2020</h2>
<li>Changed obsolete use of `void` in WebIDL to `undefined`.</li>
<li>Added some clarifications to the algorithm of <a href="#node-map-generation"></a>.</li>
<li>Added some clarifications to the algorithm of <a href="#iri-compaction"></a>.</li>
<li>Added additional language to the
<a href="#compaction-algorithm">Compaction Algorithm</a>
step <a href="#alg-compact-12_8_9_6_1">12.8.9.6.1</a> to first expand
<var>container key</var> before compacting it.</li>
</ul>
</section>
<section id="ack"
Expand Down
50 changes: 50 additions & 0 deletions tests/compact-manifest.html
Original file line number Diff line number Diff line change
Expand Up @@ -3162,6 +3162,56 @@ <h2>
</dd>
</dl>
</dd>
<dt id='t0113'>
Test t0113 Compact property index using Absolute IRI index
</dt>
<dd>
<dl class='entry'>
<dt>id</dt>
<dd>#t0113</dd>
<dt>Type</dt>
<dd>jld:PositiveEvaluationTest, jld:CompactTest</dd>
<dt>Purpose</dt>
<dd>With @container: @index and @index an absolute IRI, ensure round-tripping of compacted representation</dd>
<dt>input</dt>
<dd>
<a href='compact/0113-in.jsonld'>compact/0113-in.jsonld</a>
</dd>
<dt>context</dt>
<dd>
<a href='compact/0113-context.jsonld'>compact/0113-context.jsonld</a>
</dd>
<dt>expect</dt>
<dd>
<a href='compact/0113-out.jsonld'>compact/0113-out.jsonld</a>
</dd>
</dl>
</dd>
<dt id='t0112'>
Test t0112 Compact property index using Compact IRI index
</dt>
<dd>
<dl class='entry'>
<dt>id</dt>
<dd>#t0112</dd>
<dt>Type</dt>
<dd>jld:PositiveEvaluationTest, jld:CompactTest</dd>
<dt>Purpose</dt>
<dd>With @container: @index and @index a compact IRI, ensure round-tripping of compacted representation</dd>
<dt>input</dt>
<dd>
<a href='compact/0112-in.jsonld'>compact/0112-in.jsonld</a>
</dd>
<dt>context</dt>
<dd>
<a href='compact/0112-context.jsonld'>compact/0112-context.jsonld</a>
</dd>
<dt>expect</dt>
<dd>
<a href='compact/0112-out.jsonld'>compact/0112-out.jsonld</a>
</dd>
</dl>
</dd>
<dt id='tc001'>
Test tc001 adding new term
</dt>
Expand Down
16 changes: 16 additions & 0 deletions tests/compact-manifest.jsonld
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,22 @@
"context": "compact/0111-context.jsonld",
"expect": "compact/0111-out.jsonld",
"option": {"specVersion": "json-ld-1.1"}
}, {
"@id": "#t0113",
"@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"],
"name": "Compact property index using Absolute IRI index",
"purpose": "With @container: @index and @index an absolute IRI, ensure round-tripping of compacted representation",
"input": "compact/0113-in.jsonld",
"context": "compact/0113-context.jsonld",
"expect": "compact/0113-out.jsonld"
}, {
"@id": "#t0112",
"@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"],
"name": "Compact property index using Compact IRI index",
"purpose": "With @container: @index and @index a compact IRI, ensure round-tripping of compacted representation",
"input": "compact/0112-in.jsonld",
"context": "compact/0112-context.jsonld",
"expect": "compact/0112-out.jsonld"
}, {
"@id": "#tc001",
"@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"],
Expand Down
10 changes: 10 additions & 0 deletions tests/compact/0112-context.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"@context": {
"ex": "http://example.org/ns/",
"prop": {
"@id": "ex:prop",
"@container": "@index",
"@index": "ex:name"
}
}
}
9 changes: 9 additions & 0 deletions tests/compact/0112-in.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"http://example.org/ns/prop": [{
"@id": "http://example.org/ns/bar",
"http://example.org/ns/name": "bar"
}, {
"@id": "http://example.org/ns/foo",
"http://example.org/ns/name": "foo"
}]
}
14 changes: 14 additions & 0 deletions tests/compact/0112-out.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"@context": {
"ex": "http://example.org/ns/",
"prop": {
"@id": "ex:prop",
"@container": "@index",
"@index": "ex:name"
}
},
"prop": {
"foo": { "@id": "ex:foo"},
"bar": { "@id": "ex:bar"}
}
}
10 changes: 10 additions & 0 deletions tests/compact/0113-context.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"@context": {
"ex": "http://example.org/ns/",
"prop": {
"@id": "ex:prop",
"@container": "@index",
"@index": "http://example.org/ns/name"
}
}
}
9 changes: 9 additions & 0 deletions tests/compact/0113-in.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"http://example.org/ns/prop": [{
"@id": "http://example.org/ns/bar",
"http://example.org/ns/name": "bar"
}, {
"@id": "http://example.org/ns/foo",
"http://example.org/ns/name": "foo"
}]
}
14 changes: 14 additions & 0 deletions tests/compact/0113-out.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"@context": {
"ex": "http://example.org/ns/",
"prop": {
"@id": "ex:prop",
"@container": "@index",
"@index": "http://example.org/ns/name"
}
},
"prop": {
"foo": { "@id": "ex:foo"},
"bar": { "@id": "ex:bar"}
}
}