From a2b449d134654799b8f028713e7b656710fbcf56 Mon Sep 17 00:00:00 2001 From: Markus Lanthaler Date: Wed, 1 Aug 2012 17:17:34 +0200 Subject: [PATCH] Reintroduce @vocab This closes #26. --- spec/latest/json-ld-api/index.html | 18 +- spec/latest/json-ld-syntax/index.html | 33 ++- test-suite/tests/expand-0028-in.jsonld | 13 ++ test-suite/tests/expand-0028-out.jsonld | 23 ++ test-suite/tests/expand-manifest.jsonld | 279 ++++++++++++------------ 5 files changed, 220 insertions(+), 146 deletions(-) create mode 100644 test-suite/tests/expand-0028-in.jsonld create mode 100644 test-suite/tests/expand-0028-out.jsonld diff --git a/spec/latest/json-ld-api/index.html b/spec/latest/json-ld-api/index.html index b37ce8764..50613de71 100644 --- a/spec/latest/json-ld-api/index.html +++ b/spec/latest/json-ld-api/index.html @@ -1203,6 +1203,8 @@

Context Processing

  1. If context has a @language property, it MUST have a value of a simple string or null. Add the language to the local context.
  2. +
  3. If value has a @vocab key, it MUST have a value of a simple string + with the lexical form of an absolute IRI. Add the vocabulary mapping to the local context.
  4. Otherwise, for each property in context perform the following steps:
    1. If the property's value is a simple string, determine the IRI mapping value by @@ -1272,7 +1274,8 @@

      Context Processing

      IRI Expansion

      Keys and some values are evaluated to produce an IRI. This section defines an algorithm for transforming a value representing an IRI into an actual IRI.

      -

      IRIs may be represented as an absolute IRI, a term or a compact IRI.

      +

      IRIs may be represented as an absolute IRI, a term, + a compact IRI, or as a value relative to @vocab.

      An absolute IRI is defined in [[!RFC3987]] containing a scheme along with path and optional query and fragment segments. A relative IRI is an IRI that is relative some other absolute IRI; in the case of JSON-LD this is the base location @@ -1290,14 +1293,12 @@

      IRI Expansion

      authority (as defined in [[!RFC3986]]), generate an IRI by prepending the mapped prefix to the (possibly empty) suffix using textual concatenation. Note that an empty suffix and no suffix (meaning the value contains no ':' string at all) are treated equivalently.
    2. +
    3. Otherwise, if the IRI being processed does not contain a colon and is a property, i.e., a key's value in + a JSON object, or the value of @type and the active context has a + @vocab mapping, join the mapped value to the suffix using textual concatenation.
    4. Otherwise, use the value directly as an IRI.

    -

    - Previous versions of this specification used @base and @vocab to define IRI prefixes - used to resolve relative IRIs. It was determined that this added too much complexity, but the issue - can be re-examined in the future based on community input. -

    @@ -1359,7 +1360,10 @@

    IRI Compaction Algorithm

    term associated with the partially matched IRI in the active context concatenated with a colon (:) character and the unmatched part of iri.
  5. -
  6. If terms is empty, return iri.
  7. +
  8. If terms is empty, the IRI being processed is a property or the + value of @type and @vocab is not null and matches the beginning + of iri, return the unmatched portion of iri. Otherwise return + iri.
  9. Otherwise, return the shortest and lexicographically least value in terms.

diff --git a/spec/latest/json-ld-syntax/index.html b/spec/latest/json-ld-syntax/index.html index ccca737c9..817423675 100644 --- a/spec/latest/json-ld-syntax/index.html +++ b/spec/latest/json-ld-syntax/index.html @@ -594,6 +594,9 @@

Syntax Tokens and Keywords

@set
Used to express an unordered set of data. This keyword is described in the section titled .
+
@vocab
+
Used to set the base IRI for all property IRIs affected by the + active context. This keyword is described in section .
:
The separator for JSON keys and values that use compact IRIs.
@@ -823,15 +826,16 @@

IRIs

  1. Except within a context definition, terms in the key position in - a JSON object that have a mapping to an absolute IRI or another term in the - active context are expanded to an IRI by JSON-LD processors.
  2. + a JSON object that have a mapping or a vocabulary base IRI in the + active context are expanded to an IRI by JSON-LD processors.
  3. An IRI is generated for the string value specified using @id or @type.
  4. An IRI is generated for the string value of any key for which there are coercion rules in effect that identify the value as an @id.
-

IRIs may be represented as an absolute IRI, a relative IRI, a term, or a compact IRI.

+

IRIs may be represented as an absolute IRI, a relative IRI, a term, + a compact IRI, or as a value relative to @vocab.

An absolute IRI is defined in [[!RFC3987]] containing a scheme along with path and optional query and fragment segments. A relative IRI is an IRI @@ -906,6 +910,29 @@

IRIs

foaf:name above will automatically expand out to the IRI http://xmlns.com/foaf/0.1/name. See for more details.

+

If the @vocab is set, all keys that do not match a term or a prefix + are + + +It is often common that all types and properties come from the same vocabulary. JSON-LD's +@vocab keyword allows to set a base IRI to be used for all properties and types +that that do not match a term, a prefix, or an absolute IRI +(i.e., do not contain a colon). The @vocab mapping MUST have a value of a simple string with the +lexical form of an absolute IRI.

+ +
+
+
+

An IRI is generated when a JSON object is used in the value position that contains an @id keyword:

diff --git a/test-suite/tests/expand-0028-in.jsonld b/test-suite/tests/expand-0028-in.jsonld new file mode 100644 index 000000000..4f05d0e4f --- /dev/null +++ b/test-suite/tests/expand-0028-in.jsonld @@ -0,0 +1,13 @@ +{ + "@context": { + "@vocab": "http://example.org/vocab#", + "date": { "@type": "dateTime" } + }, + "@id": "example1", + "@type": "test", + "date": "2011-01-25T00:00:00Z", + "embed": { + "@id": "example2", + "expandedDate": { "@value": "2012-08-01T00:00:00Z", "@type": "dateTime" } + } +} diff --git a/test-suite/tests/expand-0028-out.jsonld b/test-suite/tests/expand-0028-out.jsonld new file mode 100644 index 000000000..82fcf504d --- /dev/null +++ b/test-suite/tests/expand-0028-out.jsonld @@ -0,0 +1,23 @@ +[ + { + "@id": "example1", + "@type": "http://example.org/vocab#test", + "http://example.org/vocab#date": [ + { + "@value": "2011-01-25T00:00:00Z", + "@type": "http://example.org/vocab#dateTime" + } + ], + "http://example.org/vocab#embed": [ + { + "@id": "example2", + "http://example.org/vocab#expandedDate": [ + { + "@value": "2012-08-01T00:00:00Z", + "@type": "http://example.org/vocab#dateTime" + } + ] + } + ] + } +] diff --git a/test-suite/tests/expand-manifest.jsonld b/test-suite/tests/expand-manifest.jsonld index a26c5e2c2..62ed749ad 100644 --- a/test-suite/tests/expand-manifest.jsonld +++ b/test-suite/tests/expand-manifest.jsonld @@ -4,140 +4,147 @@ "@type": "jld:Manifest", "rdfs:comment": "JSON-LD to Expansion tests use object compare", "name": "expand", - "sequence": [{ - "@type": ["test:TestCase", "jld:ExpandTest"], - "name": "id", - "input": "expand-0001-in.jsonld", - "expect": "expand-0001-out.jsonld" - }, { - "@type": ["test:TestCase", "jld:ExpandTest"], - "name": "basic", - "input": "expand-0002-in.jsonld", - "expect": "expand-0002-out.jsonld" - }, { - "@type": ["test:TestCase", "jld:ExpandTest"], - "name": "drop null and unmapped properties", - "input": "expand-0003-in.jsonld", - "expect": "expand-0003-out.jsonld" - }, { - "@type": ["test:TestCase", "jld:ExpandTest"], - "name": "optimize @set, keep empty arrays", - "input": "expand-0004-in.jsonld", - "expect": "expand-0004-out.jsonld" - }, { - "@type": ["test:TestCase", "jld:ExpandTest"], - "name": "do not expand aliased @id/@type", - "input": "expand-0005-in.jsonld", - "expect": "expand-0005-out.jsonld" - }, { - "@type": ["test:TestCase", "jld:ExpandTest"], - "name": "alias keywords", - "input": "expand-0006-in.jsonld", - "expect": "expand-0006-out.jsonld" - }, { - "@type": ["test:TestCase", "jld:ExpandTest"], - "name": "date type-coercion", - "input": "expand-0007-in.jsonld", - "expect": "expand-0007-out.jsonld" - }, { - "@type": ["test:TestCase", "jld:ExpandTest"], - "name": "@value with @language", - "input": "expand-0008-in.jsonld", - "expect": "expand-0008-out.jsonld" - }, { - "@type": ["test:TestCase", "jld:ExpandTest"], - "name": "@graph with terms", - "input": "expand-0009-in.jsonld", - "expect": "expand-0009-out.jsonld" - }, { - "@type": ["test:TestCase", "jld:ExpandTest"], - "name": "native types", - "input": "expand-0010-in.jsonld", - "expect": "expand-0010-out.jsonld" - }, { - "@type": ["test:TestCase", "jld:ExpandTest"], - "name": "coerced @id", - "input": "expand-0011-in.jsonld", - "expect": "expand-0011-out.jsonld" - }, { - "@type": ["test:TestCase", "jld:ExpandTest"], - "name": "@graph with embed", - "input": "expand-0012-in.jsonld", - "expect": "expand-0012-out.jsonld" - }, { - "@type": ["test:TestCase", "jld:ExpandTest"], - "name": "expand already expanded", - "input": "expand-0013-in.jsonld", - "expect": "expand-0013-out.jsonld" - }, { - "@type": ["test:TestCase", "jld:ExpandTest"], - "name": "@set of @value objects with keyword aliases", - "input": "expand-0014-in.jsonld", - "expect": "expand-0014-out.jsonld" - }, { - "@type": ["test:TestCase", "jld:ExpandTest"], - "name": "collapse set of sets, keep empty lists", - "input": "expand-0015-in.jsonld", - "expect": "expand-0015-out.jsonld" - }, { - "@type": ["test:TestCase", "jld:ExpandTest"], - "name": "context reset", - "input": "expand-0016-in.jsonld", - "expect": "expand-0016-out.jsonld" - }, { - "@type": ["test:TestCase", "jld:ExpandTest"], - "name": "@graph and @id aliased", - "input": "expand-0017-in.jsonld", - "expect": "expand-0017-out.jsonld" - }, { - "@type": ["test:TestCase", "jld:ExpandTest"], - "name": "override default @language in terms", - "input": "expand-0018-in.jsonld", - "expect": "expand-0018-out.jsonld" - }, { - "@type": ["test:TestCase", "jld:ExpandTest"], - "name": "remove @value = null", - "input": "expand-0019-in.jsonld", - "expect": "expand-0019-out.jsonld" - }, { - "@type": ["test:TestCase", "jld:ExpandTest"], - "name": "do not remove @graph if not at top-level", - "input": "expand-0020-in.jsonld", - "expect": "expand-0020-out.jsonld" - }, { - "@type": ["test:TestCase", "jld:ExpandTest"], - "name": "do not remove @graph at top-level if not only property", - "input": "expand-0021-in.jsonld", - "expect": "expand-0021-out.jsonld" - }, { - "@type": ["test:TestCase", "jld:ExpandTest"], - "name": "expand value with default language", - "input": "expand-0022-in.jsonld", - "expect": "expand-0022-out.jsonld" - }, { - "@type": ["test:TestCase", "jld:ExpandTest"], - "name": "Expanding lists and sets with properties having coercion coerces list/set values", - "input": "expand-0023-in.jsonld", - "expect": "expand-0023-out.jsonld" - }, { - "@type": ["test:TestCase", "jld:ExpandTest"], - "name": "Multiple contexts", - "input": "expand-0024-in.jsonld", - "expect": "expand-0024-out.jsonld" - }, { - "@type": ["test:TestCase", "jld:ExpandTest"], - "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" - }, { - "@type": ["test:TestCase", "jld:ExpandTest"], - "name": "Keep duplicate values in @list and @set", - "input": "expand-0027-in.jsonld", - "expect": "expand-0027-out.jsonld" - }] + "sequence": [ + { + "@type": ["test:TestCase", "jld:ExpandTest"], + "name": "id", + "input": "expand-0001-in.jsonld", + "expect": "expand-0001-out.jsonld" + }, { + "@type": ["test:TestCase", "jld:ExpandTest"], + "name": "basic", + "input": "expand-0002-in.jsonld", + "expect": "expand-0002-out.jsonld" + }, { + "@type": ["test:TestCase", "jld:ExpandTest"], + "name": "drop null and unmapped properties", + "input": "expand-0003-in.jsonld", + "expect": "expand-0003-out.jsonld" + }, { + "@type": ["test:TestCase", "jld:ExpandTest"], + "name": "optimize @set, keep empty arrays", + "input": "expand-0004-in.jsonld", + "expect": "expand-0004-out.jsonld" + }, { + "@type": ["test:TestCase", "jld:ExpandTest"], + "name": "do not expand aliased @id/@type", + "input": "expand-0005-in.jsonld", + "expect": "expand-0005-out.jsonld" + }, { + "@type": ["test:TestCase", "jld:ExpandTest"], + "name": "alias keywords", + "input": "expand-0006-in.jsonld", + "expect": "expand-0006-out.jsonld" + }, { + "@type": ["test:TestCase", "jld:ExpandTest"], + "name": "date type-coercion", + "input": "expand-0007-in.jsonld", + "expect": "expand-0007-out.jsonld" + }, { + "@type": ["test:TestCase", "jld:ExpandTest"], + "name": "@value with @language", + "input": "expand-0008-in.jsonld", + "expect": "expand-0008-out.jsonld" + }, { + "@type": ["test:TestCase", "jld:ExpandTest"], + "name": "@graph with terms", + "input": "expand-0009-in.jsonld", + "expect": "expand-0009-out.jsonld" + }, { + "@type": ["test:TestCase", "jld:ExpandTest"], + "name": "native types", + "input": "expand-0010-in.jsonld", + "expect": "expand-0010-out.jsonld" + }, { + "@type": ["test:TestCase", "jld:ExpandTest"], + "name": "coerced @id", + "input": "expand-0011-in.jsonld", + "expect": "expand-0011-out.jsonld" + }, { + "@type": ["test:TestCase", "jld:ExpandTest"], + "name": "@graph with embed", + "input": "expand-0012-in.jsonld", + "expect": "expand-0012-out.jsonld" + }, { + "@type": ["test:TestCase", "jld:ExpandTest"], + "name": "expand already expanded", + "input": "expand-0013-in.jsonld", + "expect": "expand-0013-out.jsonld" + }, { + "@type": ["test:TestCase", "jld:ExpandTest"], + "name": "@set of @value objects with keyword aliases", + "input": "expand-0014-in.jsonld", + "expect": "expand-0014-out.jsonld" + }, { + "@type": ["test:TestCase", "jld:ExpandTest"], + "name": "collapse set of sets, keep empty lists", + "input": "expand-0015-in.jsonld", + "expect": "expand-0015-out.jsonld" + }, { + "@type": ["test:TestCase", "jld:ExpandTest"], + "name": "context reset", + "input": "expand-0016-in.jsonld", + "expect": "expand-0016-out.jsonld" + }, { + "@type": ["test:TestCase", "jld:ExpandTest"], + "name": "@graph and @id aliased", + "input": "expand-0017-in.jsonld", + "expect": "expand-0017-out.jsonld" + }, { + "@type": ["test:TestCase", "jld:ExpandTest"], + "name": "override default @language in terms", + "input": "expand-0018-in.jsonld", + "expect": "expand-0018-out.jsonld" + }, { + "@type": ["test:TestCase", "jld:ExpandTest"], + "name": "remove @value = null", + "input": "expand-0019-in.jsonld", + "expect": "expand-0019-out.jsonld" + }, { + "@type": ["test:TestCase", "jld:ExpandTest"], + "name": "do not remove @graph if not at top-level", + "input": "expand-0020-in.jsonld", + "expect": "expand-0020-out.jsonld" + }, { + "@type": ["test:TestCase", "jld:ExpandTest"], + "name": "do not remove @graph at top-level if not only property", + "input": "expand-0021-in.jsonld", + "expect": "expand-0021-out.jsonld" + }, { + "@type": ["test:TestCase", "jld:ExpandTest"], + "name": "expand value with default language", + "input": "expand-0022-in.jsonld", + "expect": "expand-0022-out.jsonld" + }, { + "@type": ["test:TestCase", "jld:ExpandTest"], + "name": "Expanding lists and sets with properties having coercion coerces list/set values", + "input": "expand-0023-in.jsonld", + "expect": "expand-0023-out.jsonld" + }, { + "@type": ["test:TestCase", "jld:ExpandTest"], + "name": "Multiple contexts", + "input": "expand-0024-in.jsonld", + "expect": "expand-0024-out.jsonld" + }, { + "@type": ["test:TestCase", "jld:ExpandTest"], + "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" + }, { + "@type": ["test:TestCase", "jld:ExpandTest"], + "name": "Keep duplicate values in @list and @set", + "input": "expand-0027-in.jsonld", + "expect": "expand-0027-out.jsonld" + }, { + "@type": ["test:TestCase", "jld:ExpandTest"], + "name": "Use @vocab in properties and @type but not in @id", + "input": "expand-0028-in.jsonld", + "expect": "expand-0028-out.jsonld" + } + ] }