Skip to content

Expanding ordered lists #654

Closed
Closed
@pjohnston-wiley

Description

@pjohnston-wiley

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    apideferIssue deferred to future Working Group

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions