Reintroduce @vocab
authorMarkus Lanthaler <mark_lanthaler@gmx.net>
Wed, 01 Aug 2012 17:17:34 +0200
changeset 793 914d30452b7a
parent 792 7122a0f509d7
child 794 de6219d3233e
Reintroduce @vocab

This closes #26.
spec/latest/json-ld-api/index.html
spec/latest/json-ld-syntax/index.html
test-suite/tests/expand-0028-in.jsonld
test-suite/tests/expand-0028-out.jsonld
test-suite/tests/expand-manifest.jsonld
--- a/spec/latest/json-ld-api/index.html	Wed Aug 01 15:59:44 2012 +0200
+++ b/spec/latest/json-ld-api/index.html	Wed Aug 01 17:17:34 2012 +0200
@@ -1203,6 +1203,8 @@
           <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
@@ -1272,7 +1274,8 @@
   <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
@@ -1290,14 +1293,12 @@
         <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>
@@ -1359,7 +1360,10 @@
         <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>
--- a/spec/latest/json-ld-syntax/index.html	Wed Aug 01 15:59:44 2012 +0200
+++ b/spec/latest/json-ld-syntax/index.html	Wed Aug 01 17:17:34 2012 +0200
@@ -594,6 +594,9 @@
   <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>
@@ -823,15 +826,16 @@
 
 <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
@@ -906,6 +910,29 @@
 <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>
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-suite/tests/expand-0028-in.jsonld	Wed Aug 01 17:17:34 2012 +0200
@@ -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" }
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-suite/tests/expand-0028-out.jsonld	Wed Aug 01 17:17:34 2012 +0200
@@ -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"
+          }
+        ]
+      }
+    ]
+  }
+]
--- a/test-suite/tests/expand-manifest.jsonld	Wed Aug 01 15:59:44 2012 +0200
+++ b/test-suite/tests/expand-manifest.jsonld	Wed Aug 01 17:17:34 2012 +0200
@@ -4,140 +4,147 @@
   "@type": "jld:Manifest",
   "rdfs:comment": "JSON-LD to Expansion tests use object compare",
   "name": "expand",
-  "sequence": [{
-    "@type": ["test:TestCase", "jld:ExpandTest"],
-    "name": "id",
-    "input": "expand-0001-in.jsonld",
-    "expect": "expand-0001-out.jsonld"
-  }, {
-    "@type": ["test:TestCase", "jld:ExpandTest"],
-    "name": "basic",
-    "input": "expand-0002-in.jsonld",
-    "expect": "expand-0002-out.jsonld"
-  }, {
-    "@type": ["test:TestCase", "jld:ExpandTest"],
-    "name": "drop null and unmapped properties",
-    "input": "expand-0003-in.jsonld",
-    "expect": "expand-0003-out.jsonld"
-  }, {
-    "@type": ["test:TestCase", "jld:ExpandTest"],
-    "name": "optimize @set, keep empty arrays",
-    "input": "expand-0004-in.jsonld",
-    "expect": "expand-0004-out.jsonld"
-  }, {
-    "@type": ["test:TestCase", "jld:ExpandTest"],
-    "name": "do not expand aliased @id/@type",
-    "input": "expand-0005-in.jsonld",
-    "expect": "expand-0005-out.jsonld"
-  }, {
-    "@type": ["test:TestCase", "jld:ExpandTest"],
-    "name": "alias keywords",
-    "input": "expand-0006-in.jsonld",
-    "expect": "expand-0006-out.jsonld"
-  }, {
-    "@type": ["test:TestCase", "jld:ExpandTest"],
-    "name": "date type-coercion",
-    "input": "expand-0007-in.jsonld",
-    "expect": "expand-0007-out.jsonld"
-  }, {
-    "@type": ["test:TestCase", "jld:ExpandTest"],
-    "name": "@value with @language",
-    "input": "expand-0008-in.jsonld",
-    "expect": "expand-0008-out.jsonld"
-  }, {
-    "@type": ["test:TestCase", "jld:ExpandTest"],
-    "name": "@graph with terms",
-    "input": "expand-0009-in.jsonld",
-    "expect": "expand-0009-out.jsonld"
-  }, {
-    "@type": ["test:TestCase", "jld:ExpandTest"],
-    "name": "native types",
-    "input": "expand-0010-in.jsonld",
-    "expect": "expand-0010-out.jsonld"
-  }, {
-    "@type": ["test:TestCase", "jld:ExpandTest"],
-    "name": "coerced @id",
-    "input": "expand-0011-in.jsonld",
-    "expect": "expand-0011-out.jsonld"
-  }, {
-    "@type": ["test:TestCase", "jld:ExpandTest"],
-    "name": "@graph with embed",
-    "input": "expand-0012-in.jsonld",
-    "expect": "expand-0012-out.jsonld"
-  }, {
-    "@type": ["test:TestCase", "jld:ExpandTest"],
-    "name": "expand already expanded",
-    "input": "expand-0013-in.jsonld",
-    "expect": "expand-0013-out.jsonld"
-  }, {
-    "@type": ["test:TestCase", "jld:ExpandTest"],
-    "name": "@set of @value objects with keyword aliases",
-    "input": "expand-0014-in.jsonld",
-    "expect": "expand-0014-out.jsonld"
-  }, {
-    "@type": ["test:TestCase", "jld:ExpandTest"],
-    "name": "collapse set of sets, keep empty lists",
-    "input": "expand-0015-in.jsonld",
-    "expect": "expand-0015-out.jsonld"
-  }, {
-    "@type": ["test:TestCase", "jld:ExpandTest"],
-    "name": "context reset",
-    "input": "expand-0016-in.jsonld",
-    "expect": "expand-0016-out.jsonld"
-  }, {
-    "@type": ["test:TestCase", "jld:ExpandTest"],
-    "name": "@graph and @id aliased",
-    "input": "expand-0017-in.jsonld",
-    "expect": "expand-0017-out.jsonld"
-  }, {
-    "@type": ["test:TestCase", "jld:ExpandTest"],
-    "name": "override default @language in terms",
-    "input": "expand-0018-in.jsonld",
-    "expect": "expand-0018-out.jsonld"
-  }, {
-    "@type": ["test:TestCase", "jld:ExpandTest"],
-    "name": "remove @value = null",
-    "input": "expand-0019-in.jsonld",
-    "expect": "expand-0019-out.jsonld"
-  }, {
-    "@type": ["test:TestCase", "jld:ExpandTest"],
-    "name": "do not remove @graph if not at top-level",
-    "input": "expand-0020-in.jsonld",
-    "expect": "expand-0020-out.jsonld"
-  }, {
-    "@type": ["test:TestCase", "jld:ExpandTest"],
-    "name": "do not remove @graph at top-level if not only property",
-    "input": "expand-0021-in.jsonld",
-    "expect": "expand-0021-out.jsonld"
-  }, {
-    "@type": ["test:TestCase", "jld:ExpandTest"],
-    "name": "expand value with default language",
-    "input": "expand-0022-in.jsonld",
-    "expect": "expand-0022-out.jsonld"
-  }, {
-    "@type": ["test:TestCase", "jld:ExpandTest"],
-    "name": "Expanding lists and sets with properties having coercion coerces list/set values",
-    "input": "expand-0023-in.jsonld",
-    "expect": "expand-0023-out.jsonld"
-  }, {
-    "@type": ["test:TestCase", "jld:ExpandTest"],
-    "name": "Multiple contexts",
-    "input": "expand-0024-in.jsonld",
-    "expect": "expand-0024-out.jsonld"
-  }, {
-    "@type": ["test:TestCase", "jld:ExpandTest"],
-    "name": "Problematic IRI expansion tests",
-    "input": "expand-0025-in.jsonld",
-    "expect": "expand-0025-out.jsonld"
-  }, {
-    "@type": ["test:TestCase", "jld:ExpandTest"],
-    "name": "Expanding term mapping to @type uses @type syntax",
-    "input": "expand-0026-in.jsonld",
-    "expect": "expand-0026-out.jsonld"
-  }, {
-    "@type": ["test:TestCase", "jld:ExpandTest"],
-    "name": "Keep duplicate values in @list and @set",
-    "input": "expand-0027-in.jsonld",
-    "expect": "expand-0027-out.jsonld"
-  }]
+  "sequence": [
+    {
+      "@type": ["test:TestCase", "jld:ExpandTest"],
+      "name": "id",
+      "input": "expand-0001-in.jsonld",
+      "expect": "expand-0001-out.jsonld"
+    }, {
+      "@type": ["test:TestCase", "jld:ExpandTest"],
+      "name": "basic",
+      "input": "expand-0002-in.jsonld",
+      "expect": "expand-0002-out.jsonld"
+    }, {
+      "@type": ["test:TestCase", "jld:ExpandTest"],
+      "name": "drop null and unmapped properties",
+      "input": "expand-0003-in.jsonld",
+      "expect": "expand-0003-out.jsonld"
+    }, {
+      "@type": ["test:TestCase", "jld:ExpandTest"],
+      "name": "optimize @set, keep empty arrays",
+      "input": "expand-0004-in.jsonld",
+      "expect": "expand-0004-out.jsonld"
+    }, {
+      "@type": ["test:TestCase", "jld:ExpandTest"],
+      "name": "do not expand aliased @id/@type",
+      "input": "expand-0005-in.jsonld",
+      "expect": "expand-0005-out.jsonld"
+    }, {
+      "@type": ["test:TestCase", "jld:ExpandTest"],
+      "name": "alias keywords",
+      "input": "expand-0006-in.jsonld",
+      "expect": "expand-0006-out.jsonld"
+    }, {
+      "@type": ["test:TestCase", "jld:ExpandTest"],
+      "name": "date type-coercion",
+      "input": "expand-0007-in.jsonld",
+      "expect": "expand-0007-out.jsonld"
+    }, {
+      "@type": ["test:TestCase", "jld:ExpandTest"],
+      "name": "@value with @language",
+      "input": "expand-0008-in.jsonld",
+      "expect": "expand-0008-out.jsonld"
+    }, {
+      "@type": ["test:TestCase", "jld:ExpandTest"],
+      "name": "@graph with terms",
+      "input": "expand-0009-in.jsonld",
+      "expect": "expand-0009-out.jsonld"
+    }, {
+      "@type": ["test:TestCase", "jld:ExpandTest"],
+      "name": "native types",
+      "input": "expand-0010-in.jsonld",
+      "expect": "expand-0010-out.jsonld"
+    }, {
+      "@type": ["test:TestCase", "jld:ExpandTest"],
+      "name": "coerced @id",
+      "input": "expand-0011-in.jsonld",
+      "expect": "expand-0011-out.jsonld"
+    }, {
+      "@type": ["test:TestCase", "jld:ExpandTest"],
+      "name": "@graph with embed",
+      "input": "expand-0012-in.jsonld",
+      "expect": "expand-0012-out.jsonld"
+    }, {
+      "@type": ["test:TestCase", "jld:ExpandTest"],
+      "name": "expand already expanded",
+      "input": "expand-0013-in.jsonld",
+      "expect": "expand-0013-out.jsonld"
+    }, {
+      "@type": ["test:TestCase", "jld:ExpandTest"],
+      "name": "@set of @value objects with keyword aliases",
+      "input": "expand-0014-in.jsonld",
+      "expect": "expand-0014-out.jsonld"
+    }, {
+      "@type": ["test:TestCase", "jld:ExpandTest"],
+      "name": "collapse set of sets, keep empty lists",
+      "input": "expand-0015-in.jsonld",
+      "expect": "expand-0015-out.jsonld"
+    }, {
+      "@type": ["test:TestCase", "jld:ExpandTest"],
+      "name": "context reset",
+      "input": "expand-0016-in.jsonld",
+      "expect": "expand-0016-out.jsonld"
+    }, {
+      "@type": ["test:TestCase", "jld:ExpandTest"],
+      "name": "@graph and @id aliased",
+      "input": "expand-0017-in.jsonld",
+      "expect": "expand-0017-out.jsonld"
+    }, {
+      "@type": ["test:TestCase", "jld:ExpandTest"],
+      "name": "override default @language in terms",
+      "input": "expand-0018-in.jsonld",
+      "expect": "expand-0018-out.jsonld"
+    }, {
+      "@type": ["test:TestCase", "jld:ExpandTest"],
+      "name": "remove @value = null",
+      "input": "expand-0019-in.jsonld",
+      "expect": "expand-0019-out.jsonld"
+    }, {
+      "@type": ["test:TestCase", "jld:ExpandTest"],
+      "name": "do not remove @graph if not at top-level",
+      "input": "expand-0020-in.jsonld",
+      "expect": "expand-0020-out.jsonld"
+    }, {
+      "@type": ["test:TestCase", "jld:ExpandTest"],
+      "name": "do not remove @graph at top-level if not only property",
+      "input": "expand-0021-in.jsonld",
+      "expect": "expand-0021-out.jsonld"
+    }, {
+      "@type": ["test:TestCase", "jld:ExpandTest"],
+      "name": "expand value with default language",
+      "input": "expand-0022-in.jsonld",
+      "expect": "expand-0022-out.jsonld"
+    }, {
+      "@type": ["test:TestCase", "jld:ExpandTest"],
+      "name": "Expanding lists and sets with properties having coercion coerces list/set values",
+      "input": "expand-0023-in.jsonld",
+      "expect": "expand-0023-out.jsonld"
+    }, {
+      "@type": ["test:TestCase", "jld:ExpandTest"],
+      "name": "Multiple contexts",
+      "input": "expand-0024-in.jsonld",
+      "expect": "expand-0024-out.jsonld"
+    }, {
+      "@type": ["test:TestCase", "jld:ExpandTest"],
+      "name": "Problematic IRI expansion tests",
+      "input": "expand-0025-in.jsonld",
+      "expect": "expand-0025-out.jsonld"
+    }, {
+      "@type": ["test:TestCase", "jld:ExpandTest"],
+      "name": "Expanding term mapping to @type uses @type syntax",
+      "input": "expand-0026-in.jsonld",
+      "expect": "expand-0026-out.jsonld"
+    }, {
+      "@type": ["test:TestCase", "jld:ExpandTest"],
+      "name": "Keep duplicate values in @list and @set",
+      "input": "expand-0027-in.jsonld",
+      "expect": "expand-0027-out.jsonld"
+    }, {
+      "@type": ["test:TestCase", "jld:ExpandTest"],
+      "name": "Use @vocab in properties and @type but not in @id",
+      "input": "expand-0028-in.jsonld",
+      "expect": "expand-0028-out.jsonld"
+    }
+  ]
 }