Skip to content

Use LinkML-Java runtime to support YAML/JSON serialisation#7

Merged
gouttegd merged 13 commits into
masterfrom
use-linkml-runtime
Feb 27, 2026
Merged

Use LinkML-Java runtime to support YAML/JSON serialisation#7
gouttegd merged 13 commits into
masterfrom
use-linkml-runtime

Conversation

@gouttegd
Copy link
Copy Markdown
Owner

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:

- id: CHANGE:001
  type: NodeRename
  old_value: nuclear envelope
  new_value: foo bar
  about_node: GO:0005635

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.)

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.
@gouttegd gouttegd self-assigned this Feb 20, 2026
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...
@gouttegd gouttegd marked this pull request as ready for review February 27, 2026 13:20
@gouttegd gouttegd merged commit 6c59e70 into master Feb 27, 2026
1 check passed
@gouttegd gouttegd deleted the use-linkml-runtime branch February 27, 2026 13:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant