From e2d9cdd4faf12925ea3e59b3d6e73704ee52fb20 Mon Sep 17 00:00:00 2001 From: Gregg Kellogg Date: Mon, 12 Jun 2017 17:01:53 -0700 Subject: [PATCH 01/11] Added `compactToRelative` option and tests. Fixed test vocabulary to match reality. Fixes #468. --- spec/latest/json-ld-api/index.html | 10 +- test-suite/context.jsonld | 1 + test-suite/tests/compact-manifest.jsonld | 24 +- test-suite/tests/compact-r001-context.jsonld | 3 + test-suite/tests/compact-r001-in.jsonld | 4 + test-suite/tests/compact-r001-out.jsonld | 5 + test-suite/tests/compact-r002-context.jsonld | 3 + test-suite/tests/compact-r002-in.jsonld | 4 + test-suite/tests/compact-r002-out.jsonld | 5 + test-suite/vocab.html | 819 ++++++++++--------- test-suite/vocab.jsonld | 30 +- test-suite/vocab.ttl | 30 +- 12 files changed, 524 insertions(+), 414 deletions(-) create mode 100644 test-suite/tests/compact-r001-context.jsonld create mode 100644 test-suite/tests/compact-r001-in.jsonld create mode 100644 test-suite/tests/compact-r001-out.jsonld create mode 100644 test-suite/tests/compact-r002-context.jsonld create mode 100644 test-suite/tests/compact-r002-in.jsonld create mode 100644 test-suite/tests/compact-r002-out.jsonld diff --git a/spec/latest/json-ld-api/index.html b/spec/latest/json-ld-api/index.html index 7e4e0a1d7..6f0319957 100644 --- a/spec/latest/json-ld-api/index.html +++ b/spec/latest/json-ld-api/index.html @@ -2512,7 +2512,9 @@

Overview

active context's vocabulary mapping, if there is one. If the IRI could not be compacted, an attempt is made to find a compact IRI. If there is no - appropriate compact IRI, the IRI is + appropriate compact IRI, + and the compactToRelative option is true, + the IRI is transformed to a relative IRI using the document's base IRI. Finally, if the IRI or keyword still could not be compacted, it is returned @@ -2729,7 +2731,7 @@

Algorithm

  • If compact IRI is not null, return compact IRI.
  • If vocab is false then transform iri to a relative IRI using - the document's base IRI.
  • + the base IRI from active context, if it exists.
  • Finally, return iri as is.
  • @@ -4209,6 +4211,7 @@

    The JsonLdOptions Type

    (JsonLdDictionary? or USVString) expandContext = null; boolean produceGeneralizedRdf = true; USVString processingMode = null; + boolean compactToRelative = true; }; --> @@ -4243,6 +4246,9 @@

    The JsonLdOptions Type

    different optimizations. Developers must not define modes beginning with json-ld as they are reserved for future versions of this specification. +
    compactToRelative
    +
    Determines if IRIs are compacted relative to the + base option or document location when compacting.
    diff --git a/test-suite/context.jsonld b/test-suite/context.jsonld index 238bbb6f6..727c57d49 100644 --- a/test-suite/context.jsonld +++ b/test-suite/context.jsonld @@ -20,6 +20,7 @@ "description": "rdfs:comment", "base": { "@type": "@id" }, "compactArrays": { "@type": "xsd:boolean" }, + "compactToRelative": { "@type": "xsd:boolean" }, "documentLoader": { "@type": "xsd:string" }, "expandContext": { "@type": "xsd:string" }, "processingMode": { "@type": "xsd:string" }, diff --git a/test-suite/tests/compact-manifest.jsonld b/test-suite/tests/compact-manifest.jsonld index 1cf5c3953..3811862b3 100644 --- a/test-suite/tests/compact-manifest.jsonld +++ b/test-suite/tests/compact-manifest.jsonld @@ -836,6 +836,28 @@ "context": "compact-n010-context.jsonld", "expect": "compact-n010-out.jsonld", "option": {"processingMode": "json-ld-1.1"} + }, { + "@id": "#tr001", + "@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"], + "name": "Expands and compacts to document base by default", + "purpose": "Compact IRI attempts to compact document-relative IRIs", + "input": "compact-r001-in.jsonld", + "context": "compact-r001-context.jsonld", + "expect": "compact-r001-out.jsonld", + "option": {"base": "http://example.org/", "processingMode": "json-ld-1.1"} + }, { + "@id": "#tr002", + "@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"], + "name": "Expands and does not compact to document base with compactToRelative false", + "purpose": "With compactToRelative option set to false, IRIs which could be made relative to the document base are not made relative.", + "input": "compact-r002-in.jsonld", + "context": "compact-r002-context.jsonld", + "expect": "compact-r002-out.jsonld", + "option": { + "base": "http://example.org/", + "processingMode": "json-ld-1.1", + "compactToRelative": false + } }, { "@id": "#ts001", "@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"], @@ -846,7 +868,7 @@ "expect": "compact-s001-out.jsonld", "option": {"processingMode": "json-ld-1.1"} }, { - "@id": "#ts001", + "@id": "#ts002", "@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"], "name": "@context with array including @set uses array values", "purpose": "@context values may include @set along with another compatible value", diff --git a/test-suite/tests/compact-r001-context.jsonld b/test-suite/tests/compact-r001-context.jsonld new file mode 100644 index 000000000..304ef521a --- /dev/null +++ b/test-suite/tests/compact-r001-context.jsonld @@ -0,0 +1,3 @@ +{ + "@context": {"b": "http://example.com/b"} +} \ No newline at end of file diff --git a/test-suite/tests/compact-r001-in.jsonld b/test-suite/tests/compact-r001-in.jsonld new file mode 100644 index 000000000..543c3609a --- /dev/null +++ b/test-suite/tests/compact-r001-in.jsonld @@ -0,0 +1,4 @@ +{ + "@id": "a", + "http://example.com/b": {"@id": "c"} +} \ No newline at end of file diff --git a/test-suite/tests/compact-r001-out.jsonld b/test-suite/tests/compact-r001-out.jsonld new file mode 100644 index 000000000..89a6b5566 --- /dev/null +++ b/test-suite/tests/compact-r001-out.jsonld @@ -0,0 +1,5 @@ +{ + "@context": {"b": "http://example.com/b"}, + "@id": "a", + "b": {"@id": "c"} +} \ No newline at end of file diff --git a/test-suite/tests/compact-r002-context.jsonld b/test-suite/tests/compact-r002-context.jsonld new file mode 100644 index 000000000..304ef521a --- /dev/null +++ b/test-suite/tests/compact-r002-context.jsonld @@ -0,0 +1,3 @@ +{ + "@context": {"b": "http://example.com/b"} +} \ No newline at end of file diff --git a/test-suite/tests/compact-r002-in.jsonld b/test-suite/tests/compact-r002-in.jsonld new file mode 100644 index 000000000..543c3609a --- /dev/null +++ b/test-suite/tests/compact-r002-in.jsonld @@ -0,0 +1,4 @@ +{ + "@id": "a", + "http://example.com/b": {"@id": "c"} +} \ No newline at end of file diff --git a/test-suite/tests/compact-r002-out.jsonld b/test-suite/tests/compact-r002-out.jsonld new file mode 100644 index 000000000..b87865393 --- /dev/null +++ b/test-suite/tests/compact-r002-out.jsonld @@ -0,0 +1,5 @@ +{ + "@context": {"b": "http://example.com/b"}, + "@id": "http://example.org/a", + "b": {"@id": "http://example.org/c"} +} \ No newline at end of file diff --git a/test-suite/vocab.html b/test-suite/vocab.html index 6a18c5696..c4d7a1ebd 100644 --- a/test-suite/vocab.html +++ b/test-suite/vocab.html @@ -1,392 +1,433 @@ - - - - - - - - - - - Test case manifest vocabulary extensions - - - - - - -
    -

    Test case manifest vocabulary extensions

    -

    Test case manifest vocabulary extensions

    -
    -
    -
    -

    - Test Case Classes -

    -
    -
    -
    -
    -
    Compact Evaluation Test
    -

    A CompactTest modifies either a PositiveEvaluationTest, NegativeEvaluationTest, PositiveSyntaxTest or NegativeSyntaxTest. Tests are run using the compact method with the input argument from mf:action (aliased as "input" in test manifest) referencing a JSON-LD file in expanded form, context from :input (aliased as "context" in the test manifest) and optional options from :option. The expected results for a PositiveEvaluationTest MUST be compared using JSON object comparison with the processor output.

    -
    Expand Evaluation Test
    -

    A ExpandTest modifies either a PositiveEvaluationTest, NegativeEvaluationTest, PositiveSyntaxTest or NegativeSyntaxTest. Tests are run using the expand method with the input argument from mf:action (aliased as "input" in test manifest) referencing a JSON-LD file, and optional options from :option. The expected results for a PositiveEvaluationTest MUST be compared using JSON object comparison with the processor output.

    -
    Flatten Evaluation Test
    -

    A FlattenTest modifies either a PositiveEvaluationTest, NegativeEvaluationTest, PositiveSyntaxTest or NegativeSyntaxTest. Tests are run using the flatten method with the input argument from mf:action (aliased as "input" in test manifest) referencing a JSON-LD file, optional context from :input (aliased as "context" in the test manifest) and optional options from :option. The expected results for a PositiveEvaluationTest MUST be compared using JSON object comparison with the processor output.

    -
    Frame Evaluation Test
    -

    A FrameTest modifies either a PositiveEvaluationTest, NegativeEvaluationTest, PositiveSyntaxTest or NegativeSyntaxTest. Tests are run using the frame method with the input argument from mf:action (aliased as "input" in test manifest) referencing a JSON-LD file, frame from :input (aliased as "frame" in the test manifest) and optional options from :option. The expected results for a PositiveEvaluationTest MUST be compared using JSON object comparison with the processor output.

    -
    From RDF Evaluation Test
    -

    A FromRDFTest modifies either a PositiveEvaluationTest, NegativeEvaluationTest, PositiveSyntaxTest or NegativeSyntaxTest. Tests are run using the RDF to Object Conversion algorithm with the input argument from mf:action (aliased as "input" in test manifest) referencing an N-Quads file and optional options from :option. The expected results for a PositiveEvaluationTest MUST be compared using JSON object comparison with the processor output.

    -
    Negative Syntax Test
    -

    A type of test specifically for syntax testing. Syntax tests are not required to have an associated result, only an action. Negative syntax tests are tests of which the result should be a parser error.

    -
    Positive Evaluation Test
    -

    A Negative Evaluation test is successful when the result of processing the input file specified as mf:action (aliased as "input" in test manifest) results in the error identified by the literal value of mf:result (aliased as "expect" in test manifest). The specifics of invoking test, including the interpretation of options (:option) and other input files are specified through another class.

    -
    Positive Evaluation Test
    -

    A Positive Evaluation test is successful when the result of processing the input file specified as mf:action (aliased as "input" in test manifest) exactly matches the output file specified as mf:result (aliased as "expect" in test manifest) using the comparison defined in another class. The specifics of invoking test, including the interpretation of options (:option) and other input files are specified through another class.

    -
    Positive Evaluation Test
    -

    A Negative Evaluation test is successful when the result of processing the input file specified as mf:action (aliased as "input" in test manifest) results in the error identified by the literal value of mf:result (aliased as "expect" in test manifest). The specifics of invoking test, including the interpretation of options (:option) and other input files are specified through another class.

    -
    Positive Syntax Test
    -

    A type of test specifically for syntax testing. Syntax tests are not required to have an associated result, only an action.

    -
    Processor Options
    -

    Options passed to the test runner to affect invocation of the appropriate API method.

    -
    Superclass of all JSON-LD tests
    -

    All JSON-LD tests have an input file referenced using mf:action (aliased as "input" in test manifest). Positive and Negative Evaluation Tests also have a result file referenced using mf:result (aliased as "expect" in test manifest). Other tests may take different inputs and options as defined for each test class. Tests should be run with the processingMode option set to "json-ld-1.1", unless specified explicitly as a test option.

    -
    To RDF Evaluation Test
    -

    A ToRDFTest modifies either a PositiveEvaluationTest, NegativeEvaluationTest, PositiveSyntaxTest or NegativeSyntaxTest. Tests are run using the Deserialize JSON-LD to RDF algorithm with the input argument from mf:action (aliased as "input" in test manifest) referencing an JSON-LD file and optional options from :option. The expected results for a PositiveEvaluationTest are N-Quads serialized in lexographical order and MUST be compared either string comparison or Dataset as defined in RDF11-CONCEPTS.

    -
    -
    -
    -
    -

    - Test Case Properties -

    -
    -
    -
    -
    -
    HTTP link
    -
    -

    An HTTP Link header to be added to the result of requesting the input file.

    -
    - - domain: - - jld:Test -
    -
    - - range: - - xsd:boolean -
    -
    -
    HTTP status
    -
    -

    The HTTP status code that must be returned when the input file is requested. This is typically used along with the redirectTo property.

    -
    - - domain: - - jld:Test -
    -
    - - range: - - xsd:boolean -
    -
    -
    base
    -
    -

    The base IRI to use when expanding or compacting the document. If set, this overrides the input document's IRI.

    -
    - - domain: - - jld:Test -
    -
    - - range: - - rdfs:Resource -
    -
    -
    compact arrays
    -
    -

    If set to true, the JSON-LD processor replaces arrays with just one element with that element during compaction. If set to false, all arrays will remain arrays even if they have just one element.

    -
    - - domain: - - jld:Test -
    -
    - - range: - - xsd:boolean -
    -
    -
    content type
    -
    -

    The HTTP Content-Type used for the input file, in case it is a non-registered type.

    -
    - - domain: - - jld:Test -
    -
    - - range: - - xsd:boolean -
    -
    -
    expand context
    -
    -

    A context that is used to initialize the active context when expanding a document.

    -
    - - domain: - - jld:Test -
    -
    - - range: - - rdfs:Resource -
    -
    -
    input
    -
    -

    Secondary input file

    -
    - - domain: - - jld:Test -
    -
    - - range: - - rdfs:Resource -
    -
    -
    option
    -
    -

    Options affecting processing

    -
    - - domain: - - jld:Test -
    -
    - - range: - - jld:Option -
    -
    -
    processing mode
    -
    -

    If set to "json-ld-1.1", the JSON-LD processor must produce exactly the same results as the algorithms defined in this specification. If set to another value, the JSON-LD processor is allowed to extend or modify the algorithms defined in this specification to enable application-specific optimizations. The definition of such optimizations is beyond the scope of this specification and thus not defined. Consequently, different implementations may implement different optimizations. Developers must not define modes beginning with json-ld as they are reserved for future versions of this specification.

    -
    - - domain: - - jld:Option -
    -
    - - range: - - xsd:string -
    -
    -
    produce generalized RDF
    -
    -

    Unless the produce generalized RDF flag is set to true, RDF triples containing a blank node predicate are excluded from output.

    -
    - - domain: - - jld:ToRDFTest -
    -
    - - range: - - xsd:boolean -
    -
    -
    redirect to
    -
    -

    The location of a URL for redirection. A request made of the input file must be redirected to the designated URL.

    -
    - - domain: - - jld:Test -
    -
    - - range: - - xsd:boolean -
    -
    -
    use RDF types
    -
    -

    If the use rdf type flag is set to true, statements with an rdf:type predicate will not use @type, but will be transformed as a normal property.

    -
    - - domain: - - jld:FromRDFTest -
    -
    - - range: - - xsd:boolean -
    -
    -
    use document loader
    -
    -

    Test runners must implement a callback method with a method signature as defined in LoadDocumentCallback. Specifying this option requires the test runner to provide this callback to the appropriate API method using the documentLoader option.

    -
    - - domain: - - jld:Test -
    -
    - - range: - - xsd:boolean -
    -
    -
    use native types
    -
    -

    If the use native types flag is set to true, RDF literals with a datatype IRI that equal xsd:integer or xsd:double are converted to a JSON numbers and RDF literals with a datatype IRI that equals xsd:boolean are converted to true or false based on their lexical form.

    -
    - - domain: - - jld:FromRDFTest -
    -
    - - range: - - xsd:boolean -
    -
    -
    -
    -
    -
    - - - + + + + + + + + + + +Test case manifest vocabulary extensions + + + + + + +
    +

    Test case manifest vocabulary extensions

    +

    Test case manifest vocabulary extensions

    +
    +
    +
    +

    +Test Case Classes +

    +
    +
    +
    +
    +
    Compact Evaluation Test
    +

    A CompactTest modifies either a PositiveEvaluationTest, NegativeEvaluationTest, PositiveSyntaxTest or NegativeSyntaxTest. Tests are run using the compact method with the input argument from mf:action (aliased as "input" in test manifest) referencing a JSON-LD file in expanded form, context from :input (aliased as "context" in the test manifest) and optional options from :option. The expected results for a PositiveEvaluationTest MUST be compared using JSON object comparison with the processor output.

    +
    +
    Expand Evaluation Test
    +

    A ExpandTest modifies either a PositiveEvaluationTest, NegativeEvaluationTest, PositiveSyntaxTest or NegativeSyntaxTest. Tests are run using the expand method with the input argument from mf:action (aliased as "input" in test manifest) referencing a JSON-LD file, and optional options from :option. The expected results for a PositiveEvaluationTest MUST be compared using JSON object comparison with the processor output.

    +
    +
    Flatten Evaluation Test
    +

    A FlattenTest modifies either a PositiveEvaluationTest, NegativeEvaluationTest, PositiveSyntaxTest or NegativeSyntaxTest. Tests are run using the flatten method with the input argument from mf:action (aliased as "input" in test manifest) referencing a JSON-LD file, optional context from :input (aliased as "context" in the test manifest) and optional options from :option. The expected results for a PositiveEvaluationTest MUST be compared using JSON object comparison with the processor output.

    +
    +
    Frame Evaluation Test
    +

    A FrameTest modifies either a PositiveEvaluationTest, NegativeEvaluationTest, PositiveSyntaxTest or NegativeSyntaxTest. Tests are run using the frame method with the input argument from mf:action (aliased as "input" in test manifest) referencing a JSON-LD file, frame from :input (aliased as "frame" in the test manifest) and optional options from :option. The expected results for a PositiveEvaluationTest MUST be compared using JSON object comparison with the processor output.

    +
    +
    From RDF Evaluation Test
    +

    A FromRDFTest modifies either a PositiveEvaluationTest, NegativeEvaluationTest, PositiveSyntaxTest or NegativeSyntaxTest. Tests are run using the RDF to Object Conversion algorithm with the input argument from mf:action (aliased as "input" in test manifest) referencing an N-Quads file and optional options from :option. The expected results for a PositiveEvaluationTest MUST be compared using JSON object comparison with the processor output.

    +
    +
    Negative Syntax Test
    +

    A type of test specifically for syntax testing. Syntax tests are not required to have an associated result, only an action. Negative syntax tests are tests of which the result should be a parser error.

    +
    +
    Positive Evaluation Test
    +

    A Negative Evaluation test is successful when the result of processing the input file specified as mf:action (aliased as "input" in test manifest) results in the error identified by the literal value of mf:result (aliased as "expect" in test manifest). The specifics of invoking test, including the interpretation of options (:option) and other input files are specified through another class.

    +
    +
    Positive Evaluation Test
    +

    A Positive Evaluation test is successful when the result of processing the input file specified as mf:action (aliased as "input" in test manifest) exactly matches the output file specified as mf:result (aliased as "expect" in test manifest) using the comparison defined in another class. The specifics of invoking test, including the interpretation of options (:option) and other input files are specified through another class.

    +
    +
    Positive Syntax Test
    +

    A type of test specifically for syntax testing. Syntax tests are not required to have an associated result, only an action.

    +
    +
    Processor Options
    +

    Options passed to the test runner to affect invocation of the appropriate API method.

    +
    +
    Superclass of all JSON-LD tests
    +

    All JSON-LD tests have an input file referenced using mf:action (aliased as "input" in test manifest). Positive and Negative Evaluation Tests also have a result file referenced using mf:result (aliased as "expect" in test manifest). Other tests may take different inputs and options as defined for each test class. Tests should be run with the processingMode option set to "json-ld-1.1", unless specified explicitly as a test option.

    +
    +
    To RDF Evaluation Test
    +

    A ToRDFTest modifies either a PositiveEvaluationTest, NegativeEvaluationTest, PositiveSyntaxTest or NegativeSyntaxTest. Tests are run using the Deserialize JSON-LD to RDF algorithm with the input argument from mf:action (aliased as "input" in test manifest) referencing an JSON-LD file and optional options from :option. The expected results for a PositiveEvaluationTest are N-Quads serialized in lexographical order and MUST be compared either string comparison or Dataset as defined in RDF11-CONCEPTS.

    +
    +
    +
    +
    +
    +

    +Test Case Properties +

    +
    +
    +
    +
    +
    HTTP link
    +
    +

    An HTTP Link header to be added to the result of requesting the input file.

    +
    +
    + +domain: + +jld:Option +
    +
    + +range: + +xsd:boolean +
    +
    +
    HTTP status
    +
    +

    The HTTP status code that must be returned when the input file is requested. This is typically used along with the redirectTo property.

    +
    +
    + +domain: + +jld:Option +
    +
    + +range: + +xsd:boolean +
    +
    +
    base
    +
    +

    The base IRI to use when expanding or compacting the document. If set, this overrides the input document's IRI.

    +
    +
    + +domain: + +jld:Option +
    +
    + +range: + +rdfs:Resource +
    +
    +
    compact arrays
    +
    +

    If set to true, the JSON-LD processor replaces arrays with just one element with that element during compaction. If set to false, all arrays will remain arrays even if they have just one element.

    +
    +
    + +domain: + +jld:Option +
    +
    + +range: + +xsd:boolean +
    +
    +
    compact to relative
    +
    +

    If set to false, the JSON-LD processor will not attempt to compact using document-relative IRIs.

    +
    +
    + +domain: + +jld:Option +
    +
    + +range: + +xsd:boolean +
    +
    +
    content type
    +
    +

    The HTTP Content-Type used for the input file, in case it is a non-registered type.

    +
    +
    + +domain: + +jld:Option +
    +
    + +range: + +xsd:boolean +
    +
    +
    expand context
    +
    +

    A context that is used to initialize the active context when expanding a document.

    +
    +
    + +domain: + +jld:Option +
    +
    + +range: + +rdfs:Resource +
    +
    +
    input
    +
    +

    Secondary input file

    +
    +
    + +domain: + +jld:Test +
    +
    + +range: + +rdfs:Resource +
    +
    +
    option
    +
    +

    Options affecting processing

    +
    +
    + +domain: + +jld:Test +
    +
    + +range: + +jld:Option +
    +
    +
    processing mode
    +
    +

    If set to "json-ld-1.1", the JSON-LD processor must produce exactly the same results as the algorithms defined in this specification. If set to another value, the JSON-LD processor is allowed to extend or modify the algorithms defined in this specification to enable application-specific optimizations. The definition of such optimizations is beyond the scope of this specification and thus not defined. Consequently, different implementations may implement different optimizations. Developers must not define modes beginning with json-ld as they are reserved for future versions of this specification.

    +
    +
    + +domain: + +jld:Option +
    +
    + +range: + +xsd:string +
    +
    +
    produce generalized RDF
    +
    +

    Unless the produce generalized RDF flag is set to true, RDF triples containing a blank node predicate are excluded from output.

    +
    +
    + +domain: + +jld:Option +
    +
    + +range: + +xsd:boolean +
    +
    +
    redirect to
    +
    +

    The location of a URL for redirection. A request made of the input file must be redirected to the designated URL.

    +
    +
    + +domain: + +jld:Option +
    +
    + +range: + +xsd:boolean +
    +
    +
    use RDF types
    +
    +

    If the use rdf type flag is set to true, statements with an rdf:type predicate will not use @type, but will be transformed as a normal property.

    +
    +
    + +domain: + +jld:Option +
    +
    + +range: + +xsd:boolean +
    +
    +
    use document loader
    +
    +

    Test runners must implement a callback method with a method signature as defined in LoadDocumentCallback. Specifying this option requires the test runner to provide this callback to the appropriate API method using the documentLoader option.

    +
    +
    + +domain: + +jld:Option +
    +
    + +range: + +xsd:boolean +
    +
    +
    use native types
    +
    +

    If the use native types flag is set to true, RDF literals with a datatype IRI that equal xsd:integer or xsd:double are converted to a JSON numbers and RDF literals with a datatype IRI that equals xsd:boolean are converted to true or false based on their lexical form.

    +
    +
    + +domain: + +jld:Option +
    +
    + +range: + +xsd:boolean +
    +
    +
    +
    +
    +
    + + + diff --git a/test-suite/vocab.jsonld b/test-suite/vocab.jsonld index e6ef2a448..66fdf6100 100644 --- a/test-suite/vocab.jsonld +++ b/test-suite/vocab.jsonld @@ -113,7 +113,7 @@ "@id": "jld:base", "@type": "rdf:Property", "rdfs:comment": "The base IRI to use when expanding or compacting the document. If set, this overrides the input document's IRI.", - "rdfs:domain": "jld:Test", + "rdfs:domain": "jld:Option", "rdfs:label": "base", "rdfs:range": "rdfs:Resource" }, @@ -121,15 +121,23 @@ "@id": "jld:compactArrays", "@type": "rdf:Property", "rdfs:comment": "If set to `true`, the JSON-LD processor replaces arrays with just one element with that element during compaction. If set to false, all arrays will remain arrays even if they have just one element.", - "rdfs:domain": "jld:Test", + "rdfs:domain": "jld:Option", "rdfs:label": "compact arrays", "rdfs:range": "xsd:boolean" }, + { + "@id": "jld:compactToRelative", + "@type": "rdf:Property", + "rdfs:comment": "If set to `false`, the JSON-LD processor will not attempt to compact using document-relative IRIs.", + "rdfs:domain": "jld:Option", + "rdfs:label": "compact to relative", + "rdfs:range": "xsd:boolean" + }, { "@id": "jld:contentType", "@type": "rdf:Property", "rdfs:comment": "The HTTP Content-Type used for the input file, in case it is a non-registered type.", - "rdfs:domain": "jld:Test", + "rdfs:domain": "jld:Option", "rdfs:label": "content type", "rdfs:range": "xsd:boolean" }, @@ -137,7 +145,7 @@ "@id": "jld:expandContext", "@type": "rdf:Property", "rdfs:comment": "A context that is used to initialize the active context when expanding a document.", - "rdfs:domain": "jld:Test", + "rdfs:domain": "jld:Option", "rdfs:label": "expand context", "rdfs:range": "rdfs:Resource" }, @@ -145,7 +153,7 @@ "@id": "jld:httpLink", "@type": "rdf:Property", "rdfs:comment": "An HTTP Link header to be added to the result of requesting the input file.", - "rdfs:domain": "jld:Test", + "rdfs:domain": "jld:Option", "rdfs:label": "HTTP link", "rdfs:range": "xsd:boolean" }, @@ -153,7 +161,7 @@ "@id": "jld:httpStatus", "@type": "rdf:Property", "rdfs:comment": "The HTTP status code that must be returned when the input file is requested. This is typically used along with the `redirectTo` property.", - "rdfs:domain": "jld:Test", + "rdfs:domain": "jld:Option", "rdfs:label": "HTTP status", "rdfs:range": "xsd:boolean" }, @@ -185,7 +193,7 @@ "@id": "jld:produceGeneralizedRdf", "@type": "rdf:Property", "rdfs:comment": "Unless the produce generalized RDF flag is set to true, RDF triples containing a blank node predicate are excluded from output.", - "rdfs:domain": "jld:ToRDFTest", + "rdfs:domain": "jld:Option", "rdfs:label": "produce generalized RDF", "rdfs:range": "xsd:boolean" }, @@ -193,7 +201,7 @@ "@id": "jld:redirectTo", "@type": "rdf:Property", "rdfs:comment": "The location of a URL for redirection. A request made of the input file must be redirected to the designated URL.", - "rdfs:domain": "jld:Test", + "rdfs:domain": "jld:Option", "rdfs:label": "redirect to", "rdfs:range": "xsd:boolean" }, @@ -201,7 +209,7 @@ "@id": "jld:useDocumentLoader", "@type": "rdf:Property", "rdfs:comment": "Test runners must implement a callback method with a method signature as defined in [LoadDocumentCallback](http://json-ld.org/spec/latest/json-ld-api/index.html#idl-def-LoadDocumentCallback). Specifying this option requires the test runner to provide this callback to the appropriate API method using the `documentLoader` option.", - "rdfs:domain": "jld:Test", + "rdfs:domain": "jld:Option", "rdfs:label": "use document loader", "rdfs:range": "xsd:boolean" }, @@ -209,7 +217,7 @@ "@id": "jld:useNativeTypes", "@type": "rdf:Property", "rdfs:comment": "If the _use native types_ flag is set to `true`, RDF literals with a datatype IRI that equal `xsd:integer` or `xsd:double` are converted to a JSON numbers and RDF literals with a datatype IRI that equals `xsd:boolean` are converted to `true` or `false` based on their lexical form.", - "rdfs:domain": "jld:FromRDFTest", + "rdfs:domain": "jld:Option", "rdfs:label": "use native types", "rdfs:range": "xsd:boolean" }, @@ -217,7 +225,7 @@ "@id": "jld:useRdfType", "@type": "rdf:Property", "rdfs:comment": "If the _use rdf type_ flag is set to `true`, statements with an `rdf:type` predicate will not use `@type`, but will be transformed as a normal property.", - "rdfs:domain": "jld:FromRDFTest", + "rdfs:domain": "jld:Option", "rdfs:label": "use RDF types", "rdfs:range": "xsd:boolean" } diff --git a/test-suite/vocab.ttl b/test-suite/vocab.ttl index eeaed9c59..84e95a321 100644 --- a/test-suite/vocab.ttl +++ b/test-suite/vocab.ttl @@ -171,7 +171,7 @@ The base IRI to use when expanding or compacting the document. If set, this overrides the input document's IRI. """ ; - rdfs:domain :Test ; + rdfs:domain :Option ; rdfs:range rdfs:Resource . :compactArrays a rdf:Property ; @@ -181,7 +181,15 @@ with that element during compaction. If set to false, all arrays will remain arrays even if they have just one element. """ ; - rdfs:domain :Test ; + rdfs:domain :Option ; + rdfs:range xsd:boolean . + +:compactToRelative a rdf:Property ; + rdfs:label "compact to relative"; + rdfs:comment """ + If set to `false`, the JSON-LD processor will not attempt to compact using document-relative IRIs. + """ ; + rdfs:domain :Option ; rdfs:range xsd:boolean . :useDocumentLoader a rdf:Property ; @@ -192,13 +200,13 @@ Specifying this option requires the test runner to provide this callback to the appropriate API method using the `documentLoader` option. """ ; - rdfs:domain :Test ; + rdfs:domain :Option ; rdfs:range xsd:boolean . :expandContext a rdf:Property ; rdfs:label "expand context"; rdfs:comment "A context that is used to initialize the active context when expanding a document." ; - rdfs:domain :Test ; + rdfs:domain :Option ; rdfs:range rdfs:Resource . :processingMode a rdf:Property ; @@ -218,7 +226,7 @@ :produceGeneralizedRdf a rdf:Property ; rdfs:label "produce generalized RDF"; rdfs:comment "Unless the produce generalized RDF flag is set to true, RDF triples containing a blank node predicate are excluded from output." ; - rdfs:domain :ToRDFTest ; + rdfs:domain :Option ; rdfs:range xsd:boolean . :useNativeTypes a rdf:Property ; @@ -229,7 +237,7 @@ with a datatype IRI that equals `xsd:boolean` are converted to `true` or `false` based on their lexical form. """ ; - rdfs:domain :FromRDFTest ; + rdfs:domain :Option ; rdfs:range xsd:boolean . :useRdfType a rdf:Property ; @@ -238,7 +246,7 @@ If the _use rdf type_ flag is set to `true`, statements with an `rdf:type` predicate will not use `@type`, but will be transformed as a normal property. """ ; - rdfs:domain :FromRDFTest ; + rdfs:domain :Option ; rdfs:range xsd:boolean . :contentType a rdf:Property ; @@ -246,7 +254,7 @@ rdfs:comment """ The HTTP Content-Type used for the input file, in case it is a non-registered type. """ ; - rdfs:domain :Test ; + rdfs:domain :Option ; rdfs:range xsd:boolean . :redirectTo a rdf:Property ; @@ -255,7 +263,7 @@ The location of a URL for redirection. A request made of the input file must be redirected to the designated URL. """ ; - rdfs:domain :Test ; + rdfs:domain :Option ; rdfs:range xsd:boolean . :httpStatus a rdf:Property ; @@ -264,7 +272,7 @@ The HTTP status code that must be returned when the input file is requested. This is typically used along with the `redirectTo` property. """ ; - rdfs:domain :Test ; + rdfs:domain :Option ; rdfs:range xsd:boolean . :httpLink a rdf:Property ; @@ -272,5 +280,5 @@ rdfs:comment """ An HTTP Link header to be added to the result of requesting the input file. """ ; - rdfs:domain :Test ; + rdfs:domain :Option ; rdfs:range xsd:boolean . From 0d071fdb089678f5e461a474bc669a00a983c8fe Mon Sep 17 00:00:00 2001 From: Gregg Kellogg Date: Tue, 13 Jun 2017 08:27:12 -0700 Subject: [PATCH 02/11] Add mention of IRI compaction changes to changes section. --- spec/latest/json-ld-api/index.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/latest/json-ld-api/index.html b/spec/latest/json-ld-api/index.html index 6f0319957..47625b15d 100644 --- a/spec/latest/json-ld-api/index.html +++ b/spec/latest/json-ld-api/index.html @@ -4556,6 +4556,8 @@

    Changes since 1.0 Recommendation of 16 January 2014

    keyword along with @set (other than @list). This allows a way to ensure that such property values will always be expressed in array form. +
  • Added support for the compactToRelative option to allow IRI compaction () + to document relative IRIs to be disabled.
  • @@ -4567,7 +4569,6 @@

    Open Issues

    -

    From 3d347e1b9bfb8fde2ab53d7ea120d84d8e8ff7a8 Mon Sep 17 00:00:00 2001 From: Gregg Kellogg Date: Wed, 14 Jun 2017 09:14:45 -0700 Subject: [PATCH 03/11] Clean up issue markers. --- spec/latest/json-ld-api/index.html | 4 ---- spec/latest/json-ld/index.html | 3 --- 2 files changed, 7 deletions(-) diff --git a/spec/latest/json-ld-api/index.html b/spec/latest/json-ld-api/index.html index 47625b15d..0267ed097 100644 --- a/spec/latest/json-ld-api/index.html +++ b/spec/latest/json-ld-api/index.html @@ -4565,14 +4565,10 @@

    Changes since 1.0 Recommendation of 16 January 2014

    Open Issues

    The following is a list of open issues being worked on for the next release.

    -

    -

    -

    -

    diff --git a/spec/latest/json-ld/index.html b/spec/latest/json-ld/index.html index 83b2766aa..677e039f2 100644 --- a/spec/latest/json-ld/index.html +++ b/spec/latest/json-ld/index.html @@ -3944,10 +3944,7 @@

    Changes since 1.0 Recommendation of 16 January 2014

    Open Issues

    The following is a list of open issues being worked on for the next release.

    -

    -

    -

    From 59f0f3135371ef01e20fcf4214b10e7805b8c64d Mon Sep 17 00:00:00 2001 From: Gregg Kellogg Date: Mon, 3 Jul 2017 15:57:11 -0700 Subject: [PATCH 04/11] Change algorithm for creating compact IRIs to favor terms ending with colon `':'` (in which case no colon is added) or end with a gen-delim and require that such terms be simple terms. This invalidates previous tests compact-0038 and -0045, but does not seem to be with requiring a specific processor mode to enable. Fixes #405. --- spec/latest/common/terms.html | 2 +- spec/latest/json-ld-api/index.html | 49 ++++++++++++++++++-- spec/latest/json-ld/index.html | 19 ++++++-- test-suite/tests/compact-0038-out.jsonld | 10 ++-- test-suite/tests/compact-0045-context.jsonld | 2 +- test-suite/tests/compact-0045-in.jsonld | 2 +- test-suite/tests/compact-0045-out.jsonld | 2 +- test-suite/tests/compact-manifest.jsonld | 32 +++++++++++++ test-suite/tests/compact-p001-context.jsonld | 6 +++ test-suite/tests/compact-p001-in.jsonld | 5 ++ test-suite/tests/compact-p001-out.jsonld | 9 ++++ test-suite/tests/compact-p002-context.jsonld | 5 ++ test-suite/tests/compact-p002-in.jsonld | 5 ++ test-suite/tests/compact-p002-out.jsonld | 8 ++++ test-suite/tests/compact-p003-context.jsonld | 6 +++ test-suite/tests/compact-p003-in.jsonld | 6 +++ test-suite/tests/compact-p003-out.jsonld | 10 ++++ test-suite/tests/compact-p004-context.jsonld | 11 +++++ test-suite/tests/compact-p004-in.jsonld | 9 ++++ test-suite/tests/compact-p004-out.jsonld | 18 +++++++ 20 files changed, 199 insertions(+), 17 deletions(-) create mode 100644 test-suite/tests/compact-p001-context.jsonld create mode 100644 test-suite/tests/compact-p001-in.jsonld create mode 100644 test-suite/tests/compact-p001-out.jsonld create mode 100644 test-suite/tests/compact-p002-context.jsonld create mode 100644 test-suite/tests/compact-p002-in.jsonld create mode 100644 test-suite/tests/compact-p002-out.jsonld create mode 100644 test-suite/tests/compact-p003-context.jsonld create mode 100644 test-suite/tests/compact-p003-in.jsonld create mode 100644 test-suite/tests/compact-p003-out.jsonld create mode 100644 test-suite/tests/compact-p004-context.jsonld create mode 100644 test-suite/tests/compact-p004-in.jsonld create mode 100644 test-suite/tests/compact-p004-out.jsonld diff --git a/spec/latest/common/terms.html b/spec/latest/common/terms.html index 66945b3e3..dc9b218fb 100644 --- a/spec/latest/common/terms.html +++ b/spec/latest/common/terms.html @@ -252,7 +252,7 @@

    General Terminology

    term definition
    A term definition is an entry in a context, where the key defines a term which may be used within a JSON object as a property, type, or elsewhere that a string is interpreted as a vocabulary item. - Its value is either a string, expanding to an absolute IRI, or an expanded term definition. + Its value is either a string (simple term definition), expanding to an absolute IRI, or an expanded term definition.
    type map
    An type map is a JSON object value of a term defined with diff --git a/spec/latest/json-ld-api/index.html b/spec/latest/json-ld-api/index.html index 0267ed097..2f38722c1 100644 --- a/spec/latest/json-ld-api/index.html +++ b/spec/latest/json-ld-api/index.html @@ -2511,8 +2511,12 @@

    Overview

    IRI, an attempt is made to compact the IRI using the active context's vocabulary mapping, if there is one. If the IRI could not be compacted, an - attempt is made to find a compact IRI. If there is no - appropriate compact IRI, + attempt is made to find a compact IRI. + A term will be used to create a compact IRI + only if the term ends with a colon (:), or if the term + maps to a string ending with a URI gen-delim, + with preference given to term ending with a colon (:). + If there is no appropriate compact IRI, and the compactToRelative option is true, the IRI is transformed to a relative IRI using the document's @@ -2701,13 +2705,44 @@

    Algorithm

    Try to create a compact IRI, starting by initializing compact IRI to null. This variable will be used to tore the created compact IRI, if any. -
  • For each key term and value term definition in +
  • For each key term and value term definition in + the active context: +
      +
    1. If the term does not end with a colon (:), + then continue to the next term.
    2. +
    3. If the term definition is not a simple term definitions then continue to the + next term, because expanded term definitions are not used for + creating compact IRIs.
    4. +
    5. If the term definition is null, + its IRI mapping equals iri, or its + IRI mapping is not a substring at the beginning of + iri, the term cannot be used as a prefix + because it is not a partial match with iri. + Continue with the next term.
    6. +
    7. Initialize candidate by concatenating term + and the substring of iri + that follows after the value of the + term definition's + IRI mapping.
    8. +
    9. If either compact IRI is null or candidate is + shorter or the same length but lexicographically less than + compact IRI and candidate does not have a + term definition in active context or if the + term definition has an IRI mapping + that equals iri and value is null, + set compact IRI to candidate.
    10. +
    +
  • +
  • If compact IRI is null, then for each key term and value term definition in the active context:
    1. If the term contains a colon (:), then continue to the next term because terms with colons can't be used as prefixes.
    2. +
    3. If the term definition is not a simple term definitions then continue to the + next term, because expanded term definitions are not used for + creating compact IRIs.
    4. If the term definition is null, its IRI mapping equals iri, or its IRI mapping is not a substring at the beginning of @@ -4558,6 +4593,11 @@

      Changes since 1.0 Recommendation of 16 January 2014

      be expressed in array form.
    5. Added support for the compactToRelative option to allow IRI compaction () to document relative IRIs to be disabled.
    6. +
    7. In JSON-LD 1.1, terms will be used as compact IRI prefixes + when compacting only if + they are simple term definitions and either end with a URI gen-delim character, + or where the term itself ends with a colon (:). + When compacting, preference is given to terms ending in a colon.
    8. @@ -4567,8 +4607,9 @@

      Open Issues

      -

      +

      +

      diff --git a/spec/latest/json-ld/index.html b/spec/latest/json-ld/index.html index 677e039f2..19596e5e7 100644 --- a/spec/latest/json-ld/index.html +++ b/spec/latest/json-ld/index.html @@ -1043,6 +1043,12 @@

      Compact IRIs

      underscore (_), the value is interpreted as blank node identifier instead.

      +

      In JSON-LD 1.1, terms will be used as compact IRI prefixes + when compacting only if + they are simple term definitions and either end with a URI gen-delim character (e.g, + /, # and others, see RFC3986) or where the term + itself ends with a colon (:). When compacting, preference + is given to terms ending in a colon.

      It's also possible to use compact IRIs within the context as shown in the following example:

      @@ -2228,7 +2234,7 @@

      Scoped Contexts

      Scoping on @type 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.

      Scoped Contexts are a new feature in JSON-LD 1.1, requiring - processing mode set to json-ld-1.1

      + processing mode set to json-ld-1.1.

      @@ -2788,7 +2794,7 @@

      Node Identifier Indexing

      Id maps are a new feature in JSON-LD 1.1, requiring - processing mode set to json-ld-1.1

      + processing mode set to json-ld-1.1.

      @@ -2869,7 +2875,7 @@

      Node Type Indexing

      Type maps are a new feature in JSON-LD 1.1, requiring - processing mode set to json-ld-1.1

      + processing mode set to json-ld-1.1.

      @@ -2951,7 +2957,7 @@

      Nested Properties

      Nested properties are a new feature in JSON-LD 1.1, requiring - processing mode set to json-ld-1.1

      + processing mode set to json-ld-1.1.

      @@ -3937,6 +3943,11 @@

      Changes since 1.0 Recommendation of 16 January 2014

      keyword along with @set (other than @list). This allows a way to ensure that such property values will always be expressed in array form. +
    9. In JSON-LD 1.1, terms will be used as compact IRI prefixes + when compacting only if + they are simple term definitions and either end with a URI gen-delim character, + or where the term itself ends with a colon (:). + When compacting, preference is given to terms ending in a colon.
    10. diff --git a/test-suite/tests/compact-0038-out.jsonld b/test-suite/tests/compact-0038-out.jsonld index 78369d193..a8f965894 100644 --- a/test-suite/tests/compact-0038-out.jsonld +++ b/test-suite/tests/compact-0038-out.jsonld @@ -20,19 +20,19 @@ "title": { "en": { "@type": "site-cd:field-types/title_field", - "title:/value": "This is the English title" + "site-cd:node/article/title/value": "This is the English title" }, "es": { "@type": "site-cd:field-types/title_field", - "title:/value": "Este es el t’tulo espa–ol" + "site-cd:node/article/title/value": "Este es el t’tulo espa–ol" } }, "body": { "en": { "@type": "site-cd:field-types/text_with_summary", - "body:/value": "This is the English body. There is no Spanish body, so this will be displayed for both the English and Spanish versions.", - "body:/summary": "This is the teaser for the body.", - "body:/format": "full_html" + "site-cd:node/article/body/value": "This is the English body. There is no Spanish body, so this will be displayed for both the English and Spanish versions.", + "site-cd:node/article/body/summary": "This is the teaser for the body.", + "site-cd:node/article/body/format": "full_html" } }, "field_tags": { diff --git a/test-suite/tests/compact-0045-context.jsonld b/test-suite/tests/compact-0045-context.jsonld index 005f5e16d..5854b8a04 100644 --- a/test-suite/tests/compact-0045-context.jsonld +++ b/test-suite/tests/compact-0045-context.jsonld @@ -1,7 +1,7 @@ { "@context": { "term": "http://example.com/terms-are-not-considered-in-id", - "compact-iris": "http://example.com/compact-iris-", + "compact-iris": "http://example.com/compact-iris#", "property": "http://example.com/property", "@vocab": "http://example.org/vocab-is-not-considered-for-id" }, diff --git a/test-suite/tests/compact-0045-in.jsonld b/test-suite/tests/compact-0045-in.jsonld index 990d67b3d..6aa647ea2 100644 --- a/test-suite/tests/compact-0045-in.jsonld +++ b/test-suite/tests/compact-0045-in.jsonld @@ -3,7 +3,7 @@ "@id": "http://json-ld.org/test-suite/tests/term", "http://example.com/property": [ { - "@id": "http://example.com/compact-iris-are-considered", + "@id": "http://example.com/compact-iris#are-considered", "http://example.com/property": [ { "@value": "@id supports the following values: relative, absolute, and compact IRIs" } ] diff --git a/test-suite/tests/compact-0045-out.jsonld b/test-suite/tests/compact-0045-out.jsonld index 005f5e16d..5854b8a04 100644 --- a/test-suite/tests/compact-0045-out.jsonld +++ b/test-suite/tests/compact-0045-out.jsonld @@ -1,7 +1,7 @@ { "@context": { "term": "http://example.com/terms-are-not-considered-in-id", - "compact-iris": "http://example.com/compact-iris-", + "compact-iris": "http://example.com/compact-iris#", "property": "http://example.com/property", "@vocab": "http://example.org/vocab-is-not-considered-for-id" }, diff --git a/test-suite/tests/compact-manifest.jsonld b/test-suite/tests/compact-manifest.jsonld index 3811862b3..5020fe0c1 100644 --- a/test-suite/tests/compact-manifest.jsonld +++ b/test-suite/tests/compact-manifest.jsonld @@ -836,6 +836,38 @@ "context": "compact-n010-context.jsonld", "expect": "compact-n010-out.jsonld", "option": {"processingMode": "json-ld-1.1"} + }, { + "@id": "#tp001", + "@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"], + "name": "Compact IRI using term ending with ':'", + "purpose": "Compacting to compact IRIs favors terms ending in ':'", + "input": "compact-p001-in.jsonld", + "context": "compact-p001-context.jsonld", + "expect": "compact-p001-out.jsonld" + }, { + "@id": "#tp002", + "@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"], + "name": "Compact IRI does not use expanded term definition", + "purpose": "Terms with an expanded term definition are not used for creating compact IRIs", + "input": "compact-p002-in.jsonld", + "context": "compact-p002-context.jsonld", + "expect": "compact-p002-out.jsonld" + }, { + "@id": "#tp003", + "@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"], + "name": "Compact IRI does not use simple term that does not end with a gen-delim", + "purpose": "Terms not ending with a gen-delim are not used for creating compact IRIs", + "input": "compact-p003-in.jsonld", + "context": "compact-p003-context.jsonld", + "expect": "compact-p003-out.jsonld" + }, { + "@id": "#tp004", + "@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"], + "name": "Compact IRIs using simple terms ending with gen-delim", + "purpose": "All simple terms ending with gen-delim are suitable for compaction", + "input": "compact-p004-in.jsonld", + "context": "compact-p004-context.jsonld", + "expect": "compact-p004-out.jsonld" }, { "@id": "#tr001", "@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"], diff --git a/test-suite/tests/compact-p001-context.jsonld b/test-suite/tests/compact-p001-context.jsonld new file mode 100644 index 000000000..403824c82 --- /dev/null +++ b/test-suite/tests/compact-p001-context.jsonld @@ -0,0 +1,6 @@ +{ + "@context": { + "ex": "http://example.org/", + "exx:": "http://example.org/" + } +} diff --git a/test-suite/tests/compact-p001-in.jsonld b/test-suite/tests/compact-p001-in.jsonld new file mode 100644 index 000000000..19beb0f3d --- /dev/null +++ b/test-suite/tests/compact-p001-in.jsonld @@ -0,0 +1,5 @@ +{ + "@id": "http://example.org/id1", + "@type": ["http://example.org/Type1", "http://example.org/Type2"], + "http://example.org/term": {"@id": "http://example.org/id2"} +} diff --git a/test-suite/tests/compact-p001-out.jsonld b/test-suite/tests/compact-p001-out.jsonld new file mode 100644 index 000000000..493bd1c1b --- /dev/null +++ b/test-suite/tests/compact-p001-out.jsonld @@ -0,0 +1,9 @@ +{ + "@context": { + "ex": "http://example.org/", + "exx:": "http://example.org/" + }, + "@id": "exx:id1", + "@type": ["exx:Type1", "exx:Type2"], + "exx:term": {"@id": "exx:id2"} +} diff --git a/test-suite/tests/compact-p002-context.jsonld b/test-suite/tests/compact-p002-context.jsonld new file mode 100644 index 000000000..2d72ed662 --- /dev/null +++ b/test-suite/tests/compact-p002-context.jsonld @@ -0,0 +1,5 @@ +{ + "@context": { + "ex": {"@id": "http://example.org/"} + } +} diff --git a/test-suite/tests/compact-p002-in.jsonld b/test-suite/tests/compact-p002-in.jsonld new file mode 100644 index 000000000..19beb0f3d --- /dev/null +++ b/test-suite/tests/compact-p002-in.jsonld @@ -0,0 +1,5 @@ +{ + "@id": "http://example.org/id1", + "@type": ["http://example.org/Type1", "http://example.org/Type2"], + "http://example.org/term": {"@id": "http://example.org/id2"} +} diff --git a/test-suite/tests/compact-p002-out.jsonld b/test-suite/tests/compact-p002-out.jsonld new file mode 100644 index 000000000..5dfd781a7 --- /dev/null +++ b/test-suite/tests/compact-p002-out.jsonld @@ -0,0 +1,8 @@ +{ + "@context": { + "ex": {"@id": "http://example.org/"} + }, + "@id": "http://example.org/id1", + "@type": ["http://example.org/Type1", "http://example.org/Type2"], + "http://example.org/term": {"@id": "http://example.org/id2"} +} \ No newline at end of file diff --git a/test-suite/tests/compact-p003-context.jsonld b/test-suite/tests/compact-p003-context.jsonld new file mode 100644 index 000000000..589074441 --- /dev/null +++ b/test-suite/tests/compact-p003-context.jsonld @@ -0,0 +1,6 @@ +{ + "@context": { + "compact-iris:": "http://example.com/compact-iris-", + "property": "http://example.com/property" + } +} diff --git a/test-suite/tests/compact-p003-in.jsonld b/test-suite/tests/compact-p003-in.jsonld new file mode 100644 index 000000000..3d197efe9 --- /dev/null +++ b/test-suite/tests/compact-p003-in.jsonld @@ -0,0 +1,6 @@ +{ + "http://example.com/property": { + "@id": "http://example.com/compact-iris-are-considered", + "http://example.com/property": "Terms ending in ':' given special consideration" + } +} diff --git a/test-suite/tests/compact-p003-out.jsonld b/test-suite/tests/compact-p003-out.jsonld new file mode 100644 index 000000000..24eac6719 --- /dev/null +++ b/test-suite/tests/compact-p003-out.jsonld @@ -0,0 +1,10 @@ +{ + "@context": { + "compact-iris:": "http://example.com/compact-iris-", + "property": "http://example.com/property" + }, + "property": { + "@id": "compact-iris:are-considered", + "property": "Terms ending in ':' given special consideration" + } +} diff --git a/test-suite/tests/compact-p004-context.jsonld b/test-suite/tests/compact-p004-context.jsonld new file mode 100644 index 000000000..ce499b69a --- /dev/null +++ b/test-suite/tests/compact-p004-context.jsonld @@ -0,0 +1,11 @@ +{ + "@context": { + "ex": "http://example.org/", + "colon:": "ex::", + "question:": "ex:?", + "hash:": "ex:#", + "lbracket:": "ex:[", + "rbracket:": "ex:]", + "at:": "ex:@" + } +} \ No newline at end of file diff --git a/test-suite/tests/compact-p004-in.jsonld b/test-suite/tests/compact-p004-in.jsonld new file mode 100644 index 000000000..8611ba920 --- /dev/null +++ b/test-suite/tests/compact-p004-in.jsonld @@ -0,0 +1,9 @@ +{ + "http://example.org/foo": "Use term with IRI ending in '/'", + "http://example.org/:foo": "Use term with IRI ending in ':'", + "http://example.org/?foo": "Use term with IRI ending in '?'", + "http://example.org/#foo": "Use term with IRI ending in '#'", + "http://example.org/[foo": "Use term with IRI ending in '['", + "http://example.org/]foo": "Use term with IRI ending in ']'", + "http://example.org/@foo": "Use term with IRI ending in '@'" +} diff --git a/test-suite/tests/compact-p004-out.jsonld b/test-suite/tests/compact-p004-out.jsonld new file mode 100644 index 000000000..f53528409 --- /dev/null +++ b/test-suite/tests/compact-p004-out.jsonld @@ -0,0 +1,18 @@ +{ + "@context": { + "ex": "http://example.org/", + "colon:": "ex::", + "question:": "ex:?", + "hash:": "ex:#", + "lbracket:": "ex:[", + "rbracket:": "ex:]", + "at:": "ex:@" + }, + "ex:foo": "Use term with IRI ending in '/'", + "colon:foo": "Use term with IRI ending in ':'", + "question:foo": "Use term with IRI ending in '?'", + "hash:foo": "Use term with IRI ending in '#'", + "lbracket:foo": "Use term with IRI ending in '['", + "rbracket:foo": "Use term with IRI ending in ']'", + "at:foo": "Use term with IRI ending in '@'" +} \ No newline at end of file From 19f2558026c12ae91928288e3494971b1bfad444 Mon Sep 17 00:00:00 2001 From: Gregg Kellogg Date: Wed, 5 Jul 2017 16:56:22 -0700 Subject: [PATCH 05/11] Address @dlongley's [comment](https://github.com/json-ld/json-ld.org/pull/511#issuecomment-312935250) on `compactToRelative` to move setting the base IRI of the context used when compacting (flattening or framing) to the document base only if `compactToRelative` is **true**. --- spec/latest/common/common.js | 2 +- spec/latest/json-ld-api/index.html | 31 +++++++++++++++++------- spec/latest/json-ld-framing/index.html | 10 +++++++- test-suite/tests/compact-manifest.jsonld | 1 - test-suite/tests/compact-r002-in.jsonld | 4 +-- 5 files changed, 34 insertions(+), 14 deletions(-) diff --git a/spec/latest/common/common.js b/spec/latest/common/common.js index 6a85089e9..52b2207fb 100644 --- a/spec/latest/common/common.js +++ b/spec/latest/common/common.js @@ -12,7 +12,7 @@ var jsonld = { }, "JSON-LD-API": { title: "JSON-LD 1.1 Processing Algorithms and API", - href: "http://json-ld.org/spec/latest/json-ld/", + href: "http://json-ld.org/spec/latest/json-ld-api/", authors: ["Markus Lanthaler", "Gregg Kellogg", "Manu Sporny"], publisher: "W3C", status: 'CG Draft' diff --git a/spec/latest/json-ld-api/index.html b/spec/latest/json-ld-api/index.html index 2f38722c1..47ed7f21c 100644 --- a/spec/latest/json-ld-api/index.html +++ b/spec/latest/json-ld-api/index.html @@ -768,12 +768,10 @@

      Algorithm

      1. If context is null, set result to a newly-initialized active context and continue with the - next context. The base IRI of the - active context is set to the IRI of the currently being processed - document (which might be different from the currently being processed context), - if available; otherwise to null. If set, the - base - option of a JSON-LD API Implementation overrides the base IRI.
      2. + next context. + In JSON-LD 1.0, the base IRI was given + a default value here; this is now described conditionally + in .
      3. If context is a string,
        1. Set context to the result of resolving value against @@ -4073,9 +4071,16 @@

          The JsonLdProcessor Interface

          method using input and options.
        2. If context is a dictionary having an @context member, set context to that member's value, otherwise to context.
        3. +
        4. Initialize an active context using context; + the base IRI is set to + the base option from + options, if set; + otherwise, if the + compactToRelative option is + true, to the IRI of the currently being processed + document, if available; otherwise to null.
        5. Set compacted output to the result of using the - Compaction algorithm, passing - context as active context, + Compaction algorithm, using active context, an empty dictionary as inverse context, null as property, expanded input as element, and if passed, the @@ -4175,12 +4180,20 @@

          The JsonLdProcessor Interface

          method using input and options.
        6. If context is a dictionary having an @context member, set context to that member's value, otherwise to context.
        7. +
        8. Initialize an active context using context; + the base IRI is set to + the base option from + options, if set; + otherwise, if the + compactToRelative option is + true, to the IRI of the currently being processed + document, if available; otherwise to null.
        9. Initialize an empty identifier map and a counter (set to 0) to be used by the Generate Blank Node Identifier algorithm.
        10. Set flattened output to the result of using the Flattening algorithm, passing - expanded input as element, context, and if passed, the + expanded input as element, active context, and if passed, the compactArrays flag in options (which is internally passed to the Compaction algorithm).
        11. diff --git a/spec/latest/json-ld-framing/index.html b/spec/latest/json-ld-framing/index.html index 3e1c32a15..9a2cffbe0 100644 --- a/spec/latest/json-ld-framing/index.html +++ b/spec/latest/json-ld-framing/index.html @@ -1222,13 +1222,21 @@

          JsonLdProcessor

        12. Set context to the value of @context from frame, if it exists, or to a new empty context, otherwise.
        13. +
        14. Initialize an active context using context; + the base IRI is set to + the base option from + options, if set; + otherwise, if the + compactToRelative option is + true, to the IRI of the currently being processed + document, if available; otherwise to null.
        15. If frame has a top-level property which expands to @graph set the frameDefault option to options with the value true.
        16. Set framed to the result of using the Framing algorithm, passing - expanded input, expanded frame, context, and options.
        17. + expanded input, expanded frame, active context, and options.
        18. Fulfill the promise passing framed.
        diff --git a/test-suite/tests/compact-manifest.jsonld b/test-suite/tests/compact-manifest.jsonld index 5020fe0c1..e04e52e4a 100644 --- a/test-suite/tests/compact-manifest.jsonld +++ b/test-suite/tests/compact-manifest.jsonld @@ -886,7 +886,6 @@ "context": "compact-r002-context.jsonld", "expect": "compact-r002-out.jsonld", "option": { - "base": "http://example.org/", "processingMode": "json-ld-1.1", "compactToRelative": false } diff --git a/test-suite/tests/compact-r002-in.jsonld b/test-suite/tests/compact-r002-in.jsonld index 543c3609a..765625c35 100644 --- a/test-suite/tests/compact-r002-in.jsonld +++ b/test-suite/tests/compact-r002-in.jsonld @@ -1,4 +1,4 @@ { - "@id": "a", - "http://example.com/b": {"@id": "c"} + "@id": "http://example.org/a", + "http://example.com/b": {"@id": "http://example.org/c"} } \ No newline at end of file From cb04ac6a042ba606d109f2e23f3f59fcf51ed699 Mon Sep 17 00:00:00 2001 From: Gregg Kellogg Date: Wed, 5 Jul 2017 17:27:43 -0700 Subject: [PATCH 06/11] Update language on terms vs their term definitions to address @dlonley's [comment](https://github.com/json-ld/json-ld.org/pull/511#discussion_r125503306). --- spec/latest/json-ld-api/index.html | 14 +++++++------- spec/latest/json-ld/index.html | 17 ++++++++--------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/spec/latest/json-ld-api/index.html b/spec/latest/json-ld-api/index.html index 47ed7f21c..fbed1514d 100644 --- a/spec/latest/json-ld-api/index.html +++ b/spec/latest/json-ld-api/index.html @@ -2511,9 +2511,9 @@

        Overview

        if there is one. If the IRI could not be compacted, an attempt is made to find a compact IRI. A term will be used to create a compact IRI - only if the term ends with a colon (:), or if the term - maps to a string ending with a URI gen-delim, - with preference given to term ending with a colon (:). + only if the term ends with a colon (:), or if + a simple term definition is used where its value ends with a URI gen-delim, + with preference given to term maps to a string ending with a colon (:). If there is no appropriate compact IRI, and the compactToRelative option is true, the IRI is @@ -4606,11 +4606,11 @@

        Changes since 1.0 Recommendation of 16 January 2014

        be expressed in array form.
      4. Added support for the compactToRelative option to allow IRI compaction () to document relative IRIs to be disabled.
      5. -
      6. In JSON-LD 1.1, terms will be used as compact IRI prefixes +
      7. In JSON-LD 1.1, terms will be used as compact IRI prefixes when compacting only if - they are simple term definitions and either end with a URI gen-delim character, - or where the term itself ends with a colon (:). - When compacting, preference is given to terms ending in a colon.
      8. + a simple term definition is used where the value ends with a URI gen-delim character, + or where the term itself ends with a colon (:). + When compacting, preference is given to terms ending in a colon. diff --git a/spec/latest/json-ld/index.html b/spec/latest/json-ld/index.html index 19596e5e7..1c8359583 100644 --- a/spec/latest/json-ld/index.html +++ b/spec/latest/json-ld/index.html @@ -1043,12 +1043,11 @@

        Compact IRIs

        underscore (_), the value is interpreted as blank node identifier instead.

        -

        In JSON-LD 1.1, terms will be used as compact IRI prefixes +

        In JSON-LD 1.1, terms will be used as compact IRI prefixes when compacting only if - they are simple term definitions and either end with a URI gen-delim character (e.g, - /, # and others, see RFC3986) or where the term - itself ends with a colon (:). When compacting, preference - is given to terms ending in a colon.

        + a simple term definition is used where the value ends with a URI gen-delim character + (e.g, /, # and others, see [[!RFC3986]]), + or where the term itself ends with a colon (:)

        It's also possible to use compact IRIs within the context as shown in the following example:

        @@ -3943,11 +3942,11 @@

        Changes since 1.0 Recommendation of 16 January 2014

        keyword along with @set (other than @list). This allows a way to ensure that such property values will always be expressed in array form. -
      9. In JSON-LD 1.1, terms will be used as compact IRI prefixes +
      10. In JSON-LD 1.1, terms will be used as compact IRI prefixes when compacting only if - they are simple term definitions and either end with a URI gen-delim character, - or where the term itself ends with a colon (:). - When compacting, preference is given to terms ending in a colon.
      11. + a simple term definition is used where the value ends with a URI gen-delim character, + or where the term itself ends with a colon (:). + When compacting, preference is given to terms ending in a colon. From e4accad94b259a895c4ae108716c8036963ed2c4 Mon Sep 17 00:00:00 2001 From: Gregg Kellogg Date: Sun, 9 Jul 2017 13:12:16 -0700 Subject: [PATCH 07/11] Use `nest value` in term definition, rather than `@nest member`, to distinguish it from the serialized version within a context. --- spec/latest/json-ld-api/index.html | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/latest/json-ld-api/index.html b/spec/latest/json-ld-api/index.html index fbed1514d..0439ec6ef 100644 --- a/spec/latest/json-ld-api/index.html +++ b/spec/latest/json-ld-api/index.html @@ -684,7 +684,8 @@

        Context Processing Algorithm

        term definition consists of an IRI mapping, a boolean flag reverse property, an optional type mapping or language mapping, - an optional context, + an optional context, + an optional nest value, and an optional container mapping. A term definition can not only be used to map a term to an IRI, but also to map a term to a keyword, @@ -1116,7 +1117,7 @@

        Algorithm

      12. If processingMode is json-ld-1.0, an invalid term definition has been detected and processing is aborted.
      13. -
      14. Initialize nest to the value associated with the +
      15. Initialize nest value in defined to the value associated with the @nest key, which must be a string and must not be a keyword other than @nest. Otherwise, an invalid @nest value @@ -1125,7 +1126,7 @@

        Algorithm

      16. If the value contains any key other than @id, @reverse, @container, - @context, @nest, or @type, an + @context, @nest, or @type, an invalid term definition error has been detected and processing is aborted.
      17. Set the term definition of term in @@ -2135,8 +2136,7 @@

        Algorithm

        true for vocab, and inside reverse.
      18. If the term definition for item active property - in the active context has a @nest - member, that value (nest term) must be + in the active context has a nest value, that value (nest term) must be @nest, or a term definition in the active context that expands to @nest, otherwise an invalid @nest @@ -2170,7 +2170,7 @@

        Algorithm

        true for vocab, and inside reverse.
      19. If the term definition for item active property - in the active context has a @nest + in the active context has a nest value member, that value (nest term) must be @nest, or a term definition in the active context that expands to @nest, From 6c02c3230132a97495662308e9fc173b70e21854 Mon Sep 17 00:00:00 2001 From: Gregg Kellogg Date: Sun, 9 Jul 2017 16:36:40 -0700 Subject: [PATCH 08/11] Update logic on using prefixes: * Processing mode is 1.0 and the value (simple or from `@id` of an expanded definition) ends with one of the gen-delims. * Processing mode is 1.1+ and the value is simple and ends with one of the gen-delims. * Processing mode is 1.1+ and the expanded term definition is declared as `@prefix: true`. --- spec/latest/common/terms.html | 8 +- spec/latest/json-ld-api/index.html | 82 +++++++++----------- spec/latest/json-ld/index.html | 28 +++++-- test-suite/tests/compact-manifest.jsonld | 26 ++++++- test-suite/tests/compact-p001-context.jsonld | 3 +- test-suite/tests/compact-p001-out.jsonld | 11 ++- test-suite/tests/compact-p003-in.jsonld | 2 +- test-suite/tests/compact-p003-out.jsonld | 4 +- test-suite/tests/compact-p004-context.jsonld | 14 ++-- test-suite/tests/compact-p004-in.jsonld | 2 +- test-suite/tests/compact-p004-out.jsonld | 14 ++-- test-suite/tests/compact-p005-context.jsonld | 6 ++ test-suite/tests/compact-p005-in.jsonld | 6 ++ test-suite/tests/compact-p005-out.jsonld | 10 +++ test-suite/tests/compact-p006-context.jsonld | 6 ++ test-suite/tests/compact-p006-in.jsonld | 6 ++ test-suite/tests/compact-p006-out.jsonld | 10 +++ test-suite/tests/error-manifest.jsonld | 18 +++++ test-suite/tests/error-p007-context.jsonld | 5 ++ test-suite/tests/error-p007-in.jsonld | 3 + test-suite/tests/error-p008-context.jsonld | 5 ++ test-suite/tests/error-p008-in.jsonld | 3 + 22 files changed, 187 insertions(+), 85 deletions(-) create mode 100644 test-suite/tests/compact-p005-context.jsonld create mode 100644 test-suite/tests/compact-p005-in.jsonld create mode 100644 test-suite/tests/compact-p005-out.jsonld create mode 100644 test-suite/tests/compact-p006-context.jsonld create mode 100644 test-suite/tests/compact-p006-in.jsonld create mode 100644 test-suite/tests/compact-p006-out.jsonld create mode 100644 test-suite/tests/error-p007-context.jsonld create mode 100644 test-suite/tests/error-p007-in.jsonld create mode 100644 test-suite/tests/error-p008-context.jsonld create mode 100644 test-suite/tests/error-p008-in.jsonld diff --git a/spec/latest/common/terms.html b/spec/latest/common/terms.html index dc9b218fb..77b2b569c 100644 --- a/spec/latest/common/terms.html +++ b/spec/latest/common/terms.html @@ -213,10 +213,10 @@

        General Terminology

        object
        An object is a node in a linked data graph with at least one incoming edge. See RDF objectin [[RDF11-CONCEPTS]].
        -
        prefix
        - A prefix is a term that expands to a vocabulary base IRI. It - is typically used along with a suffix to form a compact IRI to create an IRI - within a vocabulary.
        +
        prefix
        + A prefix is the first component of a compact IRI which comes from a + term that maps to a string that, when prepended to the suffix of the compact IRI + results in an absolute IRI.
        processing mode
        The processing mode defines how a JSON-LD document is processed. By default, all documents are assumed to be conformat with diff --git a/spec/latest/json-ld-api/index.html b/spec/latest/json-ld-api/index.html index 0439ec6ef..5ec083195 100644 --- a/spec/latest/json-ld-api/index.html +++ b/spec/latest/json-ld-api/index.html @@ -686,6 +686,7 @@

        Context Processing Algorithm

        or language mapping, an optional context, an optional nest value, + an optional prefix flag, and an optional container mapping. A term definition can not only be used to map a term to an IRI, but also to map a term to a keyword, @@ -1033,6 +1034,14 @@

        Algorithm

        error has been detected and processing is aborted; if it equals @context, an invalid keyword alias error has been detected and processing is aborted.
      20. +
      21. If processing mode is json-ld-1.0, and the, + IRI mapping of definition ends with a URI + gen-delim character, + set the prefix flag in definition to true. + Otherwise, if the IRI mapping ends with a URI + gen-delim character, + set the prefix flag in definition to true, only if + value was originally a string.
    11. @@ -1124,9 +1133,21 @@

      Algorithm

      error has been detected and processing is aborted.
  • +
  • If value contains the key @prefix: +
      +
    1. If processingMode is json-ld-1.0, an + invalid term definition + has been detected and processing is aborted.
    2. +
    3. Initialize the prefix flag to the value associated with the + @prefix key, which must be a boolean. Otherwise, an + invalid @prefix value + error has been detected and processing is aborted.
    4. +
    +
  • If the value contains any key other than @id, @reverse, @container, - @context, @nest, or @type, an + @context, @nest, + @prefix, or @type, an invalid term definition error has been detected and processing is aborted.
  • Set the term definition of term in @@ -2511,9 +2532,8 @@

    Overview

    if there is one. If the IRI could not be compacted, an attempt is made to find a compact IRI. A term will be used to create a compact IRI - only if the term ends with a colon (:), or if - a simple term definition is used where its value ends with a URI gen-delim, - with preference given to term maps to a string ending with a colon (:). + only if the term definition contains the prefix flag + with the value true. If there is no appropriate compact IRI, and the compactToRelative option is true, the IRI is @@ -2703,49 +2723,16 @@

    Algorithm

    Try to create a compact IRI, starting by initializing compact IRI to null. This variable will be used to tore the created compact IRI, if any.
  • -
  • For each key term and value term definition in - the active context: -
      -
    1. If the term does not end with a colon (:), - then continue to the next term.
    2. -
    3. If the term definition is not a simple term definitions then continue to the - next term, because expanded term definitions are not used for - creating compact IRIs.
    4. -
    5. If the term definition is null, - its IRI mapping equals iri, or its - IRI mapping is not a substring at the beginning of - iri, the term cannot be used as a prefix - because it is not a partial match with iri. - Continue with the next term.
    6. -
    7. Initialize candidate by concatenating term - and the substring of iri - that follows after the value of the - term definition's - IRI mapping.
    8. -
    9. If either compact IRI is null or candidate is - shorter or the same length but lexicographically less than - compact IRI and candidate does not have a - term definition in active context or if the - term definition has an IRI mapping - that equals iri and value is null, - set compact IRI to candidate.
    10. -
    -
  • -
  • If compact IRI is null, then for each key term and value term definition in +
  • or each key term and value term definition in the active context:
      -
    1. If the term contains a colon (:), - then continue to the next term because - terms with colons can't be - used as prefixes.
    2. -
    3. If the term definition is not a simple term definitions then continue to the - next term, because expanded term definitions are not used for - creating compact IRIs.
    4. If the term definition is null, - its IRI mapping equals iri, or its + its IRI mapping equals iri, its IRI mapping is not a substring at the beginning of - iri, the term cannot be used as a prefix - because it is not a partial match with iri. + iri, + or the term definition does not contain + the prefix flag having a value of true, + the term cannot be used as a prefix. Continue with the next term.
    5. Initialize candidate by concatenating term, a colon (:), and the substring of iri @@ -4406,6 +4393,7 @@

      JsonLdErrorCode

      "invalid @id value", "invalid @index value", "invalid @nest value", + "invalid @prefix value", "invalid @reverse value", "invalid @version value", "invalid base IRI", @@ -4461,6 +4449,8 @@

      JsonLdErrorCode

      not a string.
  • invalid @nest value
    An invalid value for @nest has been found.
    +
    invalid @prefix value
    +
    An invalid value for @prefix has been found.
    invalid @reverse value
    An invalid value for an @reverse member has been detected, i.e., the value was not a dictionary.
    @@ -4609,8 +4599,10 @@

    Changes since 1.0 Recommendation of 16 January 2014

  • In JSON-LD 1.1, terms will be used as compact IRI prefixes when compacting only if a simple term definition is used where the value ends with a URI gen-delim character, - or where the term itself ends with a colon (:). - When compacting, preference is given to terms ending in a colon.
  • + or if their expanded term definition contains + a @prefix member with the value true. The 1.0 algorithm has + been updated to only consider terms that map to a value that ends with a URI + gen-delim character. diff --git a/spec/latest/json-ld/index.html b/spec/latest/json-ld/index.html index 1c8359583..fa4188b06 100644 --- a/spec/latest/json-ld/index.html +++ b/spec/latest/json-ld/index.html @@ -404,6 +404,9 @@

    Syntax Tokens and Keywords

    This keyword is described in .
    @nest
    Collects a set of nested properties within a node object.
    +
    @prefix
    + With the value true, allows this term to be used to construct a compact IRI + when compacting.
    @version
    Used in a context definition to set the processing mode. New features since JSON-LD 1.0 [[!JSON-LD-20140116]] described in this specification are @@ -1043,11 +1046,20 @@

    Compact IRIs

    underscore (_), the value is interpreted as blank node identifier instead.

    -

    In JSON-LD 1.1, terms will be used as compact IRI prefixes - when compacting only if - a simple term definition is used where the value ends with a URI gen-delim character - (e.g, /, # and others, see [[!RFC3986]]), - or where the term itself ends with a colon (:)

    +

    In JSON-LD 1.0, terms will be used as compact IRI prefixes when + compacting only if they map to a value that ends with a URI gen-delim character (e.g, /, + # and others, see [[!RFC3986]]).

    + +

    This represents a small change to the 1.0 algorithm to prevent IRIs + that are not really intended to be used as prefixes from being used for creating + compact IRIs.

    + +

    When processing mode is set to json-ld-1.1, terms will be used as compact IRI prefixes + when compacting only if their expanded term definition contains + a @prefix member with the value true, or if it has a + a simple term definition where the value ends with a URI gen-delim character + (e.g, /, # and others, see [[!RFC3986]]).

    It's also possible to use compact IRIs within the context as shown in the following example:

    @@ -3945,8 +3957,10 @@

    Changes since 1.0 Recommendation of 16 January 2014

  • In JSON-LD 1.1, terms will be used as compact IRI prefixes when compacting only if a simple term definition is used where the value ends with a URI gen-delim character, - or where the term itself ends with a colon (:). - When compacting, preference is given to terms ending in a colon.
  • + or if their expanded term definition contains + a @prefix member with the value true. The 1.0 algorithm has + been updated to only consider terms that map to a value that ends with a URI + gen-delim character. diff --git a/test-suite/tests/compact-manifest.jsonld b/test-suite/tests/compact-manifest.jsonld index e04e52e4a..4bd325817 100644 --- a/test-suite/tests/compact-manifest.jsonld +++ b/test-suite/tests/compact-manifest.jsonld @@ -839,16 +839,18 @@ }, { "@id": "#tp001", "@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"], - "name": "Compact IRI using term ending with ':'", - "purpose": "Compacting to compact IRIs favors terms ending in ':'", + "name": "Compact IRI does may use an expanded term definition in 1.0", + "purpose": "Terms with an expanded term definition may be used for creating compact IRIs", + "option": {"processingMode": "json-ld-1.0"}, "input": "compact-p001-in.jsonld", "context": "compact-p001-context.jsonld", "expect": "compact-p001-out.jsonld" }, { "@id": "#tp002", "@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"], - "name": "Compact IRI does not use expanded term definition", + "name": "Compact IRI does not use expanded term definition in 1.1", "purpose": "Terms with an expanded term definition are not used for creating compact IRIs", + "option": {"processingMode": "json-ld-1.1"}, "input": "compact-p002-in.jsonld", "context": "compact-p002-context.jsonld", "expect": "compact-p002-out.jsonld" @@ -868,6 +870,24 @@ "input": "compact-p004-in.jsonld", "context": "compact-p004-context.jsonld", "expect": "compact-p004-out.jsonld" + }, { + "@id": "#tp005", + "@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"], + "name": "Compact IRI uses term with definition including @prefix: true", + "purpose": "Expanded term definition may set prefix explicitly in 1.1", + "option": {"processingMode": "json-ld-1.1"}, + "input": "compact-p005-in.jsonld", + "context": "compact-p005-context.jsonld", + "expect": "compact-p005-out.jsonld" + }, { + "@id": "#tp006", + "@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"], + "name": "Compact IRI uses term with definition including @prefix: true", + "purpose": "Expanded term definition may set prefix explicitly in 1.1", + "option": {"processingMode": "json-ld-1.1"}, + "input": "compact-p006-in.jsonld", + "context": "compact-p006-context.jsonld", + "expect": "compact-p006-out.jsonld" }, { "@id": "#tr001", "@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"], diff --git a/test-suite/tests/compact-p001-context.jsonld b/test-suite/tests/compact-p001-context.jsonld index 403824c82..2d72ed662 100644 --- a/test-suite/tests/compact-p001-context.jsonld +++ b/test-suite/tests/compact-p001-context.jsonld @@ -1,6 +1,5 @@ { "@context": { - "ex": "http://example.org/", - "exx:": "http://example.org/" + "ex": {"@id": "http://example.org/"} } } diff --git a/test-suite/tests/compact-p001-out.jsonld b/test-suite/tests/compact-p001-out.jsonld index 493bd1c1b..e9d795226 100644 --- a/test-suite/tests/compact-p001-out.jsonld +++ b/test-suite/tests/compact-p001-out.jsonld @@ -1,9 +1,8 @@ { "@context": { - "ex": "http://example.org/", - "exx:": "http://example.org/" + "ex": {"@id": "http://example.org/"} }, - "@id": "exx:id1", - "@type": ["exx:Type1", "exx:Type2"], - "exx:term": {"@id": "exx:id2"} -} + "@id": "ex:id1", + "@type": ["ex:Type1", "ex:Type2"], + "ex:term": {"@id": "ex:id2"} +} \ No newline at end of file diff --git a/test-suite/tests/compact-p003-in.jsonld b/test-suite/tests/compact-p003-in.jsonld index 3d197efe9..948a5d52a 100644 --- a/test-suite/tests/compact-p003-in.jsonld +++ b/test-suite/tests/compact-p003-in.jsonld @@ -1,6 +1,6 @@ { "http://example.com/property": { "@id": "http://example.com/compact-iris-are-considered", - "http://example.com/property": "Terms ending in ':' given special consideration" + "http://example.com/property": "Prefix terms must end in a gen-delim" } } diff --git a/test-suite/tests/compact-p003-out.jsonld b/test-suite/tests/compact-p003-out.jsonld index 24eac6719..be552f3b9 100644 --- a/test-suite/tests/compact-p003-out.jsonld +++ b/test-suite/tests/compact-p003-out.jsonld @@ -4,7 +4,7 @@ "property": "http://example.com/property" }, "property": { - "@id": "compact-iris:are-considered", - "property": "Terms ending in ':' given special consideration" + "@id": "http://example.com/compact-iris-are-considered", + "property": "Prefix terms must end in a gen-delim" } } diff --git a/test-suite/tests/compact-p004-context.jsonld b/test-suite/tests/compact-p004-context.jsonld index ce499b69a..f4348ae16 100644 --- a/test-suite/tests/compact-p004-context.jsonld +++ b/test-suite/tests/compact-p004-context.jsonld @@ -1,11 +1,11 @@ { "@context": { - "ex": "http://example.org/", - "colon:": "ex::", - "question:": "ex:?", - "hash:": "ex:#", - "lbracket:": "ex:[", - "rbracket:": "ex:]", - "at:": "ex:@" + "ex": "http://example.com/", + "colon": "http://example.org/:", + "question": "http://example.org/?", + "hash": "http://example.org/#", + "lbracket": "http://example.org/[", + "rbracket": "http://example.org/]", + "at": "http://example.org/@" } } \ No newline at end of file diff --git a/test-suite/tests/compact-p004-in.jsonld b/test-suite/tests/compact-p004-in.jsonld index 8611ba920..4f9847f97 100644 --- a/test-suite/tests/compact-p004-in.jsonld +++ b/test-suite/tests/compact-p004-in.jsonld @@ -1,5 +1,5 @@ { - "http://example.org/foo": "Use term with IRI ending in '/'", + "http://example.com/foo": "Use term with IRI ending in '/'", "http://example.org/:foo": "Use term with IRI ending in ':'", "http://example.org/?foo": "Use term with IRI ending in '?'", "http://example.org/#foo": "Use term with IRI ending in '#'", diff --git a/test-suite/tests/compact-p004-out.jsonld b/test-suite/tests/compact-p004-out.jsonld index f53528409..20de37219 100644 --- a/test-suite/tests/compact-p004-out.jsonld +++ b/test-suite/tests/compact-p004-out.jsonld @@ -1,12 +1,12 @@ { "@context": { - "ex": "http://example.org/", - "colon:": "ex::", - "question:": "ex:?", - "hash:": "ex:#", - "lbracket:": "ex:[", - "rbracket:": "ex:]", - "at:": "ex:@" + "ex": "http://example.com/", + "colon": "http://example.org/:", + "question": "http://example.org/?", + "hash": "http://example.org/#", + "lbracket": "http://example.org/[", + "rbracket": "http://example.org/]", + "at": "http://example.org/@" }, "ex:foo": "Use term with IRI ending in '/'", "colon:foo": "Use term with IRI ending in ':'", diff --git a/test-suite/tests/compact-p005-context.jsonld b/test-suite/tests/compact-p005-context.jsonld new file mode 100644 index 000000000..daa9107db --- /dev/null +++ b/test-suite/tests/compact-p005-context.jsonld @@ -0,0 +1,6 @@ +{ + "@context": { + "compact-iris": {"@id": "http://example.com/compact-iris-", "@prefix": true}, + "property": "http://example.com/property" + } +} diff --git a/test-suite/tests/compact-p005-in.jsonld b/test-suite/tests/compact-p005-in.jsonld new file mode 100644 index 000000000..cef01fc88 --- /dev/null +++ b/test-suite/tests/compact-p005-in.jsonld @@ -0,0 +1,6 @@ +{ + "http://example.com/property": { + "@id": "http://example.com/compact-iris-are-considered", + "http://example.com/property": "@prefix does not require a gen-delim" + } +} diff --git a/test-suite/tests/compact-p005-out.jsonld b/test-suite/tests/compact-p005-out.jsonld new file mode 100644 index 000000000..6920c1935 --- /dev/null +++ b/test-suite/tests/compact-p005-out.jsonld @@ -0,0 +1,10 @@ +{ + "@context": { + "compact-iris": {"@id": "http://example.com/compact-iris-", "@prefix": true}, + "property": "http://example.com/property" + }, + "property": { + "@id": "compact-iris:are-considered", + "property": "@prefix does not require a gen-delim" + } +} diff --git a/test-suite/tests/compact-p006-context.jsonld b/test-suite/tests/compact-p006-context.jsonld new file mode 100644 index 000000000..daa9107db --- /dev/null +++ b/test-suite/tests/compact-p006-context.jsonld @@ -0,0 +1,6 @@ +{ + "@context": { + "compact-iris": {"@id": "http://example.com/compact-iris-", "@prefix": true}, + "property": "http://example.com/property" + } +} diff --git a/test-suite/tests/compact-p006-in.jsonld b/test-suite/tests/compact-p006-in.jsonld new file mode 100644 index 000000000..cef01fc88 --- /dev/null +++ b/test-suite/tests/compact-p006-in.jsonld @@ -0,0 +1,6 @@ +{ + "http://example.com/property": { + "@id": "http://example.com/compact-iris-are-considered", + "http://example.com/property": "@prefix does not require a gen-delim" + } +} diff --git a/test-suite/tests/compact-p006-out.jsonld b/test-suite/tests/compact-p006-out.jsonld new file mode 100644 index 000000000..6920c1935 --- /dev/null +++ b/test-suite/tests/compact-p006-out.jsonld @@ -0,0 +1,10 @@ +{ + "@context": { + "compact-iris": {"@id": "http://example.com/compact-iris-", "@prefix": true}, + "property": "http://example.com/property" + }, + "property": { + "@id": "compact-iris:are-considered", + "property": "@prefix does not require a gen-delim" + } +} diff --git a/test-suite/tests/error-manifest.jsonld b/test-suite/tests/error-manifest.jsonld index d2d3a4d1d..90890e1f4 100644 --- a/test-suite/tests/error-manifest.jsonld +++ b/test-suite/tests/error-manifest.jsonld @@ -429,6 +429,24 @@ "input": "error-p006-in.jsonld", "context": "error-p006-context.jsonld", "expect": "invalid @version value" + }, { + "@id": "#tp007", + "@type": ["jld:NegativeEvaluationTest", "jld:CompactTest"], + "name": "@prefix is not allowed in 1.0", + "purpose": "@prefix is not allowed in a term definitionin 1.0", + "option": {"processingMode": "json-ld-1.0"}, + "input": "error-p007-in.jsonld", + "context": "error-p007-context.jsonld", + "expect": "invalid term definition" + }, { + "@id": "#tp008", + "@type": ["jld:NegativeEvaluationTest", "jld:CompactTest"], + "name": "@prefix must be a boolean", + "purpose": "@prefix must be a boolean in a term definition in 1.0", + "option": {"processingMode": "json-ld-1.1"}, + "input": "error-p008-in.jsonld", + "context": "error-p008-context.jsonld", + "expect": "invalid @prefix value" }, { "@id": "#ts001", "@type": ["jld:NegativeEvaluationTest", "jld:ExpandTest"], diff --git a/test-suite/tests/error-p007-context.jsonld b/test-suite/tests/error-p007-context.jsonld new file mode 100644 index 000000000..f2829c077 --- /dev/null +++ b/test-suite/tests/error-p007-context.jsonld @@ -0,0 +1,5 @@ +{ + "@context": { + "foo": {"@id": "http://example/foo", "@prefix": true} + } +} \ No newline at end of file diff --git a/test-suite/tests/error-p007-in.jsonld b/test-suite/tests/error-p007-in.jsonld new file mode 100644 index 000000000..ffc25a6b7 --- /dev/null +++ b/test-suite/tests/error-p007-in.jsonld @@ -0,0 +1,3 @@ +{ + "http://example/foo": "bar" +} \ No newline at end of file diff --git a/test-suite/tests/error-p008-context.jsonld b/test-suite/tests/error-p008-context.jsonld new file mode 100644 index 000000000..1fde76ae9 --- /dev/null +++ b/test-suite/tests/error-p008-context.jsonld @@ -0,0 +1,5 @@ +{ + "@context": { + "foo": {"@id": "http://example/foo", "@prefix": "string"} + } +} \ No newline at end of file diff --git a/test-suite/tests/error-p008-in.jsonld b/test-suite/tests/error-p008-in.jsonld new file mode 100644 index 000000000..ffc25a6b7 --- /dev/null +++ b/test-suite/tests/error-p008-in.jsonld @@ -0,0 +1,3 @@ +{ + "http://example/foo": "bar" +} \ No newline at end of file From 526ab56183eaa5fae5ad7a23fcc8cd11f4dbf25a Mon Sep 17 00:00:00 2001 From: Gregg Kellogg Date: Sun, 9 Jul 2017 23:12:15 -0700 Subject: [PATCH 09/11] Slight improvement on creating and checking terms that can be used as prefixes. --- spec/latest/json-ld-api/index.html | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/spec/latest/json-ld-api/index.html b/spec/latest/json-ld-api/index.html index 5ec083195..6df36d9c6 100644 --- a/spec/latest/json-ld-api/index.html +++ b/spec/latest/json-ld-api/index.html @@ -1034,11 +1034,12 @@

    Algorithm

    error has been detected and processing is aborted; if it equals @context, an invalid keyword alias error has been detected and processing is aborted. -
  • If processing mode is json-ld-1.0, and the, +
  • If term does not contain a colon (:), + and if processing mode is json-ld-1.0, and the, IRI mapping of definition ends with a URI gen-delim character, set the prefix flag in definition to true. - Otherwise, if the IRI mapping ends with a URI + If processing mode is not json-ld-1.0, and the IRI mapping ends with a URI gen-delim character, set the prefix flag in definition to true, only if value was originally a string.
  • @@ -1135,7 +1136,8 @@

    Algorithm

  • If value contains the key @prefix:
      -
    1. If processingMode is json-ld-1.0, an +
    2. If processingMode is json-ld-1.0, or if + term contains a colon (:), an invalid term definition has been detected and processing is aborted.
    3. Initialize the prefix flag to the value associated with the From e6b5676af316af0246fe232b20936cc96fea9cf5 Mon Sep 17 00:00:00 2001 From: Gregg Kellogg Date: Mon, 10 Jul 2017 08:15:56 -0700 Subject: [PATCH 10/11] Add @prefix use in grammar. --- spec/latest/json-ld/index.html | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/spec/latest/json-ld/index.html b/spec/latest/json-ld/index.html index fa4188b06..21ea54c84 100644 --- a/spec/latest/json-ld/index.html +++ b/spec/latest/json-ld/index.html @@ -3699,7 +3699,8 @@

      Context Definitions

      An expanded term definition MUST be a JSON object composed of zero or more keys from @id, @reverse, - @type, @language, @context or @container. An + @type, @language, @context, + @prefix or @container. An expanded term definition SHOULD NOT contain any other keys.

      If an expanded term definition has an @reverse member, @@ -3744,14 +3745,17 @@

      Context Definitions

      If an expanded term definition has an @context member, it MUST be a valid context definition.

      +

      If the expanded term definition contains the @nest + keyword, its value MUST be either @nest, or a term + which expands to @nest.

      + +

      If the expanded term definition contains the @prefix + keyword, its value MUST be true or false.

      +

      Terms MUST NOT be used in a circular manner. That is, the definition of a term cannot depend on the definition of another term if that other term also depends on the first term.

      -

      If the expanded term definition contains the @nest - keyword, its value MUST be either @nest, or a term - which expands to @nest.

      -

      See for further discussion on contexts.

      From f87ef0e60e322682556d0e4e22e0728a46843980 Mon Sep 17 00:00:00 2001 From: Gregg Kellogg Date: Mon, 10 Jul 2017 11:52:42 -0700 Subject: [PATCH 11/11] Couple of more tests on prefixes. --- test-suite/tests/compact-manifest.jsonld | 8 ++++++++ test-suite/tests/compact-p007-context.jsonld | 6 ++++++ test-suite/tests/compact-p007-in.jsonld | 4 ++++ test-suite/tests/compact-p007-out.jsonld | 8 ++++++++ test-suite/tests/error-manifest.jsonld | 11 ++++++++++- test-suite/tests/error-p009-context.jsonld | 5 +++++ test-suite/tests/error-p009-in.jsonld | 3 +++ 7 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 test-suite/tests/compact-p007-context.jsonld create mode 100644 test-suite/tests/compact-p007-in.jsonld create mode 100644 test-suite/tests/compact-p007-out.jsonld create mode 100644 test-suite/tests/error-p009-context.jsonld create mode 100644 test-suite/tests/error-p009-in.jsonld diff --git a/test-suite/tests/compact-manifest.jsonld b/test-suite/tests/compact-manifest.jsonld index 4bd325817..eebe0a15a 100644 --- a/test-suite/tests/compact-manifest.jsonld +++ b/test-suite/tests/compact-manifest.jsonld @@ -888,6 +888,14 @@ "input": "compact-p006-in.jsonld", "context": "compact-p006-context.jsonld", "expect": "compact-p006-out.jsonld" + }, { + "@id": "#tp007", + "@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"], + "name": "Compact IRI not used as prefix", + "purpose": "Terms including a colon are excluded from being used as a prefix", + "input": "compact-p007-in.jsonld", + "context": "compact-p007-context.jsonld", + "expect": "compact-p007-out.jsonld" }, { "@id": "#tr001", "@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"], diff --git a/test-suite/tests/compact-p007-context.jsonld b/test-suite/tests/compact-p007-context.jsonld new file mode 100644 index 000000000..29d4f9743 --- /dev/null +++ b/test-suite/tests/compact-p007-context.jsonld @@ -0,0 +1,6 @@ +{ + "@context": { + "foo": "http://example.org/", + "foo:bar": "foo:baz/" + } +} diff --git a/test-suite/tests/compact-p007-in.jsonld b/test-suite/tests/compact-p007-in.jsonld new file mode 100644 index 000000000..0594114e8 --- /dev/null +++ b/test-suite/tests/compact-p007-in.jsonld @@ -0,0 +1,4 @@ +{ + "@id": "http://example.org/baz/a", + "http://example.org/baz/b": "c" +} diff --git a/test-suite/tests/compact-p007-out.jsonld b/test-suite/tests/compact-p007-out.jsonld new file mode 100644 index 000000000..48b60a7bd --- /dev/null +++ b/test-suite/tests/compact-p007-out.jsonld @@ -0,0 +1,8 @@ +{ + "@context": { + "foo": "http://example.org/", + "foo:bar": "foo:baz/" + }, + "@id": "foo:baz/a", + "foo:baz/b": "c" +} diff --git a/test-suite/tests/error-manifest.jsonld b/test-suite/tests/error-manifest.jsonld index 90890e1f4..bda5a3cfb 100644 --- a/test-suite/tests/error-manifest.jsonld +++ b/test-suite/tests/error-manifest.jsonld @@ -442,11 +442,20 @@ "@id": "#tp008", "@type": ["jld:NegativeEvaluationTest", "jld:CompactTest"], "name": "@prefix must be a boolean", - "purpose": "@prefix must be a boolean in a term definition in 1.0", + "purpose": "@prefix must be a boolean in a term definition in 1.1", "option": {"processingMode": "json-ld-1.1"}, "input": "error-p008-in.jsonld", "context": "error-p008-context.jsonld", "expect": "invalid @prefix value" + }, { + "@id": "#tp009", + "@type": ["jld:NegativeEvaluationTest", "jld:CompactTest"], + "name": "@prefix not allowed on compact IRI term", + "purpose": "If processingMode is json-ld-1.0, or if term contains a colon (:), an invalid term definition has been detected and processing is aborted.", + "option": {"processingMode": "json-ld-1.1"}, + "input": "error-p009-in.jsonld", + "context": "error-p009-context.jsonld", + "expect": "invalid term definition" }, { "@id": "#ts001", "@type": ["jld:NegativeEvaluationTest", "jld:ExpandTest"], diff --git a/test-suite/tests/error-p009-context.jsonld b/test-suite/tests/error-p009-context.jsonld new file mode 100644 index 000000000..7d7d2eae9 --- /dev/null +++ b/test-suite/tests/error-p009-context.jsonld @@ -0,0 +1,5 @@ +{ + "@context": { + "foo:bar": {"@id": "http://example/foo/bar/", "@prefix": true} + } +} \ No newline at end of file diff --git a/test-suite/tests/error-p009-in.jsonld b/test-suite/tests/error-p009-in.jsonld new file mode 100644 index 000000000..6a50fcaa1 --- /dev/null +++ b/test-suite/tests/error-p009-in.jsonld @@ -0,0 +1,3 @@ +{ + "http://example/foo/bar/": "bar" +} \ No newline at end of file