Skip to content

Add tests, algoritm, grammar, and description for @vocab: @base. #603

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 8 commits into from
Mar 13, 2018
Merged
24 changes: 16 additions & 8 deletions spec/latest/json-ld-api/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -925,10 +925,14 @@ <h3>Algorithm</h3>
<code>@vocab</code> key.</li>
<li>If <em>value</em> is <a>null</a>, remove
any <a>vocabulary mapping</a> from <em>result</em>.</li>
<li>Otherwise, if <em>value</em> is an <a>absolute IRI</a>
<li class="changed">Otherewise, if <em>value</em>
the empty string (<code>&quot;&quot;</code>),
the effective value is the current <a>base IRI</a>.</li>
<li>Otherwise, if <em>value</em> is
an <a>absolute IRI</a>
or <a>blank node identifier</a>, the <a>vocabulary mapping</a>
of <em>result</em> is set to <em>value</em>. If it is not an
<a>absolute IRI</a> or <a>blank node identifier</a>, an
of <em>result</em> is set to <em>value</em>. If it is not
an <a>absolute IRI</a>, or a <a>blank node identifier</a>, an
<a data-link-for="JsonLdErrorCode">invalid vocab mapping</a>
error has been detected and processing is aborted.</li>
</ol>
Expand Down Expand Up @@ -1147,8 +1151,8 @@ <h3>Algorithm</h3>
<ol class="algorithm">
<li>Initialize <em>container</em> to the value associated with the
<code>@container</code> key, which must be either
<span class="changed"><code>@graph</code></span>,
<span class="changed"><code>@id</code></span>,
<code class="changed">@graph</code>,
<code class="changed">@id</code>,
<code>@index</code>,
<code>@language</code>,
<code>@list</code>,
Expand Down Expand Up @@ -1351,7 +1355,7 @@ <h3>Algorithm</h3>
<a>active context</a> has a <a>vocabulary mapping</a>,
return the result of concatenating the <a>vocabulary mapping</a>
with <em>value</em>.</li>
<li>Otherwise, if <em>document relative</em> is <code>true</code>,
<li>Otherwise, if <em>document relative</em> is <code>true</code>
set <em>value</em> to the result of resolving <em>value</em> against
the <a>base IRI</a>. Only the basic algorithm in
<a data-cite="RFC3986#section-5.2">section 5.2</a>
Expand Down Expand Up @@ -3023,7 +3027,7 @@ <h3>Algorithm</h3>
</ol>
</li>
<li>If <em>compact IRI</em> is not <code>null</code>, return <em>compact IRI</em>.</li>
<li>If <em>vocab</em> is <code>false</code> then
<li>If <em>vocab</em> is <code>false</code>,
transform <em>iri</em> to a <a>relative IRI</a> using
the <span class="changed"><a>base IRI</a> from <a>active context</a>, if it exists</span>.</li>
<li>Finally, return <em>iri</em> as is.</li>
Expand Down Expand Up @@ -4269,7 +4273,7 @@ <h2>Data Round Tripping</h2>
</section>


<section class="informative">
<section>
<h2>The Application Programming Interface</h2>

<p>This API provides a clean mechanism that enables developers to convert
Expand Down Expand Up @@ -4900,6 +4904,10 @@ <h2>Changes since 1.0 Recommendation of 16 January 2014</h2>
values of maps for which there is no natural index. The <a
href="#expansion-algorithm">Expansion Algorithm</a> removes this indexing
transparently.</li>
<li>The empty string (<code>&quot;&quot;</code>) has been added as a possible value for <code>@vocab</code> in
a context. When this is set, vocabulary-relative IRIs, such as the
keys of <a>node objects</a>, are expanded or compacted relative
to the <a>base IRI</a> using string concatenation.</li>
</ul>
</section>

Expand Down
47 changes: 44 additions & 3 deletions spec/latest/json-ld/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
// document unless you know what you're doing. If in doubt ask your friendly neighbourhood
// Team Contact.
//wgPatentURI: "https://www.w3.org/2004/01/pp-impl/46168/status",
maxTocLevel: 2
maxTocLevel: 3
///alternateFormats: [ {uri: "diff-20140116.html", label: "diff to previous version"} ]
};
//]]>
Expand Down Expand Up @@ -1064,7 +1064,7 @@ <h2>Default Vocabulary</h2>
the vocabulary <a>IRI</a>, a <a>term</a> can be explicitly set
to <a>null</a> in the <a>context</a>. For instance, in the
example below the <code>databaseId</code> member would not expand to an
<a>IRI</a>.</p>
<a>IRI</a> causing the property to be dropped when expanding.</p>

<pre class="example nohighlight" data-transform="updateExample"
title="Using the null keyword to ignore data">
Expand All @@ -1081,6 +1081,43 @@ <h2>Default Vocabulary</h2>
}
-->
</pre>

<section class="changed">
<h3>Using the Document Base as the Default Vocabulary</h3>
<p>In some cases, vocabulary terms are defined directly within the document
itself, rather than in an external vocabulary. Since
<code>json-ld-1.1</code>, the <a>vocabulary mapping</a> in the <a>active
context</a> can be set to the empty string <code>&quot;&quot;</code>, which causes terms which
are expanded relative to the vocabulary, such as the keys of <a>node
objects</a>, to use the <a>base IRI</a> to create <a>absolute
IRIs</a>.</p>
<pre class="example nohighlight" data-transform="updateExample"
title="Using &quot;&quot; as the vocabulary mapping">
<!--
{
"@context": {
****"@base": "http://example/document",****
"@vocab": ****""****
},
"@id": "http://example.org/places#BrewEats",
"@type": ****"#Restaurant"****,
****"#name"****: "Brew Eats"
####...####
}
-->
</pre>
<p>This document would expand as follows:</p>
<pre class="example nohighlight" data-transform="updateExample"
title="Using @base as the vocabulary mapping (expanded)">
<!--
[{
"@id": "http://example.org/places#BrewEats",
"@type": ["http://example/document#Restaurant"],
"http://example/document#name": [{"@value": "Brew Eats"}]
}]
-->
</pre>
</section>
</section>

<section class="informative">
Expand Down Expand Up @@ -4694,7 +4731,7 @@ <h2>Context Definitions</h2>

<p>If the <a>context definition</a> has an <code>@vocab</code> key,
its value MUST be a <a>absolute IRI</a>, a <a>compact IRI</a>,
a <a>blank node identifier</a>, a <a>term</a>, or <a>null</a>.</p>
<span class="changed">an empty string</span>, <code>@base</code>, a <a>term</a>, or <a>null</a>.</p>

<p class="changed">If the <a>context definition</a> has an <code>@version</code> key,
its value MUST be a <a>number</a> with the value <code>1.1</code>.</p>
Expand Down Expand Up @@ -5003,6 +5040,10 @@ <h2>Changes since 1.0 Recommendation of 16 January 2014</h2>
may include <code>"@set"</code>, which create maps from the
graph identifier or index value similar to <a>index maps</a>
and <a>id maps</a>.</li>
<li>The empty string (<code>&quot;&quot;</code>) has been added as a possible value for <code>@vocab</code> in
a context. When this is set, vocabulary-relative IRIs, such as the
keys of <a>node objects</a>, are expanded or compacted relative
to the <a>base IRI</a> using string concatenation.</li>
</ul>
</section>

Expand Down
6 changes: 6 additions & 0 deletions test-suite/tests/compact-0095-context.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"@context": {
"@base": "http://example.com/some/",
"@vocab": ""
}
}
13 changes: 13 additions & 0 deletions test-suite/tests/compact-0095-in.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[
{
"@id": "http://example.com/some/deep/directory/and/relativePropertyIris",
"http://example.com/absolute": [{"@value": "/absolute"}],
"http://example.com/some/deep/directory/": [{"@value": "deep/directory"}],
"http://example.com/some/deep/directory/and/": [{"@value": "deep/directory/and/"}],
"http://example.com/some/#fragment-works": [{"@value": "#fragment-works"}],
"http://example.com/some/?query=works": [{"@value": "?query=works"}],
"http://example.com/some/link": [{"@value": "link"}],
"http://example.com/some/../parent": [{"@value": "../parent"}],
"http://example.com/too-many-dots": [{"@value": "too-many-dots"}]
}
]
15 changes: 15 additions & 0 deletions test-suite/tests/compact-0095-out.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"@context": {
"@base": "http://example.com/some/",
"@vocab": ""
},
"#fragment-works": "#fragment-works",
"../parent": "../parent",
"?query=works": "?query=works",
"@id": "deep/directory/and/relativePropertyIris",
"deep/directory/": "deep/directory",
"deep/directory/and/": "deep/directory/and/",
"http://example.com/absolute": "/absolute",
"http://example.com/too-many-dots": "too-many-dots",
"link": "link"
}
17 changes: 17 additions & 0 deletions test-suite/tests/compact-manifest.jsonld
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,23 @@
"context": "compact-0093-context.jsonld",
"expect": "compact-0093-out.jsonld",
"option": {"compactArrays": false, "processingMode": "json-ld-1.1", "specVersion": "json-ld-1.1"}
}, {
"@id": "#t0094",
"@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"],
"name": "Compact input with [@graph, @set] container to output without [@graph, @set] container",
"purpose": "Ensure @graph appears properly in output",
"input": "compact-0094-in.jsonld",
"context": "compact-0094-context.jsonld",
"expect": "compact-0094-out.jsonld",
"option": {"processingMode": "json-ld-1.1", "specVersion": "json-ld-1.1"}
}, {
"@id": "#t0095",
"@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"],
"name": "Relative propererty IRIs with @vocab: ''",
"purpose": "Complex use cases for relative IRI compaction or properties",
"input": "compact-0095-in.jsonld",
"context": "compact-0095-context.jsonld",
"expect": "compact-0095-out.jsonld"
}, {
"@id": "#tc001",
"@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"],
Expand Down
18 changes: 18 additions & 0 deletions test-suite/tests/expand-0092-in.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"@context": {
"@base": "http://example.com/some/deep/directory/and/file/",
"@vocab": ""
},
"@id": "relativePropertyIris",
"link": "link",
"#fragment-works": "#fragment-works",
"?query=works": "?query=works",
"./": "./",
"../": "../",
"../parent": "../parent",
"../../parent-parent-eq-root": "../../parent-parent-eq-root",
"../../../../../still-root": "../../../../../still-root",
"../.././.././../../too-many-dots": "../.././.././../../too-many-dots",
"/absolute": "/absolute",
"//example.org/scheme-relative": "//example.org/scheme-relative"
}
16 changes: 16 additions & 0 deletions test-suite/tests/expand-0092-out.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[
{
"@id": "http://example.com/some/deep/directory/and/file/relativePropertyIris",
"http://example.com/some/deep/directory/and/file/#fragment-works": [{"@value": "#fragment-works"}],
"http://example.com/some/deep/directory/and/file/../": [{"@value": "../"}],
"http://example.com/some/deep/directory/and/file/../../../../../still-root": [{"@value": "../../../../../still-root"}],
"http://example.com/some/deep/directory/and/file/../.././.././../../too-many-dots": [{"@value": "../.././.././../../too-many-dots"}],
"http://example.com/some/deep/directory/and/file/../../parent-parent-eq-root": [{"@value": "../../parent-parent-eq-root"}],
"http://example.com/some/deep/directory/and/file/../parent": [{"@value": "../parent"}],
"http://example.com/some/deep/directory/and/file/./": [{"@value": "./"}],
"http://example.com/some/deep/directory/and/file///example.org/scheme-relative": [{"@value": "//example.org/scheme-relative"}],
"http://example.com/some/deep/directory/and/file//absolute": [{"@value": "/absolute"}],
"http://example.com/some/deep/directory/and/file/?query=works": [{"@value": "?query=works"}],
"http://example.com/some/deep/directory/and/file/link": [{"@value": "link"}]
}
]
7 changes: 7 additions & 0 deletions test-suite/tests/expand-manifest.jsonld
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,13 @@
},
"input": "expand-0091-in.jsonld",
"expect": "expand-0091-out.jsonld"
}, {
"@id": "#t0092",
"@type": ["jld:PositiveEvaluationTest", "jld:ExpandTest"],
"name": "Various relative IRIs as properties with with @vocab: ''",
"purpose": "Pathological relative property IRIs",
"input": "expand-0092-in.jsonld",
"expect": "expand-0092-out.jsonld"
}, {
"@id": "#tc001",
"@type": ["jld:PositiveEvaluationTest", "jld:ExpandTest"],
Expand Down