Skip to content

Scoped contexts #247

Closed
Closed
@davidlehn

Description

@davidlehn

While designing contexts to make writing and processing JSON-LD easier there is an issue of polluting the global context namespace with term definitions. It may be beneficial to support scoped contexts or similar functionality. This could make an "enum" pattern much easier to handle.

For instance, if you have a property http://example.com/foo with possible values http://example.com/Bar and http://example.com/Baz you currently could use JSON-LD such as:

{
  "@context": {
    "ex": "http://example.com/",
    "foo": {
      "@id": "ex:foo",
      "@type": "@vocab"
    },
    "Bar": "ex:Bar",
    "Baz": "ex:Baz"
  },
  "foo": "Bar"
}

However, this has now put Bar and Baz in the "global" namespace when perhaps they are only used as values for foo.

A possible scoped context structure could limit how terms are resolved based on current processing state:

{
  "@context": {
    "ex": "http://example.com/",
    "foo": {
      "@id": "ex:foo",
      "@type": "@vocab"
      "@context": {
        "Bar": "ex:Bar",
        "Baz": "ex:Baz"
      }
    }
  },
  "foo": "Bar"
}

The above would limit the Bar and Baz expansion to only happen when used as a value for the foo property. In addition, other properties, such as bif could redefine Bar and Baz to other local values without conflicting with the terms names that foo uses.

This feature wouldn't stop anyone from using data however they want, it would just add clarity to contexts without referring to a fully defined schema. Data still needs to be validated by some other means. There is a potential issue for confusion if you have multiple terms with similar names, but I suspect the ease of use benefits would out weight the problems. The alternate less easy to use method is to define top-level terms such as FooBar and BifBar to avoid conflicts.

Current examples of where this might be of use:

https://github.com/web-payments/payswarm.com/blob/master/contexts/payswarm-v1.jsonld

PaySwarm, as of early 2013, uses a credit card schema and has a context with cardBrand with some common brand terms defined such as Visa, MasterCard, and others. Those values are not used elsewhere. Similar with bankAccountType, currency, and various other "enum" style properties.

https://developers.google.com/gmail/schemas/reference/rsvp-action

Google, as of May 2013, started using JSON-LD for email actions. In their new RsvpAction type they have an attendance property that can take on http://schema.org/RsvpAttendance/Yes|No|Maybe. Such properties would be a prime candidate for a scoped context since it's likely the schema used restricts the valid value to those three URIs.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions