Use LinkML-Java runtime to support YAML/JSON serialisation#7
Merged
Conversation
I might need to make some tweaking to the original KGCL schema in order to generate proper code, so let's bundle a copy of it.
Some of the slots in the original LinkML schema are badly typed: * the `id` slot should be a `uriOrCurie`; * the `change_date` slot should be a `datetime`.
Rename the OwlTypeEnum enumeration to OwlType. This is for compatibility with the existing code, which was using a OwlType enum that had been manually written (since at the time the LinkML Java code generator completely ignored enums). Also add a new value to represent annotation properties, since KGCL-Java can deal with those.
The LanguageTagChange and DatatypeChange classes are mixins (they both inherit from a mixin), but they are not properly declared as such, which will prevent us from excluding them from the code generation process.
Re-generate all LinkML-derived classes and enums so that they carries the annotations expected by the LinkML-Java runtime.
Amend the custom generator so that it injects the annotations required by the LinkML-Java runtime. Ideally such injections should be doable using directly the standard code generator in LinkML-Py, using the newly introduced concept of "template variant".
We were previously using a manually written OwlType enum, which: (1) had a typo that has remained undetected forever; (2) more importantly, included information about how to (de)serialise enum values from the KGCL language (e.g. OBJECT_PROPERTY is rendered/expected in KGCL language as "relation"). The now automatically generated enum cannot include such an information (which is _not_ encoded in the LinkML model at all), so we must manually deal with (de)serialisation of OwlType enum values to/from the KGCL language.
This has not been released yet, so it's not unusable outside of a system where `linkml-core` has been manually installed to the Maven local repository.
Support for type designator slots is essential in KGCL, because we cannot know in advance which type of change we might have to deserialise.
Use the LinkML-Java runtime to easily parse a KGCL changeset serialised as a YAML file. The runtime takes care of almost everything, the only snag is that we must explicitly deal with the fact that some slots in KGCL change objects may sometimes contain CURIEs even though they are not formally defined in the KGCL schema as being CURIE-typed. This is a KGCL-specific thing that the LinkML runtime cannot know about, so we need to provide it with a custom converter to handle this case. This is in fact a nice validation of the concept of custom converters.
The name of some LinkML-Java annotations has recently been changed, so we need to update the custom code generator script to reflect that. We also make sure that the SimpleChange class is configured to use its own dedicated IConverter object.
It's annoying to have to commit the generated files, but until we have a Maven plugin to automatise the generation of Java code, we cannot really avoid it. I do not want to countenance the idea of injecting a Python-dependent step in the build process, where we would need to ensure we have a running version of `linkml generate java` before we can build anything...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently, KGCL-Java only supports the KGCL “controlled natural language” – it cannot read or write KGCL change sets serialised in JSON or YAML, as in:
The upcoming LinkML-Java runtime should make it easy to support those serialisation formats.
This PR lays the groundwork for that. It mostly involves re-generating the LinkML-derived code so that it contains the various annotations required by the runtime.
(Draft because no release of the LinkML-Java runtime is available yet.)