Skip to content

Commit 84b0993

Browse files
committed
Add API text and tests for compaction and expansion of indexes using a property.
For w3c/json-ld-syntax#145.
1 parent cdf93be commit 84b0993

40 files changed

+614
-27
lines changed

common/jsonld.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ const jsonld = {
1515
authors: ['Domenic Denicola'],
1616
status: 'unofficial',
1717
date: 'January 2014'
18+
},
19+
"JCS": {
20+
title: "JSON Canonicalization Scheme (JCS)",
21+
href: 'https://tools.ietf.org/html/draft-rundgren-json-canonicalization-scheme-05#page-6',
22+
authors: ['A. Rundgren', 'B. Jordan', 'S. Erdtman'],
23+
publisher: 'Network Working Group',
24+
status: 'Internet-Draft',
25+
date: 'February 16, 2019'
1826
}
1927
},
2028
conversions: {

common/terms.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,12 @@
335335
the value MUST be a <a>node object</a>, or <a>array</a> of node objects.
336336
If the value contains a <a>term</a> expanding to <code>@type</code>,
337337
it's values are merged with the map value when expanding.</dd>
338+
<dt><dfn>JSON literal</dfn></dt><dd>
339+
A <a>JSON literal</a> is a <a>typed literal</a> where the associated <a>IRI</a> is <code>jsonld:JSON</code>.
340+
In the <a>value object</a> representation, the value of <code>@type</code> is <code>@json</code>.
341+
JSON literals represent values which are valid [[JSON]].
342+
See <dfn data-cite="JSON-LD11#dfn-json-datatype" class="preserve">JSON datatype</dfn> in [[JSON-LD11]].
343+
</dd>
338344
<dt><dfn>typed literal</dfn></dt><dd>
339345
A <a>typed literal</a> is a <a>literal</a> with an associated <a>IRI</a>
340346
which indicates the literal's datatype.

index.html

Lines changed: 63 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,7 @@ <h2>Context Processing Algorithm</h2>
926926
<span class="changed">an optional <a>context</a></span>,
927927
<span class="changed">an optional <dfn>nest value</dfn>,</span>
928928
<span class="changed">an optional <dfn>prefix flag</dfn>,</span>
929+
<span class="changed">an optional <dfn>index mapping</dfn>,</span>
929930
<span class="changed">a <dfn>sealed</dfn>, used to mark this as a sealed term,</span>
930931
and an optional <dfn>container mapping</dfn>.
931932
A <a>term definition</a> can not only be used to map a <a>term</a>
@@ -1373,6 +1374,20 @@ <h3>Algorithm</h3>
13731374
<var>container</var>.</li>
13741375
</ol>
13751376
</li>
1377+
<li class="changed">If <var>value</var> contains the <a>member</a> <code>@index</code>:
1378+
<ol>
1379+
<li>If <a>processing mode</a> is <code>json-ld-1.0</code> or
1380+
<a>container mapping</a> does not include <code>@index</code>,
1381+
an <a data-link-for="JsonLdErrorCode">invalid term definition</a>
1382+
has been detected and processing is aborted.</li>
1383+
<li>Initialize <var>index</var> to the value associated with the
1384+
<code>@index</code> <a>member</a>, which MUST a <a>string</a> expanding to an <a>absolute IRI</a>.
1385+
Otherwise, an
1386+
<a data-link-for="JsonLdErrorCode">invalid term definition</a>
1387+
has been detected and processing is aborted.</li>
1388+
<li>Set the <a>index mapping</a> of <var>definition</var> to <var>index</var></li>
1389+
</ol>
1390+
</li>
13761391
<li class="changed">If <var>value</var> contains the <a>member</a> <code>@context</code>:
13771392
<ol>
13781393
<li>If <a>processing mode</a> is <code>json-ld-1.0</code>, an
@@ -1943,8 +1958,10 @@ <h3>Algorithm</h3>
19431958
<var>value</var> is a <a class="changed">dictionary</a> then <var>value</var>
19441959
is expanded from an map as follows:
19451960
<ol>
1946-
<li>Initialize <var>expanded value</var> to an empty
1947-
<a>array</a>.</li>
1961+
<li>Initialize <var>expanded value</var> to an empty <a>array</a>.</li>
1962+
<li class="changed">Initialize <var>index key</var> to
1963+
the <var>key</var>'s <a>index mapping</a> in <a>active context</a>,
1964+
or <code>@index</code>, if it does not exist.</li>
19481965
<li>For each key-value pair <var>index</var>-<var>index value</var>
19491966
in <var>value</var>, ordered lexicographically by <var>index</var>
19501967
<span class="changed">if <a data-link-for="JsonLdOptions">ordered</a> is <code>true</code></span>:
@@ -1974,36 +1991,41 @@ <h3>Algorithm</h3>
19741991
and <a data-link-for="JsonLdOptions">ordered</a> flags</span>.</li>
19751992
<li>For each <var>item</var> in <var>index value</var>:
19761993
<ol class="algorithm changed">
1977-
<li>If <var>container mapping</var> includes
1978-
<code>@graph</code> and if <var>item</var> is not a
1979-
<a>graph object</a>, set <var>item</var> to a new
1980-
<a>dictionary</a> containing the key-value pair
1981-
<code>@graph</code>-<var>item</var>, ensuring that the
1982-
value is represented using an <a>array</a>.</li>
1983-
<li>If <var>container mapping</var> includes <code>@index</code>
1984-
and <var>item</var> does not have the <a>member</a>
1985-
<code>@index</code> and <var>expanded index</var> is not <code>@none</code>,
1986-
add the key-value pair
1987-
(<code>@index</code>-<var>index</var>) to <var>item</var>.</li>
1994+
<li>If <var>container mapping</var> includes <code>@graph</code>
1995+
and if <var>item</var> is not a <a>graph object</a>,
1996+
set <var>item</var> to a new <a>dictionary</a> containing the key-value pair
1997+
<code>@graph</code>-<var>item</var>,
1998+
ensuring that the value is represented using an <a>array</a>.</li>
1999+
<li class="changed">If <var>container mapping</var> includes <code>@index</code>,
2000+
<var>index key</var> is not <code>@index</code>,
2001+
<var>item</var> does not have a <a>member</a> <code>@index</code>
2002+
and <var>expanded index</var> is not <code>@none</code>,
2003+
set <var>index property values</var> to the concatenation of
2004+
<var>expanded index</var> with any existing values of
2005+
<var>index key</var> in <var>item</var>.
2006+
Add the key-value pair (<var>expanded index</var>-<var>index property values</var>) to <var>item</var>.
2007+
If expanded value is a value object,
2008+
it MUST NOT contain any extra properties;
2009+
an <a data-link-for="JsonLdErrorCode">invalid value object</a>
2010+
error has been detected and processing is aborted.</li>
2011+
<li>Otherwise, if <var>container mapping</var> includes <code>@index</code>,
2012+
<var>item</var> does not have a <a>member</a> <code>@index</code>,
2013+
and <var>expanded index</var> is not <code>@none</code>,
2014+
add the key-value pair (<code>@index</code>-<var>index</var>) to <var>item</var>.</li>
19882015
<li>Otherwise, if <var>container mapping</var> includes <code>@id</code>
1989-
and <var>item</var> does not have the <a>member</a>
1990-
<code>@id</code>, add the key-value pair
1991-
(<code>@id</code>-<var>expanded index</var>) to
1992-
<var>item</var>, where <var>expanded index</var> is set to the result of
1993-
using the
2016+
and <var>item</var> does not have the <a>member</a> <code>@id</code>,
2017+
add the key-value pair (<code>@id</code>-<var>expanded index</var>) to <var>item</var>,
2018+
where <var>expanded index</var> is set to the result of using the
19942019
<a href="#iri-expansion">IRI Expansion algorithm</a>,
19952020
passing <var>active context</var>, <var>index</var>, and <code>true</code>
19962021
for <var>document relative</var>, unless <var>expanded index</var>
19972022
is already set to <code>@none</code>.</li>
19982023
<li>Otherwise, if <var>container mapping</var> includes <code>@type</code>
1999-
set <var>types</var> to the concatenation of
2000-
<var>expanded index</var> with any existing values of
2001-
<code>@type</code> in <var>item</var>.
2024+
set <var>types</var> to the concatenation of <var>expanded index</var>
2025+
with any existing values of <code>@type</code> in <var>item</var>.
20022026
If <var>expanded index</var> is <code>@none</code>,
20032027
do not concatenate <var>expanded index</var> to <var>types</var>.
2004-
Add the key-value pair
2005-
(<code>@type</code>-<var>types</var>) to
2006-
<var>item</var>.</li>
2028+
Add the key-value pair (<code>@type</code>-<var>types</var>) to <var>item</var>.</li>
20072029
<li>Append <var>item</var> to <var>expanded value</var>.</li>
20082030
</ol>
20092031
</li>
@@ -2757,17 +2779,31 @@ <h3>Algorithm</h3>
27572779
either <code>@language</code>, <code>@index</code>, <code>@id</code>, or <code>@type</code>
27582780
based on the contents of <var>container</var>, as <var>var</var>, and <code>true</code>
27592781
for <var>vocab</var>.</li>
2782+
<li class="changed">Set <var>index key</var> to the value of <a>index mapping</a> in
2783+
the <a>term definition</a> associated with <var>item active property</var> in <var>active context</var>,
2784+
or <code>@index</code>, if no such value exists.</li>
27602785
<li>If <var>container</var> includes <code>@language</code> and
27612786
<var>expanded item</var> contains a
27622787
<code>@value</code> <a>member</a>, then set <var>compacted item</var>
27632788
to the value associated with its <code>@value</code> <a>member</a>.
27642789
Set <var>map key</var> to the value of <code>@language</code> in <var>expanded item</var>, if any.</li>
2765-
<li>If <var>container</var> includes <code>@index</code> set <var>map key</var> to the value of <code>@index</code> in <var>expanded item</var>, if any,
2790+
<li>Otherwise, if <var>container</var> includes <code>@index</code>
2791+
and <var>index key</var> is <code>@index</code>,
2792+
set <var>map key</var> to the value of <code>@index</code> in <var>expanded item</var>, if any,
27662793
and remove <var>container key</var> from <var>compacted item</var>.</li>
2767-
<li class="changed">If <var>container</var> includes <code>@id</code>, set
2794+
<li class="changed">Otherwise, if <var>container</var> includes <code>@index</code>
2795+
and <var>index key</var> is not <code>@index</code>,
2796+
Set <var>map key</var> to the first value of <var>container key</var> in <var>compacted item</var>, if any.
2797+
If there are remaining values in <var>compacted item</var>
2798+
for <var>compacted container</var>, set the value of
2799+
<var>compacted container</var> in <var>compacted value</var>
2800+
to those remaining values. Otherwise, remove that
2801+
<a>member</a> from <var>compacted item</var>.
2802+
</li>
2803+
<li class="changed">Otherwise, if <var>container</var> includes <code>@id</code>, set
27682804
<var>map key</var> to the value of <var>container key</var> in
27692805
<var>compacted item</var> and remove <var>container key</var> from <var>compacted item</var>.</li>
2770-
<li class="changed">If <var>container</var> is <code>@type</code>,
2806+
<li class="changed">Otherwise, if <var>container</var> is <code>@type</code>,
27712807
set <var>map key</var> to the first value of <var>container key</var> in <var>compacted item</var>, if any.
27722808
If there are remaining values in <var>compacted item</var>
27732809
for <var>compacted container</var>, set the value of

tests/compact-manifest.jsonld

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,6 +1507,60 @@
15071507
"input": "compact/p008-in.jsonld",
15081508
"context": "compact/p008-context.jsonld",
15091509
"expect": "compact/p008-out.jsonld"
1510+
}, {
1511+
"@id": "#tpi01",
1512+
"@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"],
1513+
"name": "property-valued index indexes property value, instead of property (value)",
1514+
"purpose": "Compacting property-valued indexes.",
1515+
"option": {"processingMode": "json-ld-1.1", "specVersion": "json-ld-1.1"},
1516+
"input": "compact/pi01-in.jsonld",
1517+
"context": "compact/pi01-context.jsonld",
1518+
"expect": "compact/pi01-out.jsonld"
1519+
}, {
1520+
"@id": "#tpi02",
1521+
"@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"],
1522+
"name": "property-valued index indexes property value, instead of property (multiple values)",
1523+
"purpose": "Compacting property-valued indexes.",
1524+
"option": {"processingMode": "json-ld-1.1", "specVersion": "json-ld-1.1"},
1525+
"input": "compact/pi02-in.jsonld",
1526+
"context": "compact/pi02-context.jsonld",
1527+
"expect": "compact/pi02-out.jsonld"
1528+
}, {
1529+
"@id": "#tpi03",
1530+
"@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"],
1531+
"name": "property-valued index indexes property value, instead of property (node)",
1532+
"purpose": "Compacting property-valued indexes.",
1533+
"option": {"processingMode": "json-ld-1.1", "specVersion": "json-ld-1.1"},
1534+
"input": "compact/pi03-in.jsonld",
1535+
"context": "compact/pi03-context.jsonld",
1536+
"expect": "compact/pi03-out.jsonld"
1537+
}, {
1538+
"@id": "#tpi04",
1539+
"@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"],
1540+
"name": "property-valued index indexes property value, instead of property (multiple nodes)",
1541+
"purpose": "Compacting property-valued indexes.",
1542+
"option": {"processingMode": "json-ld-1.1", "specVersion": "json-ld-1.1"},
1543+
"input": "compact/pi04-in.jsonld",
1544+
"context": "compact/pi04-context.jsonld",
1545+
"expect": "compact/pi04-out.jsonld"
1546+
}, {
1547+
"@id": "#tpi05",
1548+
"@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"],
1549+
"name": "property-valued index indexes using @none if no property value exists",
1550+
"purpose": "Compacting property-valued indexes.",
1551+
"option": {"processingMode": "json-ld-1.1", "specVersion": "json-ld-1.1"},
1552+
"input": "compact/pi05-in.jsonld",
1553+
"context": "compact/pi05-context.jsonld",
1554+
"expect": "compact/pi05-out.jsonld"
1555+
}, {
1556+
"@id": "#tpi06",
1557+
"@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"],
1558+
"name": "property-valued index indexes using @none if no property value does not compact to string",
1559+
"purpose": "Compacting property-valued indexes.",
1560+
"option": {"processingMode": "json-ld-1.1", "specVersion": "json-ld-1.1"},
1561+
"input": "compact/pi06-in.jsonld",
1562+
"context": "compact/pi06-context.jsonld",
1563+
"expect": "compact/pi06-out.jsonld"
15101564
}, {
15111565
"@id": "#tr001",
15121566
"@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"],

tests/compact/pi01-context.jsonld

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"@context": {
3+
"@version": 1.1,
4+
"@base": "http://example.com/",
5+
"@vocab": "http://example.com/",
6+
"author": {"@type": "@id", "@container": "@index", "@index": "prop"}
7+
}
8+
}

tests/compact/pi01-in.jsonld

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[{
2+
"@id": "http://example.com/article",
3+
"http://example.com/author": [
4+
{"@id": "http://example.com/person/1", "http://example.com/prop": [{"@value": "regular"}]},
5+
{"@id": "http://example.com/person/2", "http://example.com/prop": [{"@value": "guest"}]},
6+
{"@id": "http://example.com/person/3", "http://example.com/prop": [{"@value": "guest"}]}
7+
]
8+
}]

tests/compact/pi01-out.jsonld

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"@context": {
3+
"@version": 1.1,
4+
"@base": "http://example.com/",
5+
"@vocab": "http://example.com/",
6+
"author": {"@type": "@id", "@container": "@index", "@index": "prop"}
7+
},
8+
"@id": "article",
9+
"author": {
10+
"regular": {"@id": "person/1"},
11+
"guest": [{"@id": "person/2"}, {"@id": "person/3"}]
12+
}
13+
}

tests/compact/pi02-context.jsonld

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"@context": {
3+
"@version": 1.1,
4+
"@base": "http://example.com/",
5+
"@vocab": "http://example.com/",
6+
"author": {"@type": "@id", "@container": "@index", "@index": "prop"}
7+
}
8+
}

tests/compact/pi02-in.jsonld

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[{
2+
"@id": "http://example.com/article",
3+
"http://example.com/author": [
4+
{"@id": "http://example.com/person/1", "http://example.com/prop": [{"@value": "regular"}, {"@value": "foo"}]},
5+
{"@id": "http://example.com/person/2", "http://example.com/prop": [{"@value": "guest"}, {"@value": "foo"}]},
6+
{"@id": "http://example.com/person/3", "http://example.com/prop": [{"@value": "guest"}, {"@value": "foo"}]}
7+
]
8+
}]

tests/compact/pi02-out.jsonld

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"@context": {
3+
"@version": 1.1,
4+
"@base": "http://example.com/",
5+
"@vocab": "http://example.com/",
6+
"author": {"@type": "@id", "@container": "@index", "@index": "prop"}
7+
},
8+
"@id": "article",
9+
"author": {
10+
"regular": {"@id": "person/1", "prop": "foo"},
11+
"guest": [
12+
{"@id": "person/2", "prop": "foo"},
13+
{"@id": "person/3", "prop": "foo"}
14+
]
15+
}
16+
}

tests/compact/pi03-context.jsonld

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"@context": {
3+
"@version": 1.1,
4+
"@base": "http://example.com/",
5+
"@vocab": "http://example.com/",
6+
"author": {"@type": "@vocab", "@container": "@index", "@index": "prop"},
7+
"prop": {"@type": "@id"}
8+
}
9+
}

tests/compact/pi03-in.jsonld

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[{
2+
"@id": "http://example.com/article",
3+
"http://example.com/author": [
4+
{"@id": "http://example.com/person/1", "http://example.com/prop": [{"@id": "http://example.com/regular"}]},
5+
{"@id": "http://example.com/person/2", "http://example.com/prop": [{"@id": "http://example.com/guest"}]},
6+
{"@id": "http://example.com/person/3", "http://example.com/prop": [{"@id": "http://example.com/guest"}]}
7+
]
8+
}]

tests/compact/pi03-out.jsonld

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"@context": {
3+
"@version": 1.1,
4+
"@base": "http://example.com/",
5+
"@vocab": "http://example.com/",
6+
"author": {"@type": "@vocab", "@container": "@index", "@index": "prop"},
7+
"prop": {"@type": "@id"}
8+
},
9+
"@id": "article",
10+
"author": {
11+
"regular": {"@id": "person/1"},
12+
"guest": [
13+
{"@id": "person/2"},
14+
{"@id": "person/3"}
15+
]
16+
}
17+
}

tests/compact/pi04-context.jsonld

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"@context": {
3+
"@version": 1.1,
4+
"@base": "http://example.com/",
5+
"@vocab": "http://example.com/",
6+
"author": {"@type": "@vocab", "@container": "@index", "@index": "prop"},
7+
"prop": {"@type": "@id"}
8+
}
9+
}

tests/compact/pi04-in.jsonld

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[{
2+
"@id": "http://example.com/article",
3+
"http://example.com/author": [
4+
{"@id": "http://example.com/person/1", "http://example.com/prop": [{"@id": "http://example.com/regular"}, {"@id": "http://example.com/foo"}]},
5+
{"@id": "http://example.com/person/2", "http://example.com/prop": [{"@id": "http://example.com/guest"}, {"@id": "http://example.com/foo"}]},
6+
{"@id": "http://example.com/person/3", "http://example.com/prop": [{"@id": "http://example.com/guest"}, {"@id": "http://example.com/foo"}]}
7+
]
8+
}]

tests/compact/pi04-out.jsonld

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"@context": {
3+
"@version": 1.1,
4+
"@base": "http://example.com/",
5+
"@vocab": "http://example.com/",
6+
"author": {"@type": "@vocab", "@container": "@index", "@index": "prop"},
7+
"prop": {"@type": "@id"}
8+
},
9+
"@id": "article",
10+
"author": {
11+
"regular": {"@id": "person/1", "prop": "foo"},
12+
"guest": [
13+
{"@id": "person/2", "prop": "foo"},
14+
{"@id": "person/3", "prop": "foo"}
15+
]
16+
}
17+
}

0 commit comments

Comments
 (0)