Skip to content

Commit a69b1ab

Browse files
committed
Add support for using a local context defined on a term used as a @type or in a type map.
Fixes #415.
1 parent e4d1b63 commit a69b1ab

34 files changed

+415
-7
lines changed

spec/latest/json-ld-api/index.html

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,6 +1278,22 @@ <h3>Algorithm</h3>
12781278
<a href="#context-processing-algorithm">Context Processing algorithm</a>,
12791279
passing <a>active context</a> and the value of the
12801280
<code>@context</code> key as <a>local context</a>.</li>
1281+
<li class="changed">For each <em>key</em>/<em>value</em> pair in <em>element</em>
1282+
ordered lexicographically by <em>key</em> where <em>key</em> expands
1283+
to <code>@type</code> using the
1284+
<a href="#iri-expansion">IRI Expansion algorithm</a>,
1285+
passing <a>active context</a>, <em>key</em> for
1286+
<em>value</em>, and <code>true</code> for <em>vocab</em>:
1287+
<ol class="algorithm">
1288+
<li>For each <em>term</em> which is a value of <em>value</em>,
1289+
if <em>term</em>'s <a>term definition</a> in <a>active context</a>
1290+
has a <a>local context</a>, set <a>active context</a> to the result
1291+
to the result of the
1292+
<a href="#context-processing-algorithm">Context Processing algorithm</a>,
1293+
passing <a>active context</a> and the value of the
1294+
<em>term</em>'s <a>local context</a> as <a>local context</a>.</li>
1295+
</ol>
1296+
</li>
12811297
<li>Initialize an empty <a>JSON object</a>, <em>result</em>.</li>
12821298
<li id="alg-expand-each-key-value">For each <em>key</em> and <em>value</em> in <em>element</em>,
12831299
ordered lexicographically by <em>key</em>:
@@ -1494,12 +1510,21 @@ <h3>Algorithm</h3>
14941510
<li>For each key-value pair <em>index</em>-<em>index value</em>
14951511
in <em>value</em>, ordered lexicographically by <em>index</em>:
14961512
<ol class="algorithm">
1513+
<li class="changed">If <a>container mapping</a> is <code>@type</code>,
1514+
and <em>index</em>'s <a>term definition</a> in
1515+
<em>term context</em> has a <a>local context</a>, set
1516+
<em>map context</em> to the result of the <a
1517+
href="#context-processing-algorithm">Context Processing
1518+
algorithm</a>, passing <em>term context</em> as <a>active context</a> and the
1519+
value of the <em>index</em>'s <a>local context</a> as
1520+
<a>local context</a>. Otherwise, set <em>map context</em>
1521+
to <em>term context</em>.</li>
14971522
<li>If <em>index value</em> is not an <a>array</a>
14981523
set it to an <a>array</a> containing only
14991524
<em>index value</em>.</li>
15001525
<li>Initialize <em>index value</em> to the result of
15011526
using this algorithm recursively, passing
1502-
<em class="changed">term context</em> as <a>active context</a>,
1527+
<em class="changed">map context</em> as <a>active context</a>,
15031528
<em>key</em> as <a>active property</a>,
15041529
and <em>index value</em> as <em>element</em>.</li>
15051530
<li>For each <em>item</em> in <em>index value</em>:
@@ -1883,12 +1908,28 @@ <h3>Algorithm</h3>
18831908
<li>Initialize <em>compacted value</em> to an empty
18841909
<a>array</a>.</li>
18851910
<li>For each item <em>expanded type</em> in
1886-
<em>expanded value</em>, append the result of
1887-
of using the <a href="#iri-compaction">IRI Compaction algorithm</a>,
1888-
passing <a>active context</a>, <a>inverse context</a>,
1889-
<em>expanded type</em> for <em>iri</em>, and
1890-
<code>true</code> for <em>vocab</em>,
1891-
to <em>compacted value</em>.</li>
1911+
<em>expanded value</em>:
1912+
<ol class="algorithm">
1913+
<li>Set <em>term</em> to the result of
1914+
of using the <a href="#iri-compaction">IRI Compaction algorithm</a>,
1915+
passing <a>active context</a>, <a>inverse context</a>,
1916+
<em>expanded type</em> for <em>iri</em>, and
1917+
<code>true</code> for <em>vocab</em>.</li>
1918+
<li class="changed">If the <a>term definition</a> for <em>term</em> has a
1919+
<a>local context</a>:
1920+
<ol class="algorithm">
1921+
<li>Set <a>active context</a> to the result of the
1922+
<a href="#context-processing-algorithm">Context Processing algorithm</a>,
1923+
passing <a>active context</a> and the value of <em>term</em>'s
1924+
<a>local context</a> as <a>local context</a>.</li>
1925+
<li>Set <a>inverse context</a> using the
1926+
<a href="#inverse-context-creation">Inverse Context Creation algorithm</a>
1927+
using <a>active context</a>.</li>
1928+
</ol>
1929+
</li>
1930+
<li>Append <em>term</em>, to <em>compacted value</em>.</li>
1931+
</ol>
1932+
</li>
18921933
<li>If <em>compacted value</em> contains only one
18931934
item (it has a length of <code>1</code>), then
18941935
set <em>compacted value</em> to its only item.</li>

spec/latest/json-ld/index.html

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2209,6 +2209,35 @@ <h2>Scoped Contexts</h2>
22092209
}
22102210
-->
22112211
</pre>
2212+
2213+
<p>Scoping can also be performed using a term used as a value of <code>@type</code>:</p>
2214+
2215+
<pre class="example" data-transform="updateExample"
2216+
title="Defining an @context within a term definition used on @type">
2217+
<!--
2218+
{
2219+
"@context":
2220+
{
2221+
"name": "http://schema.org/name",
2222+
"interest": "http://xmlns.com/foaf/0.1/interest",
2223+
****"Document"****: {
2224+
"@id": "http://xmlns.com/foaf/0.1/Document",
2225+
****"@context": {"@vocab": "http://xmlns.com/foaf/0.1/"}****
2226+
}
2227+
},
2228+
"@type": "Person",
2229+
"name": "Manu Sporny",
2230+
"interest": {
2231+
"@id": "https://www.w3.org/TR/json-ld/",
2232+
****"@type": "Document"****,
2233+
"name": "JSON-LD",
2234+
"topic": "Linking Data"
2235+
}
2236+
}
2237+
-->
2238+
</pre>
2239+
2240+
<p>Scoping on <code>@type</code> is useful when common properties are used to relate things of different types, where the vocabularies in use within different entities calls for different context scoping. For example, `hasPart`/`partOf` may be common terms used in a document, but mean different things depending on the context.</p>
22122241
</section>
22132242

22142243

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"@context": {
3+
"@vocab": "http://example/",
4+
"Foo": {"@context": {"bar": "http://example.org/bar"}}
5+
}
6+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[
2+
{
3+
"http://example/a": [{
4+
"@type": ["http://example/Foo"],
5+
"http://example.org/bar": [{"@value": "baz"}]
6+
}]
7+
}
8+
]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"@context": {
3+
"@vocab": "http://example/",
4+
"Foo": {"@context": {"bar": "http://example.org/bar"}}
5+
},
6+
"a": {"@type": "Foo", "bar": "baz"}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"@context": {
3+
"@vocab": "http://example/",
4+
"Foo": {"@context": {"bar": {"@type": "@id"}}},
5+
"bar": {"@type": "http://www.w3.org/2001/XMLSchema#string"}
6+
}
7+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[
2+
{
3+
"http://example/a": [{
4+
"@type": ["http://example/Foo"],
5+
"http://example/bar": [{"@id": "http://example/baz"}]
6+
}]
7+
}
8+
]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"@context": {
3+
"@vocab": "http://example/",
4+
"Foo": {"@context": {"bar": {"@type": "@id"}}},
5+
"bar": {"@type": "http://www.w3.org/2001/XMLSchema#string"}
6+
},
7+
"a": {"@type": "Foo", "bar": "http://example/baz"}
8+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"@context": {
3+
"@vocab": "http://example/",
4+
"type": "@type",
5+
"Foo": {"@context": {"bar": "http://example.org/bar"}}
6+
}
7+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[
2+
{
3+
"http://example/a": [{
4+
"@type": ["http://example/Foo"],
5+
"http://example.org/bar": [{"@value": "baz"}]
6+
}]
7+
}
8+
]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"@context": {
3+
"@vocab": "http://example/",
4+
"type": "@type",
5+
"Foo": {"@context": {"bar": "http://example.org/bar"}}
6+
},
7+
"a": {"type": "Foo", "bar": "baz"}
8+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"@context": {
3+
"@vocab": "http://example/",
4+
"Foo": {"@context": {"baz": {"@type": "@vocab"}}}
5+
}
6+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[
2+
{
3+
"@type": ["http://example/Foo"],
4+
"http://example/bar": [{
5+
"http://example/baz": [{"@id": "http://example/buzz"}]
6+
}]
7+
}
8+
]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"@context": {
3+
"@vocab": "http://example/",
4+
"Foo": {"@context": {"baz": {"@type": "@vocab"}}}
5+
},
6+
"@type": "Foo",
7+
"bar": {"baz": "buzz"}
8+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"@context": {
3+
"@vocab": "http://example/",
4+
"B": {"@context": {"c": "http://example.org/c"}}
5+
}
6+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[{
2+
"http://example/a": [{
3+
"@type": ["http://example/B"],
4+
"http://example.com/a": [{"@value": "A in example.com"}],
5+
"http://example.org/c": [{"@value": "C in example.org"}]
6+
}],
7+
"http://example/c": [{"@value": "C in example"}]
8+
}]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"@context": {
3+
"@vocab": "http://example/",
4+
"B": {"@context": {"c": "http://example.org/c"}}
5+
},
6+
"a": {
7+
"@type": "B",
8+
"c": "C in example.org",
9+
"http://example.com/a": "A in example.com"
10+
},
11+
"c": "C in example"
12+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"@context": {
3+
"@vocab": "http://example/",
4+
"typemap": {"@container": "@type"},
5+
"Type": {"@context": {"a": "http://example.org/a"}}
6+
}
7+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[{
2+
"http://example/typemap": [
3+
{"http://example.org/a": [{"@value": "Object with @type <Type>"}], "@type": ["http://example/Type"]}
4+
]
5+
}]
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"@context": {
3+
"@vocab": "http://example/",
4+
"typemap": {"@container": "@type"},
5+
"Type": {"@context": {"a": "http://example.org/a"}}
6+
},
7+
"typemap": {
8+
"Type": {"a": "Object with @type <Type>"}
9+
}
10+
}

test-suite/tests/compact-manifest.jsonld

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,60 @@
684684
"context": "compact-m006-context.jsonld",
685685
"expect": "compact-m006-out.jsonld",
686686
"option": {"processingMode": "json-ld-1.1"}
687+
}, {
688+
"@id": "#tm007",
689+
"@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"],
690+
"name": "adding new term",
691+
"purpose": "scoped context on @type",
692+
"input": "compact-m007-in.jsonld",
693+
"context": "compact-m007-context.jsonld",
694+
"expect": "compact-m007-out.jsonld",
695+
"option": {"processingMode": "json-ld-1.1"}
696+
}, {
697+
"@id": "#tm008",
698+
"@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"],
699+
"name": "overriding a term",
700+
"purpose": "scoped context on @type",
701+
"input": "compact-m008-in.jsonld",
702+
"context": "compact-m008-context.jsonld",
703+
"expect": "compact-m008-out.jsonld",
704+
"option": {"processingMode": "json-ld-1.1"}
705+
}, {
706+
"@id": "#tm009",
707+
"@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"],
708+
"name": "alias of @type",
709+
"purpose": "scoped context on @type",
710+
"input": "compact-m009-in.jsonld",
711+
"context": "compact-m009-context.jsonld",
712+
"expect": "compact-m009-out.jsonld",
713+
"option": {"processingMode": "json-ld-1.1"}
714+
}, {
715+
"@id": "#tm010",
716+
"@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"],
717+
"name": "deep @context affects nested nodes",
718+
"purpose": "scoped context on @type",
719+
"input": "compact-m010-in.jsonld",
720+
"context": "compact-m010-context.jsonld",
721+
"expect": "compact-m010-out.jsonld",
722+
"option": {"processingMode": "json-ld-1.1"}
723+
}, {
724+
"@id": "#tm011",
725+
"@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"],
726+
"name": "scoped context layers on intemediate contexts",
727+
"purpose": "scoped context on @type",
728+
"input": "compact-m011-in.jsonld",
729+
"context": "compact-m011-context.jsonld",
730+
"expect": "compact-m011-out.jsonld",
731+
"option": {"processingMode": "json-ld-1.1"}
732+
}, {
733+
"@id": "#tm012",
734+
"@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"],
735+
"name": "When type is in a type map",
736+
"purpose": "scoped context on @type",
737+
"input": "compact-m012-in.jsonld",
738+
"context": "compact-m012-context.jsonld",
739+
"expect": "compact-m012-out.jsonld",
740+
"option": {"processingMode": "json-ld-1.1"}
687741
}, {
688742
"@id": "#tn001",
689743
"@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"],
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"@context": {
3+
"@vocab": "http://example/",
4+
"Foo": {"@context": {"bar": "http://example.org/bar"}}
5+
},
6+
"a": {"@type": "Foo", "bar": "baz"}
7+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[
2+
{
3+
"http://example/a": [{
4+
"@type": ["http://example/Foo"],
5+
"http://example.org/bar": [{"@value": "baz"}]
6+
}]
7+
}
8+
]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"@context": {
3+
"@vocab": "http://example/",
4+
"Foo": {"@context": {"bar": {"@type": "@id"}}},
5+
"bar": {"@type": "http://www.w3.org/2001/XMLSchema#string"}
6+
},
7+
"a": {"@type": "Foo", "bar": "http://example/baz"}
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[
2+
{
3+
"http://example/a": [{
4+
"@type": ["http://example/Foo"],
5+
"http://example/bar": [{"@id": "http://example/baz"}]
6+
}]
7+
}
8+
]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"@context": {
3+
"@vocab": "http://example/",
4+
"type": "@type",
5+
"Foo": {"@context": {"bar": "http://example.org/bar"}}
6+
},
7+
"a": {"type": "Foo", "bar": "baz"}
8+
}

0 commit comments

Comments
 (0)