Ad

JSON-LD Compact Operation Property Disambiguation

- 1 answer

Let's consider a simple JSON-LD document without a context:

[
   {
      "@id": "http://stackoverflow.com/#users",
      "http://rdfs.org/sioc/ns#name": "SO Users",
      "http://xmlns.com/foaf/0.1/member":
      {
         "@id": "http://example.com/me#me"
      }
   },
   {
      "@id": "http://example.com/me#me",
      "http://xmlns.com/foaf/0.1/givenName": "Tomasz"
   }
]

I would like to add a single @context to this document to get something like below:

{
   "@context": { /* what here? */ },
   "@graph": [
   {
      "@id": "http://stackoverflow.com/#users",
      "Name": "SO Users",
      "Members": [ "http://example.com/me#me" ]
   },
   {
      "@id": "http://example.com/me#me",
      "Name": "Tomasz"
   }]
}

The problem here would be that foaf:givenName and sioc:name properties are both mapped to Name key in json. It would not be problem when manually authoring this document, because a nested @context can be used to override properties.

However is it possible with the Compact operation as defined by JSON-LD spec? Or is the only option to map every predicate to an unambiguous property (in this case that could be Name and GivenName)

Ad

Answer

For Name to map to a different IRI within each object would require that you have a separate context in each object, or a main context and one that overrides where you want it to mean something different. However, the compaction algorithm uses a single context for the entire document, so I'm afraid that you can't do this with a standard algorithm.

An example of what you want using separate contexts could be the following:

{
   "@context": {
      "Name": "http://rdfs.org/sioc/ns#name",
      "Members": "http://xmlns.com/foaf/0.1/member" },
   "@graph": [
   {
      "@id": "http://stackoverflow.com/#users",
      "Name": "SO Users",
      "Members": [ "http://example.com/me#me" ]
   },
   {
      "@context": {"Name": "http://xmlns.com/foaf/0.1/givenName"},
      "@id": "http://example.com/me#me",
      "Name": "Tomasz"
   }]
}

We are considering a framing feature that would allow contexts to be defined and used within different frames of a document which uses object embedding, but this is just a proposal for now.

A good play to test out the effects of the different algorithms as at http://json-ld.org/playground.

Ad
source: stackoverflow.com
Ad