Added empty token and optionality tests.

Change-Id: Ief72134b076485e49828a9042f70ba805e38e659
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusQueryProcessor.java b/src/main/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusQueryProcessor.java
index c0a88c9..b0e88ef 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusQueryProcessor.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusQueryProcessor.java
@@ -251,19 +251,7 @@
         }
         LinkedHashMap<String, Object> sequence = KoralObjectGenerator
                 .makeGroup("sequence");
-        ParseTree distanceNode = getFirstChildWithCat(node, "distance");
-
-        if (distanceNode != null) {
-            Integer[] minmax = parseDistance(distanceNode);
-            LinkedHashMap<String, Object> distance = KoralObjectGenerator
-                    .makeDistance("w", minmax[0], minmax[1]);
-            sequence.put("inOrder", true);
-            ArrayList<Object> distances = new ArrayList<Object>();
-            distances.add(distance);
-            sequence.put("distances", distances);
-            // don't re-visit the emptyTokenSequence node
-            visited.add(distanceNode.getChild(0));
-        }
+        
         putIntoSuperObject(sequence);
         objectStack.push(sequence);
         stackedObjects++;
diff --git a/src/test/java/de/ids_mannheim/korap/query/test/poliqarpplus/EmptyTokenTest.java b/src/test/java/de/ids_mannheim/korap/query/test/poliqarpplus/EmptyTokenTest.java
index 3ecb4b8..6c215f9 100644
--- a/src/test/java/de/ids_mannheim/korap/query/test/poliqarpplus/EmptyTokenTest.java
+++ b/src/test/java/de/ids_mannheim/korap/query/test/poliqarpplus/EmptyTokenTest.java
@@ -232,7 +232,63 @@
 

     }

 

-

+    @Test

+    public void testBetweenTokensAndOptionality ()

+            throws JsonProcessingException, IOException {

+        query = "[base=der][][base=Mann]?";

+        qs.setQuery(query, "poliqarpplus");

+        res = mapper.readTree(qs.toJSON());

+        assertEquals("koral:group", res.at("/query/@type").asText());

+        assertEquals("operation:sequence", res.at("/query/operation").asText());

+        operands = Lists.newArrayList(res.at("/query/operands").elements());

+        assertEquals(3, operands.size());

+        

+        assertEquals("koral:token", operands.get(1).at("/@type").asText());

+        assertEquals(true, operands.get(1).at("/wrap/key").isMissingNode());

+        

+        assertEquals("koral:group", operands.get(2).at("/@type").asText());

+        assertEquals("operation:repetition",

+                operands.get(2).at("/operation").asText());

+        assertEquals("Mann", operands.get(2).at("/operands/0/wrap/key").asText());

+        assertEquals("koral:boundary",

+                operands.get(2).at("/boundary/@type").asText());

+        assertEquals(0, operands.get(2).at("/boundary/min").asInt());

+        assertEquals(1, operands.get(2).at("/boundary/max").asInt());

+    }

+        

+    @Test

+    public void testBetweenTokensAndOptionality2 ()

+            throws JsonProcessingException, IOException {

+        query = "[base=der]?[][base=Mann]?";

+        qs.setQuery(query, "poliqarpplus");

+        res = mapper.readTree(qs.toJSON());

+        assertEquals("koral:group", res.at("/query/@type").asText());

+        assertEquals("operation:sequence", res.at("/query/operation").asText());

+        operands = Lists.newArrayList(res.at("/query/operands").elements());

+        assertEquals(3, operands.size());

+        

+        assertEquals("koral:group", operands.get(0).at("/@type").asText());

+        assertEquals("operation:repetition",

+                operands.get(0).at("/operation").asText());

+        assertEquals("der", operands.get(0).at("/operands/0/wrap/key").asText());

+        assertEquals("koral:boundary",

+                operands.get(0).at("/boundary/@type").asText());

+        assertEquals(0, operands.get(0).at("/boundary/min").asInt());

+        assertEquals(1, operands.get(0).at("/boundary/max").asInt());

+        

+        assertEquals("koral:token", operands.get(1).at("/@type").asText());

+        assertEquals(true, operands.get(1).at("/wrap/key").isMissingNode());

+        

+        assertEquals("koral:group", operands.get(2).at("/@type").asText());

+        assertEquals("operation:repetition",

+                operands.get(2).at("/operation").asText());

+        assertEquals("Mann", operands.get(2).at("/operands/0/wrap/key").asText());

+        assertEquals("koral:boundary",

+                operands.get(2).at("/boundary/@type").asText());

+        assertEquals(0, operands.get(2).at("/boundary/min").asInt());

+        assertEquals(1, operands.get(2).at("/boundary/max").asInt());

+    }

+    

     @Test

     public void testQuantifierBetweenTokens1 ()

             throws JsonProcessingException, IOException {