Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scoped contexts #247

Closed
davidlehn opened this issue May 16, 2013 · 13 comments
Closed

Scoped contexts #247

davidlehn opened this issue May 16, 2013 · 13 comments

Comments

@davidlehn
Copy link
Member

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.

@dlongley
Copy link
Member

This is an interesting idea. You could think of it as if you were injecting the scoped @context into the data whenever its related term is found without having to do it in the data itself. This could also be helpful with the zero-edit design goal.

@lanthaler
Copy link
Member

This pretty much goes in the direction I tried with previous work (before JSON-LD). The conclusion I came to by talking to developers was that it is very powerful but unfortunately also very complex and difficult to evaluate as a human. (maybe it was also just the case the way I designed it back then..) Anyway, thanks for raising this.. depending on how people and up using JSON-LD this is definitely something to look into.

@davidlehn
Copy link
Member Author

In addition to the examples above it would be nice to have property scoped @vocab support as well. Similar to that being discussed in #262.

@ceefour
Copy link
Contributor

ceefour commented Nov 26, 2014

👍 for this..

@ihervin eh PaySwarm (and Google) uses JSON-LD as well, can be an inspiration for future payment API

@ariutta
Copy link

ariutta commented Dec 4, 2014

This is a difficult challenge to implement well, but if it could be done, I'd love to use it.

@ceefour
Copy link
Contributor

ceefour commented Dec 5, 2014

As it stands now, a property must be created which "encompasses" (i.e. sameAs) all other properties, even though they're semantically different :(

@davidlehn
Copy link
Member Author

@ceefour I assume you are talking about the issue of keys with the same names but should have different associated properties depending on where they are used? That is a use case that this idea could address. For now you just have to deal with the limitation and use different key names.

@ceefour
Copy link
Contributor

ceefour commented Dec 6, 2014

@davidlehn Yes. But since we're JSON first, we're doing it the other way around by using the same key names anyway. When we control the vocabulary we try to make it unique but not always possible.

E.g.

Product has status which is (enumeration) property with range ProductStatus

Order has status which is (enumeration) property with range OrderStatus

Using key names productStatus and orderStatus would feel unnatural to the JSON user.

@serialseb
Copy link

+100. We're being beaten by this a lot in our current format, and that restriction really flies in the face of json-first. It's making our like unnecessary complex. We end up injecting a context in a term with a vocab, which makes the json less than easy to deal with.

@mitar
Copy link

mitar commented Mar 21, 2016

Related: #415

@dlongley
Copy link
Member

dlongley commented Sep 29, 2016

I don't know if this has been noted anywhere else, but one case I'd like a new scoped context feature to support would be targeted aliasing of @graph. It's useful to be able to say certain parts of a JSON tree constitute a separate graphs within the dataset -- without having to use @graph and add more visually unappealing layers. This is particularly important when using digital signatures so as to prevent other JSON-LD algorithms, such as framing, from merging data into the default graph. For example:

{
  "@context": ...,
  "id": "https://example.com#foo",
  "credential": [{
    "@graph": {
      "id": "https://example.com#bar1",
      "signature": {...},
    }, {
    "@graph": {
      "id": "https://example.com#bar2",
      "signature": {...},
    }
  }]
}
{
  "@context": {
    "credental": {"@container": ["@set", "@graph"], ... },
    ...
  },
  "id": "https://example.com#foo",
  "credential": [{
    "id": "https://example.com#bar1",
    "signature": {...},
  }, {
    "id": "https://example.com#bar2",
    "signature": {...},
  }]
}

This doesn't necessarily work if you're assigning identifiers to the graphs (rather than keeping them as blank nodes), but perhaps some more thought could be put into that as well.

@gkellogg
Copy link
Member

Indeed, a useful feature, but maybe only tangentially related to @content. I think this is also covered in #398. The question is, is there a way to include the graph name in the context definition?

I'll elaborate more on a comment to #398.

@gkellogg
Copy link
Member

(Actually, it would seem to require something like @graphId in the context definition to work properly).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants