Ignore order of min/max interval in distance operators in C2 - fixes #67
Change-Id: I58b6e0bd8ac039316d532d13022ddfe3de51f148
diff --git a/Changes b/Changes
index be9fd4b..2c1bb16 100644
--- a/Changes
+++ b/Changes
@@ -1,3 +1,7 @@
+0.34 2019-07-17
+ - [bugfix] Ignore min:max order in distance operators
+ (#67; diewald)
+
0.33 2019-02-20
- Added debug flags (margaretha)
- [bugfix] Fixed poliqarp layer bug (#52; margaretha)
@@ -23,9 +27,9 @@
0.29 2018-07-23
- Added check for errors on QuerySerializer object (diewald)
- Support verbatim string values in Poliqarp
- (fixes #42; diewald)
+ (fixes #42; diewald)
- Fix support for verbatim string values in collection queries
- (diewald)
+ (diewald)
- Added hint to update the library (diewald)
0.28 2018-01-10
diff --git a/pom.xml b/pom.xml
index 1364510..a8cddbb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
<groupId>de.ids_mannheim.korap</groupId>
<artifactId>Koral</artifactId>
- <version>0.33</version>
+ <version>0.34</version>
<packaging>jar</packaging>
<name>Koral</name>
<url>http://maven.apache.org</url>
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/Cosmas2QueryProcessor.java b/src/main/java/de/ids_mannheim/korap/query/serialize/Cosmas2QueryProcessor.java
index 5f19798..4bc806a 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/Cosmas2QueryProcessor.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/Cosmas2QueryProcessor.java
@@ -641,7 +641,7 @@
boolean putIntoOverlapDisjunction = false;
- int min = 0, max = 0;
+ int tmin, min = 0, max = 0;
// possibly several distance constraints
for (int i = 0; i < dist_list.getChildCount(); i++) {
String direction = dist_list.getChild(i).getChild(0).getChild(0)
@@ -672,6 +672,13 @@
if (!meas.equals("w") && min == 0) {
processSpanDistance(meas, min, max);
}
+
+ if (max < min) {
+ tmin = min;
+ min = max;
+ max = tmin;
+ }
+
Map<String, Object> distance =
KoralObjectGenerator.makeDistance(meas, min, max);
// override @type, min/max to be treated according to
diff --git a/src/test/java/de/ids_mannheim/korap/test/cosmas2/Cosmas2QueryProcessorTest.java b/src/test/java/de/ids_mannheim/korap/test/cosmas2/Cosmas2QueryProcessorTest.java
index dedc9f3..da64bbe 100644
--- a/src/test/java/de/ids_mannheim/korap/test/cosmas2/Cosmas2QueryProcessorTest.java
+++ b/src/test/java/de/ids_mannheim/korap/test/cosmas2/Cosmas2QueryProcessorTest.java
@@ -561,6 +561,36 @@
assertEquals("Mond", res.at("/query/operands/1/operands/0/wrap/key")
.asText());
+ // Order of min and max is irrelevant in C2
+ query = "Sonne /+w4:1,s0,p3:1 Mond";
+ qs.setQuery(query, "cosmas2");
+ res = mapper.readTree(qs.toJSON());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals("cosmas:distance", res.at("/query/distances/0/@type")
+ .asText());
+ assertEquals("w", res.at("/query/distances/0/key").asText());
+ assertEquals(1, res.at("/query/distances/0/boundary/min").asInt());
+ assertEquals(4, res.at("/query/distances/0/boundary/max").asInt());
+ assertEquals("s", res.at("/query/distances/1/key").asText());
+ assertEquals(0, res.at("/query/distances/1/boundary/min").asInt());
+ assertEquals("p", res.at("/query/distances/2/key").asText());
+ assertEquals(1, res.at("/query/distances/2/boundary/min").asInt());
+ assertEquals(3, res.at("/query/distances/2/boundary/max").asInt());
+ assertEquals(true, res.at("/query/inOrder").asBoolean());
+ assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
+ assertEquals("operation:class", res.at("/query/operands/0/operation")
+ .asText());
+ assertEquals(129, res.at("/query/operands/0/classOut").asInt());
+ assertEquals(129, res.at("/query/operands/1/classOut").asInt());
+ assertEquals("koral:token", res
+ .at("/query/operands/0/operands/0/@type").asText());
+ assertEquals("Sonne", res.at("/query/operands/0/operands/0/wrap/key")
+ .asText());
+ assertEquals("Mond", res.at("/query/operands/1/operands/0/wrap/key")
+ .asText());
+
+
query = "Sonne /+w4 Mond";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());