Skip to content

Commit 4e59868

Browse files
authored
Merge pull request #21 from filip26/feat/cborld
Complete basic CBOR-LD support
2 parents 6067595 + 2c38fa7 commit 4e59868

File tree

7 files changed

+47
-10
lines changed

7 files changed

+47
-10
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ Options:
3131
Commands:
3232
expand Expand JSON-LD document
3333
compact Compact JSON-LD document using the context
34-
flatten Flatten JSON-LD document and optionally compacts it using a context
34+
flatten Flatten JSON-LD document and optionally compact it using a context
3535
frame Frame JSON-LD document using the frame
36-
fromrdf Transform N-Quads document into a JSON-LD document in expanded form
36+
fromrdf Transform N-Quads document into a JSON-LD document in an expanded form
3737
tordf Transform JSON-LD document into N-Quads document
3838
compress Compress JSON-LD document into CBOR-LD
3939
decompress Decompress CBOR-LD document into JSON-LD

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<packaging>jar</packaging>
99

1010
<name>A Command Line Processor for Linked Data Processing</name>
11+
1112
<url>https://github.com/filip26/ld-cli</url>
1213

1314
<properties>

src/main/java/com/apicatalog/cli/command/CompactCmd.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ public final class CompactCmd implements Callable<Integer> {
5050
boolean ordered = false;
5151

5252
@Option(names = { "-a", "--keep-arrays" }, description = "keep arrays with just one element")
53-
boolean compactArrays = true;
53+
boolean keepArrays = false;
5454

5555
@Option(names = { "-r", "--keep-iris" }, description = "keep absolute IRIs")
56-
boolean compactToRelative = true;
56+
boolean keepAbsoluteIris = false;
5757

5858
@Spec
5959
CommandSpec spec;
@@ -78,8 +78,8 @@ public Integer call() throws Exception {
7878

7979
api.base(base);
8080
api.ordered(ordered);
81-
api.compactArrays(compactArrays);
82-
api.compactToRelative(compactToRelative);
81+
api.compactArrays(!keepArrays);
82+
api.compactToRelative(!keepAbsoluteIris);
8383

8484
final JsonObject output = api.get();
8585

src/main/java/com/apicatalog/cli/command/CompressCmd.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
import java.util.concurrent.Callable;
66

77
import com.apicatalog.cborld.CborLd;
8+
import com.apicatalog.cborld.config.DefaultConfig;
9+
import com.apicatalog.cborld.db.DbConfig;
10+
import com.apicatalog.cborld.encoder.EncoderConfig;
811
import com.apicatalog.jsonld.document.Document;
912
import com.apicatalog.jsonld.document.JsonDocument;
1013
import com.apicatalog.jsonld.json.JsonUtils;
@@ -42,6 +45,12 @@ public final class CompressCmd implements Callable<Integer> {
4245
@Option(names = { "-b", "--base" }, description = "input document base IRI")
4346
URI base = null;
4447

48+
@Option(names = { "-a", "--keep-arrays" }, description = "keep arrays with just one element")
49+
boolean keepArrays = false;
50+
51+
@Option(names = { "-m", "--mode" }, description = "processing mode", paramLabel = "default|digitalbazaar")
52+
String mode = "default";
53+
4554
@Spec
4655
CommandSpec spec;
4756

@@ -65,10 +74,19 @@ public Integer call() throws Exception {
6574
if (JsonUtils.isNotObject(json)) {
6675
throw new IllegalArgumentException("The input docunent root is not JSON object but [" + json.getValueType() + "].");
6776
}
77+
78+
EncoderConfig config = DefaultConfig.INSTANCE;
6879

80+
if ("digitalbazaar".equalsIgnoreCase(mode)) {
81+
config = DbConfig.INSTANCE;
82+
}
83+
6984
final byte[] encoded = CborLd.encoder(json.asJsonObject())
85+
.config(config)
7086
.base(base)
87+
.compactArray(!keepArrays)
7188
.encode();
89+
7290

7391
try (FileOutputStream os = new FileOutputStream(output)) {
7492
os.write(encoded);

src/main/java/com/apicatalog/cli/command/DecompressCmd.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
import java.util.concurrent.Callable;
77

88
import com.apicatalog.cborld.CborLd;
9+
import com.apicatalog.cborld.config.DefaultConfig;
10+
import com.apicatalog.cborld.db.DbConfig;
11+
import com.apicatalog.cborld.decoder.DecoderConfig;
912
import com.apicatalog.cli.JsonOutput;
10-
import com.apicatalog.jsonld.document.Document;
1113

1214
import jakarta.json.JsonStructure;
1315
import jakarta.json.JsonValue;
@@ -40,6 +42,12 @@ public final class DecompressCmd implements Callable<Integer> {
4042
@Option(names = { "-b", "--base" }, description = "input document base IRI")
4143
URI base = null;
4244

45+
@Option(names = { "-a", "--keep-arrays" }, description = "keep arrays with just one element")
46+
boolean keepArrays = false;
47+
48+
@Option(names = { "-m", "--mode" }, description = "processing mode", paramLabel = "default|digitalbazaar")
49+
String mode = "default";
50+
4351
@Spec
4452
CommandSpec spec;
4553

@@ -50,7 +58,17 @@ public Integer call() throws Exception {
5058

5159
byte[] encoded = Files.readAllBytes(input.toPath());
5260

53-
final JsonValue output = CborLd.decoder(encoded).base(base).decode();
61+
DecoderConfig config = DefaultConfig.INSTANCE;
62+
63+
if ("digitalbazaar".equalsIgnoreCase(mode)) {
64+
config = DbConfig.INSTANCE;
65+
}
66+
67+
final JsonValue output = CborLd.decoder(encoded)
68+
.config(config)
69+
.base(base)
70+
.compactArray(!keepArrays)
71+
.decode();
5472

5573
JsonOutput.print((JsonStructure)output, pretty);
5674

src/main/java/com/apicatalog/cli/command/FlattenCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
@Command(
1919
name = "flatten",
2020
mixinStandardHelpOptions = false,
21-
description = "Flatten JSON-LD document and optionally compacts it using a context",
21+
description = "Flatten JSON-LD document and optionally compact it using a context",
2222
sortOptions = true,
2323
descriptionHeading = "%n",
2424
parameterListHeading = "%nParameters:%n",

src/main/java/com/apicatalog/cli/command/FromRdfCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
@Command(
1919
name = "fromrdf",
2020
mixinStandardHelpOptions = false,
21-
description = "Transform N-Quads document into a JSON-LD document in expanded form",
21+
description = "Transform N-Quads document into a JSON-LD document in an expanded form",
2222
sortOptions = true,
2323
descriptionHeading = "%n",
2424
parameterListHeading = "%nParameters:%n",

0 commit comments

Comments
 (0)