Skip to content

Commit 8d65e91

Browse files
authored
Merge pull request #27 from simonoakesepimorphics/tech/11.1.1-refactor
Tech/11.1.1 refactor
2 parents 1db1ace + e1bf397 commit 8d65e91

35 files changed

+439
-543
lines changed

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

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

3-
import net.bald.alias.AliasBinaryArray
4-
import net.bald.context.ContextBinaryArray
3+
import net.bald.context.ModelContext
54
import net.bald.model.ModelAliasDefinition
65
import net.bald.model.ModelBinaryArrayConverter
76
import net.bald.netcdf.NetCdfBinaryArray
@@ -39,10 +38,9 @@ class BinaryArrayConvertCli {
3938
}
4039

4140
private fun doRun(opts: CommandLineOptions) {
41+
val context = context(opts.contextLocs, opts.aliasLocs)
4242
val inputLoc = opts.inputLoc ?: throw IllegalArgumentException("First argument is required: NetCDF file to convert.")
43-
val ba = NetCdfBinaryArray.create(inputLoc, opts.uri)
44-
.withContext(opts.contextLocs)
45-
.withAlias(opts.aliasLocs)
43+
val ba = NetCdfBinaryArray.create(inputLoc, opts.uri, context)
4644
val model = ba.use(ModelBinaryArrayConverter::convert)
4745
val outputFormat = opts.outputFormat ?: "ttl"
4846

@@ -51,22 +49,15 @@ class BinaryArrayConvertCli {
5149
}
5250
}
5351

54-
private fun BinaryArray.withContext(contextLocs: List<String>): BinaryArray {
55-
val contexts = contextLocs.map { contextLoc ->
52+
private fun context(contextLocs: List<String>, aliasLocs: List<String>): ModelContext {
53+
val prefixes = contextLocs.map { contextLoc ->
5654
ModelFactory.createDefaultModel().read(contextLoc, "json-ld")
5755
}
58-
return ContextBinaryArray.create(this, contexts)
59-
}
56+
val alias = ModelFactory.createDefaultModel().apply {
57+
aliasLocs.forEach(::read)
58+
}.let(ModelAliasDefinition::create)
6059

61-
private fun BinaryArray.withAlias(aliasLocs: List<String>): BinaryArray {
62-
return if (aliasLocs.isEmpty()) {
63-
this
64-
} else {
65-
val alias = ModelFactory.createDefaultModel().apply {
66-
aliasLocs.forEach(::read)
67-
}.let(ModelAliasDefinition::create)
68-
AliasBinaryArray.create(this, alias)
69-
}
60+
return ModelContext.create(prefixes, alias)
7061
}
7162

7263
private fun options(opts: Options, vararg args: String): CommandLineOptions {
@@ -93,4 +84,4 @@ fun main(args: Array<String>) {
9384
println("Conversion failed due to error: ${e.message}")
9485
exitProcess(1)
9586
}
96-
}
87+
}

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

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

3-
import net.bald.alias.AliasBinaryArray;
4-
import net.bald.alias.AliasDefinition;
3+
import net.bald.context.AliasDefinition;
4+
import net.bald.context.ModelContext;
55
import net.bald.model.ModelAliasDefinition;
66
import net.bald.context.ContextBinaryArray;
77
import net.bald.model.ModelBinaryArrayConverter;
@@ -26,23 +26,25 @@ public static void convert() throws Exception {
2626
}
2727

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

3434
try (OutputStream output = new FileOutputStream("/path/to/output.ttl")) {
3535
model.write(output, "ttl");
3636
}
3737
}
3838

3939
public static void convertWithAliases() throws Exception {
40-
BinaryArray ba = NetCdfBinaryArray.create("/path/to/input.nc", "http://test.binary-array-ld.net/example");
40+
PrefixMapping prefix = PrefixMapping.Factory.create();
4141
Model aliasModel = ModelFactory.createDefaultModel().read("/path/to/alias.ttl", "ttl");
4242
AliasDefinition alias = ModelAliasDefinition.create(aliasModel);
43-
BinaryArray aliasBa = AliasBinaryArray.create(ba, alias);
43+
ModelContext context = ModelContext.create(prefix, alias);
4444

45-
Model model = ModelBinaryArrayConverter.convert(aliasBa);
45+
BinaryArray ba = NetCdfBinaryArray.create("/path/to/input.nc", "http://test.binary-array-ld.net/example", context);
46+
47+
Model model = ModelBinaryArrayConverter.convert(ba);
4648

4749
try (OutputStream output = new FileOutputStream("/path/to/output.ttl")) {
4850
model.write(output, "ttl");

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,7 @@ interface Attribute {
99
/**
1010
* The URI which identifies the attribute, if it has one. Otherwise, null.
1111
*/
12-
val uri: String?
13-
14-
/**
15-
* The local name of the attribute.
16-
*/
17-
val name: String
12+
val uri: String
1813

1914
/**
2015
* The values of the attribute, expressed as RDF resource or literal nodes.

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ package net.bald
66
interface AttributeSource {
77
/**
88
* Obtain the list of attributes that describe this entity.
9-
* @param prefixMapping The prefix mapping to use to expand compact URIs.
109
* @return The list of attributes.
1110
*/
12-
fun attributes(prefixMapping: org.apache.jena.shared.PrefixMapping): List<Attribute>
11+
fun attributes(): List<Attribute>
1312
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ package net.bald
66
*/
77
interface Container: AttributeSource {
88
/**
9-
* The local name of the container, if it has one.
10-
* The root container may have no name or an empty name.
9+
* The URI of the container.
1110
*/
12-
val name: String?
11+
val uri: String
1312

1413
/**
1514
* Obtain the variables associates with this container.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ package net.bald
55
*/
66
interface Var: AttributeSource {
77
/**
8-
* The local name of the variable.
8+
* The URI of the variable.
99
*/
10-
val name: String
10+
val uri: String
1111
}

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

Lines changed: 0 additions & 27 deletions
This file was deleted.

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

Lines changed: 0 additions & 18 deletions
This file was deleted.

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

Lines changed: 0 additions & 34 deletions
This file was deleted.

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

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)