LinkML-Java is an implementation of LinkML, the Linked Data Modeling Language, for the Java language.
The project’s primary aim is to provide a runtime library to facilitate working with LinkML-defined instance data – that is conformant to a LinkML schema known at compile-time – from within a Java program, by offering classes and methods to load/write the data from/to various formats, and validate and manipulate said data.
Secondary aims will include:
-
Dynamic use of schemas: Supporting manipulation of data that is conformant to a schema that is only discovered at runtime.
-
Built-in Java code generation: Allowing the generation of the Java code representing a LinkML schema directly from the runtime library (instead of having to rely on LinkML-Py’s code generator), so that the code generation step can be easily integrated within the build process of a Java project (this will most likely take the form of a Maven plugin).
For now, the runtime supports loading and writing data from and to the YAML and JSON formats. Support for other formats, especially RDF, will be added later.
Probably the most important limitation for now is the complete lack of support for dynamic enums: only “static” enums, whose permissible values are fully known at compile-time, are supported.
Currently, using the runtime supposes that the Java code representing
the LinkML-defined model is already available. Typically, it would have
been generated by LinkML-Py’s tool (linkml generate java).
Importantly, for the runtime to work properly the code must satisfy specific requirements, as outlined in the documentation. LinkML-Py’s own code generator already meets some of those requirements; hopefully it will soon provide an option to also automatically meet all of them.
Assuming you have a LinkML-defined model with a root class named Foo,
once you have generated the corresponding code, you can read an instance
of Foo from a YAML file as follows:
YAMLLoader loader = new YAMLLoader();
Foo foo = loader.loadObject(new File("foo.yaml"), Foo.class);To read a list of objects instead (if your LinkML schema does not define a top-level object, as for example with the KGCL schema):
List<Change> kgclChangeset = loader.loadObjects(new File("changes.kgcl"), Change.class);The project is currently located at https://incenp.org/dvlpt/linkml-java/. The source code is available in a Git repository at https://github.com/gouttegd/linkml-java.
LinkML-Java is distributed under the terms of the 3-clause BSD license. The full license is included in the COPYING file of the source distribution.