Skip to content

Commit ac871b2

Browse files
committed
Add Term Selection algorithm examples.
Fixes #495.
1 parent 6f71e27 commit ac871b2

File tree

1 file changed

+115
-4
lines changed

1 file changed

+115
-4
lines changed

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

Lines changed: 115 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2470,8 +2470,8 @@ <h3>Algorithm</h3>
24702470
href="#iri-compaction">IRI Compaction algorithm</a>
24712471
passing <var>active context</var>, <code>@graph</code> as
24722472
<var>var</var>, and <code>true</code> for
2473-
<var>vocab</var> using the original var>compacted
2474-
item</var> as a value.</li>
2473+
<var>vocab</var> using the original
2474+
<var>compacted item</var> as a value.</li>
24752475
<li>If expanded item contains the key <code>@id</code>,
24762476
add the key resulting from calling the <a
24772477
href="#iri-compaction">IRI Compaction algorithm</a>
@@ -3122,6 +3122,119 @@ <h3>Algorithm</h3>
31223122
<li>No matching term has been found. Return <code>null</code>.</li>
31233123
</ol>
31243124
</section>
3125+
3126+
<section class="informative">
3127+
<h3>Examples</h3>
3128+
<p>The following examples are intended to illustrate how the term selection algorithm
3129+
behaves for different term definitions and values. It is not comprehensive, but
3130+
intended to illustrate different parts of the algorithm.</p>
3131+
3132+
<section>
3133+
<h4>Language Map Term</h4>
3134+
<p>If the term definition has <code>"@container": "@language"</code>, it will only match a
3135+
<a>value object</a> having no <code>@type</code>.</p>
3136+
<pre class="example" title="Term definition with language map">
3137+
{
3138+
"@context": {"t": {"@id": "http://example/t", "@container": "@language"}}
3139+
}
3140+
</pre>
3141+
<p>The inverse context will contain the following:</p>
3142+
<pre>
3143+
{
3144+
"@language": {
3145+
"@language": {"@none": "t"},
3146+
"@type": {"@none": "t"},
3147+
"@any": {"@none": "t"}
3148+
}
3149+
}
3150+
</pre>
3151+
3152+
<aside class="example data-ignore" title="Language map term with language value">
3153+
<p>Given the member <code>{"http://example/t": {"@value": "foo", "@type": "http:/example/type"}}</code>,
3154+
The algorithm will be invoked as follows:</p>
3155+
<dl>
3156+
<dt><var>containers</var></dt>
3157+
<dd><code>["@language", "@language@set", "@set", "@none", "@index", "@index@set"]</code></dd>
3158+
<dt><var>type/language</var></dt>
3159+
<dd><code>@language</code></dd>
3160+
<dt><var>preferred values</var></dt>
3161+
<dd><code>["en", "@none"]</code></dd>
3162+
</dl>
3163+
<p>The <var>value map</var> will be set to <code>{"@none"=>"t"}</code>,
3164+
as <var>preferred values</var> contains <code>"@none"</code>,
3165+
the algorithm returns <code>"t"</code> as the term to use for compaction.</p>
3166+
</aside>
3167+
</section>
3168+
3169+
<section>
3170+
<h4>Datatyped Term</h4>
3171+
<p>If the term definition has a datatype, it will only match a
3172+
<a>value object</a> having a matching datatype.</p>
3173+
<pre class="example" title="Term definition with datatype">
3174+
{
3175+
"@context": {"t": {"@id": "http://example/t", "@type": "http:/example/type"}}
3176+
}
3177+
</pre>
3178+
<p>The inverse context will contain the following:</p>
3179+
<pre>
3180+
{
3181+
"@none": {
3182+
"@language": {},
3183+
"@type": {"http:/example/type": "t"},
3184+
"@any": {"@none": "t"}
3185+
}
3186+
}
3187+
</pre>
3188+
3189+
<aside class="example data-ignore" title="Datatyped term with datatyped value">
3190+
<p>Given the member <code>{"http://example/t": {"@value": "foo", "@type": "http:/example/type"}}</code>,
3191+
The algorithm will be invoked as follows:</p>
3192+
<dl>
3193+
<dt><var>containers</var></dt>
3194+
<dd><code>["@set", "@none", "@index", "@index@set"]</code></dd>
3195+
<dt><var>type/language</var></dt>
3196+
<dd><code>@type</code></dd>
3197+
<dt><var>preferred values</var></dt>
3198+
<dd><code>["http:/example/type", "@none"]</code></dd>
3199+
</dl>
3200+
<p>The <var>value map</var> will be set to <code>{"http:/example/type": "t"}</code>,
3201+
as <var>preferred values</var> contains <code>"http:/example/type"</code>,
3202+
the algorithm returns <code>"t"</code> as the term to use for compaction.</p>
3203+
</aside>
3204+
3205+
<aside class="example data-ignore" title="Datatyped term with simple value">
3206+
<p>Given the member <code>{"http://example/t": {"@value": "foo"}}</code>,
3207+
The algorithm will be invoked as follows:</p>
3208+
<dl>
3209+
<dt><var>containers</var></dt>
3210+
<dd><code>["@set", "@none", "@index", "@index@set", "@language", "@language@set"]</code></dd>
3211+
<dt><var>type/language</var></dt>
3212+
<dd><code>@language</code></dd>
3213+
<dt><var>preferred values</var></dt>
3214+
<dd><code>["@null", "@none"]</code></dd>
3215+
</dl>
3216+
<p>The <var>value map</var> will be set to <code>{"@none": "t"}</code>,
3217+
as no key in <var>preferred values</var> matches a key in <var>value map</var>,
3218+
the algorithm returns <code>null</code> and no term is found.</p>
3219+
</aside>
3220+
3221+
<aside class="example data-ignore" title="Datatyped term with object value">
3222+
<p>Given the member <code>{"http://example/t": {"@id": "http://example/id"}}</code>,
3223+
The algorithm will be invoked as follows:</p>
3224+
<dl>
3225+
<dt><var>containers</var></dt>
3226+
<dd><code>["@id", "@id@set", "@type", "@set@type", "@set", "@none", "@index", "@index@set"]</code></dd>
3227+
<dt><var>type/language</var></dt>
3228+
<dd><code>@type</code></dd>
3229+
<dt><var>preferred values</var></dt>
3230+
<dd><code>["@id", "@vocab", "@none"]</code></dd>
3231+
</dl>
3232+
<p>The <var>value map</var> will be set to <code>{"http:/example/type": "t"}</code>,
3233+
as no key in <var>preferred values</var> matches a key in <var>value map</var>,
3234+
the algorithm returns <code>null</code> and no term is found.</p>
3235+
</aside>
3236+
</section>
3237+
</section>
31253238
</section> <!-- end of Term Selection -->
31263239

31273240
<section>
@@ -4931,7 +5044,6 @@ <h2>Open Issues</h2>
49315044
<p class="issue defer" data-number="402"></p>
49325045
<p class="issue defer" data-number="434"></p>
49335046
<p class="issue defer" data-number="460"></p>
4934-
<p class="issue" data-number="495"></p>
49355047
<p class="issue defer" data-number="507"></p>
49365048
<p class="issue" data-number="512"></p>
49375049
<p class="issue defer" data-number="526"></p>
@@ -4942,7 +5054,6 @@ <h2>Open Issues</h2>
49425054
<p class="issue defer" data-number="583"></p>
49435055
<p class="issue defer" data-number="595"></p>
49445056
<p class="issue defer" data-number="589"></p>
4945-
<p class="issue" data-number="611"></p>
49465057
</section>
49475058

49485059
<section class="appendix informative">

0 commit comments

Comments
 (0)