Skip to content

JSON-LD 1.1 Feature Request: Prefer simple terms to complex terms when creating Compact IRIs. #405

@gkellogg

Description

@gkellogg

As mentioned in #404, JSON-LD IRI compaction to Compact IRI representations can generate non-desirable results.

Take, for example, the following JSON-LD context (abbreviated from the actual schema.org context):

{
  "@context": {
    "schema": "http://schema.org/",
    "sport": { "@id": "http://schema.org/sport", "@type": "@id" }
  }
}

Then, compact the following:

[{
  "http://schema.org/sportsEvent": {"@id": "http://example.com/event"}
}]

What you get is the following:

{
  "@context": {
    "schema": "http://schema.org/",
    "sport": {
      "@id": "http://schema.org/sport",
      "@type": "@id"
    }
  },
  "sport:sEvent": {
    "@id": "http://example.com/event"
  }
}

when, what is expected is:

{
  "@context": {
    "schema": "http://schema.org/",
    "sport": {
      "@id": "http://schema.org/sport",
      "@type": "@id"
    }
  },
  "schema:sportsEvent": {
    "@id": "http://example.com/event"
  }
}

The reason for this is that the compactIri algorithm looks for the shortest Compact IRI.

This was addressed in the Ruby JSON-LD gem in ruby-rdf/json-ld@c8760e2 by adding a simple_compact_iris option. This uses the concept of a simple term definition (i.e., a term definition which is not an expanded term definition) and favors a simple term definition over an expanded term definition when creating a Compact IRI. With this option, step 5 of the IRI Compaction Algorithm is modified:

For each key term and value term definition which is a simple term definition in the active context:

An alternative would be to make two passes, one using simple term definition and the next, if no compact IRI is generated, using expanded term definitions.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions