Combine Convert to RDF Algorithm and Node Map to RDF Conversion
authorMarkus Lanthaler <mark_lanthaler@gmx.net>
Thu, 21 Mar 2013 12:45:45 +0100
changeset 1463 d858f28af601
parent 1462 60d97dbdf19a
child 1464 765be7b47765
Combine Convert to RDF Algorithm and Node Map to RDF Conversion

Both algorithms are short and there are no recursions. It's easier to read them when they are together instead of being in separate sections. I've also clarified Object to RDF Conversion and List to RDF Conversion a bit.

Perhaps also the List to RDF Conversion should be folded into the Convert to RDF Algorithm!?

/cc @gkellogg

This addresses #218.
spec/latest/json-ld-api/index.html
--- a/spec/latest/json-ld-api/index.html	Thu Mar 21 11:44:57 2013 +0100
+++ b/spec/latest/json-ld-api/index.html	Thu Mar 21 12:45:45 2013 +0100
@@ -3111,34 +3111,81 @@
     <section class="informative">
       <h3>General Solution</h3>
 
-      <p>The JSON-LD document is expanded converted to a <i>node map</i> using the
+      <p>The JSON-LD document is expanded and converted to a <i>node map</i> using the
         <a href="#node-map-generation">Node Map Generation algorithm</a>.
         This allows each graph represented within the document to be
         extracted and flattened, making it easier to process each
         <tref>node object</tref>. Each graph from the <i>node map</i>
         is processed to extract <tref title="rdf triple">RDF triples</tref>,
-        to which any (non-default) graph name is applied to create an <tref>RDF dataset</tref>.</p>
+        to which any (non-default) graph name is applied to create an
+        <tref>RDF dataset</tref>. Each <tref>node object</tref> in the
+        <i>node map</i> has an <code>@id</code> member which corresponds to the
+        <tref title="RDF subject">RDF subject</tref>, the other members
+        represent <tref title="RDF predicate">RDF predicates</tref>. Each
+        member value is either an <tref>IRI</tref> or
+        <tref>blank node identifier</tref> or can be transformed to an
+        <tref href="http://www.w3.org/TR/rdf11-concepts/#dfn-literal">RDF literal</tref>
+        to generate an <tref>RDF triple</tref>. <tref title="list">Lists</tref>
+        are transformed into an
+        <tref href="http://www.w3.org/TR/rdf-schema/#ch_collectionvocab">RDF Collection</tref>
+        using the <a href="#list-to-rdf-conversion">List to RDF Conversion algorithm.</a></p>
     </section>
 
     <section>
       <h3>Algorithm</h3>
-      <p>The algorithm takes a JSON-LD document <i>element</i> and creates an
+
+      <p>The algorithm takes a JSON-LD document <i>element</i> and returns an
         <tref>RDF dataset</tref>.</p>
 
       <ol class="algorithm">
         <li>Expand <i>element</i> according the
           <a href="#expansion-algorithm">Expansion algorithm</a>.</li>
-        <li>Generate a <i>nodeMap</i> according the
+        <li>Generate a <i>node map</i> according the
           <a href="#node-map-generation">Node Map Generation algorithm</a>.</li>
         <li>Initialize an empty <tref>RDF dataset</tref> <i>dataset</i>.</li>
-        <li>For each <i>graph name</i> and <i>graph</i> in <i>nodeMap</i>:
+        <li>For each <i>graph name</i> and <i>graph</i> in <i>node map</i>:
           <ol class="algorithm">
-            <li>Retrieve <i>triples</i> using the
-              <a href="#node-map-to-rdf-conversion">Node Map to RDF Conversion algorithm</a>.</li>
+            <li>Initialize <i>triples</i> as an empty <tref>array</tref>.</li>
+            <li>For each <i>subject</i> and <i>node</i> in <i>graph</i>:
+              <ol class="algorithm">
+                <li>For each <i>property</i> and <i>values</i> in <i>node</i>:
+                  <ol class="algorithm">
+                    <li>If <i>property</i> is <code>@type</code>, then for each
+                      <i>type</i> in <i>values</i>, append a <tref>triple</tref>
+                      composed of <i>subject</i>, <code>rdf:type</code>,
+                      and <i>type</i> to <i>triples</i>.</li>
+                    <li>Otherwise, if <i>property</i> is a <tref>keyword</tref>
+                      continue to the next <i>property</i>-<i>values</i> pair.</li>
+                    <li>Otherwise, <i>property</i> is an <tref>IRI</tref> or
+                      <tref>blank node identifier</tref>. For each <i>item</i>
+                      in <i>values</i>:
+                      <ol class="algorithm">
+                        <li>If <i>item</i> is a <tref>list object</tref>, initialize
+                          <i>list triples</i> as an empty <tref>array</tref> and
+                          <i>list head</i> to the result of the <a
+                          href="#list-to-rdf-conversion">List Conversion algorithm</a>, passing
+                          the value associated with the <code>@list</code> key from
+                          <i>item</i> and <i>list triples</i>. Append first a
+                          <tref>triple</tref> composed of <i>subject</i>,
+                          <i>property</i>, and <i>list head</i> to <i>triples</i> and
+                          finally append all <tref title="triple">triples</tref> from
+                          <i>list triples</i> to <i>triples</i>.</li>
+                        <li>Otherwise, <i>item</i> is a <tref>value object</tref>
+                          or a <tref>node object</tref>. Append a <tref>triple</tref>
+                          composed of <i>subject</i>, <i>property</i>, and
+                          the result of using the
+                          <a href="#object-to-rdf-conversion">Object to RDF Conversion algorithm</a>
+                          passing <i>item</i> to <i>triples</i>.</li>
+                      </ol>
+                    </li>
+                  </ol>
+                </li>
+              </ol>
+            </li>
             <li>If <i>graph name</i> is <code>@default</code>, add
               <i>triples</i> to the <tref>default graph</tref> in <i>dataset</i>.</li>
             <li>Otherwise, create a <tref>named graph</tref> in <i>dataset</i>
-              composed of <i>graph name</i> and <i>triples</i>.</li>
+              composed of <i>graph name</i> and add <i>triples</i>.</li>
           </ol>
         </li>
         <li>Return <i>dataset</i>.</li>
@@ -3147,104 +3194,28 @@
   </section> <!-- end of Convert to RDF Algorithm -->
 
   <section>
-    <h3>Node Map to RDF Conversion</h3>
-
-    <p>This algorithm takes the a <i>Node Map</i> for a particular graph as generated
-      by the <a href="#node-map-generation">Node Map Generation algorithm</a>
-      and returns a set of <i>RDF triples</i>.</p>
+    <h3>Object to RDF Conversion</h3>
+
+    <p>This algorithm takes a <tref>node object</tref> or <tref>value object</tref>
+      and transforms it into an
+      <tref href="http://www.w3.org/TR/rdf11-concepts/#dfn-resource">RDF resource</tref>
+      to be used as the <tref>object</tref> of an <tref>RDF triple</tref>.</p>
 
     <section class="informative">
       <h3>Purpose</h3>
-      <p>Given a set of <tref title="node">nodes</tref> associated with a
-        <tref>JSON-LD graph</tref> as obtained from the
-        <a href="#node-map-generation">Node Map Generation algorithm</a>,
-        transform each <tref>node</tref> into one or more <tref title="RDF triple">RDF triples</tref>.</p>
-    </section>
-
-    <section class="informative">
-      <h3>General Solution</h3>
-
-      <p>Identify <tref title="RDF subject">RDF subjects</tref> and
-        <tref title="RDF predicate">RDF predicates</tref> from the <tref>node</tref> identifier
-        and properties. Transform each property value into an <tref>IRI</tref> or
-        <tref href="http://www.w3.org/TR/rdf11-concepts/#dfn-literal">RDF literal</tref>
-        to generate an <tref>RDF triple</tref>. <tref title="list">Lists</tref> are transformed into an
-        <tref href="http://www.w3.org/TR/rdf-schema/#ch_collectionvocab">RDF Collection</tref>
-        using the <a href="#list-to-rdf-conversion">List to RDF Conversion algorithm.</a></p>
-    </section>
-
-    <section>
-      <h3>Algorithm</h3>
-      <p>The <i>nodeMap</i> is represented as a <tref>JSON object</tref>
-        having keys which are node identifiers (<tref title="iri">IRIs</tref> or
-        <tref title="blank node identifier">blank node identifiers</tref>)
-        and values are <tref title="node object">Node objects</tref>.</p>
-      <ol class="algorithm">
-        <li>Initialize <i>result</i> as an empty <tref>array</tref>.</li>
-        <li>For each <i>subject</i> and <i>node</i> in <i>nodeMap</i>:
-          <ol class="algorithm">
-            <li>For each <i>property</i> and <i>values</i> in <i>node</i>:
-              <ol class="algorithm">
-                <li>If <i>property</i> is <code>@type</code>, then for each
-                  <i>type</i> in <i>values</i>, append a <tref>triple</tref>
-                  composed of <i>subject</i>, <code>rdf:type</code>,
-                  and <i>type</i> to <i>result</i>.</li>
-                <li>Otherwise, if <i>property</i> is a <tref>keyword</tref>
-                  continue to the next <i>property</i>-<i>values</i> pair.</li>
-                <li>Otherwise, <i>property</i> is an <tref>IRI</tref> or
-                  <tref>blank node identifier</tref>.</li>
-                <li>For each <i>item</i> in <i>values</i>:
-                  <ol class="algorithm">
-                    <li>If <i>item</i> is a <tref>list object</tref>, initialize
-                      <i>list result</i> as an empty <tref>array</tref>, and
-                      <i>object</i> to the result of the <a
-                      href="#list-to-rdf-conversion">List Conversion algorithm</a>, passing
-                      the value associated with the <code>@list</code> key from
-                      <i>item</i> and <i>list result</i>. Append a
-                      <tref>triple</tref> composed of <i>subject</i>,
-                      <i>property</i>, and <i>object</i> to <i>result</i> and
-                      add all <tref title="triple">triples</tref> from <i>list result</i>
-                      to <i>result</i>.</li>
-                    <li>Otherwise, <i>item</i> is a <tref>value object</tref>
-                      or a <tref>node object</tref>. Generate <i>object</i> as
-                      the result of the
-                      <a href="#object-to-rdf-conversion">Object to RDF Conversion algorithm</a>
-                      passing <i>item</i>. Append a <tref>triple</tref> composed of
-                      <i>subject</i>, <i>property</i>, and <i>object</i> to
-                      <i>result</i>.</li>
-                  </ol>
-                </li>
-              </ol>
-            </li>
-          </ol>
-        </li>
-        <li>Return <i>result</i>.</li>
-      </ol>
-    </section>
-  </section> <!-- end of Node Map to RDF Conversion -->
-
-  <section>
-    <h3>Object to RDF Conversion</h3>
-
-    <p>This algorithm takes a <tref>node</tref> or <tref>value object</tref>
-      and transforms it into an <tref
-      href="http://www.w3.org/TR/rdf11-concepts/#dfn-resource">RDF resource</tref>
-      to be used as the <tref>object</tref> or an <tref>RDF triple</tref>.</p>
-
-    <section class="informative">
-      <h3>Purpose</h3>
-
-      <p>Create an <tref>RDF resource</tref> from a <tref>node</tref> or
+
+      <p>Create an <tref>RDF resource</tref> from a <tref>node object</tref> or
         <tref>value object</tref>.</p>
     </section>
 
     <section class="informative">
       <h3>General Solution</h3>
 
-      <p>Transform <tref title="value object">value objects</tref> to their
-        <tref>RDF literal</tref> form and
-        <tref title="node object">node objects</tref> to an
-        <tref>RDF resource</tref>.</p>
+      <p><tref title="value object">Value objects</tref> are transformed to
+        <tref title="RDF literal">RDF literals</tref> whereas
+        <tref title="node object">node objects</tref> are transformed to
+        <tref title="IRI">IRIs</tref> or
+        <tref title="blank node identifier">blank node identifiers</tref>.</p>
     </section>
 
     <section>
@@ -3254,40 +3225,38 @@
         either a <tref>value object</tref> or <tref>node object</tref>.</p>
 
       <ol class="algorithm">
-        <li>If <i>item</i> is a <tref>value object</tref>:
-          <ol class="algorithm">
-            <li>Initialize <i>value</i> to the value associated with the
-              <code>@value</code> key in <i>item</i>. Initialize <i>datatype</i>
-              to the value associated with the <code>@type</code> key in
-              <i>item</i>, or <code>null</code> if <i>item</i> does not contain
-              that key.</li>
-            <li>If <i>value</i> is <tref>true</tref> or
-              <tref>false</tref>, then set <i>value</i> to its
-              <tref>canonical lexical form</tref> as defined
-              in the section <a href="#data-round-tripping">Data Round Tripping</a>.
-              If <i>datatype</i> is <tref>null</tref>, set it to
-              <code>xsd:boolean</code>.</li>
-            <li>Otherwise, if <i>value</i> is a <tref>number</tref>, then set
-              <i>value</i> to its <tref>canonical lexical form</tref> as defined
-              in the section <a href="#data-round-tripping">Data Round Tripping</a>.
-              If <i>datatype</i> is <tref>null</tref>, set it to either
-              <code>xsd:integer</code> or <code>xsd:double</code>, depending
-              on if the value contains a fractional and/or an exponential
-              component.</li>
-            <li>Otherwise, if <i>datatype</i> is <tref>null</tref>, set it to
-              <code>xsd:string</code> or <code>rdf:langString</code>, depending on if
-              item has a <code>@language</code> key.</li>
-            <li>Initialize <i>literal</i> as an <tref>RDF literal</tref> using
-              <i>value</i> and <i>datatype</i>. If <i>item</i> has the key
-              <code>@language</code> and <i>datatype</i> is
-              <code>rdf:langString</code>, then add the value associated with the
-              <code>@language</code> key as the language of <i>literal</i>.</li>
-            <li>Return <i>literal</i>.</li>
-          </ol>
+        <li>If <i>item</i> is a <tref>node object</tref> return the
+          <tref>IRI</tref> or <tref>blank node identifier</tref> associated
+          with its <code>@id</code> member.</li>
+        <li>Otherwise, <i>item</i> is a <tref>value object</tref>. Initialize
+          <i>value</i> to the value associated with the <code>@value</code>
+          member in <i>item</i>.
+        <li>Initialize <i>datatype</i> to the value associated with the
+          <code>@type</code> member of <i>item</i> or  <code>null</code> if
+          <i>item</i> does not have such a member.</li>
+        <li>If <i>value</i> is <tref>true</tref> or
+          <tref>false</tref>, set <i>value</i> to its
+          <tref>canonical lexical form</tref> as defined
+          in the section <a href="#data-round-tripping">Data Round Tripping</a>.
+          If <i>datatype</i> is <tref>null</tref>, set it to
+          <code>xsd:boolean</code>.</li>
+        <li>Otherwise, if <i>value</i> is a <tref>number</tref>, then set
+          <i>value</i> to its <tref>canonical lexical form</tref> as defined
+          in the section <a href="#data-round-tripping">Data Round Tripping</a>.
+          If <i>datatype</i> is <tref>null</tref>, set it to either
+          <code>xsd:integer</code> or <code>xsd:double</code>, depending
+          on if the value contains a fractional and/or an exponential
+          component.</li>
+        <li>Otherwise, if <i>datatype</i> is <tref>null</tref>, set it to
+          <code>xsd:string</code> or <code>rdf:langString</code>, depending on if
+          item has an <code>@language</code> member.</li>
+        <li>Initialize <i>literal</i> as an <tref>RDF literal</tref> using
+          <i>value</i> and <i>datatype</i>. If <i>item</i> has an
+          <code>@language</code> member and <i>datatype</i> is
+          <code>rdf:langString</code>, then add the value associated with the
+          <code>@language</code> key as the language of <i>literal</i>.</li>
+        <li>Return <i>literal</i>.</li>
         </li>
-        <li>Otherwise, <i>item</i> must be a <tref>node object</tref> containing
-          only <code>@id</code> having an <tref>IRI</tref> or
-          <tref>blank node identifier</tref> value. Return that value.</li>
       </ol>
     </section>
   </section> <!-- end of Object to RDF Conversion -->
@@ -3295,16 +3264,14 @@
   <section>
     <h3>List to RDF Conversion</h3>
 
-    <p>List Conversion is the process of taking a <tref>list</tref> <tref>node</tref>
+    <p>List Conversion is the process of taking a <tref>list object</tref>
       and transforming it into an
       <tref href="http://www.w3.org/TR/rdf-schema/#ch_collectionvocab">RDF Collection</tref>
-      as defined in [[!RDF-MT]].</p>
-
-    <p class="note">This algorithm does not support lists containing lists.</p>
-
+      as defined in RDF Semantics [[!RDF-MT]].</p>
 
     <section class="informative">
       <h3>Purpose</h3>
+
       <p>Transform a sequential set of <tref title="node">nodes</tref> in a
         <tref>list</tref> into the equivalent <tref>RDF Collection</tref>.</p>
     </section>
@@ -3312,39 +3279,41 @@
     <section class="informative">
       <h3>General Solution</h3>
 
-      <p>Allocate a new <tref>blank node</tref> for each element of the
-        <tref>list</tref> and generate <code>rdf:first</code> and
-        <code>rdf:rest</code> <tref title="RDF triple">triples</tref> for each,
-        returning the first <tref>blank node</tref> or <code>rdf:nil</code> if the
-        list is empty.</p>
+      <p>For each element of the <tref>list</tref> a new <tref>blank node identifier</tref>
+        is allocated which is used to generate <code>rdf:first</code> and
+        <code>rdf:rest</code> <tref title="RDF triple">triples</tref>. The
+        algorithm returns the list head, which is either the the first allocated
+        <tref>blank node identifier</tref> or <code>rdf:nil</code> if the
+        <tref>list</tref> is empty.</p>
     </section>
 
     <section>
       <h3>Algorithm</h3>
 
-      <p>The algorithm takes two inputs: an <tref>array</tref> of
-        <tref title="node">nodes</tref> <i>list</i> and an empty <tref>array</tref>
-        <i>list triples</i> used for returning the generated <tref title="RDF
-        triple">triples</tref>.</p>
+      <p>The algorithm takes two inputs: an <tref>array</tref> <i>list</i>
+        and an empty <tref>array</tref> <i>list triples</i> used for returning
+        the generated <tref title="RDF triple">triples</tref>.</p>
 
       <ol class="algorithm">
-        <li>Create a new <tref>array</tref> <i>array</i> composed of a
-          <a href="#generate-blank-node-identifier">new blank node identifier</a>
+        <li>If <i>list</i> is empty, return <code>rdf:nil</code>.</li>
+        <li>Otherwise, create an <tref>array</tref> <i>bnodes</i> composed of a
+          <a href="#generate-blank-node-identifier">newly generated blank node identifier</a>
           for each entry in <i>list</i>.</li>
-        <li>For each pair of <i>subject</i> from <i>array</i> and <i>item</i> from <i>list</i>:
+        <li>Initialize an empty <tref>array</tref> <i>list triples</i>.</li>
+        <li>For each pair of <i>subject</i> from <i>bnodes</i> and <i>item</i> from <i>list</i>:
           <ol class="algorithm">
-            <li>Generate <i>object</i> as the result of the
+            <li>Append a <tref>triple</tref> composed of <i>subject</i>,
+              <code>rdf:first</code>, and the result of using th
               <a href="#object-to-rdf-conversion">Object to RDF Conversion algorithm</a>
-              passing <i>item</i>. Append a <tref>triple</tref> composed of <i>subject</i>,
-              <code>rdf:first</code>, and <i>object</i> to <i>list triples</i>.</li>
-            <li>Set <i>rest</i> as the next entry in <i>array</i>, or if that
+              passing <i>item</i> to <i>list triples</i>.</li>
+            <li>Set <i>rest</i> as the next entry in <i>bnodes</i>, or if that
               does not exist, <code>rdf:nil</code>. Append a
               <tref>triple</tref> composed of <i>subject</i>,
               <code>rdf:rest</code>, and <i>rest</i> to <i>list triples</i>.</li>
           </ol>
         </li>
-        <li>Return the first <tref>blank node</tref> from <i>array</i> or
-          <code>rdf:nil</code> if <i>array</i> is empty.</li>
+        <li>Return the first <tref>blank node</tref> from <i>bnodes</i> or
+          <code>rdf:nil</code> if <i>bnodes</i> is empty.</li>
       </ol>
     </section>
   </section> <!-- end of List to RDF -->
@@ -3355,6 +3324,8 @@
     <p>This section describes algorithms to transform an <tref>RDF dataset</tref>
       into a JSON-LD document.</p>
 
+    <p class="note">This algorithm does not support lists containing lists.</p>
+
     <section class="informative">
       <h3>Purpose</h3>