Skip to content

Expanding ordered lists #654

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
pjohnston-wiley opened this issue May 15, 2018 · 4 comments
Closed

Expanding ordered lists #654

pjohnston-wiley opened this issue May 15, 2018 · 4 comments
Labels
api defer Issue deferred to future Working Group

Comments

@pjohnston-wiley
Copy link
Contributor

pjohnston-wiley commented May 15, 2018

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.

@pjohnston-wiley
Copy link
Contributor Author

Fixed typos in (2) & (3).

@gkellogg gkellogg added api defer Issue deferred to future Working Group labels May 29, 2018
@gkellogg
Copy link
Member

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.

@pjohnston-wiley
Copy link
Contributor Author

pjohnston-wiley commented May 30, 2018

OK, but then it may be worth mentioning this somewhere in the spec or in a field guide - once you are in the Land of JSON-LD® you are expected to relinquish all ties with rdf: constructs or you will get unexpected behaviors. Maybe it is there already and i missed it, in which case i apologize.

Thanks for the workaround - that's essentially what i ended up doing, but i was hoping for something a tiny bit more efficient.

@gkellogg
Copy link
Member

gkellogg commented Jul 8, 2018

Transfered to WG: w3c/json-ld-api#9.

@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
Labels
api defer Issue deferred to future Working Group
Projects
None yet
Development

No branches or pull requests

2 participants