Skip to content

Expanding @vocab properties consistently #56

Closed
@pjohnston-wiley

Description

@pjohnston-wiley

(I wasn't sure if this was a syntax or an API issue. If i got the wrong one, please let me know and i will refile)

Consider the following:

{
  "@context": {
    "@base": "http://example1.com/",
    "ex1": "http://example1.com/",
    "ex2": "http://example2.com/",
    "id": "@id",
    "fred": {
      "@id": "ex1:fred",
      "@type": "@vocab"
    },
    "barney": {
      "@id": "ex2:barney"
    },
    "mnemonic": "rdf:value"
  },
  "fred": [
    {
      "id": "barney",
      "mnemonic": "the sidekick"
    },
    "barney"
  ]
}

The counterintuitive result of expansion is:

[
  {
    "http://example1.com/fred": [
      {
        "@id": "http://example1.com/barney",
        "rdf:value": [
          {
            "@value": "the sidekick"
          }
        ]
      },
      {
        "@id": "http://example2.com/barney"
      }
    ]
  }
]

In other words, one barney registers as a result of the top-level @vocab declaration, while the other registers as a result of the specific barney alias against the fred property of type @vocab.

I understand why this happens, the spec has different algorithms for strings on the right of a property vs objects, but it's a bit odd. To the lay reader (i.e. me), it seems like an inconsistent application. If the IRI expansion algorithm were able to take into account explicit aliases for @vocab properties, it could be made consistent, and a similar application to compaction would deliver a symmetric behavior.

The context, in terms of practical application, is that we maintain an overarching RDF model to govern our data and i would like the folks implementing our APIs to know as little about the RDF-ness of it as possible, which is where JSON-LD comes in. By using @vocab i was able to get implementers to omit a namespace qualifier on plain taxonomy values (the second barney in the original example), but as soon as they want to include anything richer they have to qualify it. Using the same context, to guarantee semantic consistency the example would have to be written as:

{
    "fred": [
      "barney",
      {
         "id": "ex2:barney",
         "mnemonic": "the sidekick"
      }
    ]
}

i.e. we have to qualify the second barney with ex2 for it to work consistently, which means exposing API developers to the RDF-ness of our model, or breaking the connection.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions