Skip to content

Commit 10c7c22

Browse files
Merge branch 'master' of github.com:binary-array-ld/net.binary_array_ld.bald
2 parents 5791830 + 9b79dc1 commit 10c7c22

File tree

20 files changed

+155
-25
lines changed

20 files changed

+155
-25
lines changed

README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,3 @@ the `ncgen` command line tool must be available on your system.
2222

2323
You can use Maven to build this project and each of its modules with `mvn clean package`.
2424
After building, the JAR for the command line application is located at `binary-array-ld-cli/target/bald-cli.jar`.
25-
26-
27-

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class BinaryArrayConvertCli {
2121
addOption("a", "alias", true, "Comma-delimited list of RDF alias files.")
2222
addOption("c", "context", true, "Comma-delimited list of JSON-LD context files.")
2323
addOption("o", "output", true, "Output format. eg. ttl, json-ld, rdfxml.")
24+
addOption("d", "download", true, "The URL from which the original file can be downloaded.")
2425
addOption("h", "help", false, "Show help.")
2526
}
2627

@@ -42,7 +43,7 @@ class BinaryArrayConvertCli {
4243
val context = context(opts.contextLocs)
4344
val alias = alias(opts.aliasLocs)
4445
val inputLoc = opts.inputLoc ?: throw IllegalArgumentException("First argument is required: NetCDF file to convert.")
45-
val ba = NetCdfBinaryArray.create(inputLoc, opts.uri, context, alias)
46+
val ba = NetCdfBinaryArray.create(inputLoc, opts.uri, context, alias, opts.downloadUrl)
4647
val model = ba.use(ModelBinaryArrayConverter::convert)
4748
val outputFormat = opts.outputFormat ?: "ttl"
4849

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ class CommandLineOptions(
1313
val aliasLocs: List<String> get() = cmd.getOptionValue("alias")?.split(",") ?: emptyList()
1414
val contextLocs: List<String> get() = cmd.getOptionValue("context")?.split(",") ?: emptyList()
1515
val outputFormat: String? get() = cmd.getOptionValue("output")
16+
val downloadUrl: String? get() = cmd.getOptionValue("download")
1617
val help: Boolean get() = cmd.hasOption("help")
1718
}

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

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,33 @@ class BinaryArrayConvertCliTest {
9797
}
9898
}
9999

100+
@Test
101+
fun run_withDownloadUrl_outputsDownloadUrl() {
102+
val inputFile = writeToNetCdf("/netcdf/identity.cdl")
103+
val outputFile = createTempFile()
104+
run(
105+
"--uri", "http://test.binary-array-ld.net/example",
106+
"--download", "http://test.binary-array-ld.net/download/example.nc",
107+
inputFile.absolutePath,
108+
outputFile.absolutePath
109+
)
110+
111+
val model = createDefaultModel().read(outputFile.toURI().toString(), "ttl")
112+
ModelVerifier(model).apply {
113+
resource("http://test.binary-array-ld.net/example/") {
114+
format()
115+
statement(RDF.type, BALD.Container)
116+
distribution("http://test.binary-array-ld.net/download/example.nc")
117+
statement(BALD.contains, model.createResource("http://test.binary-array-ld.net/example/var0")) {
118+
statement(RDF.type, BALD.Resource)
119+
}
120+
statement(BALD.contains, model.createResource("http://test.binary-array-ld.net/example/var1")) {
121+
statement(RDF.type, BALD.Resource)
122+
}
123+
}
124+
}
125+
}
126+
100127
@Test
101128
fun run_withOutputFormat_outputsToFile() {
102129
val inputFile = writeToNetCdf("/netcdf/identity.cdl")
@@ -569,9 +596,10 @@ class BinaryArrayConvertCliTest {
569596
}
570597
}
571598

572-
private fun StatementsVerifier.distribution() {
599+
private fun StatementsVerifier.distribution(downloadUrl: String? = null) {
573600
statement(DCAT.distribution) {
574601
statement(RDF.type, DCAT.Distribution)
602+
if (downloadUrl != null) statement(DCAT.downloadURL, createResource(downloadUrl))
575603
statement(DCAT.mediaType) {
576604
statement(DCTerms.identifier, createStringLiteral("application/x-netcdf"))
577605
statement(RDF.type, DCTerms.MediaType)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public static void convert() throws Exception {
2727
public static void convertWithExternalPrefixes() throws Exception {
2828
PrefixMapping prefix = ModelFactory.createDefaultModel().read("/path/to/context.json", "json-ld");
2929
ModelContext context = ModelContext.create(prefix);
30-
BinaryArray ba = NetCdfBinaryArray.create("/path/to/input.nc", "http://test.binary-array-ld.net/example", context, null);
30+
BinaryArray ba = NetCdfBinaryArray.create("/path/to/input.nc", "http://test.binary-array-ld.net/example", context, null, null);
3131
Model model = ModelBinaryArrayConverter.convert(ba);
3232

3333
try (OutputStream output = new FileOutputStream("/path/to/output.ttl")) {
@@ -38,7 +38,7 @@ public static void convertWithExternalPrefixes() throws Exception {
3838
public static void convertWithAliases() throws Exception {
3939
Model aliasModel = ModelFactory.createDefaultModel().read("/path/to/alias.ttl", "ttl");
4040
AliasDefinition alias = ModelAliasDefinition.create(aliasModel);
41-
BinaryArray ba = NetCdfBinaryArray.create("/path/to/input.nc", "http://test.binary-array-ld.net/example", null, alias);
41+
BinaryArray ba = NetCdfBinaryArray.create("/path/to/input.nc", "http://test.binary-array-ld.net/example", null, alias, null);
4242
Model model = ModelBinaryArrayConverter.convert(ba);
4343

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

binary-array-ld-lib/src/main/kotlin/net/bald/BinaryArray.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,4 @@ interface BinaryArray: Closeable {
2828
* The distribution of the binary array, if it is available. Otherwise, null.
2929
*/
3030
val distribution: Distribution?
31-
3231
}

binary-array-ld-lib/src/main/kotlin/net/bald/Distribution.kt

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

3+
import org.apache.jena.rdf.model.Resource
4+
35
/**
46
* A distribution of a binary array file.
57
*/
@@ -8,4 +10,10 @@ interface Distribution {
810
* The media type of the binary array file.
911
*/
1012
val mediaType: String
13+
14+
/**
15+
* The URL from which this distribution of the file can be downloaded, if it has one.
16+
* Otherwise, null.
17+
*/
18+
val downloadUrl: Resource?
1119
}

binary-array-ld-lib/src/main/kotlin/net/bald/model/ModelBinaryArrayBuilder.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ class ModelBinaryArrayBuilder(
4242
val distribution = model.createResource()
4343
.addProperty(RDF.type, DCAT.Distribution)
4444
.addProperty(DCAT.mediaType, mediaType)
45+
.apply {
46+
dist.downloadUrl?.let { downloadUrl ->
47+
addProperty(DCAT.downloadURL, downloadUrl)
48+
}
49+
}
4550
root.addProperty(DCAT.distribution, distribution)
4651
}
4752
}

binary-array-ld-lib/src/test/kotlin/net/bald/model/ModelBinaryArrayBuilderTest.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class ModelBinaryArrayBuilderTest {
3636
}
3737
private val distribution = mock<Distribution> {
3838
on { mediaType } doReturn "application/x-netcdf"
39+
on { downloadUrl } doReturn createResource("http://test.binary-array-ld.net/download/example.nc")
3940
}
4041
private val ba = mock<BinaryArray> {
4142
on { this.root } doReturn root
@@ -93,7 +94,7 @@ class ModelBinaryArrayBuilderTest {
9394
ModelVerifier(model).apply {
9495
resource("http://test.binary-array-ld.net/example/") {
9596
format()
96-
distribution()
97+
distribution("http://test.binary-array-ld.net/download/example.nc")
9798
}
9899
}
99100
}

binary-array-ld-lib/src/test/kotlin/net/bald/model/StatementsVerifierExt.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,22 @@ package net.bald.model
22

33
import bald.model.StatementsVerifier
44
import org.apache.jena.rdf.model.ResourceFactory
5+
import org.apache.jena.rdf.model.ResourceFactory.createResource
56
import org.apache.jena.vocabulary.DCAT
67
import org.apache.jena.vocabulary.DCTerms
78
import org.apache.jena.vocabulary.RDF
89

910
fun StatementsVerifier.format() {
1011
statement(DCTerms.format) {
11-
statement(DCTerms.identifier,
12-
ResourceFactory.createResource("http://vocab.nerc.ac.uk/collection/M01/current/NC/"))
12+
statement(DCTerms.identifier, createResource("http://vocab.nerc.ac.uk/collection/M01/current/NC/"))
1313
statement(RDF.type, DCTerms.MediaType)
1414
}
1515
}
1616

17-
fun StatementsVerifier.distribution() {
17+
fun StatementsVerifier.distribution(downloadUrl: String? = null) {
1818
statement(DCAT.distribution) {
1919
statement(RDF.type, DCAT.Distribution)
20+
if (downloadUrl != null) statement(DCAT.downloadURL, createResource(downloadUrl))
2021
statement(DCAT.mediaType) {
2122
statement(DCTerms.identifier, ResourceFactory.createStringLiteral("application/x-netcdf"))
2223
statement(RDF.type, DCTerms.MediaType)

0 commit comments

Comments
 (0)