json-ld-api
json-ld-api copied to clipboard
Test compact#t0080 is wrong
The test compact#t0080 is wrong, IMO. The input (which is in expanded form) corresponds to the following dataset:
_:b0 <http://example.org/input> <http://example.org/gid> .
_:b1 <http://example.org/value> "x" <http://example.org/gid> .
however, the expected compacted result expands to the following dataset:
_:b0 <http://example.org/input> _:b1 .
_:b2 <http://example.org/value> "x" <http://example.org/gid> .
(and the JSON-LD expanded form has an extra level of @graph compared to the original input).
As noted by @gkellogg in a comment on a related issue:
the value of input (...) is not an anonymous named graph. (...) Arguably, the
inputterm should not be chosen, as it doesn't match.
Given the discrepancy between the input and the output, I would argue that the input term MUST not be chosen. The output of compact#t0080 should be:
{
"@context": {
"@vocab": "http://example.org/",
"input": {
"@container": "@graph"
}
},
"http://example.org/input": {
"@graph": {
"value": "x"
},
"@id": "http://example.org/gid"
}
}
The IRI Compaction algorithm clearly allows the term to be selected:
4.8.) Otherwise, if value is a graph object, prefer a mapping most appropriate for the particular value. 4.8.2) If value contains an
@identry, append the values@graph@idand@graph@id@setto containers. 4.8.3) Append the values@graph,@graph@set, and@setto containers.
It is step 4.8.3 which allows the term to be selected, so the test does not seem too be incorrect based on the algorithm text. We could consider in a future update changing the steps in the algorithm to disallow its selection, but that's not what's there right now.
however, the expected compacted result expands to the following dataset:
_:b0 <http://example.org/input> _:b1 . _:b2 <http://example.org/value> "x" <http://example.org/gid> .
Yet this is, indeed, problematic; the result expands to have the value of "input" be an anonymous named graph containing a named graph, when that is not called for.
Perhaps we should consider an erratum to 4.8.3 that makes it an otherwise as well as reconsider other steps in 4.8.
One thing we might consider as an additional step for compaction tests is that they re-expand to their inputs, although there may be some things that make this problematic.
The IRI Compaction algorithm clearly allows the term to be selected:
Yes, I didn't mean to imply that the test was inconsistent with the spec, only that what it did looked wrong (changing the underlying graph). Thanks for spotting which part of the spec was responsible.
I agree on your expected compaction result (and thus that the test output is wrong). If the input is also flattened -- turning the embedded named graph into a node reference -- it becomes what we expect. So there is a semantic discrepancy here (in the algorithm).