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
New json ld context generator #36
Conversation
I discuss here some current limitations for the generation of type scoped contexts. Consider the following TreeLDR document:
We want to generate the following JSON-LD context, with two type scoped contexts: {
"type": "@type",
"Foo": {
"@id": "https://example.com/Foo",
"bar": "https://example.com/Foo/bar"
},
"Bar": {
"@id": "https://example.com/Bar",
"foo": "https://example.com/Bar/foo"
}
} This should be doable with the command:
Anonymous layouts cause ambiguous term definitionsIn this example, each type define a This can be solved by generating a unique blank node identifier for structurally equivalent anonymous layouts. This is already the case for references. Type scoped context term nameIn this example, we expect the type scoped context to be defined with the term One solution to this problem would be to allow the definition of custom reference layouts. One could specify what values the reference can take, and how it maps to actual IRIs. For instance with an enumeration layout (not yet implemented):
This states that a value of the layout |
Until custom references are implemented, the generation of type scoped contexts is enabled only with the
|
External contexts implementation is deferred (I'll probably need to harmonize the way vocabulary is handled before I can do that). |
The current LD context generator only generates type-scoped contexts with the assumption that incoming LD documents will always advertise the type of every node using a
@type
property. For instance, take the following TreeLDR schema:using the command
tldrc -i example.tldr json-ld-context https://example.com/Foo https://example.com/Bar
, the following LD context is generated:This is correct for an input LD document such as this:
Note how each node contains a
@type
entry, which is not specified in the original TreeLDR schema. So we want to be able to handle documents where no type is specified, such asHowever it is not possible to specify the type of all the nodes using the JSON-LD context (specifying a
@type
entry inside the context only apply for value objects).The purpose of the PR is to create a new LD context generator algorithm without this limitation. Type scoped contexts are useful to avoid conflicts and ambiguities between term definitions, so they should be generated whenever possible. Otherwise, terms should be defined globally, or inside property scoped contexts to avoid clashes whenever possible (if there is no cycle).
For the above example, the following context should be generated:
Ambiguous terms
Without type scoped contexts, ambiguities can arise when two layouts define fields with the same name.
Here there is an ambiguity on the
prop
term definition. These ambiguities should be detected by the LD context generator.To solve this ambiguity, we could define some "main" layout (the expected layout of the input documents) and some included secondary layouts. Then the
prop
term of the main layout is defined globally while theprop
term of the secondary layout is defined in a property-scoped context.Type scoped contexts
Type scoped contexts can still be generated at the condition that the TreeLDR layout explicitly contains a required field holding its type.
Then the following context can be generated:
Note: we should allow
@type
to be a valid field name so we can write:which would generate the following context without
@type
alias:External contexts
Sometimes contexts are loaded alongside other contexts. For now, the context generator assumes the generated context will be the only one loader and should include all the term definitions. Instead, it would be nice to specify a list of contexts that will be loaded before the generated one. The generator can then omit the definitions already present in the input contexts.
Implementation status
json-ld
refactorExternal contexts