W3C home > Mailing lists > Public > public-linked-json@w3.org > January 2017

Scoped Contexts

From: Gregg Kellogg <gregg@greggkellogg.net>
Date: Sun, 1 Jan 2017 18:23:59 -0800
Message-Id: <5743F000-1C08-4A27-A442-7CF2CA9D6FB1@greggkellogg.net>
To: Linked JSON <public-linked-json@w3.org>
I added specification text to JSON-LD and JSON-LD-API to support scoped contexts [1]. This ended up being a fairly minor change to context, compaction and expansion algorithms. Basically, the desire is to be able to define a term with a local context such that for values of that term, the context associated with the term is used in just the same way as if the context had been specified within the source. This allows, for example, values to be included that use a different namespace for properties. For example:


{
   "@context":
  {
    "name": "http://schema.org/name",
    "interest": {
      "@id":"http://xmlns.com/foaf/0.1/interest",
      "@context": {"@vocab": "http://xmlns.com/foaf/0.1/"}
    }
  },
  "name": "Manu Sporny",
  "interest": {
    "@id": "https://www.w3.org/TR/json-ld/",
    "name": "JSON-LD",
    "topic": "Linking Data"
  }
}

Defines “interest” with a local context which uses the default vocabulary for FOAF. The node object value of “interest” then has otherwise undefined property terms expanded using the context definition contained within the “interest” term. The resulting expanded value looks like the following:


[{
  "http://schema.org/name": [{"@value": "Manu Sporny"}],
  "http://xmlns.com/foaf/0.1/interest": [{
    "@id": "https://www.w3.org/TR/json-ld/",
    "http://schema.org/name": [{"@value": "JSON-LD"}],
    "http://xmlns.com/foaf/0.1/topic": [{"@value": "Linking Data"}]
  }]
}]

Expansion is modified to look up a term context when it is encountered and use that instead of the otherwise active context when expanding values.

Compaction is modified to see if the input property parameter has a local context associated with it in active context, and to update active context accordingly.

I don’t think this should be too controversial, so I’ll give this a week for feedback before merging the pull request.

Gregg Kellogg
gregg@greggkellogg.net

[1] https://github.com/json-ld/json-ld.org/pull/445
Received on Monday, 2 January 2017 02:24:34 UTC

This archive was generated by hypermail 2.3.1 : Monday, 2 January 2017 02:24:35 UTC