From 30cc8d432e724c8d809ee32dd83e3afd238c17c5 Mon Sep 17 00:00:00 2001 From: Gregg Kellogg Date: Mon, 27 Jan 2020 15:13:38 -0800 Subject: [PATCH 1/6] Updates to pass base URL to Expansion, Context Processing and Create Term definition. For #265. --- index.html | 216 +++++++++++++++++++++++++++++------------------------ 1 file changed, 118 insertions(+), 98 deletions(-) diff --git a/index.html b/index.html index 8c7ed1ce..d2b0fef6 100644 --- a/index.html +++ b/index.html @@ -1080,16 +1080,19 @@

RDF Serialization/Deserialization

Each term definition consists of:

A term definition can not only be used to map a term @@ -1171,11 +1174,15 @@

Overview

Algorithm

This algorithm specifies how a new active context is updated - with a local context. The algorithm takes two required + with a local context. The algorithm takes three required and three optional input variables. - The required inputs are an active context and a local context. - The optional inputs are an array remote contexts, + The required inputs are + an active context, + a local context, + and a base URL used when resolving relative context URLs. + The optional inputs are + an array remote contexts, defaulting to a new empty array, which is used to detect cyclical context inclusions, override protected, defaulting to false, @@ -1209,46 +1216,21 @@

Algorithm

  • Otherwise, initialize result as a newly-initialized active context, setting previous context in result - to the previous value of result if propagate is false. + to the previous value of result if propagate is false + and base IRI to the value of the {{JsonLdOptions/base}} option + of the , + if provided, otherwise to base URL. Continue with the next context. -
    In [[[JSON-LD10]]], the base IRI was given - a default value here; this is now described conditionally - in the {{JsonLdOptions/base}} option - of the . -
  • If context is a string, -
    - In order to prevent being overly prescriptive, - this algorithm makes no statement about how internal state is kept for dereferenced context documents - and broadly applies error handling checks. - Provided that the output of the algorithm is unchanged, - implementations may employ optimizations. -
    1. Initialize context to the result of resolving context against - the base IRI - of the document containing the local context - which is established as specified in - section 5.1 Establishing a Base URI - of [[RFC3986]]. Only the basic algorithm in - section 5.2 - of [[RFC3986]] is used; neither - Syntax-Based Normalization nor - Scheme-Based Normalization - are performed. Characters additionally allowed in IRI - references are treated in the same way that unreserved - characters are treated in URI references, per - section 6.5 - of [[RFC3987]]. + base URL.
      - The base IRI of the document containing the local context - is often not the same as {{JsonLdOptions/base}} + base URL is often not the same as {{JsonLdOptions/base}} or the base IRI of the active context. - Processors are responsible for retaining the {{RemoteDocument/documentUrl}} - for documents being processed via this algorithm for use in resolving context.
    2. If the number of entries in the remote contexts array @@ -1262,25 +1244,39 @@

      Algorithm

      previously established internal representation.
      Only the `@context` entry need be retained.
    3. -
    4. Otherwise, dereference context using +
    5. Otherwise, set context document + to the {{RemoteDocument}} obtained + by dereferencing context using the LoadDocumentCallback, passing context for url, and http://www.w3.org/ns/json-ld#context for profile and for requestProfile.
      1. If context cannot be dereferenced, - or cannot be transformed into the internal representation, + + or the {{RemoteDocument/document}} from context document + cannot be transformed into the internal representation + , a loading remote context failed - error has been detected and processing is aborted. If the dereferenced document has no + error has been detected and processing is aborted.
      2. +
      3. If the {{RemoteDocument/document}} has no top-level map with an @context entry, an invalid remote context has been detected and processing is aborted.
      4. -
      5. Otherwise, set context to the value of that entry.
      6. +
      7. Set loaded context to the value of that entry.
    6. Set result to the result of recursively calling this algorithm, passing result for active context, - context for local context, and a copy of remote contexts.
    7. + loaded context for local context, + + the {{RemoteDocument/documentUrl}} of context document for base URL, + + and a copy of remote contexts. +
      If context was previously dereferenced, + processors MUST make provisions for retaining the base URL + of that context for this step.
      +
    8. Continue with the next context.
  • @@ -1316,18 +1312,7 @@

    Algorithm

    an invalid @import value error has been detected and processing is aborted.
  • Initialize import to the result of resolving the value of @import against - the base IRI which is established as specified in - section 5.1 Establishing a Base URI - of [[RFC3986]]. Only the basic algorithm in - section 5.2 - of [[RFC3986]] is used; neither - Syntax-Based Normalization nor - Scheme-Based Normalization - are performed. Characters additionally allowed in IRI - references are treated in the same way that unreserved - characters are treated in URI references, per - section 6.5 - of [[RFC3987]].
  • + base URL.
  • Dereference import using the LoadDocumentCallback, passing import for url, @@ -1459,6 +1444,7 @@

    Algorithm

    context for local context, key, defined, + base URL, and the value of the @protected entry from context, if any, for protected . @@ -1508,11 +1494,14 @@

    Overview

    Algorithm

    -

    The algorithm has four required and two optional inputs. +

    The algorithm has four required and three optional inputs. The required inputs are - an active context, a local context, - a term, and a map defined. + an active context, + a local context, + a term, + and a map defined. The optional inputs are + base URL, protected which defaults to false, and override protected, defaulting to false, which is used to allow changes to protected terms.. @@ -1561,7 +1550,10 @@

    Algorithm

    invalid term definition error has been detected and processing is aborted. Set simple term to false.
  • -
  • Create a new term definition, definition.
  • +
  • Create a new term definition, definition, + initializing prefix flag to `false`, + protected to protected, + and reverse property to `false`.
  • If the @protected entry in value is true set the protected flag in definition to true. If the value of `@protected` is not a boolean, @@ -1569,9 +1561,6 @@

    Algorithm

    If processing mode is `json-ld-1.0`, an invalid term definition has been detected and processing is aborted.
  • -
  • Otherwise, if there is no @protected entry in value - and the protected parameter is true, - set the protected in definition to true.
  • If value contains the entry @type:
    1. Initialize type to the value associated with the @@ -1632,8 +1621,6 @@

      Algorithm

      true and return.
  • -
  • Set the reverse property flag of definition - to false.
  • If value contains the entry @id and its value does not equal term:
      @@ -1787,6 +1774,7 @@

      Algorithm

      @context entry, which is treated as a local context.
    1. Invoke the Context Processing algorithm using the active context, context as local context, + base URL, and true for override protected. If any error is detected, an invalid scoped context error @@ -1795,7 +1783,8 @@

      Algorithm

      is discarded; it is called to detect errors at definition time. If used, the context will be re-processed and applied to the active context as part of expansion or compaction.

    2. -
    3. Set the local context of definition to context.
    4. +
    5. Set the local context of definition to context, + and base URL to base URL.
  • If value contains the entry @language and @@ -1844,7 +1833,7 @@

    Algorithm

    term contains a colon (:) or slash (`/`), an invalid term definition has been detected and processing is aborted.
  • -
  • Initialize the prefix flag to the value associated with the +
  • Set the prefix flag to the value associated with the @prefix entry, which MUST be a boolean. Otherwise, an invalid @prefix value error has been detected and processing is aborted.
  • @@ -2371,9 +2360,11 @@

    Overview

    Algorithm

    -

    The algorithm takes three required and three optional input variables. +

    The algorithm takes four required and three optional input variables. The required inputs are an active context, - an active property, and an element to be expanded. + an active property, an element to be expanded, + and a base URL associated with the {{RemoteDocument/documentUrl}} of the original + document to expand. The optional inputs are the {{JsonLdOptions/frameExpansion}} flag allowing special forms of input used for frame expansion, @@ -2426,7 +2417,9 @@

    Algorithm

  • If property-scoped context is defined, set active context to the result of the Context Processing algorithm, - passing active context and property-scoped context as local context.
  • + passing active context, property-scoped context as local context, + and base URL from the term definition for active property + in active context.
  • Return the result of the Value Expansion algorithm, passing the active context, active property, and @@ -2441,6 +2434,7 @@

    Algorithm

  • Initialize expanded item to the result of using this algorithm recursively, passing active context, active property, item as element, + base URL, the {{JsonLdOptions/frameExpansion}} {{JsonLdOptions/ordered}}, and from map flags.
  • @@ -2472,12 +2466,15 @@

    Algorithm

    set active context to the result of the Context Processing algorithm, passing active context, property-scoped context as local context, + base URL from the term definition for active property, + in active context and `true` for override protected.
  • If element contains the entry @context, set active context to the result of the Context Processing algorithm, - passing active context and the value of the - @context entry as local context.
  • + passing active context, the value of the + @context entry as local context + and base URL.
  • Initialize type-scoped context to active context. This is used for expanding values that may be relevant to any previous type-scoped context.
  • @@ -2494,6 +2491,8 @@

    Algorithm

    passing active context, the value of the term's local context as local context, + base URL from the term definition for value + in active context, and `false` for propagate. @@ -2590,6 +2589,7 @@

    Algorithm

    expanded value to the result of using this algorithm recursively passing active context, @graph for active property, value for element, + base URL, and the {{JsonLdOptions/frameExpansion}} and {{JsonLdOptions/ordered}} flags, @@ -2601,6 +2601,7 @@

    Algorithm

  • Set expanded value to the result of using this algorithm recursively passing active context, active property, value for element, + base URL, and the {{JsonLdOptions/frameExpansion}} and {{JsonLdOptions/ordered}} flags, ensuring that the result is an array.
  • @@ -2694,6 +2695,7 @@

    Algorithm

  • Otherwise, initialize expanded value to the result of using this algorithm recursively passing active context, active property, value for element, + base URL, and the {{JsonLdOptions/frameExpansion}} and {{JsonLdOptions/ordered}} flags, ensuring that the result is an array..
  • @@ -2703,6 +2705,7 @@

    Algorithm

    expanded value to the result of using this algorithm recursively, passing active context, active property, value for element, + base URL, and the {{JsonLdOptions/frameExpansion}} and {{JsonLdOptions/ordered}} flags.
  • If expanded property is @reverse: @@ -2714,6 +2717,7 @@

    Algorithm

    algorithm recursively, passing active context, @reverse as active property, value as element, + base URL, and the {{JsonLdOptions/frameExpansion}} and {{JsonLdOptions/ordered}} flags.
  • If expanded value contains an @reverse entry, @@ -2763,6 +2767,7 @@

    Algorithm

    Expansion Algorithm recursively, passing active context, active property, value for element, + base URL, and the {{JsonLdOptions/frameExpansion}} and {{JsonLdOptions/ordered}} flags.
  • Unless expanded value is null, @@ -2849,8 +2854,10 @@

    Algorithm

    map context to the result of the Context Processing algorithm, passing map context as active context - and the value of the index's local context - as local context.
  • + the value of the index's local context + as local context + and base URL from the term definition for index + in map context.
  • Otherwise, set map context to active context.
  • Initialize expanded index to the result of IRI expanding index.
  • @@ -2862,6 +2869,7 @@

    Algorithm

    map context as active context, key as active property, index value as element, + base URL, and the {{JsonLdOptions/frameExpansion}} and {{JsonLdOptions/ordered}} flags.
  • For each item in index value: @@ -2921,6 +2929,7 @@

    Algorithm

  • Otherwise, initialize expanded value to the result of using this algorithm recursively, passing active context, key for active property, value for element, + base URL, and the {{JsonLdOptions/frameExpansion}} and {{JsonLdOptions/ordered}} flags.
  • If expanded value is null, ignore key @@ -3397,14 +3406,17 @@

    Algorithm

    and element does not consist of a single @id entry, set active context to previous context from active context, as the scope of a term-scoped context does not apply when processing new node objects.
  • -
  • If the term definition for active property has a - local context: +
  • If the term definition for active property in active context + has a local context:
    1. Set active context to the result of the Context Processing algorithm, - passing active context, the value of the - active property's local context as local context, - and true for override protected.
    2. + passing active context, + the value of the active property's local context as local context, + + base URL from the term definition for active property + in active context, + and true for override protected.
    3. Set inverse context using the Inverse Context Creation algorithm using active context.
    4. @@ -3446,7 +3458,10 @@

      Algorithm

    5. Set active context to the result of the Context Processing algorithm, passing active context and the value of term's - local context in type-scoped context as local context.
    6. + local context in type-scoped context as local context + + base URL from the term definition for term + in type-scoped context.
    7. Set inverse context using the Inverse Context Creation algorithm using active context.
    8. @@ -5603,10 +5618,10 @@

      Algorithm

      If the documentLoader option is specified, it is used to dereference remote documents and contexts. - The documentUrl + The {{RemoteDocument/documentUrl}} in the returned RemoteDocument is used as base IRI and the - contextUrl + {{RemoteDocument/contextUrl}} is used instead of looking at the HTTP Link Header directly. For the sake of simplicity, none of the algorithms in this document mention this directly.

      @@ -5658,6 +5673,8 @@

      Algorithm

      and options, with {{JsonLdOptions/ordered}} set to false, and {{JsonLdOptions/extractAllScripts}} defaulting to false. +
    9. Set context base to the {{RemoteDocument/documentUrl}} obtained + when loading the document in the previous step.
    10. If context is a map having an @context entry, set context to that entry's value, @@ -5665,7 +5682,8 @@

      Algorithm

    11. Initialize active context to the result of the Context Processing algorithm passing a new empty context as active context - and context as local context.
    12. + context as local context, + and context base as base URL.
    13. Initialize inverse context to the result of performing the Inverse Context Creation algorithm.
    14. Initialize base IRI to the {{JsonLdOptions/base}} option from options, if set; @@ -5728,28 +5746,30 @@

      Algorithm

      for url, the {{JsonLdOptions/extractAllScripts}} option for extractAllScripts.
    15. -
    16. If document +
    17. If {{RemoteDocument/document}} from remote document is a string, transform into the internal representation. - If document cannot be transformed to the internal representation, + If {{RemoteDocument/document}} cannot be transformed to the internal representation, reject promise passing a loading document failed error.
    18. Initialize a new empty active context. - The base IRI of the active context is set to the documentUrl + The base IRI of the active context is set to the {{RemoteDocument/documentUrl}} from remote document, if available; otherwise to null. If set, the {{JsonLdOptions/base}} option from options overrides the base IRI.
    19. If an {{JsonLdOptions/expandContext}} option has been passed, update the active context using the Context Processing algorithm, - passing the {{JsonLdOptions/expandContext}} as local context. + passing the {{JsonLdOptions/expandContext}} as local context + and {{JsonLdOptions/expandContext}} as base URL. If {{JsonLdOptions/expandContext}} is a map having an @context entry, pass that entry's value instead.
    20. -
    21. If remote document has a contextUrl, +
    22. If remote document has a {{RemoteDocument/contextUrl}}, update the active context using the Context Processing algorithm, - passing the contextUrl as local context.
    23. + passing the {{RemoteDocument/contextUrl}} as local context, + and {{RemoteDocument/contextUrl}} as base URL.
    24. Set expanded output to the result of using the Expansion algorithm, passing the active context, - and document - from remote document, or input + {{RemoteDocument/document}} from remote document or input if there is no remote document as element, + {{RemoteDocument/documentUrl}} as base URL, and if passed, the {{JsonLdOptions/frameExpansion}} and {{JsonLdOptions/ordered}} flags in options. @@ -6251,7 +6271,7 @@

      LoadDocumentCallback

      +json suffix as defined in [[RFC6839]]. Reject the promise passing a loading document failed error.
    25. Create a new RemoteDocument remote document using document, - the returned Content-Type (without parameters) as contentType, + the returned Content-Type (without parameters) as {{RemoteDocument/contentType}}, any returned profile parameter, and any contextUrl.
    26. Resolve the promise with remote document.
    27. @@ -6284,7 +6304,7 @@

      LoadDocumentOptions

      unless a specific fragment identifier is targeted, extracts all encountered JSON-LD script elements using an array form, if necessary.
      profile
      -
      When the resulting contentType is text/html +
      When the resulting {{RemoteDocument/contentType}} is text/html or application/xhtml+xml, this option determines the profile to use for selecting JSON-LD script elements.
      requestProfile
      @@ -6330,7 +6350,7 @@

      RemoteDocument

      of the loaded document, exclusive of any optional parameters.
      profile
      The value of any profile parameter - retrieved as part of the original contentType.
      + retrieved as part of the original {{RemoteDocument/contentType}}.
  • @@ -6778,7 +6798,7 @@

    JsonLdErrorCode

    extracting either a specifically targeted script element, the first found JSON-LD script element, or all JSON-LD script elements. -
  • Added contentType field to RemoteDocument.
  • +
  • Added {{RemoteDocument/contentType}} field to RemoteDocument.
  • Added support for protected contexts and term definitions.
  • Because scoped contexts can lead to contexts being reloaded, replace the recursive context inclusion error with a context overflow error.
  • From 64628199c3bfefc698fdb79d3e21e46706f911bd Mon Sep 17 00:00:00 2001 From: Gregg Kellogg Date: Mon, 27 Jan 2020 15:17:07 -0800 Subject: [PATCH 2/6] Fix markup. --- index.html | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/index.html b/index.html index d2b0fef6..1e36e04f 100644 --- a/index.html +++ b/index.html @@ -1092,7 +1092,6 @@

    RDF Serialization/Deserialization

  • an optional language mapping (string),
  • an optional nest value (string),
  • and an optional type mapping (IRI).
  • -

    A term definition can not only be used to map a term @@ -2474,7 +2473,7 @@

    Algorithm

    Context Processing algorithm, passing active context, the value of the @context entry as local context - and base URL. + and base URL.
  • Initialize type-scoped context to active context. This is used for expanding values that may be relevant to any previous type-scoped context.
  • From d3825a5f5d9060e475ef2707b6697a7f844e831e Mon Sep 17 00:00:00 2001 From: Gregg Kellogg Date: Tue, 28 Jan 2020 13:30:11 -0800 Subject: [PATCH 3/6] Update index.html from @dlongley suggestion. Co-Authored-By: Dave Longley --- index.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index 1e36e04f..265be836 100644 --- a/index.html +++ b/index.html @@ -1274,7 +1274,8 @@

    Algorithm

    and a copy of remote contexts.
    If context was previously dereferenced, processors MUST make provisions for retaining the base URL - of that context for this step.
    + of that context for this step to enable the resolution of any + relative context URLs that may be encountered during processing.
  • Continue with the next context.
  • From 2e78e1d1d069b5316c1253fa37af09a04d801b3b Mon Sep 17 00:00:00 2001 From: Gregg Kellogg Date: Tue, 28 Jan 2020 13:33:02 -0800 Subject: [PATCH 4/6] Remove duplicate context reference in term definition description. --- index.html | 1 - 1 file changed, 1 deletion(-) diff --git a/index.html b/index.html index 265be836..dfa9f13d 100644 --- a/index.html +++ b/index.html @@ -1086,7 +1086,6 @@

    RDF Serialization/Deserialization

  • an optional base URL (IRI),
  • an optional context (context),
  • an optional container mapping (array of strings), -
  • an optional context (context),
  • an optional direction mapping (`"ltr"` or `"rtl"`),
  • an optional index mapping (string),
  • an optional language mapping (string),
  • From dcb7a57c5aa0086c00412776f8090030708cb593 Mon Sep 17 00:00:00 2001 From: Gregg Kellogg Date: Wed, 29 Jan 2020 11:41:27 -0800 Subject: [PATCH 5/6] Use an _original base URL_ member of an _active context_ to record the original documentUrl containing the top-most context. This is initialized in `expand()` and when a _local context_ is `null`. --- index.html | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/index.html b/index.html index dfa9f13d..e71031a6 100644 --- a/index.html +++ b/index.html @@ -1070,6 +1070,7 @@

    RDF Serialization/Deserialization

  • the active term definitions which specify how keys and values have to be interpreted (array of term definitions),
  • the current base IRI (IRI),
  • +
  • the original base URL (IRI),
  • an optional vocabulary mapping (IRI),
  • an optional default language (string),
  • an optional default base direction (`"ltr"` or `"rtl"`),
  • @@ -1154,6 +1155,15 @@

    Overview

    it may be rolled back when a new node object is entered. By default, all contexts are propagated, other than type-scoped contexts.

    +

    + When an active context is initialized, the value + of the original base URL + is initialized from the original {{RemoteDocument/documentUrl}} + of the document containing the initial context. + This is necessary when resetting the active context + by setting it to `null` + to retain the original default base IRI.

    +

    Then, for every other entry in local context, we update the term definition in result. Since term definitions in a local context @@ -1211,15 +1221,13 @@

    Algorithm

    contains any protected term definitions, an invalid context nullification has been detected and processing is aborted. -
  • Otherwise, initialize result as a - newly-initialized active context, +
  • Initialize result as a + newly-initialized active context, setting previous context in result - to the previous value of result if propagate is false - and base IRI to the value of the {{JsonLdOptions/base}} option - of the , - if provided, otherwise to base URL. - Continue with the next context. -
  • + to the previous value of result if propagate is false + and both base IRI and original base URL to the value of + original base URL in active context
    . +
  • Continue with the next context.
  • If context is a string, @@ -5750,7 +5758,7 @@

    Algorithm

    If {{RemoteDocument/document}} cannot be transformed to the internal representation, reject promise passing a loading document failed error.
  • Initialize a new empty active context. - The base IRI of the active context is set to the {{RemoteDocument/documentUrl}} + The base IRI and original base URL of the active context is set to the {{RemoteDocument/documentUrl}} from remote document, if available; otherwise to null. If set, the {{JsonLdOptions/base}} option from options overrides the base IRI.
  • From 2614999c9823ddc6195c8ad9a0aaf120e32f8486 Mon Sep 17 00:00:00 2001 From: Gregg Kellogg Date: Wed, 29 Jan 2020 11:43:08 -0800 Subject: [PATCH 6/6] Update jsonld.js. --- common/jsonld.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/jsonld.js b/common/jsonld.js index 1756474b..f37bb152 100644 --- a/common/jsonld.js +++ b/common/jsonld.js @@ -61,11 +61,11 @@ const jsonld = { }, "JCS": { title: "JSON Canonicalization Scheme (JCS)", - href: 'https://tools.ietf.org/html/draft-rundgren-json-canonicalization-scheme-05', + href: 'https://tools.ietf.org/html/draft-rundgren-json-canonicalization-scheme-17', authors: ['A. Rundgren', 'B. Jordan', 'S. Erdtman'], publisher: 'Network Working Group', status: 'Internet-Draft', - date: 'February 16, 2019' + date: '20 January 2020' }, // These necessary as specref uses the wrong URLs "RFC7231": {