Transform IRIs in @id to relative IRIs, ignore terms in @id
authorMarkus Lanthaler <mark_lanthaler@gmx.net>
Mon, 14 Jan 2013 16:25:32 +0100
changeset 1123 0c02337eb90e
parent 1122 31c3dc321d1c
child 1124 00f23c6269b6
Transform IRIs in @id to relative IRIs, ignore terms in @id

This addresses #204
spec/latest/json-ld-api/index.html
test-suite/tests/compact-0002-context.jsonld
test-suite/tests/compact-0002-out.jsonld
test-suite/tests/compact-0015-context.jsonld
test-suite/tests/compact-0015-out.jsonld
test-suite/tests/compact-0018-context.jsonld
test-suite/tests/compact-0018-out.jsonld
test-suite/tests/compact-0024-context.jsonld
test-suite/tests/compact-0024-out.jsonld
test-suite/tests/compact-0046-context.jsonld
test-suite/tests/compact-0046-in.jsonld
test-suite/tests/compact-0046-out.jsonld
test-suite/tests/compact-manifest.jsonld
test-suite/tests/expand-0002-in.jsonld
test-suite/tests/expand-0025-in.jsonld
test-suite/tests/expand-0025-out.jsonld
test-suite/tests/expand-0038-in.jsonld
test-suite/tests/expand-0048-in.jsonld
test-suite/tests/expand-0048-out.jsonld
test-suite/tests/expand-manifest.jsonld
test-suite/tests/flatten-0002-in.jsonld
test-suite/tests/flatten-0025-in.jsonld
test-suite/tests/flatten-0025-out.jsonld
test-suite/tests/flatten-0038-in.jsonld
--- a/spec/latest/json-ld-api/index.html	Mon Jan 14 11:01:58 2013 +0100
+++ b/spec/latest/json-ld-api/index.html	Mon Jan 14 16:25:32 2013 +0100
@@ -1133,9 +1133,9 @@
           <code class="error">property generator in term definition</code> error.</li>
       </ol>
     </li>
-    <li>If an <tref>IRI mapping</tref> exists for <em>value</em> in the <tref>active context</tref>
-      that is not a <tref>property generator</tref> return the value of the
-      <tref>IRI mapping</tref>.</li>
+    <li>If the <em>vocabRelative</em> flag is set to <code>true</code> and an <tref>IRI mapping</tref>
+      exists for <em>value</em> in the <tref>active context</tref> that is not a
+      <tref>property generator</tref>, return the value of the <tref>IRI mapping</tref>.</li>
     <li>If <em>value</em> contains a colon (<code>:</code>), perform the following steps:
       <ol class="algorithm">
         <li>Split <em>value</em> into a <em>prefix</em> and <em>suffix</em> at the first occurrence of
@@ -1415,8 +1415,8 @@
 
   <ol class="algorithm">
     <li>Initialize a variable <em>result</em> to <tref>null</tref>.</li>
-    <li>If an entry for <em>iri</em> exists in the <tref>inverse context</tref>,
-      perform the following steps:
+    <li>If the <em>vocabRelative</em> flag is set to <code>true</code> and an entry for
+      <em>iri</em> exists in the <tref>inverse context</tref>, perform the following steps:
       <ol class="algorithm">
         <li>If a <em>value</em> has been passed, perform the following steps:
           <ol class="algorithm">
@@ -1506,15 +1506,18 @@
           <em>termIri</em>, generate a <tref>compact IRI</tref> by concatenating the value
           of the <code>term</code> member of <em>termDefinition</em> with a colon
           (<code>:</code>) character and the unmatched part of <em>iri</em>.</li>
-        <li>If the resulting <tref>compact IRI</tref> has an entry in the <tref>active context</tref>,
-          continue with the next <em>termIri</em>-<em>termDefinition</em> pair from
-          <tref>inverse context</tref> as the <tref>compact IRI</tref> cannot be used.</li>
+        <li>If the resulting <tref>compact IRI</tref> has an entry in the <tref>active context</tref>
+          and the <em>vocabRelative</em> flag is set to <code>true</code> or the <tref>IRI mapping</tref>
+          does not correspond to <em>iri</em>, continue with the next <em>termIri</em>-<em>termDefinition</em>
+          pair from <tref>inverse context</tref> as the <tref>compact IRI</tref> cannot be used.</li>
         <li>Otherwise, if result is <tref>null</tref>, return the <tref>compact IRI</tref>; if it is
           not null, set the <code>term</code> member of <em>result</em> to the <tref>compact IRI</tref>
           and return <em>result</em>.</li>
       </ol>
     </li>
-    <li>If the <em>vocabRelative</em> flag is set to <code>true</code>, the
+    <li>If the <em>vocabRelative</em> flag is set to <code>false</code>, transform <em>iri</em> to an
+      IRI relative to the base IRI and return it.</li>
+    <li>Otherwise, if the <em>vocabRelative</em> flag is set to <code>true</code>, the
       <tref>active context</tref> has a <tref>vocabulary mapping</tref>, and <em>iri</em>
       begins with the IRI of the <tref>vocabulary mapping</tref> but is longer
       <ol class="algorithm">
--- a/test-suite/tests/compact-0002-context.jsonld	Mon Jan 14 11:01:58 2013 +0100
+++ b/test-suite/tests/compact-0002-context.jsonld	Mon Jan 14 16:25:32 2013 +0100
@@ -1,6 +1,5 @@
 {
   "@context": {
-    "id1": "http://example.com/id1",
     "t1": "http://example.com/t1",
     "t2": "http://example.com/t2",
     "term1": "http://example.com/term1",
@@ -9,4 +8,4 @@
     "term4": "http://example.com/term4",
     "term5": "http://example.com/term5"
   }
-}
\ No newline at end of file
+}
--- a/test-suite/tests/compact-0002-out.jsonld	Mon Jan 14 11:01:58 2013 +0100
+++ b/test-suite/tests/compact-0002-out.jsonld	Mon Jan 14 16:25:32 2013 +0100
@@ -1,6 +1,5 @@
 {
   "@context": {
-    "id1": "http://example.com/id1",
     "t1": "http://example.com/t1",
     "t2": "http://example.com/t2",
     "term1": "http://example.com/term1",
@@ -9,11 +8,11 @@
     "term4": "http://example.com/term4",
     "term5": "http://example.com/term5"
   },
-  "@id": "id1",
+  "@id": "http://example.com/id1",
   "@type": "t1",
   "term1": "v1",
   "term2": {"@value": "v2", "@type": "t2"},
   "term3": {"@value": "v3", "@language": "en"},
   "term4": 4,
   "term5": [50, 51]
-}
\ No newline at end of file
+}
--- a/test-suite/tests/compact-0015-context.jsonld	Mon Jan 14 11:01:58 2013 +0100
+++ b/test-suite/tests/compact-0015-context.jsonld	Mon Jan 14 16:25:32 2013 +0100
@@ -1,6 +1,5 @@
 {
   "@context": {
-    "id1": "http://example.com/id1",
     "t1": "http://example.com/t1",
     "t2": "http://example.com/t2",
     "term1": "http://example.com/term",
@@ -10,4 +9,4 @@
     "term5": {"@id": "http://example.com/term", "@language": null},
     "@language": "de"
   }
-}
\ No newline at end of file
+}
--- a/test-suite/tests/compact-0015-out.jsonld	Mon Jan 14 11:01:58 2013 +0100
+++ b/test-suite/tests/compact-0015-out.jsonld	Mon Jan 14 16:25:32 2013 +0100
@@ -1,6 +1,5 @@
 {
   "@context": {
-    "id1": "http://example.com/id1",
     "t1": "http://example.com/t1",
     "t2": "http://example.com/t2",
     "term1": "http://example.com/term",
@@ -10,7 +9,7 @@
     "term5": {"@id": "http://example.com/term", "@language": null},
     "@language": "de"
   },
-  "@id": "id1",
+  "@id": "http://example.com/id1",
   "@type": "t1",
   "term1": "v1",
   "term2": "v2",
--- a/test-suite/tests/compact-0018-context.jsonld	Mon Jan 14 11:01:58 2013 +0100
+++ b/test-suite/tests/compact-0018-context.jsonld	Mon Jan 14 16:25:32 2013 +0100
@@ -1,6 +1,5 @@
 {
   "@context": {
-    "id1": "http://example.com/id1",
     "type1": "http://example.com/t1",
     "type2": "http://example.com/t2",
     "@language": "de",
--- a/test-suite/tests/compact-0018-out.jsonld	Mon Jan 14 11:01:58 2013 +0100
+++ b/test-suite/tests/compact-0018-out.jsonld	Mon Jan 14 16:25:32 2013 +0100
@@ -1,6 +1,5 @@
 {
   "@context": {
-    "id1": "http://example.com/id1",
     "type1": "http://example.com/t1",
     "type2": "http://example.com/t2",
     "@language": "de",
@@ -11,7 +10,7 @@
     "term4": { "@id": "http://example.com/term", "@container": "@list", "@type": "type1" },
     "term5": { "@id": "http://example.com/term", "@container": "@list", "@type": "type2" }
   },
-  "@id": "id1",
+  "@id": "http://example.com/id1",
   "term": [
     "v0.1",
     { "@value": "v0.2", "@language": "en" },
--- a/test-suite/tests/compact-0024-context.jsonld	Mon Jan 14 11:01:58 2013 +0100
+++ b/test-suite/tests/compact-0024-context.jsonld	Mon Jan 14 16:25:32 2013 +0100
@@ -1,6 +1,5 @@
 {
   "@context": {
-    "id1": "http://example.com/id1",
     "type1": "http://example.com/t1",
     "type2": "http://example.com/t2",
     "@language": "de",
--- a/test-suite/tests/compact-0024-out.jsonld	Mon Jan 14 11:01:58 2013 +0100
+++ b/test-suite/tests/compact-0024-out.jsonld	Mon Jan 14 16:25:32 2013 +0100
@@ -1,6 +1,5 @@
 {
   "@context": {
-    "id1": "http://example.com/id1",
     "type1": "http://example.com/t1",
     "type2": "http://example.com/t2",
     "@language": "de",
@@ -13,7 +12,7 @@
     "termTL1": { "@id": "http://example.com/termType", "@container": "@list", "@type": "type1" },
     "termTL2": { "@id": "http://example.com/termType", "@container": "@list", "@type": "type2" }
   },
-  "@id": "id1",
+  "@id": "http://example.com/id1",
   "termLL0": [
     "termLL0.1",
     "termLL0.2"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-suite/tests/compact-0046-context.jsonld	Mon Jan 14 16:25:32 2013 +0100
@@ -0,0 +1,19 @@
+{
+  "@context": {
+    "term": "http://example.com/terms-are-not-considered-in-id",
+    "compact-iris": "http://example.com/compact-iris-",
+    "property": "http://example.com/property",
+    "@vocab": "http://example.org/vocab-is-not-considered-for-id"
+  },
+  "@id": "term",
+  "property": [
+    {
+      "@id": "compact-iris:are-considered",
+      "property": "@id supports the following values: relative, absolute, and compact IRIs"
+    },
+    {
+      "@id": "../parent-node",
+      "property": "relative IRIs get resolved against the document's base IRI"
+    }
+  ]
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-suite/tests/compact-0046-in.jsonld	Mon Jan 14 16:25:32 2013 +0100
@@ -0,0 +1,19 @@
+[
+  {
+    "@id": "http://json-ld.org/test-suite/tests/term",
+    "http://example.com/property": [
+      {
+        "@id": "http://example.com/compact-iris-are-considered",
+        "http://example.com/property": [
+          { "@value": "@id supports the following values: relative, absolute, and compact IRIs" }
+        ]
+      },
+      {
+        "@id": "http://json-ld.org/test-suite/parent-node",
+        "http://example.com/property": [
+          { "@value": "relative IRIs get resolved against the document's base IRI" }
+        ]
+      }
+    ]
+  }
+]
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-suite/tests/compact-0046-out.jsonld	Mon Jan 14 16:25:32 2013 +0100
@@ -0,0 +1,19 @@
+{
+  "@context": {
+    "term": "http://example.com/terms-are-not-considered-in-id",
+    "compact-iris": "http://example.com/compact-iris-",
+    "property": "http://example.com/property",
+    "@vocab": "http://example.org/vocab-is-not-considered-for-id"
+  },
+  "@id": "term",
+  "property": [
+    {
+      "@id": "compact-iris:are-considered",
+      "property": "@id supports the following values: relative, absolute, and compact IRIs"
+    },
+    {
+      "@id": "../parent-node",
+      "property": "relative IRIs get resolved against the document's base IRI"
+    }
+  ]
+}
--- a/test-suite/tests/compact-manifest.jsonld	Mon Jan 14 11:01:58 2013 +0100
+++ b/test-suite/tests/compact-manifest.jsonld	Mon Jan 14 16:25:32 2013 +0100
@@ -277,6 +277,12 @@
       "input": "compact-0045-in.jsonld",
       "context": "compact-0045-context.jsonld",
       "expect": "compact-0045-out.jsonld"
+    }, {
+      "@type": ["test:TestCase", "jld:CompactTest"],
+      "name": "Values of @id are transformed to relative IRIs, terms are ignored",
+      "input": "compact-0046-in.jsonld",
+      "context": "compact-0046-context.jsonld",
+      "expect": "compact-0046-out.jsonld"
     }
   ]
 }
--- a/test-suite/tests/expand-0002-in.jsonld	Mon Jan 14 11:01:58 2013 +0100
+++ b/test-suite/tests/expand-0002-in.jsonld	Mon Jan 14 16:25:32 2013 +0100
@@ -1,6 +1,5 @@
 {
   "@context": {
-    "id1": "http://example.com/id1",
     "t1": "http://example.com/t1",
     "t2": "http://example.com/t2",
     "term1": "http://example.com/term1",
@@ -9,11 +8,11 @@
     "term4": "http://example.com/term4",
     "term5": "http://example.com/term5"
   },
-  "@id": "id1",
+  "@id": "http://example.com/id1",
   "@type": "t1",
   "term1": "v1",
   "term2": {"@value": "v2", "@type": "t2"},
   "term3": {"@value": "v3", "@language": "en"},
   "term4": 4,
   "term5": [50, 51]
-}
\ No newline at end of file
+}
--- a/test-suite/tests/expand-0025-in.jsonld	Mon Jan 14 11:01:58 2013 +0100
+++ b/test-suite/tests/expand-0025-in.jsonld	Mon Jan 14 16:25:32 2013 +0100
@@ -5,6 +5,5 @@
     "bar": {"@id": "foo:bar", "@type": "@id"},
     "_": "http://example.com/underscore/"
   },
-  "@id": "_",
-  "bar": ["foo", "foo:bar"]
+  "@type": [ "foo", "foo:bar", "_" ]
 }
--- a/test-suite/tests/expand-0025-out.jsonld	Mon Jan 14 11:01:58 2013 +0100
+++ b/test-suite/tests/expand-0025-out.jsonld	Mon Jan 14 16:25:32 2013 +0100
@@ -1,7 +1,7 @@
 [{
-  "@id": "http://example.com/underscore/",
-  "http://example.com/bar": [
-    {"@id": "http://example.com/foo/"},
-    {"@id": "http://example.com/bar"}
+  "@type": [
+    "http://example.com/foo/",
+    "http://example.com/bar",
+    "http://example.com/underscore/"
   ]
-}]
\ No newline at end of file
+}]
--- a/test-suite/tests/expand-0038-in.jsonld	Mon Jan 14 11:01:58 2013 +0100
+++ b/test-suite/tests/expand-0038-in.jsonld	Mon Jan 14 16:25:32 2013 +0100
@@ -4,11 +4,11 @@
     "termId": { "@id": "term", "@type": "@id" },
     "termTyped": { "@id": "term", "@type": "_:term" }
   },
-  "@id": "term",
+  "@id": "_:term",
   "@type": "_:term",
   "term": [
     {
-      "@id": "term",
+      "@id": "_:term",
       "@type": "term",
       "termTyped": "typed value term"
     },
@@ -31,7 +31,7 @@
   ],
   "termId": [
     {
-      "@id": "term",
+      "@id": "_:term",
       "@type": "term",
       "termTyped": "typed value termId"
     },
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-suite/tests/expand-0048-in.jsonld	Mon Jan 14 16:25:32 2013 +0100
@@ -0,0 +1,19 @@
+{
+  "@context": {
+    "term": "http://example.com/terms-are-not-considered-in-id",
+    "compact-iris": "http://example.com/compact-iris-",
+    "property": "http://example.com/property",
+    "@vocab": "http://example.org/vocab-is-not-considered-for-id"
+  },
+  "@id": "term",
+  "property": [
+    {
+      "@id": "compact-iris:are-considered",
+      "property": "@id supports the following values: relative, absolute, and compact IRIs"
+    },
+    {
+      "@id": "../parent-node",
+      "property": "relative IRIs get resolved against the document's base IRI"
+    }
+  ]
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-suite/tests/expand-0048-out.jsonld	Mon Jan 14 16:25:32 2013 +0100
@@ -0,0 +1,19 @@
+[
+  {
+    "@id": "http://json-ld.org/test-suite/tests/term",
+    "http://example.com/property": [
+      {
+        "@id": "http://example.com/compact-iris-are-considered",
+        "http://example.com/property": [
+          { "@value": "@id supports the following values: relative, absolute, and compact IRIs" }
+        ]
+      },
+      {
+        "@id": "http://json-ld.org/test-suite/parent-node",
+        "http://example.com/property": [
+          { "@value": "relative IRIs get resolved against the document's base IRI" }
+        ]
+      }
+    ]
+  }
+]
--- a/test-suite/tests/expand-manifest.jsonld	Mon Jan 14 11:01:58 2013 +0100
+++ b/test-suite/tests/expand-manifest.jsonld	Mon Jan 14 16:25:32 2013 +0100
@@ -241,6 +241,11 @@
       "name": "Free-floating values in sets are removed, free-floating lists are kept",
       "input": "expand-0047-in.jsonld",
       "expect": "expand-0047-out.jsonld"
+    }, {
+      "@type": ["test:TestCase", "jld:ExpandTest"],
+      "name": "Terms are ignored in @id",
+      "input": "expand-0048-in.jsonld",
+      "expect": "expand-0048-out.jsonld"
     }
   ]
 }
--- a/test-suite/tests/flatten-0002-in.jsonld	Mon Jan 14 11:01:58 2013 +0100
+++ b/test-suite/tests/flatten-0002-in.jsonld	Mon Jan 14 16:25:32 2013 +0100
@@ -1,6 +1,5 @@
 {
   "@context": {
-    "id1": "http://example.com/id1",
     "t1": "http://example.com/t1",
     "t2": "http://example.com/t2",
     "term1": "http://example.com/term1",
@@ -9,11 +8,11 @@
     "term4": "http://example.com/term4",
     "term5": "http://example.com/term5"
   },
-  "@id": "id1",
+  "@id": "http://example.com/id1",
   "@type": "t1",
   "term1": "v1",
   "term2": {"@value": "v2", "@type": "t2"},
   "term3": {"@value": "v3", "@language": "en"},
   "term4": 4,
   "term5": [50, 51]
-}
\ No newline at end of file
+}
--- a/test-suite/tests/flatten-0025-in.jsonld	Mon Jan 14 11:01:58 2013 +0100
+++ b/test-suite/tests/flatten-0025-in.jsonld	Mon Jan 14 16:25:32 2013 +0100
@@ -5,6 +5,5 @@
     "bar": {"@id": "foo:bar", "@type": "@id"},
     "_": "http://example.com/underscore/"
   },
-  "@id": "_",
-  "bar": ["foo", "foo:bar"]
+  "@type": ["foo", "foo:bar", "_"]
 }
--- a/test-suite/tests/flatten-0025-out.jsonld	Mon Jan 14 11:01:58 2013 +0100
+++ b/test-suite/tests/flatten-0025-out.jsonld	Mon Jan 14 16:25:32 2013 +0100
@@ -1,19 +1,19 @@
 [
     {
+        "@id": "_:t0",
+        "@type": [
+            "http://example.com/foo/",
+            "http://example.com/bar",
+            "http://example.com/underscore/"
+        ]
+    },
+    {
         "@id": "http://example.com/bar"
     },
     {
         "@id": "http://example.com/foo/"
     },
     {
-        "@id": "http://example.com/underscore/",
-        "http://example.com/bar": [
-            {
-                "@id": "http://example.com/foo/"
-            },
-            {
-                "@id": "http://example.com/bar"
-            }
-        ]
+        "@id": "http://example.com/underscore/"
     }
-]
\ No newline at end of file
+]
--- a/test-suite/tests/flatten-0038-in.jsonld	Mon Jan 14 11:01:58 2013 +0100
+++ b/test-suite/tests/flatten-0038-in.jsonld	Mon Jan 14 16:25:32 2013 +0100
@@ -4,11 +4,11 @@
     "termId": { "@id": "term", "@type": "@id" },
     "termTyped": { "@id": "term", "@type": "_:term" }
   },
-  "@id": "term",
+  "@id": "_:term",
   "@type": "_:term",
   "term": [
     {
-      "@id": "term",
+      "@id": "_:term",
       "@type": "term",
       "termTyped": "typed value term"
     },
@@ -31,7 +31,7 @@
   ],
   "termId": [
     {
-      "@id": "term",
+      "@id": "_:term",
       "@type": "term",
       "termTyped": "typed value termId"
     },