Skip to content

Commit

Permalink
Reintroduce @vocab
Browse files Browse the repository at this point in the history
This closes #26.
  • Loading branch information
lanthaler committed Aug 1, 2012
1 parent 8986033 commit a2b449d
Show file tree
Hide file tree
Showing 5 changed files with 220 additions and 146 deletions.
18 changes: 11 additions & 7 deletions spec/latest/json-ld-api/index.html
Expand Up @@ -1203,6 +1203,8 @@ <h2 id="context">Context Processing</h2>
<ol class="algorithm">
<li>If <em>context</em> has a <code>@language</code> property, it MUST have a value of a
simple <tref>string</tref> or <tref>null</tref>. Add the language to the <tref>local context</tref>.</li>
<li>If <em>value</em> has a <code>@vocab</code> key, it MUST have a value of a simple <tref>string</tref>
with the lexical form of an absolute IRI. Add the vocabulary mapping to the <tref>local context</tref>.</li>
<li id="object-context">Otherwise, for each property in <em>context</em> perform the following steps:
<ol class="algorithm">
<li>If the property's value is a simple <tref>string</tref>, determine the IRI mapping value by
Expand Down Expand Up @@ -1272,7 +1274,8 @@ <h2 id="context">Context Processing</h2>
<h2>IRI Expansion</h2>
<p>Keys and some values are evaluated to produce an <tref>IRI</tref>. This section defines an algorithm for
transforming a value representing an IRI into an actual IRI.</p>
<p><tref>IRI</tref>s may be represented as an <tref>absolute IRI</tref>, a <tref>term</tref> or a <tref>compact IRI</tref>.</p>
<p><tref>IRI</tref>s may be represented as an <tref>absolute IRI</tref>, a <tref>term</tref>,
a <tref>compact IRI</tref>, or as a value relative to <code>@vocab</code>.</p>
<p>An <tdef>absolute IRI</tdef> is defined in [[!RFC3987]] containing a <em>scheme</em> along with
<em>path</em> and optional <em>query</em> and fragment segments. A <tdef>relative IRI</tdef> is an IRI
that is relative some other <tref>absolute IRI</tref>; in the case of JSON-LD this is the base location
Expand All @@ -1290,14 +1293,12 @@ <h2>IRI Expansion</h2>
<em>authority</em> (as defined in [[!RFC3986]]), generate an <tref>IRI</tref>
by prepending the mapped prefix to the (possibly empty) suffix using textual concatenation. Note that an empty
suffix and no suffix (meaning the value contains no ':' string at all) are treated equivalently.</li>
<li>Otherwise, if the IRI being processed does not contain a colon and is a property, i.e., a key's value in
a <tref>JSON object</tref>, or the value of <code>@type</code> and the active context has a
<code>@vocab</code> mapping, join the mapped value to the suffix using textual concatenation.</li>
<li>Otherwise, use the value directly as an IRI.</li>
</ol>
</p>
<p class="note">
Previous versions of this specification used <code>@base</code> and <code>@vocab</code> to define IRI prefixes
used to resolve <tref title="relative IRI">relative IRIs</tref>. It was determined that this added too much complexity, but the issue
can be re-examined in the future based on community input.
</p>
</section>

<section>
Expand Down Expand Up @@ -1359,7 +1360,10 @@ <h3>IRI Compaction Algorithm</h3>
<tref>term</tref> associated with the partially
matched IRI in the <tref>active context</tref> concatenated with a
colon (:) character and the unmatched part of <em>iri</em>.</li>
<li>If <em>terms</em> is empty, return <em>iri</em>.</li>
<li>If <em>terms</em> is empty, the <tref>IRI</tref> being processed is a property or the
value of <code>@type</code> and <code>@vocab</code> is not null and matches the beginning
of <em>iri</em>, return the unmatched portion of <em>iri</em>. Otherwise return
<em>iri</em>.</li>
<li>Otherwise, return the shortest and lexicographically least value in <em>terms</em>.</li>
</ol>
</p>
Expand Down
33 changes: 30 additions & 3 deletions spec/latest/json-ld-syntax/index.html
Expand Up @@ -594,6 +594,9 @@ <h2>Syntax Tokens and Keywords</h2>
<dt><code>@set</code></dt>
<dd>Used to express an unordered set of data.
This keyword is described in the section titled <a href="#sets-and-lists"></a>.</dd>
<dt><code>@vocab</code></dt>
<dd>Used to set the base <tref>IRI</tref> for all property IRIs affected by the
<tref>active context</tref>. This keyword is described in section <a href="#iris"></a>.</dd>
<dt><code>:</code></dt>
<dd>The separator for JSON keys and values that use
<tref title="compact_iri">compact IRIs</tref>.</dd>
Expand Down Expand Up @@ -823,15 +826,16 @@ <h2>IRIs</h2>

<ol>
<li>Except within a <tref>context</tref> definition, <tref>term</tref>s in the key position in
a <tref>JSON object</tref> that have a mapping to an <tref>absolute IRI</tref> or another <tref>term</tref> in the
<tref>active context</tref> are expanded to an IRI by JSON-LD processors.</li>
a <tref>JSON object</tref> that have a mapping or a vocabulary base <tref>IRI</tref> in the
<tref>active context</tref> are expanded to an <tref>IRI</tref> by JSON-LD processors.</li>
<li>An <tref>IRI</tref> is generated for the <tref>string</tref> value specified using
<code>@id</code> or <code>@type</code>.</li>
<li>An <tref>IRI</tref> is generated for the <tref>string</tref> value of any key for which there
are <tref>coercion</tref> rules in effect that identify the value as an <code>@id</code>.</li>
</ol>

<p>IRIs may be represented as an <tref>absolute IRI</tref>, a <tref>relative IRI</tref>, a <tref>term</tref>, or a <tref>compact IRI</tref>.</p>
<p>IRIs may be represented as an <tref>absolute IRI</tref>, a <tref>relative IRI</tref>, a <tref>term</tref>,
a <tref>compact IRI</tref>, or as a value relative to <code>@vocab</code>.</p>

<p>An <tdef>absolute IRI</tdef> is defined in [[!RFC3987]] containing a <em>scheme</em> along with
<em>path</em> and optional <em>query</em> and <em>fragment</em> segments. A <tdef>relative IRI</tdef> is an IRI
Expand Down Expand Up @@ -906,6 +910,29 @@ <h2>IRIs</h2>
<p><code>foaf:name</code> above will automatically expand out to the IRI
<code>http://xmlns.com/foaf/0.1/name</code>. See <a href="#compact-iris"></a> for more details.</p>

<p>If the <code>@vocab</code> is set, all keys that do not match a <tref>term</tref> or a <tref>prefix</tref>
are


It is often common that all types and properties come from the same vocabulary. JSON-LD's
<code>@vocab</code> keyword allows to set a base <tref>IRI</tref> to be used for all properties and types
that that do not match a <tref>term</tref>, a <tref>prefix</tref>, or an <tref>absolute IRI</tref>
(i.e., do not contain a colon). The <code>@vocab</code> mapping MUST have a value of a simple string with the
lexical form of an absolute IRI.</p>

<pre class="example" data-transform="updateExample"
title="Vocabulary base IRI">
<!--
{
****"@context": {
"@vocab": "http://xmlns.com/foaf/1.0/"
},****
"@type": ****"Person"****,
****"name"****: "Manu Sporny",
}
-->
</pre>

<p>An <tref>IRI</tref> is generated when a JSON object is used in the
value position that contains an <code>@id</code> keyword:</p>

Expand Down
13 changes: 13 additions & 0 deletions test-suite/tests/expand-0028-in.jsonld
@@ -0,0 +1,13 @@
{
"@context": {
"@vocab": "http://example.org/vocab#",
"date": { "@type": "dateTime" }
},
"@id": "example1",
"@type": "test",
"date": "2011-01-25T00:00:00Z",
"embed": {
"@id": "example2",
"expandedDate": { "@value": "2012-08-01T00:00:00Z", "@type": "dateTime" }
}
}
23 changes: 23 additions & 0 deletions test-suite/tests/expand-0028-out.jsonld
@@ -0,0 +1,23 @@
[
{
"@id": "example1",
"@type": "http://example.org/vocab#test",
"http://example.org/vocab#date": [
{
"@value": "2011-01-25T00:00:00Z",
"@type": "http://example.org/vocab#dateTime"
}
],
"http://example.org/vocab#embed": [
{
"@id": "example2",
"http://example.org/vocab#expandedDate": [
{
"@value": "2012-08-01T00:00:00Z",
"@type": "http://example.org/vocab#dateTime"
}
]
}
]
}
]

0 comments on commit a2b449d

Please sign in to comment.