Skip to content

"Create term definition" algorithm expands schema part of an absolute IRI as if it is a compact IRI #96

Closed
@lo48576

Description

@lo48576

Summary

playground: https://json-ld.org/playground/#startTab=tab-expanded&json-ld=%7B%22%40context%22%3A%7B%22http%22%3A%22schema%3A%2F%2Fhello%22%2C%22http%3A%2F%2Fexample.com%22%3A%7B%22%40type%22%3A%22http%3A%2F%2Ftype%22%7D%7D%2C%22http%3A%2F%2Fexample.com%22%3A%222000%22%7D

"Create term definition" algorithm has a step that replaces schema part of an absolute IRI to another IRI (the IRI mapping for the term that equals to the schema string).
This causes "http://example.com" to be replaced to "schema://hello//example.com" (in example above), but this is unexpected for me.

I'm not sure if this is a bug, but I want to know this is intended behavior or not.

If this is not intended, step 14.2 in JSON-LD-API 1.0 and step 17.2 in JSON-LD-API 1.1 (TR) should be like this:
"If term is a compact IRI and term's prefix has a term definition in active context, set the IRI mapping of ...".

Details

Create term definition has the steps below:

  • If term contains a colon:
    • If term is a compact IRI with a prefix that is a key in local context, recursively create term definition for the prefix.
    • If term's prefix has a term definition in active context, concatenate IRI mapping for the prefix and the term's suffix.
    • Otherwise, term is an absolute IRI or blank node identifier. Use it as is.

For exact definitions, see step 14 in JSON-LD-API 1.0 §6.2 Create Term Definition, and JSON-LD-API 1.1 §4.2 Create Term Definition step 17.

json-ld-api/index.html

Lines 1405 to 1422 in 4725397

<li>
Otherwise if the <var>term</var> contains a colon (<code>:</code>):
<ol>
<li>If <var>term</var> is a <a>compact IRI</a> with a
<a>prefix</a> that is a <a>member</a> in <var>local context</var>
a dependency has been found. Use this algorithm recursively passing
<var>active context</var>, <var>local context</var>, the
<a>prefix</a> as <var>term</var>, and <var>defined</var>.</li>
<li>If <var>term</var>'s <a>prefix</a> has a
<a>term definition</a> in <var>active context</var>, set
the <a>IRI mapping</a> of <var>definition</var> to the result of
concatenating the value associated with the <a data-lt="prefix">prefix's</a>
<a>IRI mapping</a> and the <var>term</var>'s <var>suffix</var>.</li>
<li>Otherwise, <var>term</var> is an <a>absolute IRI</a> or
<a>blank node identifier</a>. Set the <a>IRI mapping</a>
of <var>definition</var> to <var>term</var>.</li>
</ol>
</li>

The problem is the second substep, "If term's prefix has a term definition in active context, ...".
This step replaces prefix of a compact IRI (for example xsd:dateTime to http://www.w3.org/2001/XMLSchema#dateTime), which is expected behavior.
However, this condition does not require term to be a compact IRI (which is required in the previous substep), and this causes an absolute IRI to be replaced if the schema (such as http) has a corresponding term definition.
For example, http://example.com is replaced to schema://hello//example.com in such cases.

I think the second substep should be like this: "If term is a compact IRI and term's prefix has a term definition in active context, set the IRI mapping of ...".

Example

playground: https://json-ld.org/playground/#startTab=tab-expanded&json-ld=%7B%22%40context%22%3A%7B%22http%22%3A%22schema%3A%2F%2Fhello%22%2C%22http%3A%2F%2Fexample.com%22%3A%7B%22%40type%22%3A%22http%3A%2F%2Ftype%22%7D%7D%2C%22http%3A%2F%2Fexample.com%22%3A%222000%22%7D

input

Attempt to associate "2000" value to the absolute IRI http://example.com.

{
  "@context": {
    "http": "schema://hello",
    "http://example.com": {
      "@type": "http://type"
    }
  },
  "http://example.com": "2000"
}

actual output

Absolute IRI http://example.com in input document is replaced to schema://hello//example.com, as if it was a compact IRI.

[
  {
    "schema://hello//example.com": [
      {
        "@type": "http://type",
        "@value": "2000"
      }
    ]
  }
]

expected

http://example.com is preserved even when a term http is expandable to another IRI, because http://example.com is not a compact IRI.

[
  {
    "http://example.com": [
      {
        "@type": "http://type",
        "@value": "2000"
      }
    ]
  }
]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions