--- a/spec/latest/json-ld-api/index.html Fri Apr 20 13:03:51 2012 -0700
+++ b/spec/latest/json-ld-api/index.html Fri Apr 20 17:19:38 2012 -0400
@@ -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>