-
Notifications
You must be signed in to change notification settings - Fork 33
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
Update spec and add tests for limiting @type
-scoped terms to their typed object.
#89
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll need to implement this to be sure, but it looks good to me.
@dlongley if you don't mind, I'll change the title on this issue and add algorithm steps to handle it, so that it is complete. As you note, we'll need to update syntax a bit to allow for this. |
Sure and thanks, @gkellogg! |
e7a916a
to
a5c9df9
Compare
@type
-scoped terms to their typed object.@type
-scoped terms to their typed object.
@dlongley see if you like the spec text associated with the feature. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gkellogg, the algorithm text changes LGTM. The context term definition tracking stuff is slightly different from jsonld.js's implementation, but I would expect the same outcomes. I think what's in this PR is better. I had already filed an issue on jsonld.js to improve it anyway. Thanks!
<li class="changed">an optional <dfn>nest value</dfn>,</li> | ||
<li class="changed">an optional <dfn>prefix flag</dfn>,</li> | ||
<li class="changed">an optional <dfn>index mapping</dfn>,</li> | ||
<li class="changed">a <dfn>protected</dfn>, used to mark this as a protected term,</li> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might want to call protected
a protected flag
here instead.
On the last call, we discussed what might happen if someone nullified the context via a type-scoped context. This resulted in me changing my implementation to handle this case. I think the implementation is actually simpler: digitalbazaar/jsonld.js@1c00ec3 In short, whenever a type-scoped context is being processed, we save the previous active context. Then, when we call To handle property-scoped contexts that come up within a type-scoped context, we process them against the stored previous context (updating it), rather than against the current active context, as they occur "within" and apply "according to" that previous context, not the type-scoped one. At first, I was thinking that we would want the property-scoped contexts to be processed against the type-scoped context, but in practice, this is already confusing. For example, if you set With the other change that the group approved on the last call (allow redefinitions of protected terms so long as the definitions match, modulo the protected flag itself), redefining protected prefixes to the same thing within scoped contexts is not a problem. We still need to add tests for type-scoped context nullification, |
JFYI -- We've also discovered that type-scoped nullification has some other weird properties, such that it wipes out the It seems like that's quite unexpected and potentially even evil -- and this problem is totally orthogonal to the rest of these other patches (it's a separate bug that's been around that no one has detected yet). The good news is that, with the above change I mentioned, we have access to the |
Basically, this seems that we call For dealing with the context-clearing issue, I'm not sure I follow your processing. On expansion, the first thing I do is revert to the previous context, which would be |
Also, the minutes said something about wildcarding properties, but I didn't understand what this might refer to. |
Also, Expand tpr23-25 and tpr27 relate to changing a protected term definition that is equivalent, which should be in a different PR. |
03ba324
to
e15875f
Compare
Protected term redefinition tests moved here: #92 |
I'll have more to say a bit later, but the "previous context" should be whatever the context was before the type-scoped context was processed. That means that if a type-scoped context happens to be an array of contexts, the "previous context" does not change as you process each one in the array as they all apply as "type-scoped" contexts. Rather, it is only set once. Perhaps we need a better name than "previous context". Your comment about the "previous context" being Our implementation has also added some extra processing to ensure that values and subject references that occur within a typed object are expanded and compacted using the appropriate type-scoped context, rather than erroneously reverting. There's a test added to cover that case. |
So, as mentioned above, we set the previous context once at the start of context processing, prior to processing any contexts in an array of contexts. Then, when expanding digitalbazaar/jsonld.js@5e4e2e2 That ensures that the During compaction, we ensure we keep a reference to the current active context to find all of the type-scoped contexts as we process them to produce a new active context. Then we do something analogous to expansion where we use the previous context, if present, to compact any values for digitalbazaar/jsonld.js@42392d5 Lastly, also during expansion, we make sure that values and subject references are processed against the type-scoped context, as they aren't really "nested" values: digitalbazaar/jsonld.js@2ee232a With these changes, we pass the tests we've submitted here and under #92 and #93. |
JFYI, we're still working through a bug on value expansion, will let you know when we've gotten past that. |
b4e2942
to
a1a4d5a
Compare
@gkellogg, in order to expand values properly, we needed to pass in the type-scoped context and use it if present. We've added tests that expand and compact values of typed-object properties. |
Another change for you to be aware of: Since we ensure that when we combine property-scoped contexts with type-scoped contexts that we processed the property-scoped contexts against the previous context (as opposed to the type-scoped ones that will be reverted), we also need to ensure that when we expand or compact IRIs we do the same. This patch does that: digitalbazaar/jsonld.js@074527e We've added tests for this as well. |
Hopefully we're not making the algorithms full of special cases to handle this. In spite of the unexpected results, the previous was reasonably simple. I'll look at this more tomorrow. |
I don't think we've got too much of that (any more than usual for other features), but I also suspect we could unify and simplify a bit. Right now I've just got to make sure it works and the features are composable, which I believe we're in good shape for now. I have to ship our implementation to get the VCWG
Yes, but of course a simple algorithm that yields unexpected results is its own set of problems :). Also, some of the changes we've made had to do with things that weren't tested previously and did not work as is (e.g., nullification/changing type terms). I do think that changes made (which, at the end of the day weren't too numerous) can be boiled down to some organizing principles that could be potentially simplified in algorithms/implementations. Essentially, when processing contexts:
When expanding/compacting:
Thanks, @gkellogg! |
…d processing behavior.
22262b2
to
555b12a
Compare
@dlongley: I've updated the algorithms. I do not get your results for compaction c025: json-ld-api/tests/compact-manifest.jsonld Lines 1134 to 1141 in c0a1531
I do not get the same compacted result because the term definition for "nested" includes |
As I mentioned above, the minutes said something about wildcarding properties, but I didn't understand what this might refer to. Otherwise, with an exception of c025, I think work is complete here, and per the WG discussion, we can merge it when you're happy with the spec text. |
Thanks!
The value for {
"@context": {
"@version": 1.1,
"type": "@type",
"Outer": {
"@id": "ex:Outer"
},
"nested": {
"@id": "ex:nested",
"@type": "@id",
"@container": "@graph"
},
"Inner": {
"@id": "ex:Inner"
}
}
}
I think we probably need to open a new issue for that. Essentially, now you can use property-scoped term definitions within a type-scoped term definition to cause terms to be defined beyond the type-scoped object with fine grained composability and without clashes w/ This is related to:
Sounds good. I looked over the text earlier and it looked good, but perhaps something is missing given c025 (which I think has correct output as is). I'll take a closer look when I can. |
Yeah, I don't see one more change to the IRI compaction/expansion algorithms in the preview that is necessary. When expanding or compacting an IRI, if the context is from a property-term-scoped context that has been combined with a type-scoped context, we use the previous context to do the expansion/compaction (i.e., as the active context going forward). This could be added as a new step 3 in IRI expansion and step 2 in IRI compaction. My implementation sets a flag on the active context when the context is from a property-term-scoped context and then uses the presence of a previous context to check for this condition: digitalbazaar/jsonld.js@074527e I suspect that will resolve the difference with test |
I’ll check my implementation again, but I think I’ve hit everything that’s in the spec. The c025 difference is due to the term selection algorithm, the proper context is loaded when calling Compact IRI. I’ll detail the inverse context and what’s in the call to term select. It has type/language set to language, which is empty in the inverse context, so the term doesn’t get selected. Remove |
But I think the spec is missing the change that handles IRI expansion/compaction when you've got a property-term-scoped context inside a type-scoped context (see: #89 (comment)). In this case, context processing updates the previous context, which means that IRI expansion/compaction must use that context. All that's necessary is to check for that case and then assign the active context to the previous context before continuing on with those algorithms. That will cause the proper inverse context to be used, etc. |
The issue doesn't seem related to selecting a context in compact/expand IRI, as I do end up with the correct term definition when compacting; I'm not sure why the code you cite might be needed, as I'm producing all the appropriate results otherwise. What's going on when trying to do the compact IRI on "ex:nested": {
"@graph": {
"@language": {},
"@type": {"@id": "nested"},
"@any": {"@none": "nested"}
}
} This seems correct according to the algorithm in the API. Because In compact IRI, I have the following arguments to the Term Selection algorithm:
It's because As for the code to expand/compact IRI to use the previous context, can you point me to a test which should fail? It must be doing the equivalent logic elsewhere for the results to be the same, aside form c025. |
My inverse context entry for {
"@graph": [
{
"@type": [
"ex:Inner"
],
"ex:foo": [
{
"@value": "bar"
}
]
}
]
} Which results in Do you have a different value? |
I'm looking at the IRI Compaction algorithm in the spec and it looks like it has changed in a breaking way from 1.0. I'm trying to tease out the differences now. |
Yes, there's a new conditional fork for graph objects (step 2.8) in the 1.1 algorithm. Before that conditional was added, graph objects would fall through to the last step (step 2.9) and be detected as a non-value, which would cause steps 2.9.2 and 2.9.3 to run. These two steps are never run now for graph objects, so they need to be copied (or otherwise rearranged to run) into the end of 2.8. Otherwise the type/language is set to EDIT: It looks like only 2.9.2 must be copied over since |
Yes, I don't think it's needed. I've looked more closely at your changes to the compaction algorithm and it applies a simplification my implementation doesn't have. It removes the early (step 1) processing of property scoped contexts and moves it down to a new step 6 after any type-scoped context has been reverted. I'll likely update my implementation to do this when I get the chance. So it sounds like the only issue is the above missing step that will set |
Good catch, yes it struck me that the graph path wasn’t examining more properties, but it was changed so long ago. I’ll update my implementation and the spec. |
Okay, I think that did it. See if you think the new steps in IRI Compaction are correct. Then, I think we're good to merge. |
I think we're good here too. The only thing that looks a bit odd to me is that Everything else looks good. Thanks! |
The last |
Related to w3c/json-ld-syntax#174.
I've created this PR for jsonld.js with the necessary algorithm changes.
digitalbazaar/jsonld.js#312
What do you think @gkellogg?
Preview | Diff