Skip to content

Commit d90179c

Browse files
Merge branch 'master' of github.com:binary-array-ld/net.binary_array_ld.bald
# Conflicts: # docs/index.md
2 parents 7341d52 + 59f7b4e commit d90179c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1001
-262
lines changed

.github/workflows/release.yaml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# This workflow will build a Java project with Maven
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
3+
name: GitHub tagged release
4+
on:
5+
push:
6+
branches: [ "master" ]
7+
tags: [ "*" ]
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
- name: Set up JDK 1.8
14+
uses: actions/setup-java@v1
15+
with:
16+
java-version: 1.8
17+
- name: Cache Maven packages
18+
uses: actions/cache@v2
19+
with:
20+
path: ~/.m2
21+
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
22+
restore-keys: ${{ runner.os }}-m2
23+
- name: Install NetCDF tools
24+
run: sudo apt install netcdf-bin
25+
- name: Maven build
26+
run: mvn clean package
27+
- name: Create Release
28+
id: create_release
29+
uses: actions/create-release@v1
30+
env:
31+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32+
with:
33+
tag_name: ${{ github.ref }}
34+
release_name: Release ${{ github.ref }}
35+
- name: Upload Release Asset
36+
id: upload-release-asset
37+
uses: actions/upload-release-asset@v1
38+
env:
39+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
40+
with:
41+
upload_url: ${{ steps.create_release.outputs.upload_url }}
42+
asset_path: ./binary-array-ld-cli/target/bald-cli.jar
43+
asset_name: bald-cli.jar
44+
asset_content_type: application/java-archive

README.md

Lines changed: 7 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Binary Array Linked Data
22

33
[Kotlin](https://kotlinlang.org/) library and CLI for Binary Array Linked Data (BALD) functionality.
4-
* NetCDF to RDF conversion according to [OGC draft specification](http://docs.opengeospatial.org/DRAFTS/19-002.html).
4+
* [GitHub Pages](https://binary-array-ld.github.io/net.binary_array_ld.bald/)
55

66
This project consists of the following modules:
77
* **binary-array-ld-lib** Core library containing BALD functionality. In particular, binary array to linked data (RDF) conversion.
@@ -11,87 +11,17 @@ RDF representations are provided by [Apache Jena](https://jena.apache.org/).
1111
* **binary-array-ld-test** Common test utilities used by other modules.
1212
* **binary-array-ld-demo** Demonstrations of BALD API usage.
1313

14-
## Development
15-
16-
Note that, in order to run the automated tests for this project,
17-
the `ncgen` command line tool must be available on your system.
18-
1914
## Usage
2015

21-
This project can be used either as a library or as a command line application.
22-
23-
### Library
24-
25-
To use the BALD core library, add the following dependency to your Maven project:
26-
27-
```xml
28-
<dependency>
29-
<groupId>net.binary-array-ld</groupId>
30-
<artifactId>binary-array-ld-lib</artifactId>
31-
<version>${bald.version}</version>
32-
</dependency>
33-
```
34-
35-
You can implement the `net.bald.BinaryArray` interface with your own metadata representations and supply them to the API.
36-
37-
For NetCDF metadata files, you can use the pre-made NetCDF implementation in the `binary-array-ld-netcdf` module.
38-
To use this module, add the following dependency to your Maven project:
16+
See the [GitHub pages](https://binary-array-ld.github.io/net.binary_array_ld.bald/usage.html) for usage documentation.
3917

40-
```xml
41-
<dependency>
42-
<groupId>net.binary-array-ld</groupId>
43-
<artifactId>binary-array-ld-netcdf</artifactId>
44-
<version>${bald.version}</version>
45-
</dependency>
46-
```
47-
48-
#### Example
49-
Kotlin:
50-
```kotlin
51-
val ba = NetCdfBinaryArray.create("/path/to/input.nc", "http://test.binary-array-ld.net/example")
52-
val model = ModelBinaryArrayConverter.convert(ba)
53-
File("/path/to/output.ttl").outputStream.use { output ->
54-
model.write(output, "ttl")
55-
}
56-
```
57-
Java:
58-
```
59-
BinaryArray ba = NetCdfBinaryArray.create("/path/to/input.ttl", "http://test.binary-array-ld.net/example");
60-
Model model = ModelBinaryArrayConverter.convert(ba);
61-
62-
try (OutputStream output = new FileOutputStream("/path/to/output.ttl")) {
63-
model.write(output, "ttl");
64-
}
65-
```
66-
67-
### Command Line Interface
68-
69-
To use the BALD CLI, build the project using `mvn clean package` on the root directory.
70-
Then, you can run the JAR located at `binary-array-ld-cli/target/bald-cli.jar` using the `java-jar` command.
71-
72-
The application accepts arguments in the following format:
73-
```
74-
java -jar binary-array-ld-cli/target/bald-cli.jar [options] inputFile [outputFile]
75-
```
76-
Where `inputFile` is the location of the NetCDF file to convert,
77-
and `outputFile` is the location of the file in which to output the RDF graph.
78-
If you don't specify an `outputFile`, the graph will be printed on the command line.
79-
80-
By default, the RDF graph output will be in [Turtle](https://www.w3.org/TR/turtle/) format.
81-
You can use the `--output` or `-o` option to specify the RDF format to emit.
82-
This option can accept any of the RDF formats supported by Apache Jena, eg. JSON-LD and RDFXML.
18+
## Development
8319

84-
You can also supply various options.
85-
Use the `-h` or `--help` option to emit full documentation for the available options.
86-
```
87-
java -jar binary-array-ld-cli/target/bald-cli.jar -h
88-
```
20+
Note that, in order to run the automated tests for this project,
21+
the `ncgen` command line tool must be available on your system.
8922

90-
#### Example
91-
From the `binary-array-ld-cli/target` directory:
92-
```
93-
java -jar bald-cli.jar --uri http://test.binary-array-ld.net/example /path/to/netcdf.nc /path/to/graph.ttl
94-
```
23+
You can use Maven to build this project and each of its modules with `mvn clean package`.
24+
After building, the JAR for the command line application is located at `binary-array-ld-cli/target/bald-cli.jar`.
9525

9626

9727

binary-array-ld-cli/src/main/kotlin/net/bald/BinaryArrayConvertCli.kt

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package net.bald
22

3+
import net.bald.alias.AliasDefinition
34
import net.bald.context.ModelContext
4-
import net.bald.model.ModelAliasDefinition
5+
import net.bald.alias.ModelAliasDefinition
56
import net.bald.model.ModelBinaryArrayConverter
67
import net.bald.netcdf.NetCdfBinaryArray
78
import org.apache.commons.cli.DefaultParser
@@ -38,9 +39,10 @@ class BinaryArrayConvertCli {
3839
}
3940

4041
private fun doRun(opts: CommandLineOptions) {
41-
val context = context(opts.contextLocs, opts.aliasLocs)
42+
val context = context(opts.contextLocs)
43+
val alias = alias(opts.aliasLocs)
4244
val inputLoc = opts.inputLoc ?: throw IllegalArgumentException("First argument is required: NetCDF file to convert.")
43-
val ba = NetCdfBinaryArray.create(inputLoc, opts.uri, context)
45+
val ba = NetCdfBinaryArray.create(inputLoc, opts.uri, context, alias)
4446
val model = ba.use(ModelBinaryArrayConverter::convert)
4547
val outputFormat = opts.outputFormat ?: "ttl"
4648

@@ -49,15 +51,18 @@ class BinaryArrayConvertCli {
4951
}
5052
}
5153

52-
private fun context(contextLocs: List<String>, aliasLocs: List<String>): ModelContext {
54+
private fun context(contextLocs: List<String>): ModelContext {
5355
val prefixes = contextLocs.map { contextLoc ->
5456
ModelFactory.createDefaultModel().read(contextLoc, "json-ld")
5557
}
56-
val alias = ModelFactory.createDefaultModel().apply {
58+
59+
return ModelContext.create(prefixes)
60+
}
61+
62+
private fun alias(aliasLocs: List<String>): AliasDefinition {
63+
return ModelFactory.createDefaultModel().apply {
5764
aliasLocs.forEach(::read)
5865
}.let(ModelAliasDefinition::create)
59-
60-
return ModelContext.create(prefixes, alias)
6166
}
6267

6368
private fun options(opts: Options, vararg args: String): CommandLineOptions {

binary-array-ld-cli/src/test/kotlin/net/bald/BinaryArrayConvertCliTest.kt

Lines changed: 78 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import bald.jsonld.ResourceFileConverter
55
import bald.model.ModelVerifier
66
import bald.netcdf.CdlConverter.writeToNetCdf
77
import net.bald.vocab.BALD
8+
import org.apache.jena.datatypes.xsd.XSDDatatype
89
import org.apache.jena.rdf.model.ModelFactory.createDefaultModel
10+
import org.apache.jena.rdf.model.Resource
911
import org.apache.jena.rdf.model.ResourceFactory.*
1012
import org.apache.jena.riot.RiotException
1113
import org.apache.jena.vocabulary.*
@@ -360,14 +362,11 @@ class BinaryArrayConvertCliTest {
360362
statement(RDF.type, BALD.Container)
361363
statement(BALD.contains, createResource("http://test.binary-array-ld.net/example/")) {
362364
statement(TestVocab.orderedVar) {
363-
statement(RDF.first, createResource("http://test.binary-array-ld.net/example/var0"))
364-
statement(RDF.rest) {
365-
statement(RDF.first, createResource("http://test.binary-array-ld.net/example/foo/bar/var2"))
366-
statement(RDF.rest) {
367-
statement(RDF.first, createResource("http://test.binary-array-ld.net/example/baz/var3"))
368-
statement(RDF.rest, RDF.nil)
369-
}
370-
}
365+
list(
366+
createResource("http://test.binary-array-ld.net/example/var0"),
367+
createResource("http://test.binary-array-ld.net/example/foo/bar/var2"),
368+
createResource("http://test.binary-array-ld.net/example/baz/var3")
369+
)
371370
}
372371
statement(TestVocab.rootVar, createResource("http://test.binary-array-ld.net/example/var0"))
373372
statement(TestVocab.unorderedVar, createResource("http://test.binary-array-ld.net/example/foo/bar/var2"))
@@ -407,4 +406,75 @@ class BinaryArrayConvertCliTest {
407406
}
408407
}
409408
}
409+
410+
@Test
411+
fun run_withCoordinateVars_outputsCoordinateRanges() {
412+
val aliasFile = ResourceFileConverter.toFile("/turtle/alias.ttl", "ttl")
413+
val inputFile = writeToNetCdf("/netcdf/coordinate-var.cdl")
414+
val outputFile = createTempFile()
415+
416+
run(
417+
"--uri", "http://test.binary-array-ld.net/example",
418+
"--alias", aliasFile.absolutePath,
419+
inputFile.absolutePath,
420+
outputFile.absolutePath
421+
)
422+
423+
fun sortAnon(res: Resource): String {
424+
return if (res.hasProperty(BALD.target)) {
425+
res.getProperty(BALD.target).`object`.toString()
426+
} else {
427+
res.id.toString()
428+
}
429+
}
430+
431+
val model = createDefaultModel().read(outputFile.toURI().toString(), "ttl")
432+
ModelVerifier(model).apply {
433+
resource("http://test.binary-array-ld.net/example") {
434+
statement(RDF.type, BALD.Container)
435+
statement(BALD.contains, createResource("http://test.binary-array-ld.net/example/")) {
436+
statement(RDF.type, BALD.Container)
437+
statement(BALD.contains, createResource("http://test.binary-array-ld.net/example/elev"), sortAnon = ::sortAnon) {
438+
statement(RDF.type, BALD.Array)
439+
statement(RDFS.label, createPlainLiteral("height"))
440+
statement(BALD.references) {
441+
statement(RDF.type, BALD.Reference)
442+
statement(BALD.target, createResource("http://test.binary-array-ld.net/example/lat"))
443+
statement(BALD.targetRefShape) {
444+
list(createTypedLiteral(15), createTypedLiteral(1))
445+
}
446+
}
447+
statement(BALD.references) {
448+
statement(RDF.type, BALD.Reference)
449+
statement(BALD.target, createResource("http://test.binary-array-ld.net/example/lon"))
450+
statement(BALD.targetRefShape) {
451+
list(createTypedLiteral(1), createTypedLiteral(10))
452+
}
453+
}
454+
statement(BALD.shape) {
455+
list(createTypedLiteral(15), createTypedLiteral(10))
456+
}
457+
}
458+
statement(BALD.contains, createResource("http://test.binary-array-ld.net/example/lat")) {
459+
statement(RDF.type, BALD.Array)
460+
statement(RDFS.label, createPlainLiteral("latitude"))
461+
statement(BALD.arrayFirstValue, createTypedLiteral("6.5", XSDDatatype.XSDfloat))
462+
statement(BALD.arrayLastValue, createTypedLiteral("-6.5", XSDDatatype.XSDfloat))
463+
statement(BALD.shape) {
464+
list(createTypedLiteral(15))
465+
}
466+
}
467+
statement(BALD.contains, createResource("http://test.binary-array-ld.net/example/lon")) {
468+
statement(RDF.type, BALD.Array)
469+
statement(RDFS.label, createPlainLiteral("longitude"))
470+
statement(BALD.arrayFirstValue, createTypedLiteral("0.5", XSDDatatype.XSDfloat))
471+
statement(BALD.arrayLastValue, createTypedLiteral("9.5", XSDDatatype.XSDfloat))
472+
statement(BALD.shape) {
473+
list(createTypedLiteral(10))
474+
}
475+
}
476+
}
477+
}
478+
}
479+
}
410480
}

binary-array-ld-demo/src/main/java/net/bald/NetCdfConvertJava.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package net.bald;
22

3-
import net.bald.context.AliasDefinition;
3+
import net.bald.alias.AliasDefinition;
44
import net.bald.context.ModelContext;
5-
import net.bald.model.ModelAliasDefinition;
5+
import net.bald.alias.ModelAliasDefinition;
66
import net.bald.model.ModelBinaryArrayConverter;
77
import net.bald.netcdf.NetCdfBinaryArray;
88
import org.apache.jena.rdf.model.Model;
@@ -26,8 +26,8 @@ public static void convert() throws Exception {
2626

2727
public static void convertWithExternalPrefixes() throws Exception {
2828
PrefixMapping prefix = ModelFactory.createDefaultModel().read("/path/to/context.json", "json-ld");
29-
ModelContext context = ModelContext.create(prefix, null);
30-
BinaryArray ba = NetCdfBinaryArray.create("/path/to/input.nc", "http://test.binary-array-ld.net/example", context);
29+
ModelContext context = ModelContext.create(prefix);
30+
BinaryArray ba = NetCdfBinaryArray.create("/path/to/input.nc", "http://test.binary-array-ld.net/example", context, null);
3131
Model model = ModelBinaryArrayConverter.convert(ba);
3232

3333
try (OutputStream output = new FileOutputStream("/path/to/output.ttl")) {
@@ -36,13 +36,9 @@ public static void convertWithExternalPrefixes() throws Exception {
3636
}
3737

3838
public static void convertWithAliases() throws Exception {
39-
PrefixMapping prefix = PrefixMapping.Factory.create();
4039
Model aliasModel = ModelFactory.createDefaultModel().read("/path/to/alias.ttl", "ttl");
4140
AliasDefinition alias = ModelAliasDefinition.create(aliasModel);
42-
ModelContext context = ModelContext.create(prefix, alias);
43-
44-
BinaryArray ba = NetCdfBinaryArray.create("/path/to/input.nc", "http://test.binary-array-ld.net/example", context);
45-
41+
BinaryArray ba = NetCdfBinaryArray.create("/path/to/input.nc", "http://test.binary-array-ld.net/example", null, alias);
4642
Model model = ModelBinaryArrayConverter.convert(ba);
4743

4844
try (OutputStream output = new FileOutputStream("/path/to/output.ttl")) {

binary-array-ld-lib/pom.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,13 @@
4141
<version>${jena.version}</version>
4242
</dependency>
4343
</dependencies>
44+
45+
<build>
46+
<plugins>
47+
<plugin>
48+
<groupId>org.jetbrains.dokka</groupId>
49+
<artifactId>dokka-maven-plugin</artifactId>
50+
</plugin>
51+
</plugins>
52+
</build>
4453
</project>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package net.bald
2+
3+
/**
4+
* The range of values that is spanned by a coordinate variable.
5+
*/
6+
interface CoordinateRange {
7+
/**
8+
* The first value in the range, if it has one.
9+
* Otherwise, null.
10+
*/
11+
val first: Any?
12+
13+
/**
14+
* The last value in the range, if it has one.
15+
* Otherwise, null.
16+
*/
17+
val last: Any?
18+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package net.bald
2+
3+
/**
4+
* A dimension that specifies the shape of a variable.
5+
*/
6+
interface Dimension {
7+
/**
8+
* The size of the dimension.
9+
*/
10+
val size: Int
11+
12+
/**
13+
* The coordinate variable that corresponds to the dimension, if one exists.
14+
* Otherwise, null.
15+
*/
16+
val coordinate: Var?
17+
}

0 commit comments

Comments
 (0)