Bugfix for query deserialization of unspecified boundaries
diff --git a/src/main/java/de/ids_mannheim/korap/KorapQuery.java b/src/main/java/de/ids_mannheim/korap/KorapQuery.java
index 11616ea..e693b48 100644
--- a/src/main/java/de/ids_mannheim/korap/KorapQuery.java
+++ b/src/main/java/de/ids_mannheim/korap/KorapQuery.java
@@ -85,8 +85,17 @@
throw new QueryException("Boundary definition is not valid");
};
- min = json.get("min").asInt(defaultMin);
- max = json.get("max").asInt(defaultMax);
+ // Set min boundary
+ if (json.has("min"))
+ this.min = json.get("min").asInt(defaultMin);
+ else
+ this.min = defaultMin;
+
+ // Set max boundary
+ if (json.has("max"))
+ this.max = json.get("max").asInt(defaultMax);
+ else
+ this.max = defaultMax;
if (DEBUG)
log.trace("Found korap:boundary with {}:{}");
@@ -136,15 +145,18 @@
if (DEBUG)
log.trace("Found {} group", operation);
+ if (!json.has("operands"))
+ throw new QueryException("Operation needs operand list");
+
// Get all operands
JsonNode operands = json.get("operands");
+ if (!operands.isArray())
+ throw new QueryException("Operation needs operand list");
+
if (DEBUG)
log.trace("Operands are {}", operands);
- if (!json.has("operands") || !operands.isArray())
- throw new QueryException("Operation needs operand list");
-
switch (operation) {
case "operation:or":
@@ -278,15 +290,17 @@
"Text based distances are not supported yet"
);
- int min, max;
+ int min = 0, max = 100;
if (constraint.has("boundary")) {
- Boundary b = new Boundary(constraint.get("boundary"), 1,1);
+ Boundary b = new Boundary(constraint.get("boundary"), 0,100);
min = b.min;
max = b.max;
}
else {
- min = constraint.get("min").asInt(1);
- max = constraint.get("max").asInt(1);
+ if (constraint.has("min"))
+ min = constraint.get("min").asInt(0);
+ if (constraint.has("max"))
+ max = constraint.get("max").asInt(100);
};
sseqqw.withConstraint(min, max, unit);
diff --git a/src/test/java/de/ids_mannheim/korap/query/TestKorapQueryJSON.java b/src/test/java/de/ids_mannheim/korap/query/TestKorapQueryJSON.java
index 0d99899..842cead 100644
--- a/src/test/java/de/ids_mannheim/korap/query/TestKorapQueryJSON.java
+++ b/src/test/java/de/ids_mannheim/korap/query/TestKorapQueryJSON.java
@@ -274,6 +274,18 @@
assertEquals(sqwi.toQuery().toString(), "spanNext(spanOr([tokens:s:der, spanNext(tokens:s:der, spanRepetition(tokens:cnx/p:A{1,2}))]), tokens:tt/p:NN)");
};
+
+ @Test
+ public void queryJSONboundaryBug () {
+ SpanQueryWrapperInterface sqwi = jsonQuery(getClass().getResource("/queries/bsp-boundary.jsonld").getFile());
+
+ // Tal []{1,} Wald
+ assertEquals(sqwi.toQuery().toString(), "spanDistance(tokens:s:Tal, tokens:s:Wald, [(w[2:100], ordered, notExcluded)])");
+ };
+
+
+
+
public static String getString (String path) {
StringBuilder contentBuilder = new StringBuilder();
try {
diff --git a/src/test/resources/queries/bsp-boundary.jsonld b/src/test/resources/queries/bsp-boundary.jsonld
new file mode 100644
index 0000000..f93fa14
--- /dev/null
+++ b/src/test/resources/queries/bsp-boundary.jsonld
@@ -0,0 +1 @@
+{"@context":"http://ids-mannheim.de/ns/KorAP/json-ld/v0.1/context.jsonld","errors":[],"warnings":[],"announcements":["Deprecated 2014-07-24: 'min' and 'max' to be supported until 3 months from deprecation date."],"query":{"@type":"korap:group","operation":"operation:sequence","operands":[{"@type":"korap:token","wrap":{"@type":"korap:term","layer":"orth","key":"Tal","match":"match:eq"}},{"@type":"korap:token","wrap":{"@type":"korap:term","layer":"orth","key":"Wald","match":"match:eq"}}],"inOrder":true,"distances":[{"@type":"korap:distance","key":"w","boundary":{"@type":"korap:boundary","min":2},"min":2}]},"collections":[{"@type":"korap:meta-filter","@value":{"@type":"korap:term","@field":"korap:field#corpusID","@value":"WPD"}}],"meta":{"startPage":1,"itemsPerResource":1,"context":"paragraph"}}