CARVIEW |
Navigation Menu
-
Notifications
You must be signed in to change notification settings - Fork 159
Description
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": "https://purl.org/dc/elements/1.1/",
"ex": "https://example.org/vocab#",
"xsd": "https://www.w3.org/2001/XMLSchema#",
"ex:contains": {
"@type": "@id"
}
},
"@id": "https://example.org/graph/0",
"dc:creator": "Jane Doe",
"@graph": [
{
"@id": "https://example.org/library",
"@type": "ex:Library",
"ex:contains": "https://example.org/library/the-republic"
}
]
}
Such a stratified
would therefore look like:
{
"https://example.org/graph/0": {
"https://example.org/library": {
"@type": "https://example.org/vocab#Library",
"https://example.org/vocab#contains": {
"@id": "https://example.org/library/the-republic"
}
},
"https://example.org/library/the-republic": {}
},
"@graph": {
"https://example.org/graph/0": {
"https://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']['https://example.org/graph/0']['https://purl.org/dc/elements/1.1/creator'];
// "Jane Doe"
// Access a triple in a named graph
var type = stratified['https://example.org/graph/0']['https://example.org/library']['@type'];
// "https://example.org/vocab#Library"
// Before submitting a document, mutate a property
stratified['https://example.org/graph/0']['https://example.org/library/the-republic']['@type'] = 'https://example.org/vocab#Book';
// Or using an immutable spread syntax approach
var new_doc = {
...stratified,
'https://example.org/graph/0': {
...stratified['https://example.org/graph/0'],
'https://example.org/library/the-republic' : {
...stratified['https://example.org/graph/0']['https://example.org/library/the-republic'],
'@type': 'https://example.org/vocab#Book'
}
}
}