Skip to content

Commit cbdaa9b

Browse files
margarethaGerrit Code Review
authored andcommitted
Merge "Add support for "corpus" in deserialization."
2 parents a65ff48 + 24a8da6 commit cbdaa9b

File tree

8 files changed

+50
-8
lines changed

8 files changed

+50
-8
lines changed

Changes

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
0.64.3 2025-07-25
1+
0.64.3 2025-08-19
22
- [feature] Add tar and zip archive input support to Krill-Indexer (kupietz)
33
- [security] Update dependencies (kupietz)
4+
- [enhancement] Add support for "corpus" in deserialization, "collection"
5+
is marked as legacy (margaretha).
46

57
0.64.2 2025-07-02
68
- [bugfix] Restore rewrites in Meta. (diewald)

src/main/java/de/ids_mannheim/korap/Krill.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,17 @@ else if (qw.isNull()) {
211211

212212
// Parse "collection" or "collections" attribute
213213
try {
214-
if (json.has("collection")) {
214+
if (json.has("corpus")) {
215+
final JsonNode collNode = json.get("corpus");
216+
217+
// TODO: Temporary
218+
if (collNode.fieldNames().hasNext()) {
219+
this.setCollection(
220+
new KrillCollection().fromKoral(collNode));
221+
};
222+
}
223+
// EM: legacy
224+
else if (json.has("collection")) {
215225
final JsonNode collNode = json.get("collection");
216226

217227
// TODO: Temporary

src/main/java/de/ids_mannheim/korap/KrillCollection.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ public KrillCollection (String jsonString) {
104104
if (json.has("errors") && json.get("errors").size() > 0) {
105105
this.addError(StatusCodes.INVALID_QUERY, "Json has errors.");
106106
}
107+
else if (json.has("corpus")) {
108+
this.fromKoral(json.get("corpus"));
109+
}
110+
// EM: legacy
107111
else if (json.has("collection")) {
108112
this.fromKoral(json.get("collection"));
109113
}
@@ -113,7 +117,7 @@ else if (json.has("collections")) {
113117
}
114118
else {
115119
this.addError(StatusCodes.MISSING_COLLECTION,
116-
"Collection is not found");
120+
"VC is not found");
117121
this.fromBuilder(this.build().nothing());
118122
}
119123
}
@@ -216,7 +220,7 @@ else if (KrillProperties.isTest
216220
}
217221
else{
218222
this.addError(StatusCodes.MISSING_COLLECTION,
219-
"Collection is not found " + fileName);
223+
"VC is not found " + fileName);
220224
return this;
221225
};
222226

@@ -251,6 +255,10 @@ public KrillCollection fromKoral (JsonNode json) throws QueryException {
251255
private CollectionBuilder.Interface _fromKoral (JsonNode json)
252256
throws QueryException {
253257

258+
if (json.has("corpus")) {
259+
return this._fromKoral(json.at("/corpus"));
260+
};
261+
254262
if (json.has("collection")) {
255263
return this._fromKoral(json.at("/collection"));
256264
};

src/main/java/de/ids_mannheim/korap/response/Response.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,8 +557,11 @@ public JsonNode toJsonNode () {
557557
if (this.collection != null) {
558558
// && this.collection.getFilters().toArray().length > 0) {
559559
JsonNode collNode = this.collection.toJsonNode();
560-
if (collNode != null)
560+
if (collNode != null) {
561+
json.set("corpus", collNode);
562+
// EM: legacy
561563
json.set("collection", collNode);
564+
};
562565
};
563566

564567
return (JsonNode) json;

src/test/java/de/ids_mannheim/korap/cache/TestInvalidVcId.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public void testStoreVcNotExist () {
3030
VirtualCorpusCache.store(vcId, ki);
3131
});
3232
assertEquals("de.ids_mannheim.korap.util.QueryException: "
33-
+ "Collection is not found queries/collections/named-vcs/snx.jsonld",
33+
+ "VC is not found queries/collections/named-vcs/snx.jsonld",
3434
ex.getMessage());
3535
}
3636

@@ -46,7 +46,7 @@ public void testReferVcNotExist () throws IOException {
4646
Message m = result.getError(0);
4747
assertEquals(StatusCodes.MISSING_COLLECTION, m.getCode());
4848
assertEquals(
49-
"Collection is not found queries/collections/named-vcs/unknown-vc.jsonld",
49+
"VC is not found queries/collections/named-vcs/unknown-vc.jsonld",
5050
m.getMessage());
5151
assertEquals(0, result.getTotalResults());
5252
}

src/test/java/de/ids_mannheim/korap/collection/TestKrillCollectionIndex.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ public void testUnknownVC () throws IOException {
677677
Result result = krill.apply(ki);
678678

679679
assertEquals(StatusCodes.MISSING_COLLECTION, result.getError(0).getCode());
680-
assertTrue(result.getError(0).getMessage().startsWith("Collection is not found"));
680+
assertTrue(result.getError(0).getMessage().startsWith("VC is not found"));
681681
};
682682

683683
@Test

src/test/java/de/ids_mannheim/korap/collection/TestKrillCollectionJSON.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ public void collection1 () {
3232
assertEquals(kc.toString(), "pubDate:[20000101 TO 20000101]");
3333
};
3434

35+
@Test
36+
public void corpus1 () {
37+
String metaQuery = _getJSONString("corpus_1.jsonld");
38+
KrillCollection kc = new KrillCollection(metaQuery);
39+
assertEquals(kc.toString(), "pubDate:[20000101 TO 20000101]");
40+
};
3541

3642
@Test
3743
public void collection2 () {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"@context" : "http://ids-mannheim.de/ns/KorAP/json-ld/v0.2/context.jsonld",
3+
"errors" : [ ],
4+
"warnings" : [ ],
5+
"announcements" : [ ],
6+
"corpus" : {
7+
"@type" : "koral:doc",
8+
"key" : "pubDate",
9+
"type" : "type:date",
10+
"value" : "2000-01-01",
11+
"match" : "match:eq"
12+
}
13+
}

0 commit comments

Comments
 (0)