Skip to content

compaction changes the meaning of absolute IRIs in some cases #104

@pchampin

Description

@pchampin

The problem

Some absolute IRIs are undistinguishable from compact IRIs (e.g. mailto:a@b.c or tag:champin.net,2019:xyz). This is in fact the case for any IRI that has no double-slash after the first colon.

Now consider the following data (DATA1):

{
  "tag:champin.net,2019:prop": "hello world"
}

Here, the property is interpreted (by expansion or RDF-serialization) as an absolute IRI, since there is no tag prefix to interpret it as a compact IRI.

Now consider the following context (CTX1):

{"@context": {
    "tag": "http://example.org/ns/tag/"
}}

If we compact DATA1 with CTX1, we get DATA2:

{
  "@context": {
    "tag": "http://example.org/ns/tag/"
  },
  "tag:champin.net,2019:prop": "hello world"
}

(try it in the playground).

This is wrong because in DATA2, the property is now interpreted (by expansion or RDF-serialization) as http://example.org/ns/tag/champin.net,2019:prop as shown in the playground.

The compaction algorithm should detect there will be a problem when 1) it would leave an absolute IRI unmodified AND 2) the active context contains a term definition matching that IRI's scheme – call this CONDITION1.

Proposed solution 1

If CONDITION1 above is met, an error or a warning (although I would prefer an error) is raised. The rationale is that it is impossible to produce a JSON-LD document preserving this absolute IRI with the given context.

Probably this should only happen when the context has "@version": 1.1 set, to not break backward compatibility -- even though this was a bug in JSON-LD 1.0 as well...

Proposed solution 2

If CONDITION1 above is met, another context is included in the output data, which contains a fresh prefix resolving to the IRI's scheme. That fresh prefix is used to transform the absolute IRI:

{
  "@context": [
    {
      "_abs_tag": "tag:"
    },
    {
      "tag": "http://example.org/ns/tag/"
    }
  ],
  "_abs_tag:champin.net,2019:prop": "hello world"
}

But is it acceptable for the compaction algorithm to output a different context than the one given as input? Also, it might be not trivial to coin a clash-less prefix.

Proposed solution 3

Another option would be to have a microsyntax to force a string to be interpreted as an absolute IRI. This microsyntax would be used by the compaction algorithm whenever CONDITION1 above is detected. E.g.::

{
  "@context": {
    "tag": "http://example.org/ns/tag/"
  },
  "<tag:champin.net,2019:prop>": "hello world"
}

It could also be used by data authors to address the issue raised by w3c/json-ld-syntax/issues/177.

Proposed microsyntaxes:

  • put the IRI between pointy brackets, as is done in Turtle: "<tag:champin.net,2019:prop>"
  • prefix the IRI with a new "keyword-like" prefix: "@abs:tag:champin.net,2019:prop"

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions