Skip to content

Add spec text for scoped contexts #445

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 3 commits into from
Jan 7, 2017
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
258 changes: 154 additions & 104 deletions spec/latest/json-ld-api/index.html

Large diffs are not rendered by default.

95 changes: 94 additions & 1 deletion spec/latest/json-ld/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2115,6 +2115,87 @@ <h2>Reverse Properties</h2>
</pre>
</section>

<section class="informative">
<h2>Scoped Contexts</h2>

<p>An <a>expanded term definition</a> can include a <code>@context</code>
property, which defines a <a>context</a> for <a data-lt="JSON-LD
value">values</a> of properties defined using that <a>term</a>. This allows
values to use <a>term definitions</a>, <a>base IRI</a>,
<a>vocabulary mapping</a> or <a>default language</a> which is different from the
<a>node object</a> they are contained in, in exactly the same was as if the
<a>context</a> were specified within the value itself.</p>

<pre class="example" data-transform="updateExample"
title="Defining an @context within a term definition">
<!--
{
"@context":
{
"name": "http://schema.org/name",
"interest": {
"@id":"http://xmlns.com/foaf/0.1/interest",
****"@context": {"@vocab": "http://xmlns.com/foaf/0.1/"}****
}
},
"name": "Manu Sporny",
"interest": ****{
"@id": "https://www.w3.org/TR/json-ld/",
"name": "JSON-LD",
"topic": "Linking Data"
}****
}
-->
</pre>

<p>In this case, the social profile is defined using the schema.org vocabulary, but interest is imported from FOAF, and is used to define a node describing one of Manu's interests where those properties now come from the FOAF vocabulary.</p>

<p>Expanding this document, uses a combination of terms defined in the outer context, and those defined specifically for that term.</p>

<pre class="example" data-transform="updateExample"
title="Expanded document using a scoped context">
<!--
[{
"http://schema.org/name": [{"@value": "Manu Sporny"}],
"http://xmlns.com/foaf/0.1/interest": [{
"@id": "https://www.w3.org/TR/json-ld/",
"http://schema.org/name": [{"@value": "JSON-LD"}],
****"http://xmlns.com/foaf/0.1/topic": [{"@value": "Linking Data"}]****
}]
}]
-->
</pre>

<p>The <code>@reverse</code> <a>keyword</a> can also be used in
<a>expanded term definitions</a>
to create reverse properties as shown in the following example:</p>


<pre class="example" data-transform="updateExample"
title="Using @reverse to define reverse properties">
<!--
{
"@context": {
"name": "http://example.com/vocab#name",
****"children": { "@reverse": "http://example.com/vocab#parent" }****
},
"@id": "#homer",
"name": "Homer",
****"children"****: [
{
"@id": "#bart",
"name": "Bart"
},
{
"@id": "#lisa",
"name": "Lisa"
}
]
}
-->
</pre>
</section>


<section class="informative">
<h2>Named Graphs</h2>
Expand Down Expand Up @@ -3126,7 +3207,7 @@ <h2>Context Definitions</h2>

<p>An <a>expanded term definition</a> MUST be a <a>JSON object</a>
composed of zero or more keys from <code>@id</code>, <code>@reverse</code>,
<code>@type</code>, <code>@language</code> or <code>@container</code>. An
<code>@type</code>, <code>@language</code>, <code>@context</code> or <code>@container</code>. An
<a>expanded term definition</a> SHOULD NOT contain any other keys.</p>

<p>If an <a>expanded term definition</a> has an <code>@reverse</code> member,
Expand Down Expand Up @@ -3161,6 +3242,9 @@ <h2>Context Definitions</h2>
the <code>@context</code>, the associated value MUST be an
<a>index map</a>.</p>

<p>If an <a>expanded term definition</a> has an <code>@context</code> member,
it MUST be a valid <code>context definition</code>.</p>

<p><a>Terms</a> MUST NOT be used in a circular manner. That is,
the definition of a term cannot depend on the definition of another term if that other
term also depends on the first term.</p>
Expand Down Expand Up @@ -3347,6 +3431,15 @@ <h3>Serializing/Deserializing RDF</h3>
</section>
</section>

<section class="appendix informative">
<h2>Changes since 1.0 Recommendation of 16 January 2014</h2>
<ul>
<li>An <a>expanded term definition</a> can now have an
<code>@context</code> property, which defines a <a>context</a> used for values of
a <a>property</a> identified with such a <a>term</a>.</li>
</ul>
</section>

<section class="appendix informative">
<h4>Open Issues</h4>
<p>The following is a list of open issues being worked on for the next release.</p>
Expand Down
6 changes: 6 additions & 0 deletions test-suite/tests/compact-c001-context.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"@context": {
"@vocab": "http://example/",
"foo": {"@context": {"bar": "http://example.org/bar"}}
}
}
3 changes: 3 additions & 0 deletions test-suite/tests/compact-c001-in.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[{
"http://example/foo": [{"http://example.org/bar": [{"@value": "baz"}]}]
}]
9 changes: 9 additions & 0 deletions test-suite/tests/compact-c001-out.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"@context": {
"@vocab": "http://example/",
"foo": {"@context": {"bar": "http://example.org/bar"}}
},
"foo": {
"bar": "baz"
}
}
7 changes: 7 additions & 0 deletions test-suite/tests/compact-c002-context.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"@context": {
"@vocab": "http://example/",
"foo": {"@context": {"bar": {"@type": "@id"}}},
"bar": {"@type": "http://www.w3.org/2001/XMLSchema#string"}
}
}
5 changes: 5 additions & 0 deletions test-suite/tests/compact-c002-in.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[
{
"http://example/foo": [{"http://example/bar": [{"@id": "http://example/baz"}]}]
}
]
10 changes: 10 additions & 0 deletions test-suite/tests/compact-c002-out.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"@context": {
"@vocab": "http://example/",
"foo": {"@context": {"bar": {"@type": "@id"}}},
"bar": {"@type": "http://www.w3.org/2001/XMLSchema#string"}
},
"foo": {
"bar": "http://example/baz"
}
}
6 changes: 6 additions & 0 deletions test-suite/tests/compact-c003-context.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"@context": {
"@vocab": "http://example/",
"foo": {"@context": {"Bar": {"@id": "bar"}}}
}
}
9 changes: 9 additions & 0 deletions test-suite/tests/compact-c003-in.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[
{
"http://example/foo": [{
"http://example/bar": [
{"@value": "baz"}
]}
]
}
]
9 changes: 9 additions & 0 deletions test-suite/tests/compact-c003-out.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"@context": {
"@vocab": "http://example/",
"foo": {"@context": {"Bar": {"@id": "bar"}}}
},
"foo": {
"Bar": "baz"
}
}
6 changes: 6 additions & 0 deletions test-suite/tests/compact-c004-context.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"@context": {
"@vocab": "http://example/",
"foo": {"@context": {"baz": {"@type": "@id"}}}
}
}
9 changes: 9 additions & 0 deletions test-suite/tests/compact-c004-in.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[
{
"http://example/foo": [{
"http://example/bar": [{
"http://example/baz": [{"@id": "buzz"}]
}]
}]
}
]
11 changes: 11 additions & 0 deletions test-suite/tests/compact-c004-out.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"@context": {
"@vocab": "http://example/",
"foo": {"@context": {"baz": {"@type": "@id"}}}
},
"foo": {
"bar": {
"baz": "buzz"
}
}
}
6 changes: 6 additions & 0 deletions test-suite/tests/compact-c005-context.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"@context": {
"@vocab": "http://example/",
"b": {"@context": {"c": "http://example.org/c"}}
}
}
10 changes: 10 additions & 0 deletions test-suite/tests/compact-c005-in.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[{
"http://example/a": [{
"http://example.com/c": [{"@value": "C in example.com"}],
"http://example/b": [{
"http://example.com/a": [{"@value": "A in example.com"}],
"http://example.org/c": [{"@value": "C in example.org"}]
}]
}],
"http://example/c": [{"@value": "C in example"}]
}]
14 changes: 14 additions & 0 deletions test-suite/tests/compact-c005-out.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"@context": {
"@vocab": "http://example/",
"b": {"@context": {"c": "http://example.org/c"}}
},
"a": {
"b": {
"c": "C in example.org",
"http://example.com/a": "A in example.com"
},
"http://example.com/c": "C in example.com"
},
"c": "C in example"
}
40 changes: 40 additions & 0 deletions test-suite/tests/compact-manifest.jsonld
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,46 @@
"input": "compact-0072-in.jsonld",
"context": "compact-0072-context.jsonld",
"expect": "compact-0072-out.jsonld"
}, {
"@id": "#tc001",
"@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"],
"name": "adding new term",
"purpose": "Compaction using a scoped context uses term scope for selecting proper term",
"input": "compact-c001-in.jsonld",
"context": "compact-c001-context.jsonld",
"expect": "compact-c001-out.jsonld"
}, {
"@id": "#tc002",
"@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"],
"name": "overriding a term",
"purpose": "Compaction using a scoped context uses term scope for selecting proper term",
"input": "compact-c002-in.jsonld",
"context": "compact-c002-context.jsonld",
"expect": "compact-c002-out.jsonld"
}, {
"@id": "#tc003",
"@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"],
"name": "property and value with different terms mapping to the same expanded property",
"purpose": "Compaction using a scoped context uses term scope for selecting proper term",
"input": "compact-c003-in.jsonld",
"context": "compact-c003-context.jsonld",
"expect": "compact-c003-out.jsonld"
}, {
"@id": "#tc004",
"@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"],
"name": "deep @context affects nested nodes",
"purpose": "Compaction using a scoped context uses term scope for selecting proper term",
"input": "compact-c004-in.jsonld",
"context": "compact-c004-context.jsonld",
"expect": "compact-c004-out.jsonld"
}, {
"@id": "#tc005",
"@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"],
"name": "scoped context layers on intemediate contexts",
"purpose": "Compaction using a scoped context uses term scope for selecting proper term",
"input": "compact-c005-in.jsonld",
"context": "compact-c005-context.jsonld",
"expect": "compact-c005-out.jsonld"
}
]
}
6 changes: 6 additions & 0 deletions test-suite/tests/error-c001-in.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"@context": {
"term": {"@id": "http://example/", "@index": true}
},
"@id": "http://example/test#example"
}
7 changes: 7 additions & 0 deletions test-suite/tests/error-manifest.jsonld
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,13 @@
"purpose": "Verifies that an exception is raised in Flattening when conflicting indexes are found",
"input": "error-0043-in.jsonld",
"expect": "conflicting indexes"
}, {
"@id": "#t1001",
"@type": [ "jld:NegativeEvaluationTest", "jld:FlattenTest" ],
"name": "Invalid keyword in term definition",
"purpose": "Verifies that an exception is raised on expansion when a invalid term definition is found",
"input": "error-c001-in.jsonld",
"expect": "invalid term definition"
}
]
}
9 changes: 9 additions & 0 deletions test-suite/tests/expand-c001-in.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"@context": {
"@vocab": "http://example/",
"foo": {"@context": {"bar": "http://example.org/bar"}}
},
"foo": {
"bar": "baz"
}
}
5 changes: 5 additions & 0 deletions test-suite/tests/expand-c001-out.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[
{
"http://example/foo": [{"http://example.org/bar": [{"@value": "baz"}]}]
}
]
10 changes: 10 additions & 0 deletions test-suite/tests/expand-c002-in.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"@context": {
"@vocab": "http://example/",
"foo": {"@context": {"bar": {"@type": "@id"}}},
"bar": {"@type": "http://www.w3.org/2001/XMLSchema#string"}
},
"foo": {
"bar": "http://example/baz"
}
}
5 changes: 5 additions & 0 deletions test-suite/tests/expand-c002-out.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[
{
"http://example/foo": [{"http://example/bar": [{"@id": "http://example/baz"}]}]
}
]
9 changes: 9 additions & 0 deletions test-suite/tests/expand-c003-in.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"@context": {
"@vocab": "http://example/",
"foo": {"@context": {"Bar": {"@id": "bar"}}}
},
"foo": {
"Bar": "baz"
}
}
9 changes: 9 additions & 0 deletions test-suite/tests/expand-c003-out.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[
{
"http://example/foo": [{
"http://example/bar": [
{"@value": "baz"}
]}
]
}
]
Loading