Skip to content

Commit

Permalink
Clarify compact IRIs and add two test cases
Browse files Browse the repository at this point in the history
This addresses #224.
  • Loading branch information
lanthaler committed Mar 12, 2013
1 parent aa43ac1 commit 1d20718
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 60 deletions.
96 changes: 36 additions & 60 deletions spec/latest/json-ld-syntax/index.html
Expand Up @@ -861,24 +861,18 @@ <h2>Default Vocabulary</h2>
<h2>Compact IRIs</h2>

<p>A <tdef>compact IRI</tdef> is a way of expressing an <tref>IRI</tref>
using a <em>prefix</em> and <em>suffix</em> separated by a colon (<code>:</code>) which is
similar to the <cite><a href="http://www.w3.org/TR/rdfa-core/#s_curies">CURIE Syntax</a></cite>
in [[RDFA-CORE]]. The <tdef>prefix</tdef> is a <tref>term</tref> taken from the
using a <em>prefix</em> and <em>suffix</em> separated by a colon (<code>:</code>).
The <tdef>prefix</tdef> is a <tref>term</tref> taken from the
<tref>active context</tref> and is a short string identifying a
particular <tref>IRI</tref> in a JSON-LD document.
For example, the prefix <code>foaf</code> may be used as a short
hand for the Friend-of-a-Friend vocabulary, which is identified using
the IRI <code>http://xmlns.com/foaf/0.1/</code>. A developer may append
particular <tref>IRI</tref> in a JSON-LD document. For example, the
prefix <code>foaf</code> may be used as a short hand for the
Friend-of-a-Friend vocabulary, which is identified using the <tref>IRI</tref>
<code>http://xmlns.com/foaf/0.1/</code>. A developer may append
any of the FOAF vocabulary terms to the end of the prefix to specify a short-hand
version of the <tref>absolute IRI</tref> for the vocabulary term. For example,
<code>foaf:name</code> would be expanded out to the IRI
<code>foaf:name</code> would be expanded to the IRI
<code>http://xmlns.com/foaf/0.1/name</code>.</p>

<p><tref title="prefix">Prefixes</tref> are expanded when the form of the value
is a <tref>compact IRI</tref> represented as a <code>prefix:suffix</code>
combination, and the prefix matches a <tref>term</tref> defined within the
<tref>active context</tref>:</p>

<pre class="example" data-transform="updateExample"
title="Prefix expansion">
<!--
Expand All @@ -888,70 +882,52 @@ <h2>Compact IRIs</h2>
"****foaf****": "****http://xmlns.com/foaf/0.1/****"
...
},
"@type": "****foaf:Person****"
"****foaf:name****": "Dave Longley",
...
}
-->
</pre>

<p><code>foaf:name</code> above will automatically expand out to the IRI
<code>http://xmlns.com/foaf/0.1/name</code>.</p>
<p>In the example above, <code>foaf:name</code> expands to the <tref>IRI</tref>
<code>http://xmlns.com/foaf/0.1/name</code> and <code>foaf:Person</code> expands
to <code>http://xmlns.com/foaf/0.1/Person</code>.</p>

<p>Terms are interpreted as <tref title="compact iri">compact IRIs</tref> if they contain at least one
colon and the first colon is not followed by two slashes (<code>//</code>, as in
<code>http://example.com</code>). To generate the full <tref>IRI</tref>,
the value is first split into a <em>prefix</em> and <em>suffix</em> at the first
occurrence of a colon (<code>:</code>). If the <tref>active context</tref>
contains a term mapping for <em>prefix</em>, an IRI is generated by
prepending the mapped <em>prefix</em> to the (possibly empty) <em>suffix</em>
using textual concatenation. If no prefix mapping is defined, the value is interpreted
as an <tref>absolute IRI</tref>. If the prefix is an underscore
(<code>_</code>), the IRI remains unchanged.</p>
<p>Consider the following example:</p>
<p><tref title="prefix">Prefixes</tref> are expanded when the form of the value
is a <tref>compact IRI</tref> represented as a <code>prefix:suffix</code>
combination, the <em>prefix</em> matches a <tref>term</tref> defined within the
<tref>active context</tref>, and the <em>suffix</em> does not begin with two
slashes&nbsp;(<code>//</code>). The <tref>compact IRI</tref> is expanded by
concatenating the <tref>IRI</tref> mapped to the <em>prefix</em> to the (possibly empty)
<em>suffix</em>. If the <em>prefix</em> is not defined in the <tref>active context</tref>,
or the suffix begins with two slashes (such as in <code>http://example.com</code>),
the value is interpreted as <tref>absolute IRI</tref> instead. If the prefix is an
underscore (<code>_</code>), the value is interpreted as <tref>blank node identifier</tref>
instead.</p>


<p>It's also possible to use compact IRIs within the context as shown in the
following example:</p>

<pre class="example" data-transform="updateExample"
title="Compact IRIs">
title="Using vocabularies">
<!--
{
"@context":
{
****"dc": "http://purl.org/dc/elements/1.1/",****
****"ex": "http://example.org/vocab#"****
"xsd": "http://www.w3.org/2001/XMLSchema#",
****"foaf": "http://xmlns.com/foaf/0.1/"****,
****"foaf:homepage"****: { "@type": "@id" },
"picture": { "@id": ****"foaf:depiction"****, "@type": "@id" }
},
"@id": "http://example.org/library/the-republic",
"@type": ****"ex:Book"****,
****"dc:creator"****: "Plato",
****"dc:title"****: "The Republic"
"@id": "http://me.markus-lanthaler.com/",
"@type": "foaf:Person",
"foaf:name": "Markus Lanthaler",
"foaf:homepage": "http://www.markus-lanthaler.com/",
"picture": "http://twitter.com/account/profile_image/markuslanthaler"
}
-->
</pre>

<p>In this example, two different vocabularies are referred to using prefixes.
Those prefixes are then used as type and property values using the compact
IRI <code>prefix:suffix</code> notation.</p>

<p>It's also possible to use compact IRIs within the context as shown in the
following example:</p>

<pre class="example" data-transform="updateExample"
title="Using vocabularies">
<!--
{
"@context":
{
"xsd": "http://www.w3.org/2001/XMLSchema#",
****"foaf": "http://xmlns.com/foaf/0.1/"****,
****"foaf:homepage"****: { "@type": "@id" },
"picture": { "@id": ****"foaf:depiction"****, "@type": "@id" }
},
"@id": "http://me.markus-lanthaler.com/",
"@type": "foaf:Person",
"foaf:name": "Markus Lanthaler",
"foaf:homepage": "http://www.markus-lanthaler.com/",
"picture": "http://twitter.com/account/profile_image/markuslanthaler"
}
-->
</pre>
</section>

<section>
Expand Down
8 changes: 8 additions & 0 deletions test-suite/tests/expand-0067-in.jsonld
@@ -0,0 +1,8 @@
{
"@context": {
"http": "http://example.com/this-prefix-would-overwrite-all-http-iris"
},
"@id": "http://example.org/node1",
"@type": "http://example.org/type",
"http://example.org/property": "all these IRIs remain unchanged because they are interpreted as absolute IRIs"
}
9 changes: 9 additions & 0 deletions test-suite/tests/expand-0067-out.jsonld
@@ -0,0 +1,9 @@
[
{
"@id": "http://example.org/node1",
"@type": ["http://example.org/type"],
"http://example.org/property": [
{ "@value": "all these IRIs remain unchanged because they are interpreted as absolute IRIs" }
]
}
]
8 changes: 8 additions & 0 deletions test-suite/tests/expand-0068-in.jsonld
@@ -0,0 +1,8 @@
{
"@context": {
"_": "http://example.com/this-prefix-would-overwrite-all-blank-node-identifiers"
},
"@id": "_:node1",
"@type": "_:type",
"_:property": "all these IRIs remain unchanged because they are interpreted as blank node identifiers"
}
9 changes: 9 additions & 0 deletions test-suite/tests/expand-0068-out.jsonld
@@ -0,0 +1,9 @@
[
{
"@id": "_:b0",
"@type": ["_:b1"],
"_:b2": [
{ "@value": "all these IRIs remain unchanged because they are interpreted as blank node identifiers" }
]
}
]
10 changes: 10 additions & 0 deletions test-suite/tests/expand-manifest.jsonld
Expand Up @@ -338,6 +338,16 @@
"name": "Use @vocab to expand keys in reverse-maps",
"input": "expand-0066-in.jsonld",
"expect": "expand-0066-out.jsonld"
}, {
"@type": ["test:TestCase", "jld:ExpandTest"],
"name": "prefix:suffix values are not interpreted as compact IRIs if suffix begins with two slashes",
"input": "expand-0067-in.jsonld",
"expect": "expand-0067-out.jsonld"
}, {
"@type": ["test:TestCase", "jld:ExpandTest"],
"name": "prefix:suffix values are not interpreted as compact IRIs if prefix is an underscore",
"input": "expand-0068-in.jsonld",
"expect": "expand-0068-out.jsonld"
}
]
}

0 comments on commit 1d20718

Please sign in to comment.