json-ld-syntax icon indicating copy to clipboard operation
json-ld-syntax copied to clipboard

@default in @context in JSON-LD core syntax

Open lsimichael opened this issue 6 years ago • 2 comments

(See below)

lsimichael avatar Feb 11 '20 21:02 lsimichael

Hi, I have an idea for a new feature. I see there is a feature freeze for 1.1 but do not know how to submit a feature for 1.2

I am working with W3C's SHACL and there can be deeply nested nodes and properties. Each sh:node is a sh:NodeShape and each sh:property is a sh:PropertyShape, and it gets very repetitive to write out those @types each time.

I would like to be able to define a default @type for entities in the @context of a regular JSON-LD document, using the @default keyword. The default would be applied no matter how deeply nested.

I have read a discussion before that JSON-LD core syntax is not for adding information, because that is only for framing. But I hope that can be reconsidered. In my opinion this is not adding, just rearranging, since the information is provided in the @context.

(If this is impossible in the core syntax, even in a future 1.2 version, then perhaps there could be modifications made to framing to model infinite nesting.)

Here's an example in 1.1 syntax:

{
    "@context": {
        "schema": "http://schema.org/",
        "sh": "https://www.w3.org/TR/shacl/",
        "path": {
            "@id": "sh:path",
            "@type": "@id"
        },
        "class": {
            "@id": "sh:class",
            "@type": "@id"
        },
        "property": "sh:property",
        "node": "sh:node"
    },
    "@type": "sh:NodeShape",
    "class": "schema:Article",
    "property": [{
        "@type": "sh:PropertyShape",
        "path": "schema:author"
    }, {
        "@type": "sh:PropertyShape",
        "path": "schema:headline"
    }, {
        "@type": "sh:PropertyShape",
        "path": "schema:interactionStatistic",
        "node": {
            "@type": "sh:NodeShape",
            "class": "schema:InteractionCounter",
            "property": [{
                "@type": "PropertyShape",
                "path": "schema:userInteractionCount"
            }, {
                "@type": "PropertyShape",
                "path": "schema:interactionType",
                "node": {
                    "class": "schema:CommentAction"
                }
            }]
        }
    }]
}

And below would be my preferred syntax, with @default values provided in the @context.

{
    "@context": {
        "schema": "http://schema.org/",
        "sh": "https://www.w3.org/TR/shacl/",
        "path": {
            "@id": "sh:path",
            "@type": "@id"
        },
        "class": {
            "@id": "sh:class",
            "@type": "@id"
        },
        "property": {
            "@id": "sh:property",
            "@type": "sh:class",
            "@default": {
                "@type": "sh:PropertyShape"
            }
        },
        "node": {
            "@id": "sh:node",
            "@type": "sh:path",
            "@default": {
                "@type": "sh:NodeShape"
            }
        }
    },
    "@type": "sh:NodeShape",
    "class": "schema:Article",
    "property": [
        "schema:author",
        "schema:headline", {
            "path": "schema:interactionStatistic",
            "node": {
                "class": "schema:InteractionCounter",
                "property": [
                    "schema:userInteractionCount", {
                        "path": "schema:interactionType",
                        "node": "schema:CommentAction"
                    }
                ]
            }
        }
    ]
}

michaelcpuckett avatar Feb 11 '20 21:02 michaelcpuckett

This was considered in #76 and rejected as being out of scope. It certainly can be reconsidered in the future, as it is an often featured request. The solution for adding information to graphs is to use framing. See, example 23 which speaks to this specific use case.

gkellogg avatar Feb 11 '20 22:02 gkellogg