-
Notifications
You must be signed in to change notification settings - Fork 34
Expansion does not take property-scoped contexts for nested properties into account #380
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
Comments
If the notion of "Recursively repeat ..." implies a separate variable scope, then steps 3 and 8, which modify active context could be considered an isolated scope and don't affect the value of active context for the next iteration. At the least, the Note following 14.2.2 would need to clarify that those steps are done in a scope that does not allow those variables to change on successive repetition. Although, note that they are updating result, which could be considered a pass by reference. |
Also, I don't see a reasonable way to update the Compaction algorithm, so this would be a one-way transformation. Ideally, compacting a document with a context which uses a scoped-context on I'll do a PR that does expansion-only scoped contexts on aliases of |
I'm worried that we can not keep the compaction algorithm untouched, though. Consider the following context {"@context":{
"foo": "http://example.org/foo",
"bar": {"@id": "http://example.org/bar", "@nest": "nst"},
"nst": {"@id": "@nest", "@context": { "bar": "http://different.example.org/bar" }
}} used to compact { "http://example.org/bar": "BAR } I'm under the impression that it would result to { "@context": {...},
"nst": { "bar": "BAR" }
} in which |
That is indeed a problem, but I don't see how to solve it in compaction reasonably; maybe we can't support this feature. |
Steps 12.7.2.1 and 12.8.2.1 of the Compaction algorithm currently read:
We could add a condition that prevent compacting to a nesting property with a scoped context:
This wouldn't break existing test cases (as they don't have scoped context in nesting properties.
On the expansion side, it is a natural addition, and @niklasl 's use case is valid. On the compaction side, it does open a can of worms, which we don't have time address more elegantly. I think however that this solution (including my patch above) is a move in the right direction, and does not preclude a future WG to improve the compaction in order to better support this feature. |
@gkellogg, Thank you for addressing this! I believe your change addresses my issue. First, a remark on my initial assessment:
I did not interpret that correctly. (I missed that the outer nested property is turned, by type-scoped context, into a type-indexed property, where the index key represents a type which controls the inner index.) Thus the apparent inconsistency remark I made is certainly weakened. I still believe that adding this logic is consistent with what you can expect of expansion though. I'm gonna elaborate my assessment of where this leads us, possibly feeding into any future work on JSON-LD (post 1.1): I was, as you, concerned about this introducing an inconsistency with compaction. A possible mitigation, AFAIK, is that there are already certain forms that can be expanded using special contexts which cannot be compacted into the same shape. From what I've gathered (now also reported by @pchampin in #391), this is the case for nested nests (as seen e.g. in test case in06 which cannot be expanded and compacted back to the same form), nor can multiple keys mapping to the same IRI. I reckon that this may not be considered as on the same level of inconsistency as nest-scoped contexts, but it's hard to judge. This compaction limitation does prevent some aspects of the "context switcheroo" trick I'm attempting, in that I cannot turn flat data (e.g. using DC) back into the higher-resolution forms (e.g. using BibFrame). It is interesting to note that #391 indicates that there might be a possible related "missing feature": allowing for nested properties to be explicitly declared as nested within nests. My experiment indicated that such a mechanism could be used in such a flat-to-nested manoeuvre, but it's early to tell from my tinkering, and closing time for JSON-LD 1.1, alas. Maybe, there is room for a note about Compaction, to state that algorithms other than the one standardized are perfectly legal to use, as long as the produced data is conforming JSON-LD? That note could mention the examples above which aren't roundtrippable. I think that varying forms of compact JSON-LD does and may continue to abound, and that the expansion rules are the baseline contract here for interoperability. This is implicit throughout, but perhaps it can be spelled out more explicitly? (This "off the beaten spec path" goes, of course, for framing as well.) Regarding @pchampin's similar findings (recursive nests) and suggestions for mitigation, I think they're in the right direction. The example with the term "pulling the rug out from under itself" is concerning though (and the only way to prevent it is to declare the outer |
This issue was discussed in a meeting.
View the transcriptNested property-scoped fieldsRob Sanderson: #380 Gregg Kellogg: Last week we discussed that supporting this would be editorial, as no normative changes are required to make this work, only algorithm steps needs to be changed. … Algorithm should be changed to take property-scoped context to be taken into consideration. The problem is that it is not feasible IMO to do the compaction side of this using the same context, because term selection could be based on prop-scope or nested terms. So we have to decide to only do this for expansion only, and accept that it will come out differently after compaction. What do you think? Pierre-Antoine Champin: I agree. I don’t see a way to ensure round-trip of this. I’m not too concerned about that, because nested structures are not entirely round-tripable. For example, recursive lists are not round-trippable. … So I could live with scoped contexts handled in expansion, and not handled in compaction. … This raises another problem: current addition Gregg did, it is possible to expand something using scoped contexts, to get back a semantically different result, because expansion does not take into account scoped contexts. … We should probably not merge this addition change because of this unforeseen consequence. Or we can refrain from compaction if there is a scoped context. It would be a shame, but we should at least be careful not to break compaction as it is. Ivan Herman: Unsure I understand all the details. I doubt this is something we should do at this point. It sounds like something close to a new feature, and that is a no-no, which goes back to WD. … We may come back to it at some point in time, which depends on what the future holds for JSON-LD. … This sounds too much for a CR that we plan to close in a few weeks. Rob Sanderson: pchampin, could you clarify the scenario where you expand+compact and get different semantics? Pierre-Antoine Champin: #380 (comment) Rob Sanderson: I agree that this is on the border of a new feature. Pierre-Antoine Champin: If you compact the linked data, then it will compact with @nest with a custom meaning of bar in the scoped context. But if I re-expand, bar will have a different meaning.Rob Sanderson: I can see this happening in practice. Gregg Kellogg: This is editorial because the syntax doc doesn’t disallow this use-case. So we may need to do something to not make people infer that this is possible. The use case is nice, but not worth the disruption at this point. So we should defer this to a future version. Pierre-Antoine Champin: #380 (comment) Pierre-Antoine Champin: The last comment was also in that direction. The algorithm is not meant for this. Niklas agrees that this is not the right moment to handle this. Ivan Herman: Ok, let’s defer. Rob Sanderson: Does this also apply to your other issue pchampin? Pierre-Antoine Champin: No, that one points out the assymetry. Proposed resolution: Defer #380 for future version as (1) can be experimental as not forbidden, (2) borderline new feature in feature freeze, (3) dangerously asymmetric (Rob Sanderson) Gregg Kellogg: +1 Ivan Herman: +1 Harold Solbrig: +1 Ruben Taelman: +1 Tim Cole: +1 Pierre-Antoine Champin: +1 Rob Sanderson: +1 Benjamin Young: +1 David I. Lehn: +1 Resolution #1: Defer #380 for future version as (1) can be experimental as not forbidden, (2) borderline new feature in feature freeze, (3) dangerously asymmetric Gregg Kellogg: The problem with these types of things, compaction comes down to term selection algo, which is already insanely complicated. Anything adding more complexity should be carefully considered. |
* Add tests and spec text for scoped-contexts on `@nest` alias. * @pchampin suggestions: Co-Authored-By: Pierre-Antoine Champin <[email protected]> For #380
…ss-3 changes. (#616) * Add candidate change and insertions for #380/#388. * Reorder change details with newest first. * Comment out 2021-01-05 editorial changes to node-map-generation algorithm. * Comment out 2021-02-25 editorial changes to IRI expansion algorithm. * Add Candidate Correction 2 for issue #514. * CANDIDATE CORRECTION 3 for issue 565, PR 566 to "Fix context processing for reverse terms". * CANDIDATE CORRECTION 4 for `extractAllScripts` option to `toRdf()`.
There is currently a limitation in the JSON-LD 1.1 expansion algorithm which ignores property-scoped contexts for nested properties.
My specific case is:
From which I expected to get (recompacted for brevity):
(This is actually part of a "trick" (a "context switcheroo" if you will), whereby by compacting BibFrame data into indexed maps, and then swapping out the context with another one mapping to DC+BIBO, as per above, using nests with local contexts, the same structure is semantically differently interpreted (a kind of "poor man's inference", supporting different vocabulary granularities). The input for the above example is thus actual BibFrame data plus an idiomatic context for the shape, using indexes.)
That aside, I do believe that in general, for JSON-in-the-wild, it is quite plausible that structures mapped using nesting properties will vary the meaning of keys within each nest. As it stands, the current algorithm, somewhat arbitrarily IMHO, lacks this possibility. Nothing in the Syntax spec makes it obvious that this is so. In the test suite itself, in the example of test case in06, you could quite plausibly imagine that keys within the defined nests ("links", "attributes" and "relationships") could have different meanings but share the same name (e.g. "links" could use a "title" key with a different meaning from "title" within "attributes").
Furthermore, as far as I can tell, index keys in indexed properties can have property-scoped contexts (assuming that I interpret test case c013 correctly). To support that but not nests is rather unexpected, as they both represent not properties but "sectioned" data.
For reference, see my original question about this on the Public JSON-LD mailing list, and @gkellogg's reply, which included (and I quote):
Following up on that, I wonder what would happen if step 14.2.2 is just changed from:
to:
Would this really require reverting, as opposed to the regular active context state handling done in the algorithm? (Assuming of course that "recursively repeat" here, as is already implicit both here and elsewhere in the algorithm, properly scopes the passed variables to each step without polluting the other steps in the loop.)
(Note that step 3 also has to be assigned
id="alg-expand-initialize-property-scoped-context"
in the markup if the above is added.)(Although @gkellogg also noted that the algorithm neither supports local (explicit) contexts at the top-level of nested properties, I consider that a separate (potential) issue for which I see less motivation for. As I see it, the main reason for these features to exist ought to be to handle idiomatic JSON with zero edits, and not "native" JSON-LD. I see no practical reasons for it (I personally see little practical reason for explicit local contexts at all in 1.1, since scoped contexts are possible).)
I do believe that there is a missed opportunity here, especially considering the complexity which has been invested into nesting properties and scoped contexts. The "zero edits" goal, which much of JSON-LD 1.1 has put its force behind, warrants this to be thoroughly considered, even at this late hour, IMHO. I'll do what I can to help, if that's needed.
The text was updated successfully, but these errors were encountered: