Skip to content

Commit 85bf7dd

Browse files
authored
Merge pull request #449 from json-ld/issue-430-containers
Issue 430 containers
2 parents cd4bc3d + 4e390ce commit 85bf7dd

32 files changed

+454
-20
lines changed

spec/latest/common/terms.html

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,14 @@ <h1>General Terminology</h1>
110110
<a>node object</a> or a <a>value object</a> in the input.</dd>
111111
<dt><dfn data-lt="graph names">graph name</dfn></dt><dd>
112112
The <a>IRI</a> identifying a <a>named graph</a>.</dd>
113-
<dt><dfn data-lt="index maps">index map</dfn></dt><dd>
113+
<dt class="changed"><dfn data-lt="id maps">id map</dfn></dt><dd class="changed">
114+
An <a>id map</a> is a <a>JSON object</a> value of a <a>term</a> defined with
115+
<code>@container</code> set to <code>@id</code>, who's keys are
116+
interpreted as <a>IRIs</a> representing the <code>@id</code>
117+
of the associated <a>node object</a>; value MUST be a <a>node object</a>.
118+
If the value contains a property expanding to <code>@id</code>, it's value MUST
119+
be equivalent to the referencing key.</dd>
120+
<dt><dfn data-lt="index maps">index map</dfn></dt><dd>
114121
An <a>index map</a> is a <a>JSON object</a> value of a <a>term</a> defined with
115122
<code>@container</code> set to <code>@index</code>, whose values MUST be any of the following types:
116123
<a>string</a>,
@@ -244,6 +251,14 @@ <h1>General Terminology</h1>
244251
a <a>JSON object</a> as a <a>property</a>, type, or elsewhere that a string is interpreted as a vocabulary item.
245252
Its value is either a string, expanding to an absolute IRI, or an <a>expanded term definition</a>.
246253
</dd>
254+
<dt class="changed"><dfn data-lt="type maps">type map</dfn></dt><dd class="changed">
255+
An <a>type map</a> is a <a>JSON object</a> value of a <a>term</a> defined with
256+
<code>@container</code> set to <code>@type</code>, who's keys are
257+
interpreted as <a>IRIs</a> representing the <code>@type</code>
258+
of the associated <a>node object</a>;
259+
value MUST be a <a>node object</a>, or <a>array</a> of node objects.
260+
If the value contains a property expanding to <code>@type</code>, it's values
261+
are merged with the map value when expanding.</dd>
247262
<dt><dfn>typed literal</dfn></dt><dd>
248263
A <a>typed literal</a> is a <a>literal</a> with an associated <a>IRI</a>
249264
which indicates the literal's datatype. See <cite><a

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

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,7 @@ <h3>Algorithm</h3>
987987
<li>Initialize <em>container</em> to the value associated with the
988988
<code>@container</code> key, which must be either
989989
<code>@list</code>, <code>@set</code>, <code>@index</code>,
990+
<span class="changed"><code>@id</code>, <code>@type</code></span>
990991
or <code>@language</code>. Otherwise, an
991992
<a data-link-for="JsonLdErrorCode">invalid container mapping</a>
992993
has been detected and processing is aborted.</li>
@@ -1470,9 +1471,10 @@ <h3>Algorithm</h3>
14701471
</ol>
14711472
</li>
14721473
<li>Otherwise, if <em>key</em>'s <a>container mapping</a> in
1473-
<em class="changed">term context</em> is <code>@index</code> and
1474+
<em class="changed">term context</em> is <code>@index</code>,
1475+
<span class="changed"><code>@type</code>, or <code>@id</code></span> and
14741476
<em>value</em> is a <a>JSON object</a> then <em>value</em>
1475-
is expanded from an index map as follows:
1477+
is expanded from an map as follows:
14761478
<ol class="algorithm">
14771479
<li>Initialize <em>expanded value</em> to an empty
14781480
<a>array</a>.</li>
@@ -1488,11 +1490,23 @@ <h3>Algorithm</h3>
14881490
<em>key</em> as <a>active property</a>,
14891491
and <em>index value</em> as <em>element</em>.</li>
14901492
<li>For each <em>item</em> in <em>index value</em>:
1491-
<ol class="algorithm">
1492-
<li>If <em>item</em> does not have the key
1493+
<ol class="algorithm changed">
1494+
<li>If <a>container mapping</a> is <code>@index</code>
1495+
and <em>item</em> does not have the key
14931496
<code>@index</code>, add the key-value pair
14941497
(<code>@index</code>-<em>index</em>) to
14951498
<em>item</em>.</li>
1499+
<li>Otherwise, if <a>container mapping</a> is <code>@id</code>
1500+
and <em>item</em> does not have the key
1501+
<code>@id</code>, add the key-value pair
1502+
(<code>@id</code>-<em>index</em>) to
1503+
<em>item</em>.</li>
1504+
<li>Otherwise, if <a>container mapping</a> is <code>@type</code>
1505+
set <em>types</em> to the concatenation of <em>index
1506+
value</em> with any existing values of
1507+
<code>@type</code> in <em>item</em> and add the
1508+
key-value pair (<code>@type</code>-<em>types</em>) to
1509+
<em>item</em>.</li>
14961510
<li>Append <em>item</em> to <em>expanded value</em>.</li>
14971511
</ol>
14981512
</li>
@@ -1994,20 +2008,39 @@ <h3>Algorithm</h3>
19942008
</ol>
19952009
</li>
19962010
<li>
1997-
If <em>container</em> is <code>@language</code> or
1998-
<code>@index</code>:
2011+
If <em>container</em> is <code>@language</code>,
2012+
<code>@index</code>, <span class="changed"><code>@id</code>,
2013+
or <code>@type</code></span>:
19992014
<ol class="algorithm">
20002015
<li>If <em>item active property</em> is not a key in
20012016
<em>result</em>, initialize it to an empty <a>JSON object</a>.
20022017
Initialize <em>map object</em> to the value of <em>item active property</em>
20032018
in <em>result</em>.</li>
2019+
<li>Set <em>compacted container</em> to the result of calling the
2020+
<a href="#iri-compaction">IRI Compaction algorithm</a>
2021+
passing <a>active context</a>,
2022+
<em>container</em> as <em>iri</em>, and <code>true</code>
2023+
for <em>vocab</em>.</li>
20042024
<li>If <em>container</em> is <code>@language</code> and
20052025
<em>compacted item</em> contains the key
20062026
<code>@value</code>, then set <em>compacted item</em>
20072027
to the value associated with its <code>@value</code> key.</li>
2008-
<li>Initialize <em>map key</em> to the value associated with
2028+
<li>If <em>container</em> is <code>@index</code>,
2029+
set <em>map key</em> to the value associated with
20092030
with the key that equals <em>container</em> in
20102031
<em>expanded item</em>.</li>
2032+
<li class="changed">If <em>container</em> is <code>@id</code>, set
2033+
<em>map key</em> to the value associated with the key that equals
2034+
<em>compacted container</em> in <em>compacted item</em>
2035+
and remove that key-value pair from <em>compacted item</em>.</li>
2036+
<li class="changed">If <em>container</em> is <code>@type</code>,
2037+
set <em>map key</em> to the first value associated with
2038+
the key that equals <em>container</em> in <em>expanded
2039+
item</em>. If there are remaining values in <em>compacted
2040+
item</em> for <em>compacted container</em>, set the value
2041+
of <em>compacted container</em> in <em>compacted
2042+
value</em> to those remaining values. Otherwise, remove
2043+
that key-value pair from <em>compacted item</em>.</li>
20112044
<li>If <em>map key</em> is not a key in <em>map object</em>,
20122045
then set this key's value in <em>map object</em>
20132046
to <em>compacted item</em>. Otherwise, if the value
@@ -2284,9 +2317,10 @@ <h3>Algorithm</h3>
22842317
variables will keep track of the preferred
22852318
<a>type mapping</a> or <a>language mapping</a> for
22862319
a <a>term</a>, based on what is compatible with <em>value</em>.</li>
2287-
<li>If <em>value</em> is a <a>JSON object</a> that contains the
2288-
key <code>@index</code>, then append the value <code>@index</code>
2289-
to <em>containers</em>.</li>
2320+
<li>If <em>value</em> is a <a>JSON object</a>,
2321+
<span class="changed">then for the keywords <code>@index</code>,
2322+
<code>@id</code>, and <code>@type</code>, if <em>value</em>
2323+
contains that <a>keyword</a>, append it to <em>containers</em>.</span></li>
22902324
<li>If <em>reverse</em> is <code>true</code>, set <em>type/language</em>
22912325
to <code>@type</code>, <em>type/language value</em> to
22922326
<code>@reverse</code>, and append <code>@set</code> to <em>containers</em>.</li>
@@ -4208,6 +4242,8 @@ <h2>Changes since 1.0 Recommendation of 16 January 2014</h2>
42084242
<li>A new <a href="#merge-node-maps" class="sectionRef"></a> is required
42094243
for framing, to create a single graph from the <a data-lt="default graph">default</a>
42104244
and <a>named graphs</a>.</li>
4245+
<li><code>@container</code> values within an <a>expanded term definition</a> may now
4246+
include <code>@id</code> and <code>@type</code>, corresponding to <a>id maps</a> and <a>type maps</a>.</li>
42114247
</ul>
42124248
</section>
42134249

spec/latest/json-ld/index.html

Lines changed: 131 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2583,6 +2583,107 @@ <h2>Data Indexing</h2>
25832583
</table>
25842584
</section>
25852585

2586+
<section class="informative changed">
2587+
<h2>Node Identifier Indexing</h2>
2588+
2589+
<p>In addition to <a>index maps</a>, JSON-LD introduces the notion of <a>id maps</a>
2590+
for structuring data. The id indexing feature allows an author to
2591+
structure data using a simple key-value map where the keys map
2592+
to <a>IRIs</a>. This enables direct access to associated <a>node objects</a>
2593+
instead of having to scan an array in search of a specific item.
2594+
In JSON-LD such data can be specified by associating the
2595+
<code>@id</code> <a>keyword</a> with a
2596+
<code>@container</code> declaration in the context:</p>
2597+
2598+
<pre class="example" data-transform="updateExample"
2599+
title="Indexing data in JSON-LD by node identifiers">
2600+
<!--
2601+
{
2602+
"@context":
2603+
{
2604+
"schema": "http://schema.org/",
2605+
"name": "schema:name",
2606+
"body": "schema:articleBody",
2607+
"words": "schema:wordCount",
2608+
"post": {
2609+
"@id": "schema:blogPost",
2610+
****"@container": "@id"****
2611+
}
2612+
},
2613+
"@id": "http://example.com/",
2614+
"@type": "schema:Blog",
2615+
"name": "World Financial News",
2616+
****"post": {
2617+
"http://example.com/posts/1/en": {
2618+
"body": "World commodities were up today with heavy trading of crude oil...",
2619+
"words": 1539
2620+
},
2621+
"http://example.com/posts/1/de": {
2622+
"body": "Die Werte an Warenbörsen stiegen im Sog eines starken Handels von Rohöl...",
2623+
"words": 1204
2624+
}****
2625+
}
2626+
}
2627+
-->
2628+
</pre>
2629+
2630+
<p>In the example above, the <code>post</code> <a>term</a> has
2631+
been marked as an <a>id map</a>. The <code>http://example.com/posts/1/en</code> and
2632+
<code>http://example.com/posts/1/de</code> keys will be interpreted
2633+
as the <code>@id</code> property of the <a>node object</a> value.</p>
2634+
2635+
<p>The interpretation of the data above is exactly the same
2636+
as that in <a class="sectionRef" href="#data-indexing"></a>
2637+
using a JSON-LD processor.</p>
2638+
</section>
2639+
2640+
<section class="informative changed">
2641+
<h2>Node Type Indexing</h2>
2642+
2643+
<p>In addition to <a data-lt="id map">id</a> and <a>index maps</a>, JSON-LD introduces the notion of <a>type maps</a>
2644+
for structuring data. The type indexing feature allows an author to
2645+
structure data using a simple key-value map where the keys map
2646+
to <a>IRIs</a>. This enables data to be structured based on the <code>@type</code>
2647+
of specific <a>node objects</a>.
2648+
In JSON-LD such data can be specified by associating the
2649+
<code>@type</code> <a>keyword</a> with a
2650+
<code>@container</code> declaration in the context:</p>
2651+
2652+
<pre class="example" data-transform="updateExample"
2653+
title="Indexing data in JSON-LD by node identifiers">
2654+
<!--
2655+
{
2656+
"@context":
2657+
{
2658+
"schema": "http://schema.org/",
2659+
"name": "schema:name",
2660+
"affiliation": {
2661+
"@id": "schema:affiliation",
2662+
****"@container": "@type"****
2663+
}
2664+
},
2665+
"name": "Manu Sporny",
2666+
"affiliation": {
2667+
****"schema:Corporpation"****: {
2668+
"@id": "http://digitalbazaar.com/",
2669+
"name": "Digital Bazaar"
2670+
},
2671+
****"schema:ProfessionalService"****: {
2672+
"@id": "https://spec-ops.io",
2673+
"name": "Spec-Ops"
2674+
}
2675+
2676+
}
2677+
}
2678+
-->
2679+
</pre>
2680+
2681+
<p>In the example above, the <code>affiliation</code> <a>term</a> has
2682+
been marked as an <a>type map</a>. The <code>schema:Corporpation</code> and
2683+
<code>schema:ProfessionalService</code> keys will be interpreted
2684+
as the <code>@type</code> property of the <a>node object</a> value.</p>
2685+
</section>
2686+
25862687
<section class="informative">
25872688
<h3>Expanded Document Form</h3>
25882689

@@ -3186,6 +3287,34 @@ <h2>Index Maps</h2>
31863287
<p>See <a class="sectionRef" href="#data-indexing"></a> for further information on this topic.</p>
31873288
</section>
31883289

3290+
<section class="changed">
3291+
<h2>Id Maps</h2>
3292+
3293+
<p>An <a>id map</a> is used to associate an <a>IRI</a> with a value that allows easy
3294+
programatic access. An <a>id map</a> may be used as a term value within a <a>node object</a> if the <a>term</a>
3295+
is defined with <code>@container</code> set to <code>@id</code>. The keys of an <a>id map</a> MUST be <a>IRIs</a>
3296+
(<a>relative IRI</a>, <a>compact IRI</a> (including <a>blank node identifiers</a>), or <a>absolute IRI</a>)
3297+
and the values MUST be <a>node objects</a>.</p>
3298+
3299+
<p>If the value contains a property expanding to <code>@id</code>, it's value MUST
3300+
be equivalent to the referencing key. Otherwise, the property from the value is used as
3301+
the <code>@id</code> of the <a>node object</a> value when expanding.</p>
3302+
</section>
3303+
3304+
<section class="changed">
3305+
<h2>Type Maps</h2>
3306+
3307+
<p>An <a>type map</a> is used to associate an <a>IRI</a> with a value that allows easy
3308+
programatic access. An <a>id map</a> may be used as a term value within a <a>node object</a> if the <a>term</a>
3309+
is defined with <code>@container</code> set to <code>@id</code>. The keys of an <a>id map</a> MUST be <a>IRIs</a>
3310+
(<a>relative IRI</a>, <a>compact IRI</a> (including <a>blank node identifiers</a>), or <a>absolute IRI</a>)
3311+
and the values MUST be <a>node objects</a>.</p>
3312+
3313+
<p>If the value contains a property expanding to <code>@id</code>, it's value MUST
3314+
be equivalent to the referencing key. Otherwise, the property from the value is used as
3315+
the <code>@id</code> of the <a>node object</a> value when expanding.</p>
3316+
</section>
3317+
31893318
<section class="normative">
31903319
<h2>Context Definitions</h2>
31913320

@@ -3451,17 +3580,16 @@ <h2>Changes since 1.0 Recommendation of 16 January 2014</h2>
34513580
<li>An <a>expanded term definition</a> can now have an
34523581
<code>@context</code> property, which defines a <a>context</a> used for values of
34533582
a <a>property</a> identified with such a <a>term</a>.</li>
3583+
<li><code>@container</code> values within an <a>expanded term definition</a> may now
3584+
include <code>@id</code> and <code>@type</code>, corresponding to <a>id maps</a> and <a>type maps</a>.</li>
34543585
</ul>
34553586
</section>
34563587

34573588
<section class="appendix informative">
34583589
<h4>Open Issues</h4>
34593590
<p>The following is a list of open issues being worked on for the next release.</p>
3460-
<p class="issue" data-number="12"></p>
34613591
<p class="issue" data-number="195"></p>
34623592
<p class="issue" data-number="246"></p>
3463-
<p class="issue" data-number="247"></p>
3464-
<p class="issue" data-number="262"></p>
34653593
<p class="issue" data-number="269"></p>
34663594
<p class="issue" data-number="271"></p>
34673595
<p class="issue" data-number="272"></p>

test-suite/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Tests are defined into _compact_, _expand_, _flatten_, _frame_, _normalize_, and
2323
contained within the _sparql_ document using a SPARQL endpoint. The end result is a
2424
yes/no on whether the expected triples were extracted by the JSON-LD processor.
2525

26+
Unless `processingMode` is set explicitly in a test entry, `processingMode` is compatible with both `json-ld-1.0` and `json-ld-1.1`. Otherwise, a JSON-LD 1.0 processor should not run tests marked `json-ld-1.1` and a JSON-LD 1.1 processor should not run tests marked `json-ld-1.0`.
2627

2728
Contributing
2829
------------

test-suite/index.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ <h2 id="design" class="span12" style="text-align: center;">Running the test suit
166166
<p>To run the tests, create a test runner which will run through each test manifest
167167
and execute the tests defined within the manifest using the rules associated with
168168
each <code>@type</code> defined for the test case as defined in <a href="vocab">the test vocabulary</a>.</p>
169+
<p>Unless <code>processingMode</code> is set explicitly in a test entry,
170+
<code>processingMode</code> is compatible with both <code>json-ld-1.0</code> and
171+
<code>json-ld-1.1</code>. Otherwise, a JSON-LD 1.0 processor should not run
172+
tests marked <code>json-ld-1.1</code> and a JSON-LD 1.1 processor should not run
173+
tests marked <code>json-ld-1.0</code>. </p>
169174
<p>Note that property values are typed, and those which are typed as <code>@id</code> must
170175
be treated as IRIs relative to the manifest test base. In particular, this means that
171176
<em>input</em>, </em>context</em>, <em>frame</em>, and <em>expandContext</em> are to be
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+
"idmap": {"@container": "@id"}
5+
}
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[{
2+
"http://example/idmap": [
3+
{"http://example/label": [{"@value": "Object with @id _:bar"}], "@id": "_:bar"},
4+
{"http://example/label": [{"@value": "Object with @id <foo>"}], "@id": "http://example.org/foo"}
5+
]
6+
}]
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+
"idmap": {"@container": "@id"}
5+
},
6+
"idmap": {
7+
"http://example.org/foo": {"label": "Object with @id <foo>"},
8+
"_:bar": {"label": "Object with @id _:bar"}
9+
}
10+
}
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+
"idmap": {"@container": "@id"}
5+
}
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[{
2+
"http://example/idmap": [
3+
{"@id": "_:foo", "http://example/label": [{"@value": "Object with @id _:bar"}]},
4+
{"@id": "http://example.org/bar", "http://example/label": [{"@value": "Object with @id <foo>"}]}
5+
]
6+
}]
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+
"idmap": {"@container": "@id"}
5+
},
6+
"idmap": {
7+
"_:foo": {"label": "Object with @id _:bar"},
8+
"http://example.org/bar": {"label": "Object with @id <foo>"}
9+
}
10+
}
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+
"typemap": {"@container": "@type"}
5+
}
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[{
2+
"http://example/typemap": [
3+
{"http://example/label": [{"@value": "Object with @type _:bar"}], "@type": ["_:bar"]},
4+
{"http://example/label": [{"@value": "Object with @type <foo>"}], "@type": ["http://example.org/foo"]}
5+
]
6+
}]

0 commit comments

Comments
 (0)