Library
Javadocs are available here. You can find Java examples here.
To use the BALD core library in your Maven project, add the following dependency:
<dependency>
<groupId>net.binary-array-ld</groupId>
<artifactId>binary-array-ld-lib</artifactId>
<version>${bald.version}</version>
</dependency>
To convert NetCDF metadata files, you can use the pre-made NetCDF implementation in the binary-array-ld-netcdf
module.
To use this module, add the following dependency to your Maven project:
<dependency>
<groupId>net.binary-array-ld</groupId>
<artifactId>binary-array-ld-netcdf</artifactId>
<version>${bald.version}</version>
</dependency>
Simple Usage
You can use the NetCdfLd.convert
method to convert NetCDF binary array metadata to an RDF graph in Apache Jena model form.
See the Jena docs for how to use the Model
class.
The model can be serialised to a file using the write
method.
The NetCdfLd.convert
method accepts the following parameters:
Parameter | Type | Description |
---|---|---|
input | URI | The location of the NetCDF binary array file to convert. |
uri | String | The URI that identifies the binary array. Optional. |
contexts | List<URI> | The locations of files containing JSON-LD contexts. Optional. |
aliases | List<URI> | The locations of files containing alias definitions. Optional. |
downloadUrl | String | The URL from which the NetCDF file can be downloaded. Optional. |
Optional parameters are optional in Kotlin or nullable in Java.
Example
To read a NetCDF binary array and emit it to a file in Turtle format:
Kotlin
val input = File("/path/to/input.nc").toURI()
val model = NetCdfLd.convert(input, "http://test.binary-array-ld.net/example")
File("/path/to/output.ttl").outputStream().use { output ->
model.write(output, "ttl")
}
Java
File input = new File("/path/to/input.nc").toURI();
Model model = NetCdfLd.INSTANCE.convert(input, "http://test.binary-array-ld.net/example", null, null);
try (OutputStream output = new FileOutputStream("/path/to/output.ttl")) {
model.write(output, "ttl");
}
Advanced Usage
For some purposes, you may prefer to use the components of the BALD library individually.
You can use the NetCdfBinaryArray.create
method to create a new binary array representation from a NetCDF file.
NetCDF and CDL file formats are supported.
You can also optionally supply a URI as the identifier of the dataset.
You can pass the resulting BinaryArray
instance to the ModelBinaryArrayConverter.convert
method to obtain the RDF graph as a Jena model.
You can also implement the BinaryArray
interface with your own binary array metadata representations.
Example
To read a NetCDF binary array and emit it to a file in Turtle format:
Kotlin
val ba = NetCdfBinaryArray.create("/path/to/input.nc", "http://test.binary-array-ld.net/example")
val model = ModelBinaryArrayConverter.convert(ba)
File("/path/to/output.ttl").outputStream().use { output ->
model.write(output, "ttl")
}
Java
BinaryArray ba = NetCdfBinaryArray.create("/path/to/input.ttl", "http://test.binary-array-ld.net/example");
Model model = ModelBinaryArrayConverter.convert(ba);
try (OutputStream output = new FileOutputStream("/path/to/output.ttl")) {
model.write(output, "ttl");
}
Context
The library supports contexts. You can find the documentation for this feature here.
Aliases
The library supports aliases. You can find the documentation for this feature here.
Download URL
The library supports download URLs.