API updates for Value Expansion, Value Compaction, and the Expansion algorithm.
authorGregg Kellogg <gregg@kellogg-assoc.com>
Wed, 28 Dec 2011 17:42:12 -0800
changeset 307 57bd60fd0811
parent 306 06dd483c271e
child 308 c38887cddb2d
API updates for Value Expansion, Value Compaction, and the Expansion algorithm.
spec/latest/json-ld-api/index.html
--- a/spec/latest/json-ld-api/index.html	Tue Dec 27 17:18:02 2011 -0800
+++ b/spec/latest/json-ld-api/index.html	Wed Dec 28 17:42:12 2011 -0800
@@ -877,7 +877,7 @@
 
   <p>The algorithm for generating a compacted IRI is:
     <ol class="algorithm">
-      <li>Otherwise, search every key-value pair in the <tref>active context</tref> for
+      <li>Search every key-value pair in the <tref>active context</tref> for
         a <tref>term</tref> that is a complete match
         against the IRI. If a complete match is found, the resulting compacted
         IRI is the <tref>term</tref> associated with the IRI in the
@@ -899,24 +899,27 @@
     are required to be expanded at times when processing JSON-LD documents.
   </p>
 
-  <p>The algorithm for expanding a value is:
+  <p>The algorithm for expanding a value <em>value</em> takes an <tref>active property</tref>
+    and <tref>active context</tref>. It is implemented as follows:</p>
     <ol class="algorithm">
-      <li>If the key that is associated with the value has an associated
-        coercion entry in the <tref>local context</tref>, the resulting
-        expansion is an object populated according to the following steps:
-        <ol class="algorithm">
-          <li>If the coercion target is <code>@id</code>, expand the value
-            by adding a new key-value pair where the key is <code>@id</code>
-            and the value is the expanded IRI according to the
-            <a href="#iri-expansion">IRI Expansion</a> rules.</li>
-          <li>If the coercion target is a typed literal, expand the value
-            by adding two new key-value pairs. The first key-value pair
-            will be <code>@literal</code> and the unexpanded value. The second
-            key-value pair will be <code>@type</code> and the associated
-            coercion datatype expanded according to the
-            <a href="#iri-expansion">IRI Expansion</a> rules.</li>
-        </ol>
-      </li>
+      <li>If <em>value</em> is <tref>true</tref>, <tref>false</tref> or <tref>number</tref>, expand the value by
+        adding a two new key-value pairs. The first key-value pair will be <code>@literal</code> and
+        the string representation of <em>value</em>. The second key-value pair will be <code>@type></code>,
+        and the expanded version of <code>xsd:boolean</code>, <code>xsd:integer</code>, or <code>xsd:double</code>,
+        depending on <em>value</em>.
+      <li>Otherwise, if <tref>active property</tref> is the target of an <code>@id</code> coercion,
+        expand the value by adding a new key-value pair where the
+        key is <code>@id</code> and the value is the expanded IRI according to the <a href="#iri-expansion">IRI
+        Expansion</a> rules.</li>
+      <li>Otherwise, if <tref>active property</tref> is the target of typed literal coercion,
+        expand <em>value</em> by adding two new key-value pairs. The first key-value pair will be <code>@literal</code>
+        and the unexpanded value. The second key-value pair will be <code>@type</code> and the associated coercion
+        datatype expanded according to the <a href="#iri-expansion">IRI Expansion</a> rules.</li>
+      <li>Otherwise, if the <tref>active context</tref> has a <code>@language</code>, 
+        expand <em>value</em> by adding two new key-value pairs. The first key-value pair will be <code>@literal</code>
+        and the unexpanded value. The second key-value pair will be <code>@language</code> and value of
+        <code>@language</code> from the <tref>active context</tref>.</li> <li>Otherwise, <em>value</em> is already
+        expanded.</li>
     </ol>
   </p>
 </section>
@@ -928,24 +931,31 @@
     times when processing JSON-LD documents.
   </p>
 
-  <p>The algorithm for compacting a value is:
-    <ol class="algorithm">
-      <li>If the <tref>local context</tref> contains a coercion target for the
-        key that is associated with the value, compact the value using the
-        following steps:
-        <ol class="algorithm">
-          <li>If the coercion target is an <code>@id</code>, the compacted
-            value is the value associated with the <code>@id</code> key,
-            processed according to the
-            <a href="#iri-compaction">IRI Compaction</a> steps.</li>
-          <li>If the coercion target is a typed literal, the compacted
-            value is the value associated with the <code>@literal</code> key.
-          </li>
-          <li>Otherwise, the value is not modified.</li>
-        </ol>
-      </li>
-    </ol>
-  </p>
+  <p>The algorithm for compacting an expanded value <em>value</em> takes an <tref>active property</tref>
+    and <tref>active context</tref>. It is implemented as follows:</p>
+  <ol class="algorithm">
+    <li>If the value may be expressed as <tref>true</tref>, <tref>false</tref> or <tref>number</tref>,
+      the value is the native representation of the <code>@literal</code> value.</li>
+    <li>Otherwise, if the <tref>active context</tref> contains a coercion target for the
+      key that matches the expression of the value, compact the value using the
+      following steps:
+      <ol class="algorithm">
+        <li>If the coercion target is an <code>@id</code>, the compacted
+          value is the value associated with the <code>@id</code> key,
+          processed according to the
+          <a href="#iri-compaction">IRI Compaction</a> steps.</li>
+        <li>If the coercion target is a typed literal, the compacted
+          value is the value associated with the <code>@literal</code> key.</li>
+      </ol>
+    </li>
+    <li>Otherwise, if the <tref>active context</tref> contains a <code>@language</code>, which
+      matches the <code>@language</code> of the value, or the value has only a <code>@literal</code> key, the compacted
+      value is the value associated with the <code>@literal</code> key.</li>
+    <li>Otherwise, if the value contains a <code>@type</code> key, the compacted value
+      is the value with the <code>@type</code> value processed according to the
+      <a href="#iri-compaction">IRI Compaction</a> steps.</li>
+    <li>Otherwise, the value is not modified.</li>
+  </ol>
 </section>
 
 <section>
@@ -994,30 +1004,44 @@
 <h3>Expansion Algorithm</h3>
 
 <p class="issue">This algorithm is a work in progress, do not implement it.</p>
+<p>The algorithm takes three input variables: an <tref>active context</tref>, an <tref>active property</tref>,
+  and a <em>value</em> to be expanded. To begin, the <tref>active context</tref> is set to the <tref>initial
+  context</tref>, <tref>active property</tref> is set to nil, and <em>value</em> is set to the <tref>JSON-LD
+  input</tref>.</p>
 
 <ol class="algorithm">
-  <li>If the top-level item in the <tref>JSON-LD input</tref> is an <tref>array</tref>,
-    process each item in the <tref>array</tref> recursively using this algorithm.</li>
-  <li>If the top-level item in the <tref>JSON-LD input</tref> is an object,
-    update the <tref>local context</tref> according to the steps outlined in
-    the <a href="#context">context</a> section. Process each key, expanding
-    the key according to the <a href="#iri-expansion">IRI Expansion</a> rules.
+  <li>If <em>value</em> is an <tref>array</tref>, process each item in <em>value</em> recursively
+    using this algorithm, passing copies of the <tref>active context</tref> and <tref>active property</tref>.</li>
+  <li>Otherwise, if <em>value</em> is an object
     <ol class="algorithm">
-      <li>Process each value associated with each key:
+      <li>Update the <tref>active context</tref> according to the steps outlined in
+      the <a href="#context">context</a> section and remove it from the expanded result.</li>
+      <li>For each key and value in <em>value</em>:
         <ol class="algorithm">
+          <li>If the key is <code>@id</code> or <code>@type</code> and the value is a <tref>string</tref>,
+            expand the value according to <a href="#iri-expansion">IRI Expansion</a>.</li>
+          <li>Otherwise, if the key is <code>@literal</code>, the value MUST be a <tref>string</tref> and
+            is not subject to further expansion.</li>
+          <li>Otherwise, if the key is not a keyword, expand the key according to
+            <a href="#iri-expansion">IRI Expansion</a> rules and set as <tref>active property</tref>.</li>
+          <li>If the value is an <tref>array</tref>, and <tref>active property</tref> is subject to <code>@list</code>
+            expansion, replace the value with a new key-value key where the key is <code>@list</code> and value
+            set to the current value.</li>
           <li>If the value is an <tref>array</tref>, process each item in the <tref>array</tref>
-            recursively using this algorithm.</li>
+            recursively using this algorithm, passing copies of the <tref>active context</tref> and <tref>active
+            property</tref>.</li>
           <li>If the value is an object, process the object recursively
-            using this algorithm.</li>
-          <li>Otherwise, check to see the associated key has an associated
-            coercion rule. If the value should be coerced, expand the value
-            according to the <a href="#value-expansion">Value Expansion</a> rules.
-            If the value does not need to be coerced, leave the value as-is.</li>
+            using this algorithm, passing copies of the <tref>active context</tref> and <tref>active
+            property</tref>.</li>
+          <li>Otherwise, expand the value according to the <a href="#value-expansion">Value Expansion</a> rules,
+            passing <tref>active property</tref>.
         </ol>
       </li>
       <li>Remove the context from the object.</li>
     </ol>
   </li>
+  <li>Otherwise, expand <em>value</em> according to the <a href="#value-expansion">Value Expansion</a> rules,
+    passing <tref>active property</tref>.
 </ol>
 </section>