Skip to content

Commit

Permalink
Merge pull request #462 from json-ld/issue-415-scope-on-type
Browse files Browse the repository at this point in the history
Issue 415 scope on type
  • Loading branch information
gkellogg committed Feb 15, 2017
2 parents 5644fdd + 4a06154 commit 297d6d7
Show file tree
Hide file tree
Showing 48 changed files with 652 additions and 107 deletions.
64 changes: 32 additions & 32 deletions spec/latest/common/terms.html

Large diffs are not rendered by default.

135 changes: 94 additions & 41 deletions spec/latest/json-ld-api/index.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion spec/latest/json-ld-framing/index.html
Expand Up @@ -199,7 +199,7 @@ <h2>How to Read this Document</h2>

<p>
To understand the basics in this specification you must first be familiar with
<a data-cite="rfc7159">JSON</a>, which is detailed in [[!RFC7159]]. You must also understand the
<a data-cite="RFC7159">JSON</a>, which is detailed in [[!RFC7159]]. You must also understand the
JSON-LD Syntax [[!JSON-LD]], which is the base syntax used by all of the
algorithms in this document,
and the JSON-LD API [[!JSON-LD-API]]. To understand the API and how it is
Expand Down
82 changes: 55 additions & 27 deletions spec/latest/json-ld/index.html
Expand Up @@ -220,7 +220,7 @@ <h2>How to Read this Document</h2>
providing a standard library interface for common JSON-LD operations.</p>

<p>To understand the basics in this specification you must first be familiar with
<a data-cite="rfc7159">JSON</a>, which is detailed in [[!RFC7159]].</p>
<a data-cite="RFC7159">JSON</a>, which is detailed in [[!RFC7159]].</p>

<p>This document almost exclusively uses the term IRI
(<a data-cite="ld-glossary#internationalized-resource-identifier">Internationalized Resource Indicator</a>)
Expand Down Expand Up @@ -450,7 +450,7 @@ <h1>Basic Concepts</h1>
tokens such as "name", "homepage", etc.</p>

<p>Linked Data, and the Web in general, uses <a>IRIs</a>
(<a data-cite="rfc3987#section-2">Internationalized Resource Identifiers</a> as described in [[!RFC3987]]) for unambiguous
(<a data-cite="RFC3987#section-2">Internationalized Resource Identifiers</a> as described in [[!RFC3987]]) for unambiguous
identification. The idea is to use <a>IRIs</a>
to assign unambiguous identifiers to data that may be of use to other developers.
It is useful for <a>terms</a>,
Expand Down Expand Up @@ -571,7 +571,7 @@ <h2>The Context</h2>
is ignored when the document is used as an external JSON-LD context document.</p>

<p>JSON documents can be interpreted as JSON-LD without having to be modified by
referencing a <a>context</a> via an <a data-cite="rfc5988#section-5">HTTP Link Header</a>
referencing a <a>context</a> via an <a data-cite="RFC5988#section-5">HTTP Link Header</a>
as described in <a class="sectionRef" href="#interpreting-json-as-json-ld"></a>. It is also
possible to apply a custom context using the JSON-LD API [[JSON-LD-API]].</p>

Expand Down Expand Up @@ -613,12 +613,12 @@ <h2>The Context</h2>
<section class="informative">
<h2>IRIs</h2>

<p><a>IRIs</a> (<a data-cite="rfc3987#section-2">Internationalized Resource Identifiers</a>
<p><a>IRIs</a> (<a data-cite="RFC3987#section-2">Internationalized Resource Identifiers</a>
[[!RFC3987]]) are fundamental to Linked Data as that is how most
<a>nodes</a> and <a>properties</a>
are identified. In JSON-LD, IRIs may be represented as an
<a>absolute IRI</a> or a <a>relative IRI</a>. An
<a data-cite="rfc3987#section-1.3">absolute IRI</a> is defined in [[!RFC3987]] as containing a
<a data-cite="RFC3987#section-1.3">absolute IRI</a> is defined in [[!RFC3987]] as containing a
<em>scheme</em> along with <em>path</em> and optional <em>query</em> and
<em>fragment</em> segments. A <a>relative IRI</a> is an IRI
that is relative to some other <a>absolute IRI</a>.
Expand Down Expand Up @@ -863,7 +863,7 @@ <h2>Base IRI</h2>

<p>JSON-LD allows <a>IRI</a>s to be specified in a relative form which is
resolved against the document base according
<a data-cite="rfc3986#section-5.1">section 5.1 Establishing a Base URI</a>
<a data-cite="RFC3986#section-5.1">section 5.1 Establishing a Base URI</a>
of [[RFC3986]]. The <a>base IRI</a> may be explicitly set with a <a>context</a>
using the <code>@base</code> keyword.</p>

Expand Down Expand Up @@ -1491,7 +1491,7 @@ <h2>Advanced Context Usage</h2>
<h2>Interpreting JSON as JSON-LD</h2>

<p>Ordinary JSON documents can be interpreted as JSON-LD by referencing a JSON-LD
<a>context</a> document in an <a data-cite="rfc5988#section-5">HTTP Link Header</a>. Doing so allows JSON to
<a>context</a> document in an <a data-cite="RFC5988#section-5">HTTP Link Header</a>. Doing so allows JSON to
be unambiguously machine-readable without requiring developers to drastically
change their documents and provides an upgrade path for existing infrastructure
without breaking existing clients that rely on the <code>application/json</code>
Expand All @@ -1500,7 +1500,7 @@ <h2>Interpreting JSON as JSON-LD</h2>

<p>In order to use an external context with an ordinary JSON document, an author
MUST specify an <a>IRI</a> to a valid <a>JSON-LD document</a> in
an <a data-cite="rfc5988#section-5">HTTP Link Header</a> [[!RFC5988]] using the <code>http://www.w3.org/ns/json-ld#context</code>
an <a data-cite="RFC5988#section-5">HTTP Link Header</a> [[!RFC5988]] using the <code>http://www.w3.org/ns/json-ld#context</code>
link relation. The referenced document MUST have a top-level <a>JSON object</a>.
The <code>@context</code> subtree within that object is added to the top-level
<a>JSON object</a> of the referencing document. If an <a>array</a>
Expand All @@ -1510,7 +1510,7 @@ <h2>Interpreting JSON as JSON-LD</h2>
of the <code>@context</code> subtree in the referenced document MUST be
discarded. Effectively this means that the <a>active context</a> is
initialized with the referenced external <a>context</a>. A response MUST NOT
contain more than one <a data-cite="rfc5988#section-5">HTTP Link Header</a> [[!RFC5988]] using the
contain more than one <a data-cite="RFC5988#section-5">HTTP Link Header</a> [[!RFC5988]] using the
<code>http://www.w3.org/ns/json-ld#context</code> link relation.</p>

<p>The following example demonstrates the use of an external context with an
Expand Down Expand Up @@ -1542,7 +1542,7 @@ <h2>Interpreting JSON as JSON-LD</h2>
served with the <code>application/ld+json</code>
media type MUST have all context information, including references to external
contexts, within the body of the document. Contexts linked via a
<code>http://www.w3.org/ns/json-ld#context</code> <a data-cite="rfc5988#section-5">HTTP Link Header</a> MUST be
<code>http://www.w3.org/ns/json-ld#context</code> <a data-cite="RFC5988#section-5">HTTP Link Header</a> MUST be
ignored for such documents.</p>
</section>

Expand Down Expand Up @@ -1571,7 +1571,7 @@ <h2>String Internationalization</h2>

<p>The example above would associate the <code>ja</code> language
code with the two <a>strings</a> <em>花澄</em> and <em>科学者</em>.
<a data-cite="bcp47#section-2">Languages codes</a> are defined in [[!BCP47]]. The <a>default language</a> applies to all
<a data-cite="BCP47#section-2">Languages codes</a> are defined in [[!BCP47]]. The <a>default language</a> applies to all
<a>string</a> values that are not <a href="#type-coercion">type coerced</a>.</p>

<p>To clear the <a>default language</a> for a subtree, <code>@language</code> can
Expand Down Expand Up @@ -2150,7 +2150,7 @@ <h2>Scoped Contexts</h2>
{
"name": "http://schema.org/name",
"interest": {
"@id":"http://xmlns.com/foaf/0.1/interest",
"@id": "http://xmlns.com/foaf/0.1/interest",
****"@context": {"@vocab": "http://xmlns.com/foaf/0.1/"}****
}
},
Expand Down Expand Up @@ -2186,7 +2186,6 @@ <h2>Scoped Contexts</h2>
<a>expanded term definitions</a>
to create reverse properties as shown in the following example:</p>


<pre class="example" data-transform="updateExample"
title="Using @reverse to define reverse properties">
<!--
Expand All @@ -2210,6 +2209,35 @@ <h2>Scoped Contexts</h2>
}
-->
</pre>

<p>Scoping can also be performed using a term used as a value of <code>@type</code>:</p>

<pre class="example" data-transform="updateExample"
title="Defining an @context within a term definition used on @type">
<!--
{
"@context":
{
"name": "http://schema.org/name",
"interest": "http://xmlns.com/foaf/0.1/interest",
****"Document"****: {
"@id": "http://xmlns.com/foaf/0.1/Document",
****"@context": {"@vocab": "http://xmlns.com/foaf/0.1/"}****
}
},
"@type": "Person",
"name": "Manu Sporny",
"interest": {
"@id": "https://www.w3.org/TR/json-ld/",
****"@type": "Document"****,
"name": "JSON-LD",
"topic": "Linking Data"
}
}
-->
</pre>

<p>Scoping on <code>@type</code> is useful when common properties are used to relate things of different types, where the vocabularies in use within different entities calls for different context scoping. For example, `hasPart`/`partOf` may be common terms used in a document, but mean different things depending on the context.</p>
</section>


Expand Down Expand Up @@ -3017,7 +3045,7 @@ <h1>Data Model</h1>
<p>JSON-LD is a serialization format for Linked Data based on JSON.
It is therefore important to distinguish between the syntax, which is
defined by JSON in [[!RFC7159]], and the <dfn>data model</dfn> which is
an extension of the <a data-cite="rdf11-concepts#data-model">RDF data model</a> [[!RDF11-CONCEPTS]]. The precise
an extension of the <a data-cite="RDF11-CONCEPTS#data-model">RDF data model</a> [[!RDF11-CONCEPTS]]. The precise
details of how JSON-LD relates to the RDF data model are given in
<a class="sectionRef" href="#relationship-to-rdf"></a>.</p>

Expand Down Expand Up @@ -3071,14 +3099,14 @@ <h1>Data Model</h1>
<li>A <a>typed value</a> consists of a value, which is a string, and a type, which is an
<a>IRI</a>.</li>
<li>A <a>language-tagged string</a>
consists of a string and a non-empty <a data-cite="bcp47#section-2">language tag</a> as defined by [[BCP47]].
consists of a string and a non-empty <a data-cite="BCP47#section-2">language tag</a> as defined by [[BCP47]].
The language tag MUST be well-formed according to section
<a data-cite="bcp47#section-2.2.9">2.2.9 Classes of Conformance</a>
<a data-cite="BCP47#section-2.2.9">2.2.9 Classes of Conformance</a>
of [[BCP47]].</li>
<li>A <a>list</a> is a sequence of zero or more <a>IRIs</a>,
<a>blank nodes</a>, and <a>JSON-LD values</a>.
<a>Lists</a> are interpreted as
<dfn data-cite="rdf11-mt#rdf-collections">RDF list structures</dfn> [[RDF11-MT]].</li>
<dfn data-cite="RDF11-MT#rdf-collections">RDF list structures</dfn> [[RDF11-MT]].</li>
</ul>

<p><a>JSON-LD documents</a> MAY contain data
Expand All @@ -3098,7 +3126,7 @@ <h1>JSON-LD Grammar</h1>
<p>This appendix restates the syntactic conventions described in the
previous sections more formally.</p>

<p>A <a>JSON-LD document</a> MUST be valid <a data-cite="rfc7159#section-2">JSON text</a> as described
<p>A <a>JSON-LD document</a> MUST be valid <a data-cite="RFC7159#section-2">JSON text</a> as described
in [[!RFC7159]].</p>

<p>A <a>JSON-LD document</a> MUST be a single <a>node object</a>
Expand Down Expand Up @@ -3277,7 +3305,7 @@ <h2>Value Objects</h2>
an <a>absolute IRI</a>, a <a>relative IRI</a>, or <a>null</a>.</p>

<p>The value associated with the <code>@language</code> key MUST have the
<a data-cite="bcp47#section-2.1.1">lexical form</a> described in [[!BCP47]], or be <a>null</a>.</p>
<a data-cite="BCP47#section-2.1.1">lexical form</a> described in [[!BCP47]], or be <a>null</a>.</p>

<p>The value associated with the <code>@index</code> key MUST be a
<a>string</a>.</p>
Expand Down Expand Up @@ -3429,7 +3457,7 @@ <h2>Context Definitions</h2>
and <code>@vocab</code>.</p>

<p>If the <a>context definition</a> has an <code>@language</code> key,
its value MUST have the <a data-cite="bcp47#section-2.1.1">lexical form</a> described in [[!BCP47]] or be <a>null</a>.</p>
its value MUST have the <a data-cite="BCP47#section-2.1.1">lexical form</a> described in [[!BCP47]] or be <a>null</a>.</p>

<p>If the <a>context definition</a> has an <code>@base</code> key,
its value MUST be an <a>absolute IRI</a>, a <a>relative IRI</a>,
Expand Down Expand Up @@ -3475,7 +3503,7 @@ <h2>Context Definitions</h2>
<a>keyword</a> <code>@id</code> or <code>@vocab</code>.</p>

<p>If the <a>expanded term definition</a> contains the <code>@language</code> <a>keyword</a>,
its value MUST have the <a data-cite="bcp47#section-2.1.1">lexical form</a> described in [[!BCP47]] or be <a>null</a>.</p>
its value MUST have the <a data-cite="BCP47#section-2.1.1">lexical form</a> described in [[!BCP47]] or be <a>null</a>.</p>

<p>If the <a>expanded term definition</a> contains the <code>@container</code>
<a>keyword</a>, its value MUST be either <code>@list</code>, <code>@set</code>,
Expand Down Expand Up @@ -3506,12 +3534,12 @@ <h2>Context Definitions</h2>
<h2>Relationship to RDF</h2>

<p>JSON-LD is a
<dfn data-cite="rdf11-concepts#dfn-concrete-rdf-syntax">concrete RDF syntax</dfn>
<dfn data-cite="RDF11-CONCEPTS#dfn-concrete-rdf-syntax">concrete RDF syntax</dfn>
as described in [[RDF11-CONCEPTS]]. Hence, a JSON-LD document is both an
RDF document <em>and</em> a JSON document and correspondingly represents an
instance of an RDF data model. However, JSON-LD also extends the RDF data
model to optionally allow JSON-LD to serialize
<dfn data-cite="rdf11-concepts#dfn-generalized-rdf-dataset" data-lt="generalized rdf dataset">generalized RDF Datasets</dfn>.
<dfn data-cite="RDF11-CONCEPTS#dfn-generalized-rdf-dataset" data-lt="generalized rdf dataset">generalized RDF Datasets</dfn>.
The JSON-LD extensions to the RDF data model are:</p>

<ul>
Expand Down Expand Up @@ -3559,7 +3587,7 @@ <h2>Relationship to RDF</h2>
<a>blank nodes</a> used as
<a>properties</a> to <a>IRIs</a>,
by minting new "Skolem IRIs" as per
<a data-cite="rdf11-concepts#section-skolemization">Replacing Blank Nodes with IRIs</a>
<a data-cite="RDF11-CONCEPTS#section-skolemization">Replacing Blank Nodes with IRIs</a>
of [[RDF11-CONCEPTS]].</li>
</ul>

Expand All @@ -3569,7 +3597,7 @@ <h2>Relationship to RDF</h2>

<p>Even though JSON-LD serializes
<a>generalized RDF Datasets</a>, it can
also be used as a <dfn data-cite="rdf11-concepts#dfn-rdf-source">RDF graph source</dfn>.
also be used as a <dfn data-cite="RDF11-CONCEPTS#dfn-rdf-source">RDF graph source</dfn>.
In that case, a consumer MUST only use the default graph and ignore all named graphs.
This allows servers to expose data in languages such as Turtle and JSON-LD
using content negotiation.</p>
Expand Down Expand Up @@ -4101,7 +4129,7 @@ <h3>application/ld+json</h3>
<p>When processing the "profile" media type parameter, it is important to
note that its value contains one or more URIs and not IRIs. In some cases
it might therefore be necessary to convert between IRIs and URIs as specified in
<a data-cite="rfc3986#section-5.1">section 3 Relationship between IRIs and URIs</a>
<a data-cite="RFC3986#section-5.1">section 3 Relationship between IRIs and URIs</a>
of [[RFC3987]].</p>
</dd>
</dl>
Expand Down Expand Up @@ -4169,7 +4197,7 @@ <h3>application/ld+json</h3>

<p>Fragment identifiers used with <a href="#application-ld-json">application/ld+json</a>
are treated as in RDF syntaxes, as per
<a data-cite="rdf11-concepts#section-fragID">RDF 1.1 Concepts and Abstract Syntax</a>
<a data-cite="RDF11-CONCEPTS#section-fragID">RDF 1.1 Concepts and Abstract Syntax</a>
[[RDF11-CONCEPTS]].</p>
</section>

Expand Down
7 changes: 7 additions & 0 deletions test-suite/tests/compact-m005-context.jsonld
@@ -0,0 +1,7 @@
{
"@context": {
"@vocab": "http://example/",
"ex": "http://example.org/",
"idmap": {"@container": "@id"}
}
}
5 changes: 5 additions & 0 deletions test-suite/tests/compact-m005-in.jsonld
@@ -0,0 +1,5 @@
[{
"http://example/idmap": [
{"http://example/label": [{"@value": "Object with @id <foo>"}], "@id": "http://example.org/foo"}
]
}]
10 changes: 10 additions & 0 deletions test-suite/tests/compact-m005-out.jsonld
@@ -0,0 +1,10 @@
{
"@context": {
"@vocab": "http://example/",
"ex": "http://example.org/",
"idmap": {"@container": "@id"}
},
"idmap": {
"ex:foo": {"label": "Object with @id <foo>"}
}
}
6 changes: 6 additions & 0 deletions test-suite/tests/compact-m006-context.jsonld
@@ -0,0 +1,6 @@
{
"@context": {
"@vocab": "http://example/",
"typemap": {"@container": "@type"}
}
}
5 changes: 5 additions & 0 deletions test-suite/tests/compact-m006-in.jsonld
@@ -0,0 +1,5 @@
[{
"http://example/typemap": [
{"http://example/label": [{"@value": "Object with @type <foo>"}], "@type": ["http://example/Foo"]}
]
}]
9 changes: 9 additions & 0 deletions test-suite/tests/compact-m006-out.jsonld
@@ -0,0 +1,9 @@
{
"@context": {
"@vocab": "http://example/",
"typemap": {"@container": "@type"}
},
"typemap": {
"Foo": {"label": "Object with @type <foo>"}
}
}
6 changes: 6 additions & 0 deletions test-suite/tests/compact-m007-context.jsonld
@@ -0,0 +1,6 @@
{
"@context": {
"@vocab": "http://example/",
"Foo": {"@context": {"bar": "http://example.org/bar"}}
}
}
8 changes: 8 additions & 0 deletions test-suite/tests/compact-m007-in.jsonld
@@ -0,0 +1,8 @@
[
{
"http://example/a": [{
"@type": ["http://example/Foo"],
"http://example.org/bar": [{"@value": "baz"}]
}]
}
]
7 changes: 7 additions & 0 deletions test-suite/tests/compact-m007-out.jsonld
@@ -0,0 +1,7 @@
{
"@context": {
"@vocab": "http://example/",
"Foo": {"@context": {"bar": "http://example.org/bar"}}
},
"a": {"@type": "Foo", "bar": "baz"}
}
7 changes: 7 additions & 0 deletions test-suite/tests/compact-m008-context.jsonld
@@ -0,0 +1,7 @@
{
"@context": {
"@vocab": "http://example/",
"Foo": {"@context": {"bar": {"@type": "@id"}}},
"bar": {"@type": "http://www.w3.org/2001/XMLSchema#string"}
}
}
8 changes: 8 additions & 0 deletions test-suite/tests/compact-m008-in.jsonld
@@ -0,0 +1,8 @@
[
{
"http://example/a": [{
"@type": ["http://example/Foo"],
"http://example/bar": [{"@id": "http://example/baz"}]
}]
}
]
8 changes: 8 additions & 0 deletions test-suite/tests/compact-m008-out.jsonld
@@ -0,0 +1,8 @@
{
"@context": {
"@vocab": "http://example/",
"Foo": {"@context": {"bar": {"@type": "@id"}}},
"bar": {"@type": "http://www.w3.org/2001/XMLSchema#string"}
},
"a": {"@type": "Foo", "bar": "http://example/baz"}
}
7 changes: 7 additions & 0 deletions test-suite/tests/compact-m009-context.jsonld
@@ -0,0 +1,7 @@
{
"@context": {
"@vocab": "http://example/",
"type": "@type",
"Foo": {"@context": {"bar": "http://example.org/bar"}}
}
}

0 comments on commit 297d6d7

Please sign in to comment.