w3c / json-ld-api

JSON-LD 1.1 Processing Algorithms and API Specification
https://w3c.github.io/json-ld-api/
Other
76 stars 29 forks source link

Expanding ordered lists #9

Closed gkellogg closed 6 years ago

gkellogg commented 6 years ago

Consider the following inputs:

(1)

{
    "@graph": [{
        "@id": "http://example.com/Flintstone",
        "@type": [
            "http://www.w3.org/ns/shacl#PropertyShape"
        ],
        "http://www.w3.org/ns/shacl#or": [{
            "@list": [
                {
                    "http://www.w3.org/ns/shacl#class": [{
                        "@id": "http://example.com/Fred"
                    }]
                },
                {
                    "http://www.w3.org/ns/shacl#class": [{
                        "@id": "http://example.com/Wilma"
                    }]
                }
            ]
        }]
    }]
}

and

(2)

{
    "@graph": [
        {
            "@id": "http://example.com/Flintstone",
            "@type": [
                "http://www.w3.org/ns/shacl#PropertyShape"
            ],
            "http://www.w3.org/ns/shacl#or": [{
                "@id": "_:4"
            }]
        },
        {
            "@id": "_:4",
            "http://www.w3.org/1999/02/22-rdf-syntax-ns#first": [{
                "@id": "_:1"
            }],
            "http://www.w3.org/1999/02/22-rdf-syntax-ns#rest": [{
                "@id": "_:2"
            }]
        },
        {
            "@id": "_:1",
            "http://www.w3.org/ns/shacl#class": [{
                "@id": "http://example.com/Fred"
            }]
        },
        {
            "@id": "_:2",
            "http://www.w3.org/1999/02/22-rdf-syntax-ns#first": [{
                "@id": "_:3"
            }],
            "http://www.w3.org/1999/02/22-rdf-syntax-ns#rest": [{
                "@list": []
            }]
        },
        {
            "@id": "_:3",
            "http://www.w3.org/ns/shacl#class": [{
                "@id": "http://example.com/Wilma"
            }]
        }
    ]
}

When resolved as N-Quads on the playground, they both result in:

(3)

<http://example.com/Flintstone> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/ns/shacl#PropertyShape> .
<http://example.com/Flintstone> <http://www.w3.org/ns/shacl#or> _:b0 .
_:b0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> _:b1 .
_:b0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:b2 .
_:b1 <http://www.w3.org/ns/shacl#class> <http://example.com/Fred> .
_:b2 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> _:b3 .
_:b2 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .
_:b3 <http://www.w3.org/ns/shacl#class> <http://example.com/Wilma> .

In other words, they are semantically identical, ordered lists.

However, if i submit them to JSON-LD expansion, the former preserves @list, while the latter preserves the rdf:List construct. This causes knock-on inconsistencies when i compact and/or frame.

In order to resolve this, i propose that the expansion algorithm explicitly take into account rdf:Lists in expanded form. In other words, whether the input is (1) or (2), the result of expansion should always be:

[{
"@id": "http://example.com/Flintstone", 
"@type": ["http://www.w3.org/ns/shacl#PropertyShape"], 
"http://www.w3.org/ns/shacl#or": [
  {"@list": [
    {"http://www.w3.org/ns/shacl#class": [{"@id": "http://example.com/Fred"}]}, 
    {"http://www.w3.org/ns/shacl#class": [{"@id": "http://example.com/Wilma"}]}
  ]}]
}]

Alternatively, you can specify that any conversion to JSON-LD always convert rdfLists to @list form. This would then effectively make rdf:first/rdf:rest verboten in JSON-LD-land. I realize the algorithm seems to cover the conversion (though i admit not fully understanding how), but the spec itself does not preclude JSON-LD with explicit rdf:firsts.

Original issue: Expanding ordered lists #654.

gkellogg commented 6 years ago

I added this for WG review, but I don't think we'll end up bringing further RDF interpretation into algorithms other than to/from RDF. This would also mean interpreting rdf:type as @type, something we explicitly avoided in 1.0.

To work around this would be to turn your JSON-LD source using rdf:List into quads, and then perform the fromRDF algorithm to get it back into normal JSON-LD form.

azaroth42 commented 6 years ago

Closing, wontfix, as the API should not make decisions based on rdf predicates. WG Resolution: https://www.w3.org/2018/json-ld-wg/Meetings/Minutes/2018/2018-08-03-json-ld#section2-1