Skip to content

Commit

Permalink
Add API text and tests for compaction and expansion of indexes using …
Browse files Browse the repository at this point in the history
…a property.

For w3c/json-ld-syntax#145.
  • Loading branch information
gkellogg committed Apr 15, 2019
1 parent 541ff29 commit d6b60ad
Show file tree
Hide file tree
Showing 38 changed files with 600 additions and 27 deletions.
90 changes: 63 additions & 27 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,7 @@ <h2>Context Processing Algorithm</h2>
<span class="changed">an optional <a>context</a></span>,
<span class="changed">an optional <dfn>nest value</dfn>,</span>
<span class="changed">an optional <dfn>prefix flag</dfn>,</span>
<span class="changed">an optional <dfn>index mapping</dfn>,</span>
<span class="changed">a <dfn>protected</dfn>, used to mark this as a protected term,</span>
and an optional <dfn>container mapping</dfn>.
A <a>term definition</a> can not only be used to map a <a>term</a>
Expand Down Expand Up @@ -1389,6 +1390,20 @@ <h3>Algorithm</h3>
<var>container</var>.</li>
</ol>
</li>
<li class="changed">If <var>value</var> contains the <a>member</a> <code>@index</code>:
<ol>
<li>If <a>processing mode</a> is <code>json-ld-1.0</code> or
<a>container mapping</a> does not include <code>@index</code>,
an <a data-link-for="JsonLdErrorCode">invalid term definition</a>
has been detected and processing is aborted.</li>
<li>Initialize <var>index</var> to the value associated with the
<code>@index</code> <a>member</a>, which MUST a <a>string</a> expanding to an <a>absolute IRI</a>.
Otherwise, an
<a data-link-for="JsonLdErrorCode">invalid term definition</a>
has been detected and processing is aborted.</li>
<li>Set the <a>index mapping</a> of <var>definition</var> to <var>index</var></li>
</ol>
</li>
<li class="changed">If <var>value</var> contains the <a>member</a> <code>@context</code>:
<ol>
<li>If <a>processing mode</a> is <code>json-ld-1.0</code>, an
Expand Down Expand Up @@ -1972,8 +1987,10 @@ <h3>Algorithm</h3>
<var>value</var> is a <a class="changed">dictionary</a> then <var>value</var>
is expanded from an map as follows:
<ol>
<li>Initialize <var>expanded value</var> to an empty
<a>array</a>.</li>
<li>Initialize <var>expanded value</var> to an empty <a>array</a>.</li>
<li class="changed">Initialize <var>index key</var> to
the <var>key</var>'s <a>index mapping</a> in <a>active context</a>,
or <code>@index</code>, if it does not exist.</li>
<li>For each key-value pair <var>index</var>-<var>index value</var>
in <var>value</var>, ordered lexicographically by <var>index</var>
<span class="changed">if <a data-link-for="JsonLdOptions">ordered</a> is <code>true</code></span>:
Expand Down Expand Up @@ -2003,36 +2020,41 @@ <h3>Algorithm</h3>
and <a data-link-for="JsonLdOptions">ordered</a> flags</span>.</li>
<li>For each <var>item</var> in <var>index value</var>:
<ol class="algorithm changed">
<li>If <var>container mapping</var> includes
<code>@graph</code> and if <var>item</var> is not a
<a>graph object</a>, set <var>item</var> to a new
<a>dictionary</a> containing the key-value pair
<code>@graph</code>-<var>item</var>, ensuring that the
value is represented using an <a>array</a>.</li>
<li>If <var>container mapping</var> includes <code>@index</code>
and <var>item</var> does not have the <a>member</a>
<code>@index</code> and <var>expanded index</var> is not <code>@none</code>,
add the key-value pair
(<code>@index</code>-<var>index</var>) to <var>item</var>.</li>
<li>If <var>container mapping</var> includes <code>@graph</code>
and if <var>item</var> is not a <a>graph object</a>,
set <var>item</var> to a new <a>dictionary</a> containing the key-value pair
<code>@graph</code>-<var>item</var>,
ensuring that the value is represented using an <a>array</a>.</li>
<li class="changed">If <var>container mapping</var> includes <code>@index</code>,
<var>index key</var> is not <code>@index</code>,
<var>item</var> does not have a <a>member</a> <code>@index</code>
and <var>expanded index</var> is not <code>@none</code>,
set <var>index property values</var> to the concatenation of
<var>expanded index</var> with any existing values of
<var>index key</var> in <var>item</var>.
Add the key-value pair (<var>expanded index</var>-<var>index property values</var>) to <var>item</var>.
If expanded value is a value object,
it MUST NOT contain any extra properties;
an <a data-link-for="JsonLdErrorCode">invalid value object</a>
error has been detected and processing is aborted.</li>
<li>Otherwise, if <var>container mapping</var> includes <code>@index</code>,
<var>item</var> does not have a <a>member</a> <code>@index</code>,
and <var>expanded index</var> is not <code>@none</code>,
add the key-value pair (<code>@index</code>-<var>index</var>) to <var>item</var>.</li>
<li>Otherwise, if <var>container mapping</var> includes <code>@id</code>
and <var>item</var> does not have the <a>member</a>
<code>@id</code>, add the key-value pair
(<code>@id</code>-<var>expanded index</var>) to
<var>item</var>, where <var>expanded index</var> is set to the result of
using the
and <var>item</var> does not have the <a>member</a> <code>@id</code>,
add the key-value pair (<code>@id</code>-<var>expanded index</var>) to <var>item</var>,
where <var>expanded index</var> is set to the result of using the
<a href="#iri-expansion">IRI Expansion algorithm</a>,
passing <var>active context</var>, <var>index</var>, and <code>true</code>
for <var>document relative</var>, unless <var>expanded index</var>
is already set to <code>@none</code>.</li>
<li>Otherwise, if <var>container mapping</var> includes <code>@type</code>
set <var>types</var> to the concatenation of
<var>expanded index</var> with any existing values of
<code>@type</code> in <var>item</var>.
set <var>types</var> to the concatenation of <var>expanded index</var>
with any existing values of <code>@type</code> in <var>item</var>.
If <var>expanded index</var> is <code>@none</code>,
do not concatenate <var>expanded index</var> to <var>types</var>.
Add the key-value pair
(<code>@type</code>-<var>types</var>) to
<var>item</var>.</li>
Add the key-value pair (<code>@type</code>-<var>types</var>) to <var>item</var>.</li>
<li>Append <var>item</var> to <var>expanded value</var>.</li>
</ol>
</li>
Expand Down Expand Up @@ -2792,17 +2814,31 @@ <h3>Algorithm</h3>
either <code>@language</code>, <code>@index</code>, <code>@id</code>, or <code>@type</code>
based on the contents of <var>container</var>, as <var>var</var>, and <code>true</code>
for <var>vocab</var>.</li>
<li class="changed">Set <var>index key</var> to the value of <a>index mapping</a> in
the <a>term definition</a> associated with <var>item active property</var> in <var>active context</var>,
or <code>@index</code>, if no such value exists.</li>
<li>If <var>container</var> includes <code>@language</code> and
<var>expanded item</var> contains a
<code>@value</code> <a>member</a>, then set <var>compacted item</var>
to the value associated with its <code>@value</code> <a>member</a>.
Set <var>map key</var> to the value of <code>@language</code> in <var>expanded item</var>, if any.</li>
<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,
<li>Otherwise, if <var>container</var> includes <code>@index</code>
and <var>index key</var> is <code>@index</code>,
set <var>map key</var> to the value of <code>@index</code> in <var>expanded item</var>, if any,
and remove <var>container key</var> from <var>compacted item</var>.</li>
<li class="changed">If <var>container</var> includes <code>@id</code>, set
<li class="changed">Otherwise, if <var>container</var> includes <code>@index</code>
and <var>index key</var> is not <code>@index</code>,
Set <var>map key</var> to the first value of <var>container key</var> in <var>compacted item</var>, if any.
If there are remaining values in <var>compacted item</var>
for <var>compacted container</var>, set the value of
<var>compacted container</var> in <var>compacted value</var>
to those remaining values. Otherwise, remove that
<a>member</a> from <var>compacted item</var>.
</li>
<li class="changed">Otherwise, if <var>container</var> includes <code>@id</code>, set
<var>map key</var> to the value of <var>container key</var> in
<var>compacted item</var> and remove <var>container key</var> from <var>compacted item</var>.</li>
<li class="changed">If <var>container</var> is <code>@type</code>,
<li class="changed">Otherwise, if <var>container</var> is <code>@type</code>,
set <var>map key</var> to the first value of <var>container key</var> in <var>compacted item</var>, if any.
If there are remaining values in <var>compacted item</var>
for <var>compacted container</var>, set the value of
Expand Down
54 changes: 54 additions & 0 deletions tests/compact-manifest.jsonld
Original file line number Diff line number Diff line change
Expand Up @@ -1598,6 +1598,60 @@
"input": "compact/p008-in.jsonld",
"context": "compact/p008-context.jsonld",
"expect": "compact/p008-out.jsonld"
}, {
"@id": "#tpi01",
"@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"],
"name": "property-valued index indexes property value, instead of property (value)",
"purpose": "Compacting property-valued indexes.",
"option": {"processingMode": "json-ld-1.1", "specVersion": "json-ld-1.1"},
"input": "compact/pi01-in.jsonld",
"context": "compact/pi01-context.jsonld",
"expect": "compact/pi01-out.jsonld"
}, {
"@id": "#tpi02",
"@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"],
"name": "property-valued index indexes property value, instead of property (multiple values)",
"purpose": "Compacting property-valued indexes.",
"option": {"processingMode": "json-ld-1.1", "specVersion": "json-ld-1.1"},
"input": "compact/pi02-in.jsonld",
"context": "compact/pi02-context.jsonld",
"expect": "compact/pi02-out.jsonld"
}, {
"@id": "#tpi03",
"@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"],
"name": "property-valued index indexes property value, instead of property (node)",
"purpose": "Compacting property-valued indexes.",
"option": {"processingMode": "json-ld-1.1", "specVersion": "json-ld-1.1"},
"input": "compact/pi03-in.jsonld",
"context": "compact/pi03-context.jsonld",
"expect": "compact/pi03-out.jsonld"
}, {
"@id": "#tpi04",
"@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"],
"name": "property-valued index indexes property value, instead of property (multiple nodes)",
"purpose": "Compacting property-valued indexes.",
"option": {"processingMode": "json-ld-1.1", "specVersion": "json-ld-1.1"},
"input": "compact/pi04-in.jsonld",
"context": "compact/pi04-context.jsonld",
"expect": "compact/pi04-out.jsonld"
}, {
"@id": "#tpi05",
"@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"],
"name": "property-valued index indexes using @none if no property value exists",
"purpose": "Compacting property-valued indexes.",
"option": {"processingMode": "json-ld-1.1", "specVersion": "json-ld-1.1"},
"input": "compact/pi05-in.jsonld",
"context": "compact/pi05-context.jsonld",
"expect": "compact/pi05-out.jsonld"
}, {
"@id": "#tpi06",
"@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"],
"name": "property-valued index indexes using @none if no property value does not compact to string",
"purpose": "Compacting property-valued indexes.",
"option": {"processingMode": "json-ld-1.1", "specVersion": "json-ld-1.1"},
"input": "compact/pi06-in.jsonld",
"context": "compact/pi06-context.jsonld",
"expect": "compact/pi06-out.jsonld"
}, {
"@id": "#tr001",
"@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"],
Expand Down
8 changes: 8 additions & 0 deletions tests/compact/pi01-context.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"@context": {
"@version": 1.1,
"@base": "http://example.com/",
"@vocab": "http://example.com/",
"author": {"@type": "@id", "@container": "@index", "@index": "prop"}
}
}
8 changes: 8 additions & 0 deletions tests/compact/pi01-in.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[{
"@id": "http://example.com/article",
"http://example.com/author": [
{"@id": "http://example.com/person/1", "http://example.com/prop": [{"@value": "regular"}]},
{"@id": "http://example.com/person/2", "http://example.com/prop": [{"@value": "guest"}]},
{"@id": "http://example.com/person/3", "http://example.com/prop": [{"@value": "guest"}]}
]
}]
13 changes: 13 additions & 0 deletions tests/compact/pi01-out.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"@context": {
"@version": 1.1,
"@base": "http://example.com/",
"@vocab": "http://example.com/",
"author": {"@type": "@id", "@container": "@index", "@index": "prop"}
},
"@id": "article",
"author": {
"regular": {"@id": "person/1"},
"guest": [{"@id": "person/2"}, {"@id": "person/3"}]
}
}
8 changes: 8 additions & 0 deletions tests/compact/pi02-context.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"@context": {
"@version": 1.1,
"@base": "http://example.com/",
"@vocab": "http://example.com/",
"author": {"@type": "@id", "@container": "@index", "@index": "prop"}
}
}
8 changes: 8 additions & 0 deletions tests/compact/pi02-in.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[{
"@id": "http://example.com/article",
"http://example.com/author": [
{"@id": "http://example.com/person/1", "http://example.com/prop": [{"@value": "regular"}, {"@value": "foo"}]},
{"@id": "http://example.com/person/2", "http://example.com/prop": [{"@value": "guest"}, {"@value": "foo"}]},
{"@id": "http://example.com/person/3", "http://example.com/prop": [{"@value": "guest"}, {"@value": "foo"}]}
]
}]
16 changes: 16 additions & 0 deletions tests/compact/pi02-out.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"@context": {
"@version": 1.1,
"@base": "http://example.com/",
"@vocab": "http://example.com/",
"author": {"@type": "@id", "@container": "@index", "@index": "prop"}
},
"@id": "article",
"author": {
"regular": {"@id": "person/1", "prop": "foo"},
"guest": [
{"@id": "person/2", "prop": "foo"},
{"@id": "person/3", "prop": "foo"}
]
}
}
9 changes: 9 additions & 0 deletions tests/compact/pi03-context.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"@context": {
"@version": 1.1,
"@base": "http://example.com/",
"@vocab": "http://example.com/",
"author": {"@type": "@vocab", "@container": "@index", "@index": "prop"},
"prop": {"@type": "@id"}
}
}
8 changes: 8 additions & 0 deletions tests/compact/pi03-in.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[{
"@id": "http://example.com/article",
"http://example.com/author": [
{"@id": "http://example.com/person/1", "http://example.com/prop": [{"@id": "http://example.com/regular"}]},
{"@id": "http://example.com/person/2", "http://example.com/prop": [{"@id": "http://example.com/guest"}]},
{"@id": "http://example.com/person/3", "http://example.com/prop": [{"@id": "http://example.com/guest"}]}
]
}]
17 changes: 17 additions & 0 deletions tests/compact/pi03-out.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"@context": {
"@version": 1.1,
"@base": "http://example.com/",
"@vocab": "http://example.com/",
"author": {"@type": "@vocab", "@container": "@index", "@index": "prop"},
"prop": {"@type": "@id"}
},
"@id": "article",
"author": {
"regular": {"@id": "person/1"},
"guest": [
{"@id": "person/2"},
{"@id": "person/3"}
]
}
}
9 changes: 9 additions & 0 deletions tests/compact/pi04-context.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"@context": {
"@version": 1.1,
"@base": "http://example.com/",
"@vocab": "http://example.com/",
"author": {"@type": "@vocab", "@container": "@index", "@index": "prop"},
"prop": {"@type": "@id"}
}
}
8 changes: 8 additions & 0 deletions tests/compact/pi04-in.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[{
"@id": "http://example.com/article",
"http://example.com/author": [
{"@id": "http://example.com/person/1", "http://example.com/prop": [{"@id": "http://example.com/regular"}, {"@id": "http://example.com/foo"}]},
{"@id": "http://example.com/person/2", "http://example.com/prop": [{"@id": "http://example.com/guest"}, {"@id": "http://example.com/foo"}]},
{"@id": "http://example.com/person/3", "http://example.com/prop": [{"@id": "http://example.com/guest"}, {"@id": "http://example.com/foo"}]}
]
}]
17 changes: 17 additions & 0 deletions tests/compact/pi04-out.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"@context": {
"@version": 1.1,
"@base": "http://example.com/",
"@vocab": "http://example.com/",
"author": {"@type": "@vocab", "@container": "@index", "@index": "prop"},
"prop": {"@type": "@id"}
},
"@id": "article",
"author": {
"regular": {"@id": "person/1", "prop": "foo"},
"guest": [
{"@id": "person/2", "prop": "foo"},
{"@id": "person/3", "prop": "foo"}
]
}
}
8 changes: 8 additions & 0 deletions tests/compact/pi05-context.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"@context": {
"@version": 1.1,
"@base": "http://example.com/",
"@vocab": "http://example.com/",
"author": {"@type": "@id", "@container": "@index", "@index": "prop"}
}
}
8 changes: 8 additions & 0 deletions tests/compact/pi05-in.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[{
"@id": "http://example.com/article",
"http://example.com/author": [
{"@id": "http://example.com/person/1"},
{"@id": "http://example.com/person/2"},
{"@id": "http://example.com/person/3"}
]
}]
12 changes: 12 additions & 0 deletions tests/compact/pi05-out.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"@context": {
"@version": 1.1,
"@base": "http://example.com/",
"@vocab": "http://example.com/",
"author": {"@type": "@id", "@container": "@index", "@index": "prop"}
},
"@id": "article",
"author": {
"@none": ["person/1", "person/2", "person/3"]
}
}
8 changes: 8 additions & 0 deletions tests/compact/pi06-context.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"@context": {
"@version": 1.1,
"@base": "http://example.com/",
"@vocab": "http://example.com/",
"author": {"@type": "@id", "@container": "@index", "@index": "prop"}
}
}
Loading

0 comments on commit d6b60ad

Please sign in to comment.