Fix distance constraint serialization bug
Change-Id: If3a3614bdb3600e9431aaee23f776a9c0139ad4e
diff --git a/Changes b/Changes
index 3b4f0bf..a681cc0 100644
--- a/Changes
+++ b/Changes
@@ -1,6 +1,7 @@
0.55.3 2016-02-15
- - [bugfix] use base foundry for default sentences and paragraphs
+ - [bugfix] Use base foundry for default sentences and paragraphs
(diewald)
+ - [bugfix] Distance constraint exclusion serialized (diewald)
0.55.2 2016-02-13
- [bugfix] Fixed support for corpus and doc IDs containing
diff --git a/src/main/java/de/ids_mannheim/korap/KrillQuery.java b/src/main/java/de/ids_mannheim/korap/KrillQuery.java
index ec028f0..f2cf859 100644
--- a/src/main/java/de/ids_mannheim/korap/KrillQuery.java
+++ b/src/main/java/de/ids_mannheim/korap/KrillQuery.java
@@ -911,6 +911,11 @@
unit = value.append("base/s:").append(unit).toString();
};
+ // Set distance exclusion
+ Boolean exclusion = false;
+ if (constraint.has("exclude"))
+ exclusion = constraint.get("exclude").asBoolean();
+
// Sanitize boundary
if (max < min)
max = min;
@@ -919,7 +924,7 @@
log.trace("Add distance constraint of '{}': {}-{}", unit,
min, max);
- sseqqw.withConstraint(min, max, unit);
+ sseqqw.withConstraint(min, max, unit, exclusion);
};
};
diff --git a/src/test/java/de/ids_mannheim/korap/query/TestSpanSequenceQueryJSON.java b/src/test/java/de/ids_mannheim/korap/query/TestSpanSequenceQueryJSON.java
index d95ccfc..d88eb62 100644
--- a/src/test/java/de/ids_mannheim/korap/query/TestSpanSequenceQueryJSON.java
+++ b/src/test/java/de/ids_mannheim/korap/query/TestSpanSequenceQueryJSON.java
@@ -303,7 +303,7 @@
@Test
public void queryJSONseqMultipleDistances () throws QueryException {
- SpanQueryWrapper sqwi = jsonQueryFile("multiple-distances.jsonld");
+ SpanQueryWrapper sqwi = jsonQueryFile("distance-multiple.jsonld");
// er []{,10} kann []{1,10} sagte
assertEquals(
@@ -311,6 +311,20 @@
sqwi.toQuery().toString());
};
+ @Test
+ public void queryJSONseqSentenceDistance () throws QueryException {
+ SpanQueryWrapper sqwi = jsonQueryFile("distance-sentence.jsonld");
+
+ assertEquals("spanElementDistance({129: tokens:s:der}, {129: tokens:s:Baum}, [(base/s:s[0:0], notOrdered, notExcluded)])",sqwi.toQuery().toString());
+ };
+
+ @Test
+ public void queryJSONseqSentenceDistanceExcluded () throws QueryException {
+ SpanQueryWrapper sqwi = jsonQueryFile("distance-sentence-excluded.jsonld");
+
+ assertEquals("spanElementDistance({129: tokens:s:der}, {129: tokens:s:Baum}, [(base/s:s[0:0], notOrdered, excluded)])",sqwi.toQuery().toString());
+ };
+
// get query wrapper based on json file
public SpanQueryWrapper jsonQueryFile (String filename) {
diff --git a/src/test/resources/queries/sequence/multiple-distances.jsonld b/src/test/resources/queries/sequence/distance-multiple.jsonld
similarity index 100%
rename from src/test/resources/queries/sequence/multiple-distances.jsonld
rename to src/test/resources/queries/sequence/distance-multiple.jsonld
diff --git a/src/test/resources/queries/sequence/distance-sentence-excluded.jsonld b/src/test/resources/queries/sequence/distance-sentence-excluded.jsonld
new file mode 100644
index 0000000..1676714
--- /dev/null
+++ b/src/test/resources/queries/sequence/distance-sentence-excluded.jsonld
@@ -0,0 +1,57 @@
+{
+ "@context":"http://ids-mannheim.de/ns/KorAP/json-ld/v0.3/context.jsonld",
+ "collection":null,
+ "query": {
+ "distances": [
+ {
+ "max": 0,
+ "min": 0,
+ "boundary": {
+ "min": 0,
+ "@type": "koral:boundary",
+ "max": 0
+ },
+ "@type": "cosmas:distance",
+ "key": "s",
+ "exclude" : true
+ }
+ ],
+ "@type": "koral:group",
+ "operands": [
+ {
+ "@type": "koral:group",
+ "operands": [
+ {
+ "@type": "koral:token",
+ "wrap": {
+ "@type": "koral:term",
+ "layer": "orth",
+ "key": "der",
+ "match": "match:eq"
+ }
+ }
+ ],
+ "operation": "operation:class",
+ "classOut": 129
+ },
+ {
+ "classOut": 129,
+ "operation": "operation:class",
+ "operands": [
+ {
+ "wrap": {
+ "match": "match:eq",
+ "@type": "koral:term",
+ "key": "Baum",
+ "layer": "orth"
+ },
+ "@type": "koral:token"
+ }
+ ],
+ "@type": "koral:group"
+ }
+ ],
+ "inOrder": false,
+ "operation": "operation:sequence"
+ }
+}
diff --git a/src/test/resources/queries/sequence/distance-sentence.jsonld b/src/test/resources/queries/sequence/distance-sentence.jsonld
new file mode 100644
index 0000000..435693f
--- /dev/null
+++ b/src/test/resources/queries/sequence/distance-sentence.jsonld
@@ -0,0 +1,56 @@
+{
+ "@context":"http://ids-mannheim.de/ns/KorAP/json-ld/v0.3/context.jsonld",
+ "collection":null,
+ "query":{
+ "distances": [
+ {
+ "max": 0,
+ "min": 0,
+ "boundary": {
+ "max": 0,
+ "min": 0,
+ "@type": "koral:boundary"
+ },
+ "@type": "cosmas:distance",
+ "key": "s"
+ }
+ ],
+ "@type": "koral:group",
+ "operands": [
+ {
+ "classOut": 129,
+ "operands": [
+ {
+ "@type": "koral:token",
+ "wrap": {
+ "@type": "koral:term",
+ "key": "der",
+ "layer": "orth",
+ "match": "match:eq"
+ }
+ }
+ ],
+ "operation": "operation:class",
+ "@type": "koral:group"
+ },
+ {
+ "classOut": 129,
+ "operation": "operation:class",
+ "operands": [
+ {
+ "@type": "koral:token",
+ "wrap": {
+ "match": "match:eq",
+ "@type": "koral:term",
+ "layer": "orth",
+ "key": "Baum"
+ }
+ }
+ ],
+ "@type": "koral:group"
+ }
+ ],
+ "inOrder": false,
+ "operation": "operation:sequence"
+ }
+}