Skip to content

"Stratified" or "Dictionaried" API feature #460

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

Closed
jmatsushita opened this issue Jan 27, 2017 · 3 comments
Closed

"Stratified" or "Dictionaried" API feature #460

jmatsushita opened this issue Jan 27, 2017 · 3 comments

Comments

@jmatsushita
Copy link

Hi there,

I was looking for a way to access properties in a JSON-LD document based on triples (to patch the document). This would mean having a view which creates a dictionary for a given document. The term Normalisation is already used, but this approach would be close to the way https://github.com/paularmstrong/normalizr. D3 uses https://github.com/d3/d3-hierarchy/blob/master/README.md#stratify in a slightly different way but with the same general intent.

The goal would be to be able to address document values with this syntax stratified_doc[triple.subject][triple.predicate] or even better stratified[triple.graph][triple.subject][triple.predicate].

This could also be a @stratified parameter for expansion.

Example

For a document:

{
  "@context": {
    "dc": "http://purl.org/dc/elements/1.1/",
    "ex": "http://example.org/vocab#",
    "xsd": "http://www.w3.org/2001/XMLSchema#",
    "ex:contains": {
      "@type": "@id"
    }
  },
  "@id": "http://example.org/graph/0",
  "dc:creator": "Jane Doe",
  "@graph": [
    {
      "@id": "http://example.org/library",
      "@type": "ex:Library",
      "ex:contains": "http://example.org/library/the-republic"
    }
  ]
}

Such a stratified would therefore look like:

{
  "http://example.org/graph/0": {
   "http://example.org/library": {
      "@type": "http://example.org/vocab#Library",
      "http://example.org/vocab#contains": {
        "@id": "http://example.org/library/the-republic"
      }
    },
    "http://example.org/library/the-republic": {}
  },
  "@graph": {
    "http://example.org/graph/0": {
      "http://purl.org/dc/elements/1.1/creator": "Jane Doe"
    }
  }
}

This would therefore allow to do the following:

// Access a triple from the default graph
var creator = stratified['@graph']['http://example.org/graph/0']['http://purl.org/dc/elements/1.1/creator'];
// "Jane Doe"

// Access a triple in a named graph
var type = stratified['http://example.org/graph/0']['http://example.org/library']['@type'];
// "http://example.org/vocab#Library"

// Before submitting a document, mutate a property
stratified['http://example.org/graph/0']['http://example.org/library/the-republic']['@type'] = 'http://example.org/vocab#Book';

// Or using an immutable spread syntax approach
var new_doc = { 
  ...stratified, 
  'http://example.org/graph/0': {
    ...stratified['http://example.org/graph/0'],
    'http://example.org/library/the-republic' : {
      ...stratified['http://example.org/graph/0']['http://example.org/library/the-republic'],
      '@type': 'http://example.org/vocab#Book'
    }
  }
}
@gkellogg
Copy link
Member

This looks similar to the @id maps feature that was added recently (see Node Identifier Indexing. But, that hasn't been extended to graphs quite yet. There is a separate issue on an @graph container #195. You might look at these in the current spec drafts to see how they might handle your use case.

@lanthaler
Copy link
Member

Some JSON-LD processors already allow you to access data in such a way. Niklas also wrote down the Connect draft a while ago

@gkellogg
Copy link
Member

Framing also has @embed: @link for in-memory use, although I'm not sure it belongs as part of the core framing algorithm.

@gkellogg gkellogg added the defer Issue deferred to future Working Group label Apr 4, 2018
@gkellogg gkellogg removed the defer Issue deferred to future Working Group label Jul 8, 2018
@gkellogg gkellogg closed this as completed Jul 8, 2018
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

3 participants