Open niklasl opened 1 year ago
I think it's described using the following steps:
property-scoped context
to the embedded context resolved using the active context
.active context
to that property-scoped context
.IRI expanding
is a shortcut to expand using the active context, so that would be how "Item" is turned into "https://example.org/ns/Item".I think the algorithm is correct, but there are definitely a lot of moving parts. If you had passed the test suite other than this newly defined test, then that would indicate that the test coverage should be improved. Please go ahead and add a PR for the new expansion test (and corresponding toRdf test).
I thought so too, but as my implementation is basically a transcription of the algorithm into Python (with some minor optimizations and refactored parts), I wondered why it didn't work.
Apparently, step 13.8.3.4 occurs for expansion of the index
(i.e. the index key, see 13.8.3) before the active property becomes, in my example, typeDescribed
. The current context is still the parent context, as is evident in step 13.5:
Initialize container mapping to key's container mapping in active context.
The key
here is, with the above example, set to typeDescribed
, and it is not, here, used as the active property
. Thus the active context under which the index
is expanded as an IRI is not the property scoped context
. It is true that step 3 and 8 has been invoked by this time, but via step 13.8.3.6, within the recursive call, i.e. within its own scope. So for the index value
the active context is determined from typeDescribed
, and the local context becomes active. But step 13.8.3.7.4 is not invoked there, since we're processing the index value
. Once the recursive call exits, the algoritm proceeds with 13.8.3.7, so when we reach 13.8.3.7.4 to expand the index
, as specified, the active context is not the property scoped one.
I believe this is why your (and now also my) implementation uses a container context
(which is a "sibling" to the container mapping
of the key
term definition in the active context
). It appears to be an optimization, but it also introduces and uses this context, determined from the key
, which is not spelled out to be used in the algorithm.
Yes, my analysis started at the wrong point:
{"label": "Item"}
with "typeDescribed" as active property.
You're expecting that 13.8.3.4 would set expanded index using the property-scoped context which would result in "https://example.org/ns/Item" instead of "https://example.org/ns#Item". Indeed, my code creates container context at about 13.8.2 using the following Ruby code:
# While processing index keys, if container includes @type, clear type-scoped term definitions
container_context = if container.include?('@type') && context.previous_context
context.previous_context
elsif container.include?('@id') && context.term_definitions[key]
id_context = context.term_definitions[key].context if context.term_definitions[key]
if id_context.nil?
context
else
log_debug("expand", depth: log_depth.to_i) {"id_context: #{id_context.inspect}"}
context.parse(id_context, base: @options[:base], propagate: false)
end
else
context
end
At this point, it seems odd that I'd have such relatively complex code without something corresponding in the algorithm text. Definitely seems a substantive Erratum is in order.
When expanding this compact data:
I cannot tell from the spec (step 13.8.3.7.4 of the expansion algorithm) whether the key
Item
will be resolved against the local context or not. Actually, reading the spec I see nothing that sets the active context to the local context of thetypeDescribed
before reaching 13.8.3.7.4, although I would expect that this is the intention. Both the JSON-LD Playground and the Ruby RDF Distiller do expand the above to this:In the Ruby code corresponding to step 13.8.2 and onwards, IIRC, a
container_context
is defined and from thereon used.Unless I've missed something in the algorithm that clarifies that something like this is required, I believe we should clarify this exhaustively in the spec, and add this test case (unless I've overlooked an existing one for this).
I've made a similar adjustment to TRLD to reflect this presumably desired behaviour.