Updated expansion algorithm to allow for terms being aliased to @type, so that @type can be called with subject reference in addition to a string (or array of either of those).
Added expand-0026 to test collapsing the property rdf:type to @type if set in the @context.
Remove step 1 in expand IRI so that rdf:type is not given special treatment.
Add noType option to fromRDF to inhibit using @type for rdf:type properties.
This closes issue #91
--- a/spec/latest/json-ld-api/index.html Tue Apr 24 15:31:40 2012 -0700
+++ b/spec/latest/json-ld-api/index.html Tue Apr 24 16:49:23 2012 -0700
@@ -543,7 +543,8 @@
the given <code>input</code>.</dd>
<dt>optional JsonLdOptions options</dt>
<dd>A set of options that MAY affect the expansion algorithm such as, e.g., the
- input document's base <tref>IRI</tref>.</dd>
+ input document's base <tref>IRI</tref>. This also includes <code>optimize</code>,
+ which if set will cause processor-specific optimization.</dd>
</dl>
<dl class="exception" title="InvalidContext">
@@ -618,7 +619,9 @@
<dd>A callback that is called when processing is complete on
the given <code>input</code>.</dd>
<dt>optional JsonLdOptions options</dt>
- <dd>A set of options that will affect the algorithm.</dd>
+ <dd>A set of options that will affect the algorithm. This includes <code>notType</code>,
+ which if set to <tref>true</tref> causes the resulting document to use <code>rdf:type</code>
+ as a property, instead of <code>@type</code>.</dd>
</dl>
</dd>
@@ -730,6 +733,10 @@
optimization is beyond the scope of this specification and thus
not defined. Consequently, different implementations MAY implement
different optimization algorithms.</dd>
+ <dt>boolean noType</dt>
+ <dd>If set to <code>true</code>, the JSON-LD processor will not use the
+ <code>@type</code> property when generating the output, and will use the
+ expanded <code>rdf:type</code> IRI as the property instead of <code>@type</code>.</dd>
</dl>
</section>
@@ -1118,7 +1125,6 @@
<h3>IRI Compaction 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>, 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>,
@@ -1393,10 +1399,18 @@
property from <em>element</em>.</li>
<li>If the <em>property</em> is <code>@id</code> the <em>value</em> MUST be a <tref>string</tref>.
Expand the <em>value</em> according to <a href="#iri-expansion">IRI Expansion</a>.</li>
- <li>Otherwise, if the <em>property</em> is <code>@type</code> the <em>value</em>
- MUST be a <tref>string</tref>, an <tref>array</tref> of <tref>string</tref>s, or an empty
- <tref>JSON object</tref>. Expand <em>value</em> or each of it's entries according to
- <a href="#iri-expansion">IRI Expansion</a>.</li>
+ <li>Otherwise, if the <em>property</em> is <code>@type</code>:
+ <ol class="algorithm">
+ <li>If <em>value</em> is a <tref>string</tref>, expand according to <a href="#iri-expansion">IRI Expansion</a>.</li>
+ <li>Otherwise, if <em>value</em> is a <tref>subject reference</tref>, the expanded value
+ is the result of performing <a href="#iri-expansion">IRI Expansion</a> on the value of <code>@id</code>.</li>
+ <li>Otherwise, if <em>value</em> is a <tref>JSON Object</tref>, it must be empty (used for
+ <a href="#framing">Framing</a>).</li>
+ <li>Otherwise, if <em>value</em> is an <tref>array</tref>, all elements must be either a
+ <tref>string</tref> or <tref>subject reference</tref>. Expand <em>value</em> for each
+ of it's entries using the previous three steps.</li>
+ </ol>
+ </li>
<li>Otherwise, if the <em>property</em> is <code>@value</code> or <code>@language</code> the <em>value</em> MUST NOT be a
<tref>JSON object</tref> or an <tref>array</tref>.</li>
<li>Otherwise, if the <em>property</em> is <code>@list</code>, <code>@set</code>, or <code>@graph</code>, expand <em>value</em>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test-suite/tests/expand-0026-in.jsonld Tue Apr 24 16:49:23 2012 -0700
@@ -0,0 +1,20 @@
+{
+ "@context": {
+ "http://www.w3.org/1999/02/22-rdf-syntax-ns#type": {"@id": "@type", "@type": "@id"}
+ },
+ "@graph": [
+ {
+ "@id": "http://example.com/a",
+ "http://www.w3.org/1999/02/22-rdf-syntax-ns#type": "http://example.com/b"
+ }, {
+ "@id": "http://example.com/c",
+ "http://www.w3.org/1999/02/22-rdf-syntax-ns#type": [
+ "http://example.com/d",
+ {"@id": "http://example.com/e"}
+ ]
+ }, {
+ "@id": "http://example.com/f",
+ "http://www.w3.org/1999/02/22-rdf-syntax-ns#type": {"@id": "http://example.com/g"}
+ }
+ ]
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test-suite/tests/expand-0026-out.jsonld Tue Apr 24 16:49:23 2012 -0700
@@ -0,0 +1,21 @@
+[
+ {
+ "@id": "http://example.com/a",
+ "@type": [
+ "http://example.com/b"
+ ]
+ },
+ {
+ "@id": "http://example.com/c",
+ "@type": [
+ "http://example.com/d",
+ "http://example.com/e"
+ ]
+ },
+ {
+ "@id": "http://example.com/f",
+ "@type": [
+ "http://example.com/g"
+ ]
+ }
+]
\ No newline at end of file
--- a/test-suite/tests/expand-manifest.jsonld Tue Apr 24 15:31:40 2012 -0700
+++ b/test-suite/tests/expand-manifest.jsonld Tue Apr 24 16:49:23 2012 -0700
@@ -129,5 +129,10 @@
"name": "Problematic IRI expansion tests",
"input": "expand-0025-in.jsonld",
"expect": "expand-0025-out.jsonld"
+ }, {
+ "@type": ["test:TestCase", "jld:ExpandTest"],
+ "name": "Expanding term mapping to @type uses @type syntax",
+ "input": "expand-0026-in.jsonld",
+ "expect": "expand-0026-out.jsonld"
}]
}