Merge remote-tracking branch 'origin/master'
authorGregg Kellogg <gregg@kellogg-assoc.com>
Fri, 20 Apr 2012 15:26:39 -0700
changeset 555 8d3486fd6a14
parent 551 f91157433793 (current diff)
parent 554 b080658ef650 (diff)
child 556 02ca6891380e
child 557 54d08e1f0d7c
Merge remote-tracking branch 'origin/master'
spec/latest/json-ld-api/index.html
--- a/playground/jsonld.js	Fri Apr 20 15:26:32 2012 -0700
+++ b/playground/jsonld.js	Fri Apr 20 15:26:39 2012 -0700
@@ -387,6 +387,9 @@
   callback = arguments[callbackArg];
 
   // set default options
+  if(!('base' in options)) {
+    options.base = '';
+  }
   if(!('resolver' in options)) {
     options.resolver = jsonld.urlResolver;
   }
@@ -501,6 +504,9 @@
   var callback = arguments[callbackArg];
 
   // set default options
+  if(!('base' in options)) {
+    options.base = '';
+  }
   if(!('resolver' in options)) {
     options.resolver = jsonld.urlResolver;
   }
@@ -1111,9 +1117,9 @@
       // @graph must be an array or an object
       if(prop === '@graph' && !(_isObject(value) || _isArray(value))) {
         throw new JsonLdError(
-            'Invalid JSON-LD syntax; "@value" value must not be an ' +
-            'object or an array.',
-            'jsonld.SyntaxError', {value: value});
+          'Invalid JSON-LD syntax; "@value" value must not be an ' +
+          'object or an array.',
+          'jsonld.SyntaxError', {value: value});
       }
 
       // @value must not be an object or an array
@@ -1476,7 +1482,7 @@
     if(!_isObject(ctx)) {
       throw new JsonLdError(
         'Invalid JSON-LD syntax; @context must be an object.',
-        {context: ctx});
+        'jsonld.SyntaxError', {context: ctx});
     }
 
     // define context mappings for keys in local context
@@ -2226,8 +2232,7 @@
   if(!_isArray(frame) || frame.length !== 1 || !_isObject(frame[0])) {
     throw new JsonLdError(
       'Invalid JSON-LD syntax; a JSON-LD frame must be a single object.',
-      'jsonld.SyntaxError',
-      {frame: frame});
+      'jsonld.SyntaxError', {frame: frame});
   }
 }
 
@@ -2731,13 +2736,14 @@
     if(key !== '@language') {
       throw new JsonLdError(
         'Invalid JSON-LD syntax; keywords cannot be overridden.',
-        {context: ctx});
+        'jsonld.SyntaxError', {context: ctx});
     }
 
     if(value !== null && !_isString(value)) {
       throw new JsonLdError(
         'Invalid JSON-LD syntax; the value of "@language" in a ' +
-        '@context must be a string or null.', {context: ctx});
+        '@context must be a string or null.',
+        'jsonld.SyntaxError', {context: ctx});
     }
 
     if(value === null) {
@@ -2795,7 +2801,8 @@
   if(!_isObject(value)) {
     throw new JsonLdError(
       'Invalid JSON-LD syntax; @context property values must be ' +
-      'strings or objects.', {context: ctx});
+      'strings or objects.',
+      'jsonld.SyntaxError', {context: ctx});
   }
 
   // create new mapping
@@ -2806,7 +2813,7 @@
     if(!_isString(id)) {
       throw new JsonLdError(
         'Invalid JSON-LD syntax; @context @id values must be strings.',
-        {context: ctx});
+        'jsonld.SyntaxError', {context: ctx});
     }
 
     // expand @id to full IRI
@@ -2820,7 +2827,7 @@
     if(prefix === null) {
       throw new JsonLdError(
         'Invalid JSON-LD syntax; @context terms must define an @id.',
-        {context: ctx, key: key});
+        'jsonld.SyntaxError', {context: ctx, key: key});
     }
 
     // set @id based on prefix parent
@@ -2839,7 +2846,7 @@
     if(!_isString(type)) {
       throw new JsonLdError(
         'Invalid JSON-LD syntax; @context @type values must be strings.',
-        {context: ctx});
+        'jsonld.SyntaxError', {context: ctx});
     }
 
     if(type !== '@id') {
@@ -2857,7 +2864,7 @@
       throw new JsonLdError(
         'Invalid JSON-LD syntax; @context @container value must be ' +
         '"@list" or "@set".',
-        {context: ctx});
+        'jsonld.SyntaxError', {context: ctx});
     }
 
     // add @container to mapping
@@ -2870,7 +2877,7 @@
       throw new JsonLdError(
         'Invalid JSON-LD syntax; @context @language value must be ' +
         'a string or null.',
-        {context: ctx});
+        'jsonld.SyntaxError', {context: ctx});
     }
 
     // add @language to mapping
@@ -2959,7 +2966,8 @@
   if(!_isAbsoluteIri(value)) {
     throw new JsonLdError(
       'Invalid JSON-LD syntax; a @context value does not expand to ' +
-      'an absolute IRI.', {context: ctx, value: value});
+      'an absolute IRI.',
+      'jsonld.SyntaxError', {context: ctx, value: value});
   }
 
   return value;
--- a/spec/latest/json-ld-api/index.html	Fri Apr 20 15:26:32 2012 -0700
+++ b/spec/latest/json-ld-api/index.html	Fri Apr 20 15:26:39 2012 -0700
@@ -1111,95 +1111,116 @@
   <h3>Algorithm</h3>
   <p>The algorithm for generating a <tref>compact IRI</tref> is:
     <ol class="algorithm">
-      <li>If <em>iri</em> is <code>rdf:type</code> and <em>value</em> is <tref>null</tref>, return <code>@type</code>.</li>
-      <li>Create a list of terms <em>terms</em> by searchin every key-value pair in the
-        <tref>active context</tref> for a <tref>term</tref> that is a complete match
-        against <em>iri</em>.</li>
-      <li>Create a mapping from each <em>term</em> (<em>term map</em>) for holding associated
-        <tref title="term rank">term ranks</tref>.</li>
-      <li>If <em>value</em> is a <tref>JSON object</tref> containing only the property <code>@list</code>:
+      <li>If <em>iri</em> is <code>rdf:type</code>, return <code>@type</code>.</li>
+      <li>Create an empty list of terms <em>terms</em> that will be populated with
+        <tref>term</tref>s that are ranked according to how closely they match
+        <em>value</em>. Initialize <em>highest rank</em> to <code>0</code>,
+        and set a flag <em>list container</em> to <code>false</code>.</li>
+      <li>For each <em>term</em> in the <tref>active context</tref>:
         <ol class="algorithm">
-          <li>For each entry in <em>terms</em> which
-            has <code>@container</code> set to <code>@list</code> in the <tref>active context</tref>,
-            add an entry to <em>term map</em> as the sum of the <tref>term 
-            rank</tref> for every entry in the list, removing entries having a 
-            <tref>term rank</tref> of <code>0</code>.</li>
-          <li>Remove entries from <em>terms</em> which have <code>@container</code>
-            set to <code>@set</code> in the <tref>active context</tref>.</li>
+          <li>If the <em>term</em>'s <tref>IRI</tref> is not a complete match against
+            <em>iri</em>, continue to the next <em>term</em>.</li>
+          <li>If <em>value</em> is a <tref>JSON object</tref> containing only the property <code>@list</code>:
+            <ol class="algorithm">
+              <li>If <em>term</em> has a <code>@container</code> set to <code>@set</code>, continue
+                to the next <em>term</em>.</li>
+              <li>If <em>list container</em> is <code>true</code> and <em>term</em> does not have a
+                <code>container</code> set to <code>@list</code>, continue to the next <em>term</em>.</li>
+            </ol>
+          </li>
+          <li>Otherwise, if <em>term</em> has a <code>container</code> set to <code>@list</code>,
+            continue to the next <em>term</em>.</li>
+          <li>Set <em>rank</em> to the <tref>term rank</tref> of <em>value</em> by passing
+            passing <em>term</em>, <em>value</em>, and <tref>active context</tref> to
+            the <a href="#term-rank-algorithm">Term Rank Algorithm</a>.</li>
+          <li>If <em>rank</em> is greater than <code>0</code>:
+            <ol class="algorithm">
+              <li>If <em>term</em> has a <code>container</code> set to <code>@set</code>, then add
+                <code>1</code> to <em>rank</em>.</li>
+              <li>If <em>value</em> is a <tref>JSON object</tref> containing only the property <code>@list</code>
+                and <em>list container</em> is <code>false</code> and <em>term</em> has a <code>container</code>
+                set to <code>@list</code>, then set <em>list container</em> to <code>true</code>, clear
+                <em>terms</em>, set <em>highest rank</em> to <em>rank</em>, and add <em>term</em> to <em>terms</em>.</li>
+              <li>Otherwise, if <em>rank</em> is greater than or equal to <em>highest rank</em>:
+                <ol class="algorithm">
+                  <li>If <em>rank</em> is greater than <em>highest rank</em>, clear <em>terms</em> and set
+                    <em>highest rank</em> to <em>rank</em>.</li>
+                  <li>Add <em>term</em> to <em>terms</em>.</li>
+                </ol>
+              </li>
+            </ol>
+          </li>
         </ol>
       </li>
-      <li>If <em>term map</em> is empty:
-        <ol class="algorithm">
-          <li>Remove entries from <em>terms</em> which have <code>@container</code>
-            set to <code>@list</code> in the <tref>active context</tref>.</li>
-          <li>For each entry in <em>terms</em>,
-            add an entry to <em>term map</em> as the <tref>term rank</tref> for <em>value</em>,
-            removing entries having a <tref>term rank</tref> of <code>0</code>.</li>
-        </ol>
-      </li>
-      <li>Create a new list of terms <em>terms</em> by selecting the keys from <em>term map</em>
-        sharing the same <tref>term rank</tref> where that is the largest such value in
-        <em>term map</em>.</li>
       <li>If <em>terms</em> is empty, add a <tref>compact IRI</tref> representation of <em>iri</em>
         for each <tref>term</tref> in the <tref>active context</tref> which 
         maps to an <tref>IRI</tref> which is a prefix for <em>iri</em> where 
-        the resulting <tref>compact IRI</tref> has no <code>@type</code> 
-        coercion, <code>@container</code> or <code>@language</code> specified 
-        in the <tref>active context</tref>. The resulting <tref>compact 
-        IRI</tref> is the <tref>term</tref> associated with the partially 
+        the resulting <tref>compact IRI</tref> is not a <tref>term</tref> in the
+        <tref>active context</tref>. The resulting <tref>compact IRI</tref> is the
+        <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, add <em>iri</em> to <em>terms</em>.</li>
-      <li>The final value is the shortest and lexicographically least value in <em>terms</em>.</li>
+      <li>If <em>terms</em> is empty, return <em>iri</em>.</li>
+      <li>Return the shortest and lexicographically least value in <em>terms</em>.</li>
     </ol>
   </p>
 </section>
 
 <section>
-<h3>Term Rank</h3>
+<h3>Term Rank Algorithm</h3>
 <p>When selecting among multiple possible terms for a given property, it may be that multiple
   <tref title="term">terms</tref> are defined with the same <tref>IRI</tref>, but differ in <code>@type</code>, <code>@container</code>
   or <code>@language</code>. The purpose of this algorithm is to take an <tref>term</tref>
   and a value and give it a <tdef>term rank</tdef>. The selection can then be based, partly, on
   the term having the highest <tref>term rank</tref>.</p>
-<p>Given a <tref>term</tref> <em>term</em>, <em>value</em> and <tref>active context</tref>
-  determin the <tref>term rank</tref> using the following steps:</p>
+<p>Given a <tref>term</tref> <em>term</em>, <em>value</em>, and <tref>active context</tref>
+  determine the <tref>term rank</tref> using the following steps:</p>
 <ol class="algorithm">
-  <li>If <em>value</em> is <tref>null</tref>, <tref>term rank</tref> is <code>3</code>,</li>
-  <li>Otherwise, <em>value</em> is a <tref>true</tref>, <tref>false</tref>, or
-    <tref>number</tref> and <em>term</em> has a 
+  <li>If <em>value</em> is <tref>null</tref>, <tref>term rank</tref> is <code>3</code>.</li>
+  <li>Otherwise, if <em>value</em> is a <tref>JSON object</tref> containing only the property <code>@list</code>:
+    <ol class="algorithm">
+      <li>If the <code>@list</code> property is an empty array, if <em>term</em> has <code>@container</code>
+        set to <code>@list</code>, <tref>term rank</tref> is <code>1</code>, otherwise <code>0</code>.</li>
+      <li>Otherwise, return the sum of the <tref>term rank</tref>s for every entry in the list.</li>
+    </ol>
+  </li>
+  <li>Otherwise, if <em>value</em> is <tref>true</tref>, <tref>false</tref>, or
+    a <tref>number</tref>, if <em>term</em> has a 
     <code>@type</code> coercion to <code>xsd:boolean</code>, 
-    <code>xsd:integer</code> or <code>xsd:double</code> respectively, 
-    <tref>term rank</tref> is <code>3</code>, otherwise <code>2</code>.</li>
+    <code>xsd:integer</code>, or <code>xsd:double</code> respectively, 
+    <tref>term rank</tref> is <code>3</code>, otherwise if <em>term</em> has no <code>@type</code> or
+    <code>@language</code> it is <code>2</code>, otherwise <code>1</code>.</li>
   <li>Otherwise, if <em>value</em> is a <tref>string</tref>, it represents a string value
     with no <code>@language</code>. If <em>term</em> has <code>@language</code> <tref>null</tref>,
     or <em>term</em> has no <code>@type</code> or <code>@language</code> and the <tref>active context</tref>
     has no <code>@language</code>, <tref>term rank</tref> is <code>3</code>, otherwise <code>0</code>.</li>
-  <li>Otherwise, <em>value</em> MUST be a <tref>JSON object</tref> having a <code>@value</code>
-    or <code>@id</code> property.
+  <li>Otherwise, <em>value</em> MUST be a <tref>subject definition</tref>, <tref>subject reference</tref>,
+    or a <tref>JSON object</tref> having a <code>@value</code>.
     <ol class="algorithm">
-      <li>If <em>value</em> has an <code>@id</code> property, and term has <code>@type</code>
-        coerced to <code>@id</code>, <tref>term rank</tref> is <code>3</code>, otherwise
+      <li>If <em>value</em> has an <code>@value</code> property, it must have either a <code>@type</code>
+        or a <code>@language</code>:
+        <ol class="algorithm">
+          <li>If <em>value</em> has a <code>@type</code> property matching a
+            <code>@type</code> coercion for <em>term</em>, <tref>term rank</tref> 
+            is <code>3</code>, otherwise if <em>term</em> has no <code>@type</code> 
+            coersion and no <code>@language</code>, <tref>term rank</tref> is 
+            <code>1</code>, otherwise <code>0</code>.</li>
+          <li>Otherwise, if <em>value</em> has a <code>@language</code> property matching a
+            <code>@language</code> definition for <em>term</em> (or 
+            <em>term</em> has no <code>@type</code> or <code>@language</code> definition and
+            <code>@language</code> in the <tref>active context</tref> matches the 
+            <em>value</em> <code>@language</code>), <tref>term rank</tref> is 
+            <code>3</code>, otherwise if <em>term</em> has no <code>@type</code> 
+            coersion and no <code>@language</code>, <tref>term rank</tref> is 
+            <code>1</code>, otherwise <code>0</code>.</li>
+        </ol>
+      </li>
+      <li>Otherwise, if <em>term</em> has <code>@type</code> coerced to <code>@id</code>,
+        <tref>term rank</tref> is <code>3</code>, otherwise
         if <em>term</em> has no <code>@type</code> coersion and no <code>@language</code>,
         <tref>term rank</tref> is <code>1</code>, otherwise <code>0</code>.</li>
-      <li>Otherwise, if <em>value</em> has a <code>@type</code> property matching a
-        <code>@type</code> coercion for <em>term</em>, <tref>term rank</tref> 
-        is <code>3</code>, otherwise if <em>term</em> has no <code>@type</code> 
-        coersion and no <code>@language</code>, <tref>term rank</tref> is 
-        <code>1</code>, otherwise <code>0</code>.</li>
-      <li>Otherwise, if <em>value</em> has a <code>@language</code> property matching a
-        <code>@language</code> definition for <em>term</em> (or 
-        <em>term</em> has no <code>@type</code> or <code>@language</code> definition and
-        <code>@language</code> in the <tref>active context</tref> matches the 
-        <em>value</em> <code>@language</code>), <tref>term rank</tref> is 
-        <code>3</code>, otherwise if <em>term</em> has no <code>@type</code> 
-        coersion and no <code>@language</code>, <tref>term rank</tref> is 
-        <code>1</code>, otherwise <code>0</code>.</li>
     </ol>
   </li>
-  <li>If <tref>term rank</tref> is greater than <code>0</code> and <em>term</em> has
-    <code>@container</code> set to <code>@set</code>, increase <tref>term rank</tref>
-    by <code>1</code>.</li>
   <li>Return <tref>term rank</tref>.</li>
 </ol>
 </section>