Skip to content

Commit 2bc5de0

Browse files
Documentation & Release workflow (#30)
* Test upload * Fix path * fix packaging * conditional upload * conditional upload fix * Release workflow * release * fix * fix upload and tag * Set theme jekyll-theme-slate * Create index.md Initialise GH pages * Docs * Move index * GH pages links * Refator model context and aliases as separate concepts * Add branch specifier on release workflow * Fix cyclic method call * Move alias class to separate package * Move model alias definition into alias package * Add Javadoc plugin for lib and netcdf modules
1 parent 77208e0 commit 2bc5de0

File tree

25 files changed

+405
-158
lines changed

25 files changed

+405
-158
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-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>

binary-array-ld-lib/src/main/kotlin/net/bald/context/AliasDefinition.kt renamed to binary-array-ld-lib/src/main/kotlin/net/bald/alias/AliasDefinition.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package net.bald.context
1+
package net.bald.alias
22

33
import org.apache.jena.rdf.model.Property
44
import org.apache.jena.rdf.model.Resource
@@ -29,6 +29,9 @@ interface AliasDefinition {
2929
*/
3030
fun isReferenceProperty(prop: Property): Boolean
3131

32+
/**
33+
* A substitute [AliasDefinition] implementation that represents a null or empty definition.
34+
*/
3235
object Empty: AliasDefinition {
3336
override fun property(identifier: String): Property? {
3437
return null

binary-array-ld-lib/src/main/kotlin/net/bald/model/ModelAliasDefinition.kt renamed to binary-array-ld-lib/src/main/kotlin/net/bald/alias/ModelAliasDefinition.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
package net.bald.model
1+
package net.bald.alias
22

3-
import net.bald.context.AliasDefinition
43
import net.bald.vocab.BALD
54
import org.apache.jena.rdf.model.*
65
import org.apache.jena.vocabulary.DCTerms
Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
package net.bald.context
22

3-
import org.apache.jena.rdf.model.Property
4-
import org.apache.jena.rdf.model.Resource
53
import org.apache.jena.shared.PrefixMapping
64

75
/**
86
* The external context in which a binary array can be resolved.
9-
* This includes resource and property aliases as defined by [AliasDefinition]
10-
* and the available namespace prefix mappings.
11-
* @see AliasDefinition
7+
* This includes any available namespace prefix mappings.
128
*/
13-
interface ModelContext: AliasDefinition {
9+
interface ModelContext {
1410
/**
1511
* Prefix mappings that are available in this context.
1612
*/
@@ -21,41 +17,24 @@ interface ModelContext: AliasDefinition {
2117
*/
2218
object Empty: ModelContext {
2319
override val prefixMapping: PrefixMapping get() = PrefixMapping.Factory.create()
24-
override fun property(identifier: String): Property? = null
25-
override fun resource(identifier: String): Resource? = null
26-
override fun isReferenceProperty(prop: Property): Boolean = false
2720
}
2821

2922
/**
3023
* A basic [ModelContext] implementation that simply composes the prefix mapping and alias elements.
3124
*/
3225
class Base(
33-
override val prefixMapping: PrefixMapping,
34-
private val alias: AliasDefinition
35-
): ModelContext {
36-
override fun property(identifier: String): Property? {
37-
return alias.property(identifier)
38-
}
39-
40-
override fun resource(identifier: String): Resource? {
41-
return alias.resource(identifier)
42-
}
43-
44-
override fun isReferenceProperty(prop: Property): Boolean {
45-
return alias.isReferenceProperty(prop)
46-
}
47-
}
26+
override val prefixMapping: PrefixMapping
27+
): ModelContext
4828

4929
companion object {
5030
/**
5131
* Instantiate a wrapper for the external elements which contextualise a binary array conversion.
5232
* @throws IllegalArgumentException If there are conflicting definitions in the prefix mappings.
5333
* @param prefixes The contextual prefix mappings.
54-
* @param alias The contextual alias definition.
5534
* @return The [ModelContext].
5635
*/
5736
@JvmStatic
58-
fun create(prefixes: List<PrefixMapping>, alias: AliasDefinition? = null): ModelContext {
37+
fun create(prefixes: List<PrefixMapping>): ModelContext {
5938
val prefix = if (prefixes.isEmpty()) {
6039
PrefixMapping.Factory.create()
6140
} else {
@@ -73,15 +52,15 @@ interface ModelContext: AliasDefinition {
7352
}
7453
}
7554
}
76-
return create(prefix, alias)
55+
return create(prefix)
7756
}
7857

7958
/**
8059
* @see create
8160
*/
8261
@JvmStatic
83-
fun create(prefix: PrefixMapping, alias: AliasDefinition? = null): ModelContext {
84-
return Base(prefix, alias ?: AliasDefinition.Empty)
62+
fun create(prefix: PrefixMapping): ModelContext {
63+
return Base(prefix)
8564
}
8665
}
8766
}

binary-array-ld-lib/src/test/kotlin/net/bald/context/ModelContextTest.kt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
package net.bald.context
22

3-
import com.nhaarman.mockitokotlin2.mock
43
import org.apache.jena.shared.PrefixMapping
54
import org.apache.jena.vocabulary.DCTerms
65
import org.apache.jena.vocabulary.SKOS
76
import org.apache.jena.vocabulary.VCARD
8-
import org.junit.jupiter.api.*
7+
import org.junit.jupiter.api.Test
8+
import org.junit.jupiter.api.assertThrows
99
import kotlin.test.assertEquals
1010

1111
class ModelContextTest {
1212
private val prefix = PrefixMapping.Factory.create()
1313
.setNsPrefix("skos", SKOS.uri)
1414
.setNsPrefix("dct", DCTerms.getURI())
15-
private val alias = mock<AliasDefinition>()
16-
private val context = ModelContext.create(prefix, alias)
15+
private val context = ModelContext.create(prefix)
1716

1817
/**
1918
* Requirements class B-4
@@ -41,7 +40,7 @@ class ModelContextTest {
4140
.setNsPrefix("vcard", VCARD.uri)
4241
.setNsPrefix("dct", DCTerms.getURI())
4342
)
44-
val context = ModelContext.create(prefixes, alias)
43+
val context = ModelContext.create(prefixes)
4544
val result = context.prefixMapping.nsPrefixMap
4645
val expected = mapOf(
4746
"skos" to SKOS.uri,
@@ -65,7 +64,7 @@ class ModelContextTest {
6564
.setNsPrefix("dct", DCTerms.getURI())
6665
)
6766
val iae = assertThrows<IllegalArgumentException> {
68-
ModelContext.create(prefixes, alias)
67+
ModelContext.create(prefixes)
6968
}
7069
assertEquals("The namespace prefixes [skos] have conflicting definitions in contexts.", iae.message)
7170
}

0 commit comments

Comments
 (0)