Let @vocab take precedence over compact IRIs in compaction
authorMarkus Lanthaler <mark_lanthaler@gmx.net>
Tue, 02 Apr 2013 18:07:07 +0200
changeset 1530 ffb8a581df0c
parent 1529 0f3e729d4e3c
child 1531 579c2a8d4c3a
Let @vocab take precedence over compact IRIs in compaction

This addresses #235.
spec/latest/json-ld-api/index.html
spec/latest/json-ld/index.html
test-suite/tests/compact-0023-context.jsonld
test-suite/tests/compact-0023-out.jsonld
test-suite/tests/compact-manifest.jsonld
--- a/spec/latest/json-ld-api/index.html	Tue Apr 02 17:31:20 2013 +0200
+++ b/spec/latest/json-ld-api/index.html	Tue Apr 02 18:07:07 2013 +0200
@@ -2329,7 +2329,7 @@
         it is relative to <tref title="active context">active context's</tref>
         <tref>vocabulary mapping</tref>. In order to select the most appropriate
         <tref>term</tref>, we may have to collect information about the passed
-        <i>value</i>. This information includes whic
+        <i>value</i>. This information includes which
         <tref title="container mapping">container mappings</tref>
         would be preferred for expressing the <i>value</i>, and what its
         <tref>type mapping</tref> or <tref>language mapping</tref> is. For
@@ -2341,11 +2341,11 @@
         return the most appropriate <tref>term</tref> to use.</p>
 
       <p>If no <tref>term</tref> was found that could be used to compact the
-        <tref>IRI</tref>, then an attempt is made to find a <tref>compact IRI</tref>
-        to use. If there is no appropriate <tref>compact IRI</tref>, then, if
-        the <tref>IRI</tref> is relative to
-        <tref title="active context">active context's</tref>
-        <tref>vocabulary mapping</tref>, then it is used. Otherwise, it is
+        <tref>IRI</tref>, an attempt is made compact the <tref>IRI</tref> using the
+        <tref title="active context">active context's</tref> <tref>vocabulary mapping</tref>,
+        if there is one. If the <tref>IRI</tref> could not be compacted, an
+        attempt is made to find a <tref>compact IRI</tref>. If there is no
+        appropriate <tref>compact IRI</tref>, the <tref>IRI</tref> is
         transformed to a <tref>relative IRI</tref> using the document's
         <tref>base IRI</tref>. Finally, if the <tref>IRI</tref> or
         <tref>keyword</tref> still could not be compacted, it is returned
@@ -2512,10 +2512,23 @@
           </ol>
         </li>
         <li>At this point, there is no simple <tref>term</tref> that <i>iri</i>
-          can be compacted to. Instead, try to create a <tref>compact IRI</tref>,
-          starting by initializing <i>compact IRI</i> to <tref>null</tref>. This
-          variable will be used to store the created <tref>compact IRI</tref>, if
-          any.</li>
+          can be compacted to. If <i>vocab</i> is <tref>true</tref> and
+          <tref>active context</tref> has a <tref>vocabulary mapping</tref>:
+          <ol class="algorithm">
+            <li>If <i>iri</i> begins with the
+              <tref title="vocabulary mapping">vocabulary mapping's</tref> value
+              but is longer, then initialize <i>suffix</i> to the substring
+              of <i>iri</i> that does not match. If <i>suffix</i> does not
+              have a <tref>term definition</tref> in <tref>active context</tref>,
+              then return <i>suffix</i>.</li>
+          </ol>
+        </li>
+        <li>The <i>iri</i> could not be compacted using the
+          <tref title="active context">active context's</tref> <tref>vocabulary mapping</tref>.
+          Try to create a <tref>compact IRI</tref>, starting by initializing
+          <i>compact IRI</i> to <tref>null</tref>. This variable will be used to
+          tore the created <tref>compact IRI</tref>, if any.</li>
+        </li>
         <li>For each key <tref>term</tref> and value <tref>term definition</tref> in
           the <tref>active context</tref>:
           <ol class="algorithm">
@@ -2544,19 +2557,6 @@
           </ol>
         </li>
         <li>If <i>compact IRI</i> is not <tref>null</tref>, return <i>compact IRI</i>.</li>
-        <li>At this point, there is no <tref>compact IRI</tref> that <i>iri</i>
-          can be compacted to, so if <i>vocab</i> is
-          <tref>true</tref> and <tref>active context</tref> has a
-          <tref>vocabulary mapping</tref>:
-          <ol class="algorithm">
-            <li>If <i>iri</i> begins with the
-              <tref title="vocabulary mapping">vocabulary mapping's</tref> value
-              but is longer, then initialize <i>suffix</i> to the substring
-              of <i>iri</i> that does not match. If <i>suffix</i> does not
-              have a <tref>term definition</tref> in <tref>active context</tref>,
-              then return <i>suffix</i>.</li>
-          </ol>
-        </li>
         <li>If <i>vocab</i> is <tref>false</tref> then
           transform <i>iri</i> to a <tref>relative IRI</tref> using
           the document's base <tref>IRI</tref>.</li>
--- a/spec/latest/json-ld/index.html	Tue Apr 02 17:31:20 2013 +0200
+++ b/spec/latest/json-ld/index.html	Tue Apr 02 18:07:07 2013 +0200
@@ -792,8 +792,8 @@
 
   <div class="issue atrisk" data-number="1" title="@base keyword">
     <p class="atrisk-head">Note: This feature is
-      <a href="http://www.w3.org/2005/10/Process-20051014/tr#cfi">"at risk"</a> and may be removed from
-      this specification based on feedback. Please send feedback to
+      <a href="http://www.w3.org/2005/10/Process-20051014/tr#cfi">"at risk"</a> and may
+      be removed from this specification based on feedback. Please send feedback to
       <a href="mailto:[email protected]">[email protected]</a>.
       For the current status see
       <a href="http://www.w3.org/2011/rdf-wg/wiki/JSON-LD_Features_at_Risk">features "at risk" in JSON-LD 1.0</a></p>
@@ -1979,8 +1979,8 @@
 
   <div class="issue atrisk" data-number="2" title="Reverse properties">
     <p class="atrisk-head">Note: This feature is
-      <a href="http://www.w3.org/2005/10/Process-20051014/tr#cfi">"at risk"</a> and may be removed from
-      this specification based on feedback. Please send feedback to
+      <a href="http://www.w3.org/2005/10/Process-20051014/tr#cfi">"at risk"</a> and may
+      be removed from this specification based on feedback. Please send feedback to
       <a href="mailto:[email protected]">[email protected]</a>.
       For the current status see
       <a href="http://www.w3.org/2011/rdf-wg/wiki/JSON-LD_Features_at_Risk">features "at risk" in JSON-LD 1.0</a></p>
@@ -2733,8 +2733,8 @@
 
   <div class="issue atrisk" data-number="3" title="Allow blank nodes to be used as graph name or property">
     <p class="atrisk-head">Note: This feature is
-      <a href="http://www.w3.org/2005/10/Process-20051014/tr#cfi">"at risk"</a> and may be removed from
-      this specification based on feedback. Please send feedback to
+      <a href="http://www.w3.org/2005/10/Process-20051014/tr#cfi">"at risk"</a> and may
+      be removed from this specification based on feedback. Please send feedback to
       <a href="mailto:[email protected]">[email protected]</a>.
       For the current status see
       <a href="http://www.w3.org/2011/rdf-wg/wiki/JSON-LD_Features_at_Risk">features "at risk" in JSON-LD 1.0</a></p>
@@ -3052,8 +3052,8 @@
 
   <div class="issue atrisk" data-number="1" title="@base keyword">
     <p class="atrisk-head">Note: This feature is
-      <a href="http://www.w3.org/2005/10/Process-20051014/tr#cfi">"at risk"</a> and may be removed from
-      this specification based on feedback. Please send feedback to
+      <a href="http://www.w3.org/2005/10/Process-20051014/tr#cfi">"at risk"</a> and may
+      be removed from this specification based on feedback. Please send feedback to
       <a href="mailto:[email protected]">[email protected]</a>.
       For the current status see
       <a href="http://www.w3.org/2011/rdf-wg/wiki/JSON-LD_Features_at_Risk">features "at risk" in JSON-LD 1.0</a></p>
--- a/test-suite/tests/compact-0023-context.jsonld	Tue Apr 02 17:31:20 2013 +0200
+++ b/test-suite/tests/compact-0023-context.jsonld	Tue Apr 02 18:07:07 2013 +0200
@@ -1,7 +1,7 @@
 {
   "@context": {
-    "@vocab": "http://example.com/subdir/",
-    "ex": "http://example.com/",
-    "ex:subdir/vocab/date": { "@type": "vocab/types/dateTime" }
+    "@vocab": "http://example.com/",
+    "ex": "http://example.com/subdir/",
+    "ex:vocab/date": { "@type": "ex:vocab/types/dateTime" }
   }
 }
--- a/test-suite/tests/compact-0023-out.jsonld	Tue Apr 02 17:31:20 2013 +0200
+++ b/test-suite/tests/compact-0023-out.jsonld	Tue Apr 02 18:07:07 2013 +0200
@@ -1,17 +1,17 @@
 {
   "@context": {
-    "@vocab": "http://example.com/subdir/",
-    "ex": "http://example.com/",
-    "ex:subdir/vocab/date": { "@type": "vocab/types/dateTime" }
+    "@vocab": "http://example.com/",
+    "ex": "http://example.com/subdir/",
+    "ex:vocab/date": { "@type": "ex:vocab/types/dateTime" }
   },
-  "@id": "ex:subdir/id/1",
-  "@type": "ex:subdir/vocab/types/Test",
-  "ex:subdir/vocab/date": "2011-01-25T00:00:00Z",
-  "ex:subdir/vocab/embed": {
-    "@id": "ex:subdir/id/2",
-    "ex:subdir/vocab/expandedDate": {
+  "@id": "ex:id/1",
+  "@type": "subdir/vocab/types/Test",
+  "ex:vocab/date": "2011-01-25T00:00:00Z",
+  "subdir/vocab/embed": {
+    "@id": "ex:id/2",
+    "subdir/vocab/expandedDate": {
       "@value": "2012-08-01T00:00:00Z",
-      "@type": "ex:subdir/vocab/types/dateTime"
+      "@type": "subdir/vocab/types/dateTime"
     }
   }
 }
--- a/test-suite/tests/compact-manifest.jsonld	Tue Apr 02 17:31:20 2013 +0200
+++ b/test-suite/tests/compact-manifest.jsonld	Tue Apr 02 18:07:07 2013 +0200
@@ -140,7 +140,7 @@
       "expect": "compact-0022-out.jsonld"
     }, {
       "@type": ["test:TestCase", "jld:CompactTest"],
-      "name": "Prefixes have precedence over @vocab - even if the result is longer",
+      "name": "@vocab takes precedence over prefixes - even if the result is longer",
       "input": "compact-0023-in.jsonld",
       "context": "compact-0023-context.jsonld",
       "expect": "compact-0023-out.jsonld"