(Note, this impacts YAML-LD which will treat input as multiple documents when extractAllScripts is true, which is the default for flatten() and toRdf()).
Because expansion is part of flattening, that @graph will now be treated like a named graph. In the expand() algorithm, it's only if the result is an object containing only the key @graph that @graph is eliminated.
Updating flatten() to make sure that the default for extractAllScripts is false (see #603) would help, but would still leave a problem with toRdf() where the default is explicitly true resulting in a named graph result, which does not seem to be intended.
A possible remedy for this would be to update step 8.1 of expand() to allow for an array and extracting the content of @graph for each contained object should achieve the desired affect.
Even though the HTML use case is fairly narrow, it affects all use of flatten() and toRdf() for YAML-LD.
Discussed on [today's call](https://json-ld.org/minutes/2024-07-10/#44)
https://github.com/w3c/json-ld-api/issues/604 -> Issue 604 Using flatten() on HTML input having a single script element with an object with `@graph` results in named graph (by gkellogg) [spec:enhancement] [needs discussion] [ErratumRaised] ✪
Gregg Kellogg: Use `@included` instead of `@graph` if this is a problem. ✪
PROPOSAL: No change to current behavior. Document issues in JSON-LD and YAML-LD
Pierre-Antoine Champin: Looking at the issue, I realized that the Rust library for JSON-LD is not compliant. It does remove `@graph` using example input. ✪
... We might be missing a test about this case. I haven't had a chance to check yet.
... I mostly copied the first JSON example which is just an array with an object using @context and `@graph` and nothing else.
RESOLUTION: No change to current behavior. Document issues in JSON-LD and YAML-LD
(Note, this impacts YAML-LD which will treat input as multiple documents when
extractAllScripts
istrue
, which is the default forflatten()
andtoRdf()
).Given an input document such as the following:
Extracting this using the
extractAllScripts
options gives the following:Expanding this retains
@graph
:Where I think the expected result is:
Because expansion is part of flattening, that
@graph
will now be treated like a named graph. In theexpand()
algorithm, it's only if the result is an object containing only the key@graph
that@graph
is eliminated.Updating
flatten()
to make sure that the default forextractAllScripts
is false (see #603) would help, but would still leave a problem withtoRdf()
where the default is explicitly true resulting in a named graph result, which does not seem to be intended.A possible remedy for this would be to update step 8.1 of
expand()
to allow for an array and extracting the content of@graph
for each contained object should achieve the desired affect.Even though the HTML use case is fairly narrow, it affects all use of
flatten()
andtoRdf()
for YAML-LD.