Skip to content

Commit c88290e

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 2a9008f commit c88290e

38 files changed

+600
-27
lines changed

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>protected</dfn>, used to mark this as a protected 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
@@ -1956,8 +1971,10 @@ <h3>Algorithm</h3>
19561971
<var>value</var> is a <a class="changed">dictionary</a> then <var>value</var>
19571972
is expanded from an map as follows:
19581973
<ol>
1959-
<li>Initialize <var>expanded value</var> to an empty
1960-
<a>array</a>.</li>
1974+
<li>Initialize <var>expanded value</var> to an empty <a>array</a>.</li>
1975+
<li class="changed">Initialize <var>index key</var> to
1976+
the <var>key</var>'s <a>index mapping</a> in <a>active context</a>,
1977+
or <code>@index</code>, if it does not exist.</li>
19611978
<li>For each key-value pair <var>index</var>-<var>index value</var>
19621979
in <var>value</var>, ordered lexicographically by <var>index</var>
19631980
<span class="changed">if <a data-link-for="JsonLdOptions">ordered</a> is <code>true</code></span>:
@@ -1987,36 +2004,41 @@ <h3>Algorithm</h3>
19872004
and <a data-link-for="JsonLdOptions">ordered</a> flags</span>.</li>
19882005
<li>For each <var>item</var> in <var>index value</var>:
19892006
<ol class="algorithm changed">
1990-
<li>If <var>container mapping</var> includes
1991-
<code>@graph</code> and if <var>item</var> is not a
1992-
<a>graph object</a>, set <var>item</var> to a new
1993-
<a>dictionary</a> containing the key-value pair
1994-
<code>@graph</code>-<var>item</var>, ensuring that the
1995-
value is represented using an <a>array</a>.</li>
1996-
<li>If <var>container mapping</var> includes <code>@index</code>
1997-
and <var>item</var> does not have the <a>member</a>
1998-
<code>@index</code> and <var>expanded index</var> is not <code>@none</code>,
1999-
add the key-value pair
2000-
(<code>@index</code>-<var>index</var>) to <var>item</var>.</li>
2007+
<li>If <var>container mapping</var> includes <code>@graph</code>
2008+
and if <var>item</var> is not a <a>graph object</a>,
2009+
set <var>item</var> to a new <a>dictionary</a> containing the key-value pair
2010+
<code>@graph</code>-<var>item</var>,
2011+
ensuring that the value is represented using an <a>array</a>.</li>
2012+
<li class="changed">If <var>container mapping</var> includes <code>@index</code>,
2013+
<var>index key</var> is not <code>@index</code>,
2014+
<var>item</var> does not have a <a>member</a> <code>@index</code>
2015+
and <var>expanded index</var> is not <code>@none</code>,
2016+
set <var>index property values</var> to the concatenation of
2017+
<var>expanded index</var> with any existing values of
2018+
<var>index key</var> in <var>item</var>.
2019+
Add the key-value pair (<var>expanded index</var>-<var>index property values</var>) to <var>item</var>.
2020+
If expanded value is a value object,
2021+
it MUST NOT contain any extra properties;
2022+
an <a data-link-for="JsonLdErrorCode">invalid value object</a>
2023+
error has been detected and processing is aborted.</li>
2024+
<li>Otherwise, if <var>container mapping</var> includes <code>@index</code>,
2025+
<var>item</var> does not have a <a>member</a> <code>@index</code>,
2026+
and <var>expanded index</var> is not <code>@none</code>,
2027+
add the key-value pair (<code>@index</code>-<var>index</var>) to <var>item</var>.</li>
20012028
<li>Otherwise, if <var>container mapping</var> includes <code>@id</code>
2002-
and <var>item</var> does not have the <a>member</a>
2003-
<code>@id</code>, add the key-value pair
2004-
(<code>@id</code>-<var>expanded index</var>) to
2005-
<var>item</var>, where <var>expanded index</var> is set to the result of
2006-
using the
2029+
and <var>item</var> does not have the <a>member</a> <code>@id</code>,
2030+
add the key-value pair (<code>@id</code>-<var>expanded index</var>) to <var>item</var>,
2031+
where <var>expanded index</var> is set to the result of using the
20072032
<a href="#iri-expansion">IRI Expansion algorithm</a>,
20082033
passing <var>active context</var>, <var>index</var>, and <code>true</code>
20092034
for <var>document relative</var>, unless <var>expanded index</var>
20102035
is already set to <code>@none</code>.</li>
20112036
<li>Otherwise, if <var>container mapping</var> includes <code>@type</code>
2012-
set <var>types</var> to the concatenation of
2013-
<var>expanded index</var> with any existing values of
2014-
<code>@type</code> in <var>item</var>.
2037+
set <var>types</var> to the concatenation of <var>expanded index</var>
2038+
with any existing values of <code>@type</code> in <var>item</var>.
20152039
If <var>expanded index</var> is <code>@none</code>,
20162040
do not concatenate <var>expanded index</var> to <var>types</var>.
2017-
Add the key-value pair
2018-
(<code>@type</code>-<var>types</var>) to
2019-
<var>item</var>.</li>
2041+
Add the key-value pair (<code>@type</code>-<var>types</var>) to <var>item</var>.</li>
20202042
<li>Append <var>item</var> to <var>expanded value</var>.</li>
20212043
</ol>
20222044
</li>
@@ -2776,17 +2798,31 @@ <h3>Algorithm</h3>
27762798
either <code>@language</code>, <code>@index</code>, <code>@id</code>, or <code>@type</code>
27772799
based on the contents of <var>container</var>, as <var>var</var>, and <code>true</code>
27782800
for <var>vocab</var>.</li>
2801+
<li class="changed">Set <var>index key</var> to the value of <a>index mapping</a> in
2802+
the <a>term definition</a> associated with <var>item active property</var> in <var>active context</var>,
2803+
or <code>@index</code>, if no such value exists.</li>
27792804
<li>If <var>container</var> includes <code>@language</code> and
27802805
<var>expanded item</var> contains a
27812806
<code>@value</code> <a>member</a>, then set <var>compacted item</var>
27822807
to the value associated with its <code>@value</code> <a>member</a>.
27832808
Set <var>map key</var> to the value of <code>@language</code> in <var>expanded item</var>, if any.</li>
2784-
<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,
2809+
<li>Otherwise, if <var>container</var> includes <code>@index</code>
2810+
and <var>index key</var> is <code>@index</code>,
2811+
set <var>map key</var> to the value of <code>@index</code> in <var>expanded item</var>, if any,
27852812
and remove <var>container key</var> from <var>compacted item</var>.</li>
2786-
<li class="changed">If <var>container</var> includes <code>@id</code>, set
2813+
<li class="changed">Otherwise, if <var>container</var> includes <code>@index</code>
2814+
and <var>index key</var> is not <code>@index</code>,
2815+
Set <var>map key</var> to the first value of <var>container key</var> in <var>compacted item</var>, if any.
2816+
If there are remaining values in <var>compacted item</var>
2817+
for <var>compacted container</var>, set the value of
2818+
<var>compacted container</var> in <var>compacted value</var>
2819+
to those remaining values. Otherwise, remove that
2820+
<a>member</a> from <var>compacted item</var>.
2821+
</li>
2822+
<li class="changed">Otherwise, if <var>container</var> includes <code>@id</code>, set
27872823
<var>map key</var> to the value of <var>container key</var> in
27882824
<var>compacted item</var> and remove <var>container key</var> from <var>compacted item</var>.</li>
2789-
<li class="changed">If <var>container</var> is <code>@type</code>,
2825+
<li class="changed">Otherwise, if <var>container</var> is <code>@type</code>,
27902826
set <var>map key</var> to the first value of <var>container key</var> in <var>compacted item</var>, if any.
27912827
If there are remaining values in <var>compacted item</var>
27922828
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
@@ -1598,6 +1598,60 @@
15981598
"input": "compact/p008-in.jsonld",
15991599
"context": "compact/p008-context.jsonld",
16001600
"expect": "compact/p008-out.jsonld"
1601+
}, {
1602+
"@id": "#tpi01",
1603+
"@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"],
1604+
"name": "property-valued index indexes property value, instead of property (value)",
1605+
"purpose": "Compacting property-valued indexes.",
1606+
"option": {"processingMode": "json-ld-1.1", "specVersion": "json-ld-1.1"},
1607+
"input": "compact/pi01-in.jsonld",
1608+
"context": "compact/pi01-context.jsonld",
1609+
"expect": "compact/pi01-out.jsonld"
1610+
}, {
1611+
"@id": "#tpi02",
1612+
"@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"],
1613+
"name": "property-valued index indexes property value, instead of property (multiple values)",
1614+
"purpose": "Compacting property-valued indexes.",
1615+
"option": {"processingMode": "json-ld-1.1", "specVersion": "json-ld-1.1"},
1616+
"input": "compact/pi02-in.jsonld",
1617+
"context": "compact/pi02-context.jsonld",
1618+
"expect": "compact/pi02-out.jsonld"
1619+
}, {
1620+
"@id": "#tpi03",
1621+
"@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"],
1622+
"name": "property-valued index indexes property value, instead of property (node)",
1623+
"purpose": "Compacting property-valued indexes.",
1624+
"option": {"processingMode": "json-ld-1.1", "specVersion": "json-ld-1.1"},
1625+
"input": "compact/pi03-in.jsonld",
1626+
"context": "compact/pi03-context.jsonld",
1627+
"expect": "compact/pi03-out.jsonld"
1628+
}, {
1629+
"@id": "#tpi04",
1630+
"@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"],
1631+
"name": "property-valued index indexes property value, instead of property (multiple nodes)",
1632+
"purpose": "Compacting property-valued indexes.",
1633+
"option": {"processingMode": "json-ld-1.1", "specVersion": "json-ld-1.1"},
1634+
"input": "compact/pi04-in.jsonld",
1635+
"context": "compact/pi04-context.jsonld",
1636+
"expect": "compact/pi04-out.jsonld"
1637+
}, {
1638+
"@id": "#tpi05",
1639+
"@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"],
1640+
"name": "property-valued index indexes using @none if no property value exists",
1641+
"purpose": "Compacting property-valued indexes.",
1642+
"option": {"processingMode": "json-ld-1.1", "specVersion": "json-ld-1.1"},
1643+
"input": "compact/pi05-in.jsonld",
1644+
"context": "compact/pi05-context.jsonld",
1645+
"expect": "compact/pi05-out.jsonld"
1646+
}, {
1647+
"@id": "#tpi06",
1648+
"@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"],
1649+
"name": "property-valued index indexes using @none if no property value does not compact to string",
1650+
"purpose": "Compacting property-valued indexes.",
1651+
"option": {"processingMode": "json-ld-1.1", "specVersion": "json-ld-1.1"},
1652+
"input": "compact/pi06-in.jsonld",
1653+
"context": "compact/pi06-context.jsonld",
1654+
"expect": "compact/pi06-out.jsonld"
16011655
}, {
16021656
"@id": "#tr001",
16031657
"@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+
}

tests/compact/pi05-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/pi05-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"},
5+
{"@id": "http://example.com/person/2"},
6+
{"@id": "http://example.com/person/3"}
7+
]
8+
}]

tests/compact/pi05-out.jsonld

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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+
"@none": ["person/1", "person/2", "person/3"]
11+
}
12+
}

tests/compact/pi06-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+
}

0 commit comments

Comments
 (0)