Changed the implementation for distance query with optionality. 

Change-Id: I7d974a6be69aa38d0248b0ca10b17f9da4e8ada5
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..89fe13f 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
@@ -28,7 +28,8 @@
  * This class expects the Poliqarp+ ANTLR grammar shipped with Koral
  * v0.3.0.
  * 
- * @author Joachim Bingel (bingel@ids-mannheim.de)
+ * @author Joachim Bingel (bingel@ids-mannheim.de), Eliza Margaretha
+ *         (margaretha@ids-mannheim.de)
  * @version 0.3.0
  * @since 0.1.0
  */
@@ -38,6 +39,7 @@
             .getLogger(PoliqarpPlusQueryProcessor.class);
     private int classCounter = 1;
 
+    boolean isExpansion = false;
     LinkedHashMap<ParseTree, Integer> classWrapRegistry = new LinkedHashMap<ParseTree, Integer>();
 
 
@@ -66,8 +68,8 @@
             processNode(tree);
         }
         else {
-            addError(StatusCodes.MALFORMED_QUERY, "Could not parse query >>> "
-                    + query + " <<<.");
+            addError(StatusCodes.MALFORMED_QUERY,
+                    "Could not parse query >>> " + query + " <<<.");
         }
     }
 
@@ -91,7 +93,7 @@
         // Top-down processing
         if (visited.contains(node))
             return;
-        else
+        else if (!isExpansion)
             visited.add(node);
 
         String nodeCat = getNodeCat(node);
@@ -151,7 +153,7 @@
         }
 
         if (nodeCat.equals("disjunction")) {
-            processDisjunction(node);
+            processDisjunction();
         }
 
         if (nodeCat.equals("position")) {
@@ -234,9 +236,8 @@
      */
     private void processSequence (ParseTree node) {
         // skip in case of emptyTokenSequence or emptyTokenSequenceClass
-        if (node.getChildCount() == 1
-                && getNodeCat(node.getChild(0))
-                        .startsWith("emptyTokenSequence")) {
+        if (node.getChildCount() == 1 && getNodeCat(node.getChild(0))
+                .startsWith("emptyTokenSequence")) {
             return;
         }
         // skip in case this sequence is just a container for an alignment 
@@ -261,6 +262,30 @@
             ArrayList<Object> distances = new ArrayList<Object>();
             distances.add(distance);
             sequence.put("distances", distances);
+
+            // Check optionality
+            ParseTree lastChildNode = node.getChild(node.getChildCount() - 1);
+            if (getNodeCat(lastChildNode).equals("segment")) {
+                ParseTree quantification = getFirstChildWithCat(lastChildNode,
+                        "repetition");
+                if (quantification != null) {
+                    minmax = parseRepetition(quantification);
+                    if (minmax[0] == 0 && minmax[1] == 1) {
+                        visited.add(quantification);
+                        processDisjunction();
+                        // create expansion
+                        isExpansion = true;
+                        LinkedHashMap<String, Object> expansionSequence = KoralObjectGenerator
+                                .makeGroup("sequence");
+                        putIntoSuperObject(expansionSequence);
+                        objectStack.push(expansionSequence);
+                        processNode(node.getChild(0));
+                        processNode(distanceNode.getChild(0));
+                        isExpansion = false;
+                        objectStack.pop();
+                    }
+                }
+            }
             // don't re-visit the emptyTokenSequence node
             visited.add(distanceNode.getChild(0));
         }
@@ -273,6 +298,7 @@
     @SuppressWarnings("unchecked")
     /**
      * empty tokens at beginning/end of sequence
+     * 
      * @param node
      */
     private void processEmptyTokenSequence (ParseTree node) {
@@ -298,8 +324,8 @@
     private void processEmptyTokenSequenceClass (ParseTree node) {
         int classId = 1;
         if (hasChild(node, "spanclass_id")) {
-            classId = Integer.parseInt(node.getChild(1).getChild(0)
-                    .toStringTree(parser));
+            classId = Integer.parseInt(
+                    node.getChild(1).getChild(0).toStringTree(parser));
         }
         LinkedHashMap<String, Object> classGroup = KoralObjectGenerator
                 .makeSpanClass(classId);
@@ -391,7 +417,7 @@
         int i = 1;
         if (node.getChild(0).getText().equals("^")) {
             i = 0; // if there is no first child (anchor is at extreme left or
-                   // right of segment), start counting at 0 in the loop
+                  // right of segment), start counting at 0 in the loop
         }
         // for every alignment anchor, get its left and right child and register
         // these to be wrapped in classes.
@@ -477,7 +503,7 @@
     }
 
 
-    private void processDisjunction (ParseTree node) {
+    private void processDisjunction () {
         LinkedHashMap<String, Object> disjunction = KoralObjectGenerator
                 .makeGroup("disjunction");
         putIntoSuperObject(disjunction);
@@ -633,8 +659,8 @@
         addWarning("You used the 'meta' keyword in a PoliqarpPlus query. This"
                 + " feature is currently not supported. Please use virtual "
                 + "collections to restrict documents by metadata.");
-        CollectionQueryProcessor cq = new CollectionQueryProcessor(node
-                .getChild(1).getText());
+        CollectionQueryProcessor cq = new CollectionQueryProcessor(
+                node.getChild(1).getText());
         requestMap.put("collection", cq.getRequestMap().get("collection"));
         for (ParseTree child : getChildren(node)) {
             visited.add(child);
@@ -777,7 +803,8 @@
 
             // Term is defined recursive with non-necessary brackets
             if (getNodeCat(node.getChild(0)).equals("(")) {
-                return parseTermOrTermGroup(node.getChild(1), negatedGlobal, mode);
+                return parseTermOrTermGroup(node.getChild(1), negatedGlobal,
+                        mode);
             };
 
             String key = null;
@@ -868,7 +895,8 @@
 
             // TermGroup is defined recursive with non-necessary brackets
             if (getNodeCat(node.getChild(0)).equals("(")) {
-                return parseTermOrTermGroup(node.getChild(1), negatedGlobal, mode);
+                return parseTermOrTermGroup(node.getChild(1), negatedGlobal,
+                        mode);
             };
 
             // For termGroups, establish a boolean relation between
@@ -959,8 +987,8 @@
     private Integer[] parseDistance (ParseTree distanceNode) {
         int emptyTokenSeqIndex = getNodeCat(distanceNode).equals("distance") ? 0
                 : 2;
-        Integer[] minmax = parseEmptySegments(distanceNode
-                .getChild(emptyTokenSeqIndex));
+        Integer[] minmax = parseEmptySegments(
+                distanceNode.getChild(emptyTokenSeqIndex));
         Integer min = minmax[0];
         Integer max = minmax[1];
         //        min++;
@@ -1023,8 +1051,8 @@
 
             // Get starting rule from parser
             Method startRule = PoliqarpPlusParser.class.getMethod("request");
-            tree = (ParserRuleContext) startRule
-                    .invoke(parser, (Object[]) null);
+            tree = (ParserRuleContext) startRule.invoke(parser,
+                    (Object[]) null);
         }
         // Some things went wrong ...
         catch (Exception e) {
diff --git a/src/test/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusQueryProcessorTest.java b/src/test/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusQueryProcessorTest.java
index 73f54e1..57ea313 100644
--- a/src/test/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusQueryProcessorTest.java
+++ b/src/test/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusQueryProcessorTest.java
@@ -41,7 +41,8 @@
 
 
     @Test
-    public void testSingleTokens () throws JsonProcessingException, IOException {
+    public void testSingleTokens ()
+            throws JsonProcessingException, IOException {
         query = "[base=Mann]";
         qs.setQuery(query, "poliqarpplus");
         res = mapper.readTree(qs.toJSON());
@@ -86,8 +87,8 @@
 
 
     @Test
-    public void testNegatedTokens () throws JsonProcessingException,
-            IOException {
+    public void testNegatedTokens ()
+            throws JsonProcessingException, IOException {
         query = "![p!=NN]";
         qs.setQuery(query, "poliqarpplus");
         res = mapper.readTree(qs.toJSON());
@@ -157,6 +158,7 @@
         assertEquals("match:eq", res.at("/query/wrap/match").asText());
     }
 
+
     @Test
     public void testRegexEscape () throws JsonProcessingException, IOException {
         // Escape regex symbols
@@ -191,8 +193,10 @@
         assertEquals("a\\.\\+\\?\\\\", res.at("/query/wrap/key").asText());
     }
 
+
     @Test
-    public void testRegexWhiteSpace () throws JsonProcessingException, IOException {
+    public void testRegexWhiteSpace ()
+            throws JsonProcessingException, IOException {
         // Escape regex symbols
         query = "\"a b\"";
         qs.setQuery(query, "poliqarpplus");
@@ -231,18 +235,18 @@
 
 
     @Test
-    public void testCaseSensitivityFlag () throws JsonProcessingException,
-            IOException {
+    public void testCaseSensitivityFlag ()
+            throws JsonProcessingException, IOException {
         query = "[orth=deutscher/i]";
         qs.setQuery(query, "poliqarpplus");
         res = mapper.readTree(qs.toJSON());
         assertEquals("koral:token", res.at("/query/@type").asText());
         assertEquals("koral:term", res.at("/query/wrap/@type").asText());
         assertEquals("deutscher", res.at("/query/wrap/key").asText());
-        assertEquals(true, res.at("/query/wrap/flags:caseInsensitive")
-                .isMissingNode());
-        assertEquals("flags:caseInsensitive", res.at("/query/wrap/flags/0")
-                .asText());
+        assertEquals(true,
+                res.at("/query/wrap/flags:caseInsensitive").isMissingNode());
+        assertEquals("flags:caseInsensitive",
+                res.at("/query/wrap/flags/0").asText());
         assertEquals("orth", res.at("/query/wrap/layer").asText());
         assertEquals("match:eq", res.at("/query/wrap/match").asText());
 
@@ -252,8 +256,8 @@
         assertEquals("koral:token", res.at("/query/@type").asText());
         assertEquals("koral:term", res.at("/query/wrap/@type").asText());
         assertEquals("deutscher", res.at("/query/wrap/key").asText());
-        assertEquals("flags:caseInsensitive", res.at("/query/wrap/flags/0")
-                .asText());
+        assertEquals("flags:caseInsensitive",
+                res.at("/query/wrap/flags/0").asText());
         assertEquals("orth", res.at("/query/wrap/layer").asText());
         assertEquals("match:eq", res.at("/query/wrap/match").asText());
 
@@ -316,7 +320,7 @@
 
         query = "<\".*\">";
         qs.setQuery(query, "poliqarpplus");
-       res = mapper.readTree(qs.toJSON());
+        res = mapper.readTree(qs.toJSON());
         assertEquals("koral:span", res.at("/query/@type").asText());
         assertEquals(".*", res.at("/query/wrap/key").asText());
         assertEquals("type:regex", res.at("/query/wrap/type").asText());
@@ -401,17 +405,14 @@
         assertEquals("true", res.at("/query/inOrder").asText());
         assertEquals("koral:distance", res.at("/query/distances").elements()
                 .next().at("/@type").asText());
-        assertEquals("w",
-                res.at("/query/distances").elements().next().at("/key")
-                        .asText());
+        assertEquals("w", res.at("/query/distances").elements().next()
+                .at("/key").asText());
         assertEquals("koral:boundary", res.at("/query/distances").elements()
                 .next().at("/boundary/@type").asText());
-        assertEquals(1,
-                res.at("/query/distances").elements().next()
-                        .at("/boundary/min").asInt());
-        assertEquals(1,
-                res.at("/query/distances").elements().next()
-                        .at("/boundary/max").asInt());
+        assertEquals(1, res.at("/query/distances").elements().next()
+                .at("/boundary/min").asInt());
+        assertEquals(1, res.at("/query/distances").elements().next()
+                .at("/boundary/max").asInt());
         operands = Lists.newArrayList(res.at("/query/operands").elements());
         assertEquals("koral:token", operands.get(0).at("/@type").asText());
         assertEquals("der", operands.get(0).at("/wrap/key").asText());
@@ -430,17 +431,14 @@
         assertEquals("true", res.at("/query/inOrder").asText());
         assertEquals("koral:distance", res.at("/query/distances").elements()
                 .next().at("/@type").asText());
-        assertEquals("w",
-                res.at("/query/distances").elements().next().at("/key")
-                        .asText());
+        assertEquals("w", res.at("/query/distances").elements().next()
+                .at("/key").asText());
         assertEquals("koral:boundary", res.at("/query/distances").elements()
                 .next().at("/boundary/@type").asText());
-        assertEquals(2,
-                res.at("/query/distances").elements().next()
-                        .at("/boundary/min").asInt());
-        assertEquals(2,
-                res.at("/query/distances").elements().next()
-                        .at("/boundary/max").asInt());
+        assertEquals(2, res.at("/query/distances").elements().next()
+                .at("/boundary/min").asInt());
+        assertEquals(2, res.at("/query/distances").elements().next()
+                .at("/boundary/max").asInt());
         operands = Lists.newArrayList(res.at("/query/operands").elements());
         assertEquals("koral:token", operands.get(0).at("/@type").asText());
         assertEquals("der", operands.get(0).at("/wrap/key").asText());
@@ -459,17 +457,14 @@
         assertEquals("true", res.at("/query/inOrder").asText());
         assertEquals("koral:distance", res.at("/query/distances").elements()
                 .next().at("/@type").asText());
-        assertEquals("w",
-                res.at("/query/distances").elements().next().at("/key")
-                        .asText());
+        assertEquals("w", res.at("/query/distances").elements().next()
+                .at("/key").asText());
         assertEquals("koral:boundary", res.at("/query/distances").elements()
                 .next().at("/boundary/@type").asText());
-        assertEquals(1,
-                res.at("/query/distances").elements().next()
-                        .at("/boundary/min").asInt());
-        assertEquals(2,
-                res.at("/query/distances").elements().next()
-                        .at("/boundary/max").asInt());
+        assertEquals(1, res.at("/query/distances").elements().next()
+                .at("/boundary/min").asInt());
+        assertEquals(2, res.at("/query/distances").elements().next()
+                .at("/boundary/max").asInt());
         operands = Lists.newArrayList(res.at("/query/operands").elements());
         assertEquals("koral:token", operands.get(0).at("/@type").asText());
         assertEquals("der", operands.get(0).at("/wrap/key").asText());
@@ -488,17 +483,14 @@
         assertEquals("true", res.at("/query/inOrder").asText());
         assertEquals("koral:distance", res.at("/query/distances").elements()
                 .next().at("/@type").asText());
-        assertEquals("w",
-                res.at("/query/distances").elements().next().at("/key")
-                        .asText());
+        assertEquals("w", res.at("/query/distances").elements().next()
+                .at("/key").asText());
         assertEquals("koral:boundary", res.at("/query/distances").elements()
                 .next().at("/boundary/@type").asText());
-        assertEquals(1,
-                res.at("/query/distances").elements().next()
-                        .at("/boundary/min").asInt());
-        assertEquals(true,
-                res.at("/query/distances").elements().next()
-                        .at("/boundary/max").isMissingNode());
+        assertEquals(1, res.at("/query/distances").elements().next()
+                .at("/boundary/min").asInt());
+        assertEquals(true, res.at("/query/distances").elements().next()
+                .at("/boundary/max").isMissingNode());
         operands = Lists.newArrayList(res.at("/query/operands").elements());
         assertEquals("koral:token", operands.get(0).at("/@type").asText());
         assertEquals("der", operands.get(0).at("/wrap/key").asText());
@@ -517,17 +509,14 @@
         assertEquals("true", res.at("/query/inOrder").asText());
         assertEquals("koral:distance", res.at("/query/distances").elements()
                 .next().at("/@type").asText());
-        assertEquals("w",
-                res.at("/query/distances").elements().next().at("/key")
-                        .asText());
+        assertEquals("w", res.at("/query/distances").elements().next()
+                .at("/key").asText());
         assertEquals("koral:boundary", res.at("/query/distances").elements()
                 .next().at("/boundary/@type").asText());
-        assertEquals(0,
-                res.at("/query/distances").elements().next()
-                        .at("/boundary/min").asInt());
-        assertEquals(true,
-                res.at("/query/distances").elements().next()
-                        .at("/boundary/max").isMissingNode());
+        assertEquals(0, res.at("/query/distances").elements().next()
+                .at("/boundary/min").asInt());
+        assertEquals(true, res.at("/query/distances").elements().next()
+                .at("/boundary/max").isMissingNode());
 
         query = "[base=der][]{2,5}[base=Mann][]?[][base=Frau]";
         qs.setQuery(query, "poliqarpplus");
@@ -537,41 +526,34 @@
         assertEquals("true", res.at("/query/inOrder").asText());
         assertEquals("koral:distance", res.at("/query/distances").elements()
                 .next().at("/@type").asText());
-        assertEquals("w",
-                res.at("/query/distances").elements().next().at("/key")
-                        .asText());
+        assertEquals("w", res.at("/query/distances").elements().next()
+                .at("/key").asText());
         assertEquals("koral:boundary", res.at("/query/distances").elements()
                 .next().at("/boundary/@type").asText());
-        assertEquals(2,
-                res.at("/query/distances").elements().next()
-                        .at("/boundary/min").asInt());
-        assertEquals(5,
-                res.at("/query/distances").elements().next()
-                        .at("/boundary/max").asInt());
+        assertEquals(2, res.at("/query/distances").elements().next()
+                .at("/boundary/min").asInt());
+        assertEquals(5, res.at("/query/distances").elements().next()
+                .at("/boundary/max").asInt());
         operands = Lists.newArrayList(res.at("/query/operands").elements());
         assertEquals("koral:token", operands.get(0).at("/@type").asText());
         assertEquals("der", operands.get(0).at("/wrap/key").asText());
         assertEquals("lemma", operands.get(0).at("/wrap/layer").asText());
         assertEquals("match:eq", operands.get(0).at("/wrap/match").asText());
         assertEquals("koral:group", operands.get(1).at("/@type").asText());
-        assertEquals("operation:sequence", operands.get(1).at("/operation")
-                .asText());
+        assertEquals("operation:sequence",
+                operands.get(1).at("/operation").asText());
         assertEquals("koral:distance", operands.get(1).get("distances")
                 .elements().next().at("/@type").asText());
         assertEquals("w", operands.get(1).get("distances").elements().next()
                 .at("/key").asText());
         assertEquals("koral:boundary", operands.get(1).get("distances")
                 .elements().next().at("/boundary/@type").asText());
-        assertEquals(
-                1,
-                operands.get(1).get("distances").elements().next()
-                        .at("/boundary/min").asInt());
-        assertEquals(
-                2,
-                operands.get(1).get("distances").elements().next()
-                        .at("/boundary/max").asInt());
-        operands = Lists.newArrayList(operands.get(1).get("operands")
-                .elements());
+        assertEquals(1, operands.get(1).get("distances").elements().next()
+                .at("/boundary/min").asInt());
+        assertEquals(2, operands.get(1).get("distances").elements().next()
+                .at("/boundary/max").asInt());
+        operands = Lists
+                .newArrayList(operands.get(1).get("operands").elements());
         assertEquals("Mann", operands.get(0).at("/wrap/key").asText());
         assertEquals("lemma", operands.get(0).at("/wrap/layer").asText());
         assertEquals("match:eq", operands.get(0).at("/wrap/match").asText());
@@ -592,34 +574,32 @@
         assertEquals("lemma", operands.get(0).at("/wrap/layer").asText());
         assertEquals("match:eq", operands.get(0).at("/wrap/match").asText());
         assertEquals("koral:group", operands.get(1).at("/@type").asText());
-        assertEquals("operation:sequence", operands.get(1).at("/operation")
-                .asText());
+        assertEquals("operation:sequence",
+                operands.get(1).at("/operation").asText());
         assertEquals("koral:distance", operands.get(1).get("distances")
                 .elements().next().at("/@type").asText());
         assertEquals("w", operands.get(1).get("distances").elements().next()
                 .at("/key").asText());
         assertEquals("koral:boundary", operands.get(1).get("distances")
                 .elements().next().at("/boundary/@type").asText());
-        assertEquals(
-                0,
-                operands.get(1).get("distances").elements().next()
-                        .at("/boundary/min").asInt());
+        assertEquals(0, operands.get(1).get("distances").elements().next()
+                .at("/boundary/min").asInt());
         assertEquals(true, operands.get(1).get("distances").elements().next()
                 .at("/boundary/max").isMissingNode());
-        operands = Lists.newArrayList(operands.get(1).get("operands")
-                .elements());
+        operands = Lists
+                .newArrayList(operands.get(1).get("operands").elements());
         assertEquals("der", operands.get(0).at("/wrap/key").asText());
         assertEquals("lemma", operands.get(0).at("/wrap/layer").asText());
         assertEquals("match:eq", operands.get(0).at("/wrap/match").asText());
         assertEquals("koral:group", operands.get(1).at("/@type").asText());
-        assertEquals("operation:position", operands.get(1).at("/operation")
-                .asText());
+        assertEquals("operation:position",
+                operands.get(1).at("/operation").asText());
     }
 
 
     @Test
-    public void testDistancesWithClass () throws JsonProcessingException,
-            IOException {
+    public void testDistancesWithClass ()
+            throws JsonProcessingException, IOException {
         query = "[base=der]{[]}[base=Mann]";
         qs.setQuery(query, "poliqarpplus");
         res = mapper.readTree(qs.toJSON());
@@ -631,11 +611,11 @@
         assertEquals("der", operands.get(0).at("/wrap/key").asText());
         assertEquals("Mann", operands.get(2).at("/wrap/key").asText());
         assertEquals("koral:group", operands.get(1).at("/@type").asText());
-        assertEquals("operation:class", operands.get(1).at("/operation")
-                .asText());
+        assertEquals("operation:class",
+                operands.get(1).at("/operation").asText());
         assertEquals(1, operands.get(1).at("/classOut").asInt());
-        operands = Lists.newArrayList(operands.get(1).at("/operands")
-                .elements());
+        operands = Lists
+                .newArrayList(operands.get(1).at("/operands").elements());
         assertEquals("koral:token", operands.get(0).at("/@type").asText());
         assertEquals(true, operands.get(0).at("/wrap").isMissingNode());
         assertEquals(1, res.at("/meta/highlight/0").asInt());
@@ -644,8 +624,8 @@
         qs.setQuery(query, "poliqarpplus");
         res = mapper.readTree(qs.toJSON());
         operands = Lists.newArrayList(res.at("/query/operands").elements());
-        assertEquals("operation:class", operands.get(1).at("/operation")
-                .asText());
+        assertEquals("operation:class",
+                operands.get(1).at("/operation").asText());
         assertEquals(2, operands.get(1).at("/classOut").asInt());
         assertEquals(2, res.at("/meta/highlight/0").asInt());
 
@@ -653,8 +633,8 @@
         qs.setQuery(query, "poliqarpplus");
         res = mapper.readTree(qs.toJSON());
         operands = Lists.newArrayList(res.at("/query/operands").elements());
-        assertEquals("operation:class", operands.get(1).at("/operation")
-                .asText());
+        assertEquals("operation:class",
+                operands.get(1).at("/operation").asText());
         assertEquals(3, operands.get(1).at("/classOut").asInt());
         assertEquals(3, res.at("/meta/highlight/0").asInt());
         assertEquals("operation:class",
@@ -668,8 +648,8 @@
         qs.setQuery(query, "poliqarpplus");
         res = mapper.readTree(qs.toJSON());
         operands = Lists.newArrayList(res.at("/query/operands").elements());
-        assertEquals("operation:class", operands.get(0).at("/operation")
-                .asText());
+        assertEquals("operation:class",
+                operands.get(0).at("/operation").asText());
         assertEquals(1, operands.get(0).at("/classOut").asInt());
         assertEquals(1, res.at("/meta/highlight/0").asInt());
 
@@ -678,8 +658,8 @@
         res = mapper.readTree(qs.toJSON());
         operands = Lists.newArrayList(res.at("/query/operands").elements());
         assertEquals(1, operands.size());  // class operation may only have one operand (the sequence)
-        operands = Lists.newArrayList(operands.get(0).at("/operands")
-                .elements());
+        operands = Lists
+                .newArrayList(operands.get(0).at("/operands").elements());
         assertEquals(3, operands.size());  // the sequence has three operands ("der", "[]" and "Mann")
         assertEquals(1, res.at("/meta/highlight/0").asInt());
         assertEquals(2, res.at("/meta/highlight/1").asInt());
@@ -694,7 +674,7 @@
         res = mapper.readTree(qs.toJSON());
         assertEquals("koral:token", res.at("/query/@type").asText());
         assertEquals(true, res.at("/query/key").isMissingNode());
-        
+
         query = "contains(<s>, [])";
         qs.setQuery(query, "poliqarpplus");
         res = mapper.readTree(qs.toJSON());
@@ -714,98 +694,82 @@
         assertEquals("koral:group", res.at("/query/operands/1/@type").asText());
         assertEquals("operation:repetition",
                 res.at("/query/operands/1/operation").asText());
-        assertEquals("koral:token", res
-                .at("/query/operands/1/operands/0/@type").asText());
-        assertEquals(true, res.at("/query/operands/1/operands/0/key")
-                .isMissingNode());
+        assertEquals("koral:token",
+                res.at("/query/operands/1/operands/0/@type").asText());
+        assertEquals(true,
+                res.at("/query/operands/1/operands/0/key").isMissingNode());
 
         query = "contains(<s>, {1:[]{3}})";
         qs.setQuery(query, "poliqarpplus");
         res = mapper.readTree(qs.toJSON());
         assertEquals("s", res.at("/query/operands/0/wrap/key").asText());
         assertEquals("koral:group", res.at("/query/operands/1/@type").asText());
-        assertEquals("operation:class", res.at("/query/operands/1/operation")
-                .asText());
+        assertEquals("operation:class",
+                res.at("/query/operands/1/operation").asText());
         assertEquals("operation:repetition",
                 res.at("/query/operands/1/operands/0/operation").asText());
-        assertEquals("koral:token",
-                res.at("/query/operands/1/operands/0/operands/0/@type")
-                        .asText());
-        assertEquals(true, res
-                .at("/query/operands/1/operands/0/operands/0/key")
+        assertEquals("koral:token", res
+                .at("/query/operands/1/operands/0/operands/0/@type").asText());
+        assertEquals(true, res.at("/query/operands/1/operands/0/operands/0/key")
                 .isMissingNode());
 
     }
 
 
     @Test
-    public void testEmptyTokenSequence () throws JsonProcessingException, IOException {
+    public void testEmptyTokenSequence ()
+            throws JsonProcessingException, IOException {
         query = "[]{3}";
         qs.setQuery(query, "poliqarpplus");
         res = mapper.readTree(qs.toJSON());
 
-        assertEquals("koral:group",
-                     res.at("/query/@type").asText());
+        assertEquals("koral:group", res.at("/query/@type").asText());
         assertEquals("operation:repetition",
-                     res.at("/query/operation").asText());
-        assertEquals("koral:token",
-                     res.at("/query/operands/0/@type").asText());
+                res.at("/query/operation").asText());
+        assertEquals("koral:token", res.at("/query/operands/0/@type").asText());
         assertEquals("koral:boundary",
-                     res.at("/query/boundary/@type").asText());
-        assertEquals(3,
-                     res.at("/query/boundary/min").asInt());
-        assertEquals(3,
-                     res.at("/query/boundary/max").asInt());
+                res.at("/query/boundary/@type").asText());
+        assertEquals(3, res.at("/query/boundary/min").asInt());
+        assertEquals(3, res.at("/query/boundary/max").asInt());
 
         query = "[]{1,3}";
         qs.setQuery(query, "poliqarpplus");
         res = mapper.readTree(qs.toJSON());
 
-        assertEquals("koral:group",
-                     res.at("/query/@type").asText());
+        assertEquals("koral:group", res.at("/query/@type").asText());
         assertEquals("operation:repetition",
-                     res.at("/query/operation").asText());
-        assertEquals("koral:token",
-                     res.at("/query/operands/0/@type").asText());
+                res.at("/query/operation").asText());
+        assertEquals("koral:token", res.at("/query/operands/0/@type").asText());
         assertEquals("koral:boundary",
-                     res.at("/query/boundary/@type").asText());
-        assertEquals(1,
-                     res.at("/query/boundary/min").asInt());
-        assertEquals(3,
-                     res.at("/query/boundary/max").asInt());
+                res.at("/query/boundary/@type").asText());
+        assertEquals(1, res.at("/query/boundary/min").asInt());
+        assertEquals(3, res.at("/query/boundary/max").asInt());
 
 
         query = "[]{ , 3}";
         qs.setQuery(query, "poliqarpplus");
         res = mapper.readTree(qs.toJSON());
 
-        assertEquals("koral:group",
-                     res.at("/query/@type").asText());
+        assertEquals("koral:group", res.at("/query/@type").asText());
         assertEquals("operation:repetition",
-                     res.at("/query/operation").asText());
-        assertEquals("koral:token",
-                     res.at("/query/operands/0/@type").asText());
+                res.at("/query/operation").asText());
+        assertEquals("koral:token", res.at("/query/operands/0/@type").asText());
         assertEquals("koral:boundary",
-                     res.at("/query/boundary/@type").asText());
-        assertEquals(0,
-                     res.at("/query/boundary/min").asInt());
-        assertEquals(3,
-                     res.at("/query/boundary/max").asInt());
+                res.at("/query/boundary/@type").asText());
+        assertEquals(0, res.at("/query/boundary/min").asInt());
+        assertEquals(3, res.at("/query/boundary/max").asInt());
 
         query = "[]{4,}";
         qs.setQuery(query, "poliqarpplus");
         res = mapper.readTree(qs.toJSON());
 
-        assertEquals("koral:group",
-                     res.at("/query/@type").asText());
+        assertEquals("koral:group", res.at("/query/@type").asText());
         assertEquals("operation:repetition",
-                     res.at("/query/operation").asText());
-        assertEquals("koral:token",
-                     res.at("/query/operands/0/@type").asText());
+                res.at("/query/operation").asText());
+        assertEquals("koral:token", res.at("/query/operands/0/@type").asText());
         assertEquals("koral:boundary",
-                     res.at("/query/boundary/@type").asText());
-        assertEquals(4,
-                     res.at("/query/boundary/min").asInt());
+                res.at("/query/boundary/@type").asText());
+        assertEquals(4, res.at("/query/boundary/min").asInt());
         assertTrue(res.at("/query/boundary/max").isMissingNode());
     }
 
@@ -825,12 +789,12 @@
         res = mapper.readTree(qs.toJSON());
         operands = Lists.newArrayList(res.at("/query/operands").elements());
         assertEquals("koral:group", operands.get(0).at("/@type").asText());
-        assertEquals("operation:repetition", operands.get(0).at("/operation")
-                .asText());
+        assertEquals("operation:repetition",
+                operands.get(0).at("/operation").asText());
         assertEquals(2, operands.get(0).at("/boundary/min").asInt());
         assertEquals(2, operands.get(0).at("/boundary/max").asInt());
-        operands = Lists.newArrayList(operands.get(0).at("/operands")
-                .elements());
+        operands = Lists
+                .newArrayList(operands.get(0).at("/operands").elements());
         assertEquals("koral:token", operands.get(0).at("/@type").asText());
         assertEquals(true, operands.get(0).at("/key").isMissingNode());
 
@@ -860,34 +824,61 @@
         assertEquals("koral:token", operands.get(0).at("/@type").asText());
         assertEquals(true, operands.get(0).at("/key").isMissingNode());
     }
-    
+
+
     @Test
-    public void testDistanceWithEmptyTokenAndOptionality() throws JsonProcessingException, IOException{
-    	query = "[base=der][][base=Mann]?";
-    	qs.setQuery(query, "poliqarpplus");
-        res = mapper.readTree(qs.toJSON());
+    public void testDistanceWithEmptyTokenAndOptionality ()
+            throws JsonProcessingException, IOException {
+        query = "[base=der][][base=Mann]?";
+        qs.setQuery(query, "poliqarpplus");
+        String koralQuery = qs.toJSON();
+        res = mapper.readTree(koralQuery);
+
+        assertEquals("koral:group", res.at("/query/@type").asText());
+        assertEquals("operation:disjunction", res.at("/query/operation").asText());
         
-        String path = "/query";
-        String serializedQuery = mapper.writeValueAsString(res.at(path));
-        //System.out.println(serializedQuery);
+        String disjunctionOperand1 = "/query/operands/0/";
+        assertEquals("operation:sequence", res.at(disjunctionOperand1+"operation").asText());
+        assertEquals("der", res.at(disjunctionOperand1+"operands/0/wrap/key").asText());
+        assertEquals("koral:token", res.at(disjunctionOperand1+"operands/1/@type").asText());
         
-//        {"@type":"koral:group",
-//        	"operation":"operation:sequence",
-//        	"operands":[
-//        		{"@type":"koral:token",
-//        			"wrap":{"@type":"koral:term","key":"der","layer":"lemma","match":"match:eq"}},
-//        		{"@type":"koral:group",
-//        				"operation":"operation:repetition",
-//        				"operands":[{
-//        					"@type":"koral:token","wrap":{"@type":"koral:term","key":"Mann","layer":"lemma","match":"match:eq"}}],
-//        				"boundary":{"@type":"koral:boundary","min":0,"max":1}}
-//        	],
-//        	"inOrder":true,
-//        	"distances":[
-//	             {"@type":"koral:distance",
-//	            	 "key":"w",
-//	            	 "boundary":{
-//	            	 	"@type":"koral:boundary","min":1,"max":1},"min":1,"max":1}]}
+        String disjunctionOperand2 = "/query/operands/1/";
+        assertEquals("operation:sequence", res.at(disjunctionOperand2+"operation").asText());
+        assertEquals("der", res.at(disjunctionOperand2+"operands/0/wrap/key").asText());
+        assertEquals("Mann", res.at(disjunctionOperand2+"operands/1/wrap/key").asText());
+        assertEquals("1", res.at(disjunctionOperand2+"distances/0/boundary/min").asText());
+        assertEquals("1", res.at(disjunctionOperand2+"distances/0/boundary/max").asText());
+        
+    }
+
+    @Test
+    public void testDistanceWithEmptyTokenAndOptionality2 ()
+            throws JsonProcessingException, IOException {
+        query = "[base=der][base=bose][][base=Mann]?";
+        qs.setQuery(query, "poliqarpplus");
+        String koralQuery = qs.toJSON();
+        res = mapper.readTree(koralQuery);
+
+        assertEquals("koral:group", res.at("/query/@type").asText());
+        assertEquals("operation:sequence", res.at("/query/operation").asText());
+        
+        assertEquals("koral:token", res.at("/query/operands/0/@type").asText());
+        assertEquals("der", res.at("/query/operands/0/wrap/key").asText());
+        
+        assertEquals("koral:group", res.at("/query/operands/1/@type").asText());
+        assertEquals("operation:disjunction", res.at("/query/operands/1/operation").asText());
+        
+        String disjunctionOperand1 = "/query/operands/1/operands/0/";
+        assertEquals("operation:sequence", res.at(disjunctionOperand1+"operation").asText());
+        assertEquals("bose", res.at(disjunctionOperand1+"operands/0/wrap/key").asText());
+        assertEquals("koral:token", res.at(disjunctionOperand1+"operands/1/@type").asText());
+        
+        String disjunctionOperand2 = "/query/operands/1/operands/1/";
+        assertEquals("operation:sequence", res.at(disjunctionOperand2+"operation").asText());
+        assertEquals("bose", res.at(disjunctionOperand2+"operands/0/wrap/key").asText());
+        assertEquals("Mann", res.at(disjunctionOperand2+"operands/1/wrap/key").asText());
+        assertEquals("1", res.at(disjunctionOperand2+"distances/0/boundary/min").asText());
+        assertEquals("1", res.at(disjunctionOperand2+"distances/0/boundary/max").asText());
     }
 
     @Test
@@ -896,8 +887,8 @@
         qs.setQuery(query, "poliqarpplus");
         res = mapper.readTree(qs.toJSON());
         assertEquals("koral:group", res.at("/query/@type").asText());
-        assertEquals("operation:repetition", res.at("/query/operation")
-                .asText());
+        assertEquals("operation:repetition",
+                res.at("/query/operation").asText());
         assertEquals("der", res.at("/query/operands/0/wrap/key").asText());
         assertEquals(3, res.at("/query/boundary/min").asInt());
         assertEquals(3, res.at("/query/boundary/max").asInt());
@@ -935,8 +926,8 @@
 
 
     @Test
-    public void testGroupRepetition () throws JsonProcessingException,
-            IOException {
+    public void testGroupRepetition ()
+            throws JsonProcessingException, IOException {
         query = "contains(<s>, (der){3})";
         qs.setQuery(query, "poliqarpplus");
         res = mapper.readTree(qs.toJSON());
@@ -952,8 +943,8 @@
         qs.setQuery(query, "poliqarpplus");
         res = mapper.readTree(qs.toJSON());
         assertEquals(3, res.at("/query/operands/1/boundary/min").asInt());
-        assertEquals(true, res.at("/query/operands/1/boundary/max")
-                .isMissingNode());
+        assertEquals(true,
+                res.at("/query/operands/1/boundary/max").isMissingNode());
 
         query = "contains(<s>, (der){,3})";
         qs.setQuery(query, "poliqarpplus");
@@ -971,8 +962,8 @@
         qs.setQuery(query, "poliqarpplus");
         res = mapper.readTree(qs.toJSON());
         assertEquals(0, res.at("/query/operands/1/boundary/min").asInt());
-        assertEquals(true, res.at("/query/operands/1/boundary/max")
-                .isMissingNode());
+        assertEquals(true,
+                res.at("/query/operands/1/boundary/max").isMissingNode());
     };
 
 
@@ -1003,12 +994,12 @@
         assertEquals("frames:isAround", res.at("/query/frames/0").asText());
         assertEquals("s", res.at("/query/operands/0/wrap/key").asText());
         assertEquals("koral:group", res.at("/query/operands/1/@type").asText());
-        assertEquals("operation:sequence", res
-                .at("/query/operands/1/operation").asText());
-        assertEquals("der", res.at("/query/operands/1/operands/0/wrap/key")
-                .asText());
-        assertEquals("Mann", res.at("/query/operands/1/operands/1/wrap/key")
-                .asText());
+        assertEquals("operation:sequence",
+                res.at("/query/operands/1/operation").asText());
+        assertEquals("der",
+                res.at("/query/operands/1/operands/0/wrap/key").asText());
+        assertEquals("Mann",
+                res.at("/query/operands/1/operands/1/wrap/key").asText());
 
         query = "contains(<s>,[orth=der][orth=Mann]*)";
         qs.setQuery(query, "poliqarpplus");
@@ -1018,14 +1009,14 @@
         assertEquals("frames:isAround", res.at("/query/frames/0").asText());
         assertEquals("s", res.at("/query/operands/0/wrap/key").asText());
         assertEquals("koral:group", res.at("/query/operands/1/@type").asText());
-        assertEquals("operation:sequence", res
-                .at("/query/operands/1/operation").asText());
-        assertEquals("der", res.at("/query/operands/1/operands/0/wrap/key")
-                .asText());
+        assertEquals("operation:sequence",
+                res.at("/query/operands/1/operation").asText());
+        assertEquals("der",
+                res.at("/query/operands/1/operands/0/wrap/key").asText());
         assertEquals("operation:repetition",
                 res.at("/query/operands/1/operands/1/operation").asText());
-        assertEquals(0, res.at("/query/operands/1/operands/1/boundary/min")
-                .asInt());
+        assertEquals(0,
+                res.at("/query/operands/1/operands/1/boundary/min").asInt());
         assertEquals(true, res.at("/query/operands/1/operands/1/boundary/max")
                 .isMissingNode());
         assertEquals("Mann",
@@ -1037,14 +1028,14 @@
         res = mapper.readTree(qs.toJSON());
         assertEquals("s", res.at("/query/operands/0/wrap/key").asText());
         assertEquals("koral:group", res.at("/query/operands/1/@type").asText());
-        assertEquals("frames:startsWith", res.at("/query/operands/1/frames/0")
-                .asText());
-        assertEquals("operation:position", res
-                .at("/query/operands/1/operation").asText());
-        assertEquals("np", res.at("/query/operands/1/operands/0/wrap/key")
-                .asText());
-        assertEquals("pp", res.at("/query/operands/1/operands/1/wrap/key")
-                .asText());
+        assertEquals("frames:startsWith",
+                res.at("/query/operands/1/frames/0").asText());
+        assertEquals("operation:position",
+                res.at("/query/operands/1/operation").asText());
+        assertEquals("np",
+                res.at("/query/operands/1/operands/0/wrap/key").asText());
+        assertEquals("pp",
+                res.at("/query/operands/1/operands/1/wrap/key").asText());
 
         query = "[base=Auto]overlaps(<s>, der)";
         qs.setQuery(query, "poliqarpplus");
@@ -1052,18 +1043,18 @@
         assertEquals("koral:group", res.at("/query/@type").asText());
         assertEquals("operation:sequence", res.at("/query/operation").asText());
         assertEquals("koral:group", res.at("/query/operands/1/@type").asText());
-        assertEquals("operation:position", res
-                .at("/query/operands/1/operation").asText());
-        assertEquals("frames:overlapsLeft", res
-                .at("/query/operands/1/frames/0").asText());
+        assertEquals("operation:position",
+                res.at("/query/operands/1/operation").asText());
+        assertEquals("frames:overlapsLeft",
+                res.at("/query/operands/1/frames/0").asText());
         assertEquals("frames:overlapsRight",
                 res.at("/query/operands/1/frames/1").asText());
-        assertEquals("koral:span", res.at("/query/operands/1/operands/0/@type")
-                .asText());
-        assertEquals("s", res.at("/query/operands/1/operands/0/wrap/key")
-                .asText());
-        assertEquals("koral:token", res
-                .at("/query/operands/1/operands/1/@type").asText());
+        assertEquals("koral:span",
+                res.at("/query/operands/1/operands/0/@type").asText());
+        assertEquals("s",
+                res.at("/query/operands/1/operands/0/wrap/key").asText());
+        assertEquals("koral:token",
+                res.at("/query/operands/1/operands/1/@type").asText());
 
         query = "[base=Auto]            overlaps(<s>, der)";
         qs.setQuery(query, "poliqarpplus");
@@ -1071,24 +1062,24 @@
         assertEquals("koral:group", res.at("/query/@type").asText());
         assertEquals("operation:sequence", res.at("/query/operation").asText());
         assertEquals("koral:group", res.at("/query/operands/1/@type").asText());
-        assertEquals("operation:position", res
-                .at("/query/operands/1/operation").asText());
-        assertEquals("frames:overlapsLeft", res
-                .at("/query/operands/1/frames/0").asText());
+        assertEquals("operation:position",
+                res.at("/query/operands/1/operation").asText());
+        assertEquals("frames:overlapsLeft",
+                res.at("/query/operands/1/frames/0").asText());
         assertEquals("frames:overlapsRight",
                 res.at("/query/operands/1/frames/1").asText());
-        assertEquals("koral:span", res.at("/query/operands/1/operands/0/@type")
-                .asText());
-        assertEquals("s", res.at("/query/operands/1/operands/0/wrap/key")
-                .asText());
-        assertEquals("koral:token", res
-                .at("/query/operands/1/operands/1/@type").asText());
+        assertEquals("koral:span",
+                res.at("/query/operands/1/operands/0/@type").asText());
+        assertEquals("s",
+                res.at("/query/operands/1/operands/0/wrap/key").asText());
+        assertEquals("koral:token",
+                res.at("/query/operands/1/operands/1/@type").asText());
     };
 
 
     @Test
-    public void testCoordinatedFields () throws JsonProcessingException,
-            IOException {
+    public void testCoordinatedFields ()
+            throws JsonProcessingException, IOException {
         query = "[base=Mann&(cas=N|cas=A)]";
         qs.setQuery(query, "poliqarpplus");
         res = mapper.readTree(qs.toJSON());
@@ -1096,18 +1087,18 @@
         assertEquals("relation:and", res.at("/query/wrap/relation").asText());
         assertEquals("Mann", res.at("/query/wrap/operands/0/key").asText());
         assertEquals("lemma", res.at("/query/wrap/operands/0/layer").asText());
-        assertEquals("koral:termGroup", res.at("/query/wrap/operands/1/@type")
-                .asText());
-        assertEquals("relation:or", res.at("/query/wrap/operands/1/relation")
-                .asText());
-        assertEquals("N", res.at("/query/wrap/operands/1/operands/0/key")
-                .asText());
-        assertEquals("cas", res.at("/query/wrap/operands/1/operands/0/layer")
-                .asText());
-        assertEquals("A", res.at("/query/wrap/operands/1/operands/1/key")
-                .asText());
-        assertEquals("cas", res.at("/query/wrap/operands/1/operands/1/layer")
-                .asText());
+        assertEquals("koral:termGroup",
+                res.at("/query/wrap/operands/1/@type").asText());
+        assertEquals("relation:or",
+                res.at("/query/wrap/operands/1/relation").asText());
+        assertEquals("N",
+                res.at("/query/wrap/operands/1/operands/0/key").asText());
+        assertEquals("cas",
+                res.at("/query/wrap/operands/1/operands/0/layer").asText());
+        assertEquals("A",
+                res.at("/query/wrap/operands/1/operands/1/key").asText());
+        assertEquals("cas",
+                res.at("/query/wrap/operands/1/operands/1/layer").asText());
 
         query = "[base=Mann&cas=N&gen=m]";
         qs.setQuery(query, "poliqarpplus");
@@ -1116,23 +1107,24 @@
         assertEquals("relation:and", res.at("/query/wrap/relation").asText());
         assertEquals("Mann", res.at("/query/wrap/operands/0/key").asText());
         assertEquals("lemma", res.at("/query/wrap/operands/0/layer").asText());
-        assertEquals("koral:termGroup", res.at("/query/wrap/operands/1/@type")
-                .asText());
-        assertEquals("relation:and", res.at("/query/wrap/operands/1/relation")
-                .asText());
-        assertEquals("N", res.at("/query/wrap/operands/1/operands/0/key")
-                .asText());
-        assertEquals("cas", res.at("/query/wrap/operands/1/operands/0/layer")
-                .asText());
-        assertEquals("m", res.at("/query/wrap/operands/1/operands/1/key")
-                .asText());
-        assertEquals("gen", res.at("/query/wrap/operands/1/operands/1/layer")
-                .asText());
+        assertEquals("koral:termGroup",
+                res.at("/query/wrap/operands/1/@type").asText());
+        assertEquals("relation:and",
+                res.at("/query/wrap/operands/1/relation").asText());
+        assertEquals("N",
+                res.at("/query/wrap/operands/1/operands/0/key").asText());
+        assertEquals("cas",
+                res.at("/query/wrap/operands/1/operands/0/layer").asText());
+        assertEquals("m",
+                res.at("/query/wrap/operands/1/operands/1/key").asText());
+        assertEquals("gen",
+                res.at("/query/wrap/operands/1/operands/1/layer").asText());
     }
 
+
     @Test
-    public void testUnnecessaryParentheses () throws JsonProcessingException,
-            IOException {
+    public void testUnnecessaryParentheses ()
+            throws JsonProcessingException, IOException {
         query = "[(base=Mann)]";
         qs.setQuery(query, "poliqarpplus");
         res = mapper.readTree(qs.toJSON());
@@ -1153,60 +1145,43 @@
         qs.setQuery(query, "poliqarpplus");
         res = mapper.readTree(qs.toJSON());
         assertEquals("koral:token", res.at("/query/@type").asText());
-        assertEquals("koral:termGroup", res.at("/query/wrap/@type")
-                .asText());
-        assertEquals("relation:and", res.at("/query/wrap/relation")
-                     .asText());
-        assertEquals("Mann", res.at("/query/wrap/operands/0/key")
-                     .asText());
-        assertEquals("lemma", res.at("/query/wrap/operands/0/layer")
-                     .asText());
-        assertEquals("N", res.at("/query/wrap/operands/1/key")
-                     .asText());
-        assertEquals("cas", res.at("/query/wrap/operands/1/layer")
-                     .asText());
+        assertEquals("koral:termGroup", res.at("/query/wrap/@type").asText());
+        assertEquals("relation:and", res.at("/query/wrap/relation").asText());
+        assertEquals("Mann", res.at("/query/wrap/operands/0/key").asText());
+        assertEquals("lemma", res.at("/query/wrap/operands/0/layer").asText());
+        assertEquals("N", res.at("/query/wrap/operands/1/key").asText());
+        assertEquals("cas", res.at("/query/wrap/operands/1/layer").asText());
 
 
         query = "[(((base=Mann&cas=N)))]";
         qs.setQuery(query, "poliqarpplus");
         res = mapper.readTree(qs.toJSON());
         assertEquals("koral:token", res.at("/query/@type").asText());
-        assertEquals("koral:termGroup", res.at("/query/wrap/@type")
-                .asText());
-        assertEquals("relation:and", res.at("/query/wrap/relation")
-                     .asText());
-        assertEquals("Mann", res.at("/query/wrap/operands/0/key")
-                     .asText());
-        assertEquals("lemma", res.at("/query/wrap/operands/0/layer")
-                     .asText());
-        assertEquals("N", res.at("/query/wrap/operands/1/key")
-                     .asText());
-        assertEquals("cas", res.at("/query/wrap/operands/1/layer")
-                     .asText());
+        assertEquals("koral:termGroup", res.at("/query/wrap/@type").asText());
+        assertEquals("relation:and", res.at("/query/wrap/relation").asText());
+        assertEquals("Mann", res.at("/query/wrap/operands/0/key").asText());
+        assertEquals("lemma", res.at("/query/wrap/operands/0/layer").asText());
+        assertEquals("N", res.at("/query/wrap/operands/1/key").asText());
+        assertEquals("cas", res.at("/query/wrap/operands/1/layer").asText());
 
 
         query = "[(((base=Mann&((cas=N)))))]";
         qs.setQuery(query, "poliqarpplus");
         res = mapper.readTree(qs.toJSON());
         assertEquals("koral:token", res.at("/query/@type").asText());
-        assertEquals("koral:termGroup", res.at("/query/wrap/@type")
-                .asText());
-        assertEquals("relation:and", res.at("/query/wrap/relation")
-                     .asText());
-        assertEquals("Mann", res.at("/query/wrap/operands/0/key")
-                     .asText());
-        assertEquals("lemma", res.at("/query/wrap/operands/0/layer")
-                     .asText());
-        assertEquals("N", res.at("/query/wrap/operands/1/key")
-                     .asText());
-        assertEquals("cas", res.at("/query/wrap/operands/1/layer")
-                     .asText());
+        assertEquals("koral:termGroup", res.at("/query/wrap/@type").asText());
+        assertEquals("relation:and", res.at("/query/wrap/relation").asText());
+        assertEquals("Mann", res.at("/query/wrap/operands/0/key").asText());
+        assertEquals("lemma", res.at("/query/wrap/operands/0/layer").asText());
+        assertEquals("N", res.at("/query/wrap/operands/1/key").asText());
+        assertEquals("cas", res.at("/query/wrap/operands/1/layer").asText());
 
     };
 
+
     @Test
-    public void testTokenSequence () throws JsonProcessingException,
-            IOException {
+    public void testTokenSequence ()
+            throws JsonProcessingException, IOException {
         query = "[base=Mann][orth=Frau]";
         qs.setQuery(query, "poliqarpplus");
         res = mapper.readTree(qs.toJSON());
@@ -1232,13 +1207,14 @@
 
 
     @Test
-    public void testDisjSegments () throws JsonProcessingException, IOException {
+    public void testDisjSegments ()
+            throws JsonProcessingException, IOException {
         query = "[base=der]|[base=das]";
         qs.setQuery(query, "poliqarpplus");
         res = mapper.readTree(qs.toJSON());
         assertEquals("koral:group", res.at("/query/@type").asText());
-        assertEquals("operation:disjunction", res.at("/query/operation")
-                .asText());
+        assertEquals("operation:disjunction",
+                res.at("/query/operation").asText());
         assertEquals("koral:token", res.at("/query/operands/0/@type").asText());
         assertEquals("koral:token", res.at("/query/operands/1/@type").asText());
         assertEquals("der", res.at("/query/operands/0/wrap/key").asText());
@@ -1268,41 +1244,41 @@
         qs.setQuery(query, "poliqarpplus");
         res = mapper.readTree(qs.toJSON());
         assertEquals("koral:group", res.at("/query/@type").asText());
-        assertEquals("operation:disjunction", res.at("/query/operation")
-                .asText());
+        assertEquals("operation:disjunction",
+                res.at("/query/operation").asText());
         assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
-        assertEquals("operation:sequence", res
-                .at("/query/operands/0/operation").asText());
-        assertEquals("koral:token", res
-                .at("/query/operands/0/operands/0/@type").asText());
-        assertEquals("der", res.at("/query/operands/0/operands/0/wrap/key")
-                .asText());
-        assertEquals("katze", res.at("/query/operands/0/operands/1/wrap/key")
-                .asText());
-        assertEquals("eine", res.at("/query/operands/1/operands/0/wrap/key")
-                .asText());
-        assertEquals("baum", res.at("/query/operands/1/operands/1/wrap/key")
-                .asText());
+        assertEquals("operation:sequence",
+                res.at("/query/operands/0/operation").asText());
+        assertEquals("koral:token",
+                res.at("/query/operands/0/operands/0/@type").asText());
+        assertEquals("der",
+                res.at("/query/operands/0/operands/0/wrap/key").asText());
+        assertEquals("katze",
+                res.at("/query/operands/0/operands/1/wrap/key").asText());
+        assertEquals("eine",
+                res.at("/query/operands/1/operands/0/wrap/key").asText());
+        assertEquals("baum",
+                res.at("/query/operands/1/operands/1/wrap/key").asText());
 
         query = "[orth=der][base=katze]|[orth=eine][base=baum]";
         qs.setQuery(query, "poliqarpplus");
         res = mapper.readTree(qs.toJSON());
         assertEquals("koral:group", res.at("/query/@type").asText());
-        assertEquals("operation:disjunction", res.at("/query/operation")
-                .asText());
+        assertEquals("operation:disjunction",
+                res.at("/query/operation").asText());
         assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
-        assertEquals("operation:sequence", res
-                .at("/query/operands/0/operation").asText());
-        assertEquals("koral:token", res
-                .at("/query/operands/0/operands/0/@type").asText());
-        assertEquals("der", res.at("/query/operands/0/operands/0/wrap/key")
-                .asText());
-        assertEquals("katze", res.at("/query/operands/0/operands/1/wrap/key")
-                .asText());
-        assertEquals("eine", res.at("/query/operands/1/operands/0/wrap/key")
-                .asText());
-        assertEquals("baum", res.at("/query/operands/1/operands/1/wrap/key")
-                .asText());
+        assertEquals("operation:sequence",
+                res.at("/query/operands/0/operation").asText());
+        assertEquals("koral:token",
+                res.at("/query/operands/0/operands/0/@type").asText());
+        assertEquals("der",
+                res.at("/query/operands/0/operands/0/wrap/key").asText());
+        assertEquals("katze",
+                res.at("/query/operands/0/operands/1/wrap/key").asText());
+        assertEquals("eine",
+                res.at("/query/operands/1/operands/0/wrap/key").asText());
+        assertEquals("baum",
+                res.at("/query/operands/1/operands/1/wrap/key").asText());
 
         query = "[orth=der]([base=katze]|[orth=eine])[base=baum]";
         qs.setQuery(query, "poliqarpplus");
@@ -1315,19 +1291,19 @@
         assertEquals("koral:token", res.at("/query/operands/0/@type").asText());
         assertEquals("koral:token", res.at("/query/operands/2/@type").asText());
         assertEquals("der", res.at("/query/operands/0/wrap/key").asText());
-        assertEquals("katze", res.at("/query/operands/1/operands/0/wrap/key")
-                .asText());
-        assertEquals("eine", res.at("/query/operands/1/operands/1/wrap/key")
-                .asText());
+        assertEquals("katze",
+                res.at("/query/operands/1/operands/0/wrap/key").asText());
+        assertEquals("eine",
+                res.at("/query/operands/1/operands/1/wrap/key").asText());
         assertEquals("baum", res.at("/query/operands/2/wrap/key").asText());
 
         query = "[orth=der][base=katze]|[orth=der][base=hund]|[orth=der][base=baum]";
         qs.setQuery(query, "poliqarpplus");
         res = mapper.readTree(qs.toJSON());
-        assertEquals("der", res.at("/query/operands/2/operands/0/wrap/key")
-                .asText());
-        assertEquals("baum", res.at("/query/operands/2/operands/1/wrap/key")
-                .asText());
+        assertEquals("der",
+                res.at("/query/operands/2/operands/0/wrap/key").asText());
+        assertEquals("baum",
+                res.at("/query/operands/2/operands/1/wrap/key").asText());
 
         query = "[orth=der]([base=katze]|[base=hund]|[base=baum])";
         qs.setQuery(query, "poliqarpplus");
@@ -1338,24 +1314,24 @@
         assertEquals("operation:disjunction",
                 res.at("/query/operands/1/operation").asText());
         assertEquals("koral:token", res.at("/query/operands/0/@type").asText());
-        assertEquals("koral:token", res
-                .at("/query/operands/1/operands/0/@type").asText());
-        assertEquals("koral:token", res
-                .at("/query/operands/1/operands/1/@type").asText());
-        assertEquals("koral:token", res
-                .at("/query/operands/1/operands/2/@type").asText());
-        assertEquals("katze", res.at("/query/operands/1/operands/0/wrap/key")
-                .asText());
-        assertEquals("hund", res.at("/query/operands/1/operands/1/wrap/key")
-                .asText());
-        assertEquals("baum", res.at("/query/operands/1/operands/2/wrap/key")
-                .asText());
+        assertEquals("koral:token",
+                res.at("/query/operands/1/operands/0/@type").asText());
+        assertEquals("koral:token",
+                res.at("/query/operands/1/operands/1/@type").asText());
+        assertEquals("koral:token",
+                res.at("/query/operands/1/operands/2/@type").asText());
+        assertEquals("katze",
+                res.at("/query/operands/1/operands/0/wrap/key").asText());
+        assertEquals("hund",
+                res.at("/query/operands/1/operands/1/wrap/key").asText());
+        assertEquals("baum",
+                res.at("/query/operands/1/operands/2/wrap/key").asText());
     }
 
 
     @Test
-    public void testTokenSpanSequence () throws JsonProcessingException,
-            IOException {
+    public void testTokenSpanSequence ()
+            throws JsonProcessingException, IOException {
         query = "[base=Mann]<vp>";
         qs.setQuery(query, "poliqarpplus");
         res = mapper.readTree(qs.toJSON());
@@ -1408,27 +1384,27 @@
         assertEquals("operation:class", res.at("/query/operation").asText());
         assertEquals(1, res.at("/query/classOut").asInt());
         assertEquals(true, res.at("/query/classIn").isMissingNode());
-        assertEquals("Mann", res.at("/query/operands/0/operands/0/wrap/key")
-                .asText());
-        assertEquals("Frau", res.at("/query/operands/0/operands/1/wrap/key")
-                .asText());
+        assertEquals("Mann",
+                res.at("/query/operands/0/operands/0/wrap/key").asText());
+        assertEquals("Frau",
+                res.at("/query/operands/0/operands/1/wrap/key").asText());
 
         query = "{[base=Mann]}{[orth=Frau]}";
         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());
-        assertEquals("operation:class", res.at("/query/operands/0/operation")
-                .asText());
+        assertEquals("operation:class",
+                res.at("/query/operands/0/operation").asText());
         assertEquals(1, res.at("/query/operands/0/classOut").asInt());
-        assertEquals("operation:class", res.at("/query/operands/1/operation")
-                .asText());
+        assertEquals("operation:class",
+                res.at("/query/operands/1/operation").asText());
         assertEquals(1, res.at("/query/operands/1/classOut").asInt());
         assertEquals(true, res.at("/query/classIn").isMissingNode());
-        assertEquals("Mann", res.at("/query/operands/0/operands/0/wrap/key")
-                .asText());
-        assertEquals("Frau", res.at("/query/operands/1/operands/0/wrap/key")
-                .asText());
+        assertEquals("Mann",
+                res.at("/query/operands/0/operands/0/wrap/key").asText());
+        assertEquals("Frau",
+                res.at("/query/operands/1/operands/0/wrap/key").asText());
 
         query = "[p=NN]{[base=Mann][orth=Frau]}";
         qs.setQuery(query, "poliqarpplus");
@@ -1436,8 +1412,8 @@
         assertEquals("koral:group", res.at("/query/@type").asText());
         assertEquals("operation:sequence", res.at("/query/operation").asText());
         assertEquals("koral:group", res.at("/query/operands/1/@type").asText());
-        assertEquals("operation:class", res.at("/query/operands/1/operation")
-                .asText());
+        assertEquals("operation:class",
+                res.at("/query/operands/1/operation").asText());
         assertEquals(1, res.at("/query/operands/1/classOut").asInt());
         assertEquals(true, res.at("/query/operands/1/classIn").isMissingNode());
         assertEquals("Mann",
@@ -1453,8 +1429,8 @@
         assertEquals("koral:group", res.at("/query/@type").asText());
         assertEquals("operation:sequence", res.at("/query/operation").asText());
         assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
-        assertEquals("operation:class", res.at("/query/operands/0/operation")
-                .asText());
+        assertEquals("operation:class",
+                res.at("/query/operands/0/operation").asText());
         assertEquals(1, res.at("/query/operands/0/classOut").asInt());
         assertEquals(true, res.at("/query/operands/0/classIn").isMissingNode());
         assertEquals("Mann",
@@ -1470,10 +1446,11 @@
         res = mapper.readTree(qs.toJSON());
         assertEquals("koral:group", res.at("/query/@type").asText());
         assertEquals("operation:class", res.at("/query/operation").asText());
-        assertEquals("operation:sequence", res
-                .at("/query/operands/0/operation").asText());
+        assertEquals("operation:sequence",
+                res.at("/query/operands/0/operation").asText());
         assertEquals(2, res.at("/query/classOut").asInt());
-        assertEquals(1, res.at("/query/operands/0/operands/0/classOut").asInt());
+        assertEquals(1,
+                res.at("/query/operands/0/operands/0/classOut").asInt());
         assertEquals(2, res.at("/meta/highlight/0").asInt());
         assertEquals(1, res.at("/meta/highlight/1").asInt());
     }
@@ -1487,11 +1464,12 @@
         assertEquals("koral:reference", res.at("/query/@type").asText());
         assertEquals("operation:focus", res.at("/query/operation").asText());
         assertEquals(1, res.at("/query/classRef/0").asInt());
-        assertEquals("operation:sequence", res
-                .at("/query/operands/0/operation").asText());
+        assertEquals("operation:sequence",
+                res.at("/query/operands/0/operation").asText());
         assertEquals("operation:class",
                 res.at("/query/operands/0/operands/1/operation").asText());
-        assertEquals(1, res.at("/query/operands/0/operands/1/classOut").asInt());
+        assertEquals(1,
+                res.at("/query/operands/0/operands/1/classOut").asInt());
         assertEquals("Mann",
                 res.at("/query/operands/0/operands/1/operands/0/wrap/key")
                         .asText());
@@ -1503,12 +1481,10 @@
         assertEquals("operation:sequence",
                 res.at("/query/operands/0/operands/1/operands/0/operation")
                         .asText());
-        assertEquals(
-                "Mann",
+        assertEquals("Mann",
                 res.at("/query/operands/0/operands/1/operands/0/operands/0/wrap/key")
                         .asText());
-        assertEquals(
-                "geht",
+        assertEquals("geht",
                 res.at("/query/operands/0/operands/1/operands/0/operands/1/wrap/key")
                         .asText());
 
@@ -1516,7 +1492,8 @@
         qs.setQuery(query, "poliqarpplus");
         res = mapper.readTree(qs.toJSON());
         assertEquals(2, res.at("/query/classRef/0").asInt());
-        assertEquals(2, res.at("/query/operands/0/operands/1/classOut").asInt());
+        assertEquals(2,
+                res.at("/query/operands/0/operands/1/classOut").asInt());
         assertEquals(2, res.at("/meta/highlight/0").asInt());
 
         query = "focus(3:startswith(<s>,{3:<np>}))";
@@ -1525,21 +1502,22 @@
         assertEquals(3, res.at("/query/classRef/0").asInt());
         assertEquals("koral:reference", res.at("/query/@type").asText());
         assertEquals("operation:focus", res.at("/query/operation").asText());
-        assertEquals("operation:position", res
-                .at("/query/operands/0/operation").asText());
+        assertEquals("operation:position",
+                res.at("/query/operands/0/operation").asText());
         assertEquals("operation:class",
                 res.at("/query/operands/0/operands/1/operation").asText());
-        assertEquals(3, res.at("/query/operands/0/operands/1/classOut").asInt());
-        assertEquals("frames:startsWith", res.at("/query/operands/0/frames/0")
-                .asText());
+        assertEquals(3,
+                res.at("/query/operands/0/operands/1/classOut").asInt());
+        assertEquals("frames:startsWith",
+                res.at("/query/operands/0/frames/0").asText());
         assertEquals(3, res.at("/meta/highlight/0").asInt());
 
         query = "focus(1000:startswith(<s>,{1000:<np>}))";
         qs.setQuery(query, "poliqarpplus");
         res = mapper.readTree(qs.toJSON());
         assertEquals(1000, res.at("/query/classRef/0").asInt());
-        assertEquals(1000, res.at("/query/operands/0/operands/1/classOut")
-                .asInt());
+        assertEquals(1000,
+                res.at("/query/operands/0/operands/1/classOut").asInt());
         assertEquals(1000, res.at("/meta/highlight/0").asInt());
 
         query = "focus(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))";
@@ -1548,34 +1526,30 @@
         assertEquals(3, res.at("/query/classRef/0").asInt());
         assertEquals("koral:reference", res.at("/query/@type").asText());
         assertEquals("operation:focus", res.at("/query/operation").asText());
-        assertEquals("operation:position", res
-                .at("/query/operands/0/operation").asText());
-        assertEquals("frames:startsWith", res.at("/query/operands/0/frames/0")
-                .asText());
+        assertEquals("operation:position",
+                res.at("/query/operands/0/operation").asText());
+        assertEquals("frames:startsWith",
+                res.at("/query/operands/0/frames/0").asText());
         assertEquals("operation:class",
                 res.at("/query/operands/0/operands/1/operation").asText());
-        assertEquals(3, res.at("/query/operands/0/operands/1/classOut").asInt());
+        assertEquals(3,
+                res.at("/query/operands/0/operands/1/classOut").asInt());
         assertEquals("operation:sequence",
                 res.at("/query/operands/0/operands/1/operands/0/operation")
                         .asText());
-        assertEquals(
-                "operation:class",
+        assertEquals("operation:class",
                 res.at("/query/operands/0/operands/1/operands/0/operands/1/operation")
                         .asText());
-        assertEquals(
-                1,
+        assertEquals(1,
                 res.at("/query/operands/0/operands/1/operands/0/operands/1/classOut")
                         .asInt());
-        assertEquals(
-                "operation:sequence",
+        assertEquals("operation:sequence",
                 res.at("/query/operands/0/operands/1/operands/0/operands/1/operands/0/operation")
                         .asText());
-        assertEquals(
-                "operation:class",
+        assertEquals("operation:class",
                 res.at("/query/operands/0/operands/1/operands/0/operands/1/operands/0/operands/1/operation")
                         .asText());
-        assertEquals(
-                2,
+        assertEquals(2,
                 res.at("/query/operands/0/operands/1/operands/0/operands/1/operands/0/operands/1/classOut")
                         .asInt());
 
@@ -1592,8 +1566,8 @@
         res = mapper.readTree(qs.toJSON());
         assertEquals(2, res.at("/query/classRef/0").asInt());
         assertEquals(3, res.at("/query/classRef/1").asInt());
-        assertEquals("classRefOp:intersection", res.at("/query/classRefOp")
-                .asText());
+        assertEquals("classRefOp:intersection",
+                res.at("/query/classRefOp").asText());
         assertEquals("koral:reference", res.at("/query/@type").asText());
         assertEquals("operation:split", res.at("/query/operation").asText());
         assertEquals(3, res.at("/meta/highlight/0").asInt());
@@ -1604,8 +1578,10 @@
         qs.setQuery(query, "poliqarpplus");
         res = mapper.readTree(qs.toJSON());
         assertEquals(1, res.at("/query/classRef/0").asInt());
-        assertEquals(1, res.at("/query/operands/0/operands/0/classOut").asInt());
-        assertEquals(1, res.at("/query/operands/0/operands/1/classOut").asInt());
+        assertEquals(1,
+                res.at("/query/operands/0/operands/0/classOut").asInt());
+        assertEquals(1,
+                res.at("/query/operands/0/operands/1/classOut").asInt());
     }
 
 
@@ -1635,12 +1611,12 @@
         assertEquals("operation:focus", res.at("/query/operation").asText());
         assertEquals(1, res.at("/query/spanRef/0").asInt());
         assertEquals(4, res.at("/query/spanRef/1").asInt());
-        assertEquals("frames:isAround", res.at("/query/operands/0/frames/0")
-                .asText());
-        assertEquals("s", res.at("/query/operands/0/operands/0/wrap/key")
-                .asText());
-        assertEquals("Haus", res.at("/query/operands/0/operands/1/wrap/key")
-                .asText());
+        assertEquals("frames:isAround",
+                res.at("/query/operands/0/frames/0").asText());
+        assertEquals("s",
+                res.at("/query/operands/0/operands/0/wrap/key").asText());
+        assertEquals("Haus",
+                res.at("/query/operands/0/operands/1/wrap/key").asText());
     }
 
 
@@ -1651,7 +1627,8 @@
         res = mapper.readTree(qs.toJSON());
         assertEquals("koral:group", res.at("/query/@type").asText());
         assertEquals("operation:relation", res.at("/query/operation").asText());
-        assertEquals("koral:relation", res.at("/query/relation/@type").asText());
+        assertEquals("koral:relation",
+                res.at("/query/relation/@type").asText());
         assertEquals("c", res.at("/query/relation/wrap/layer").asText());
         assertEquals("s", res.at("/query/operands/0/wrap/key").asText());
         assertEquals("np", res.at("/query/operands/1/wrap/key").asText());
@@ -1661,7 +1638,8 @@
         res = mapper.readTree(qs.toJSON());
         assertEquals("koral:group", res.at("/query/@type").asText());
         assertEquals("operation:relation", res.at("/query/operation").asText());
-        assertEquals("koral:relation", res.at("/query/relation/@type").asText());
+        assertEquals("koral:relation",
+                res.at("/query/relation/@type").asText());
         assertEquals("Baum", res.at("/query/operands/0/wrap/key").asText());
         assertEquals("np", res.at("/query/operands/1/wrap/key").asText());
 
@@ -1676,7 +1654,8 @@
         res = mapper.readTree(qs.toJSON());
         assertEquals("lemma", res.at("/query/operands/1/wrap/layer").asText());
         assertEquals("Baum", res.at("/query/operands/1/wrap/key").asText());
-        assertEquals("koral:relation", res.at("/query/relation/@type").asText());
+        assertEquals("koral:relation",
+                res.at("/query/relation/@type").asText());
         assertEquals("mate", res.at("/query/relation/wrap/foundry").asText());
         assertEquals("d", res.at("/query/relation/wrap/layer").asText());
         assertEquals("HEAD", res.at("/query/relation/wrap/key").asText());
@@ -1688,7 +1667,8 @@
         assertEquals("fällen", res.at("/query/operands/0/wrap/key").asText());
         assertEquals("lemma", res.at("/query/operands/1/wrap/layer").asText());
         assertEquals("Baum", res.at("/query/operands/1/wrap/key").asText());
-        assertEquals("koral:relation", res.at("/query/relation/@type").asText());
+        assertEquals("koral:relation",
+                res.at("/query/relation/@type").asText());
         assertEquals("d", res.at("/query/relation/wrap/layer").asText());
 
         query = "dominates(Baum,<np>)";
@@ -1696,7 +1676,8 @@
         res = mapper.readTree(qs.toJSON());
         assertEquals("orth", res.at("/query/operands/0/wrap/layer").asText());
         assertEquals("Baum", res.at("/query/operands/0/wrap/key").asText());
-        assertEquals("koral:relation", res.at("/query/relation/@type").asText());
+        assertEquals("koral:relation",
+                res.at("/query/relation/@type").asText());
         assertEquals("c", res.at("/query/relation/wrap/layer").asText());
 
         query = "dominates(cnx/c:<vp>,<np>)";
@@ -1711,8 +1692,8 @@
         assertEquals("cnx", res.at("/query/relation/wrap/foundry").asText());
         assertEquals("c", res.at("/query/relation/wrap/layer").asText());
         assertEquals(0, res.at("/query/relation/boundary/min").asInt());
-        assertEquals(true, res.at("/query/relation/boundary/max")
-                .isMissingNode());
+        assertEquals(true,
+                res.at("/query/relation/boundary/max").isMissingNode());
 
         query = "dominates(cnx/c{1,5}:<vp>,<np>)";
         qs.setQuery(query, "poliqarpplus");
@@ -1740,13 +1721,13 @@
         qs.setQuery(query, "poliqarpplus");
         res = mapper.readTree(qs.toJSON());
         assertEquals("operation:sequence", res.at("/query/operation").asText());
-        assertEquals("der", res.at("/query/operands/0/operands/0/wrap/key")
-                .asText());
+        assertEquals("der",
+                res.at("/query/operands/0/operands/0/wrap/key").asText());
         assertEquals(1, res.at("/query/operands/0/classOut").asInt());
-        assertEquals("Mann", res.at("/query/operands/1/operands/0/wrap/key")
-                .asText());
-        assertEquals("operation:class", res.at("/query/operands/1/operation")
-                .asText());
+        assertEquals("Mann",
+                res.at("/query/operands/1/operands/0/wrap/key").asText());
+        assertEquals("operation:class",
+                res.at("/query/operands/1/operation").asText());
         assertEquals(2, res.at("/query/operands/1/classOut").asInt());
         assertEquals(1, res.at("/meta/alignment/0/0").asInt());
         assertEquals(2, res.at("/meta/alignment/0/1").asInt());
@@ -1755,13 +1736,13 @@
         qs.setQuery(query, "poliqarpplus");
         res = mapper.readTree(qs.toJSON());
         assertEquals("operation:sequence", res.at("/query/operation").asText());
-        assertEquals("der", res.at("/query/operands/0/operands/0/wrap/key")
-                .asText());
+        assertEquals("der",
+                res.at("/query/operands/0/operands/0/wrap/key").asText());
         assertEquals(1, res.at("/query/operands/0/classOut").asInt());
-        assertEquals("große", res.at("/query/operands/1/operands/0/wrap/key")
-                .asText());
-        assertEquals("operation:class", res.at("/query/operands/1/operation")
-                .asText());
+        assertEquals("große",
+                res.at("/query/operands/1/operands/0/wrap/key").asText());
+        assertEquals("operation:class",
+                res.at("/query/operands/1/operation").asText());
         assertEquals(2, res.at("/query/operands/1/classOut").asInt());
         assertEquals("Mann", res.at("/query/operands/2/wrap/key").asText());
         assertEquals(1, res.at("/meta/alignment/0/0").asInt());
@@ -1771,10 +1752,10 @@
         query = "([base=a]^[base=b])|[base=c]";
         qs.setQuery(query, "poliqarpplus");
         res = mapper.readTree(qs.toJSON());
-        assertEquals("operation:disjunction", res.at("/query/operation")
-                .asText());
-        assertEquals("operation:sequence", res
-                .at("/query/operands/0/operation").asText());
+        assertEquals("operation:disjunction",
+                res.at("/query/operation").asText());
+        assertEquals("operation:sequence",
+                res.at("/query/operands/0/operation").asText());
         assertEquals("operation:class",
                 res.at("/query/operands/0/operands/1/operation").asText());
         assertEquals("a",
@@ -1784,8 +1765,10 @@
                 res.at("/query/operands/0/operands/1/operands/0/wrap/key")
                         .asText());
         assertEquals("c", res.at("/query/operands/1/wrap/key").asText());
-        assertEquals(1, res.at("/query/operands/0/operands/0/classOut").asInt());
-        assertEquals(2, res.at("/query/operands/0/operands/1/classOut").asInt());
+        assertEquals(1,
+                res.at("/query/operands/0/operands/0/classOut").asInt());
+        assertEquals(2,
+                res.at("/query/operands/0/operands/1/classOut").asInt());
         assertEquals(1, res.at("/meta/alignment/0/0").asInt());
         assertEquals(2, res.at("/meta/alignment/0/1").asInt());
 
@@ -1798,8 +1781,8 @@
         assertEquals("b",
                 res.at("/query/operands/0/operands/1/operands/0/wrap/key")
                         .asText());
-        assertEquals("c", res.at("/query/operands/0/operands/2/wrap/key")
-                .asText());
+        assertEquals("c",
+                res.at("/query/operands/0/operands/2/wrap/key").asText());
         assertEquals("d", res.at("/query/operands/1/wrap/key").asText());
 
         query = "([base=a]^[base=b]^[base=c])|[base=d]";
@@ -1808,15 +1791,18 @@
         assertEquals("a",
                 res.at("/query/operands/0/operands/0/operands/0/wrap/key")
                         .asText());
-        assertEquals(1, res.at("/query/operands/0/operands/0/classOut").asInt());
+        assertEquals(1,
+                res.at("/query/operands/0/operands/0/classOut").asInt());
         assertEquals("b",
                 res.at("/query/operands/0/operands/1/operands/0/wrap/key")
                         .asText());
-        assertEquals(2, res.at("/query/operands/0/operands/1/classOut").asInt());
+        assertEquals(2,
+                res.at("/query/operands/0/operands/1/classOut").asInt());
         assertEquals("c",
                 res.at("/query/operands/0/operands/2/operands/0/wrap/key")
                         .asText());
-        assertEquals(3, res.at("/query/operands/0/operands/2/classOut").asInt());
+        assertEquals(3,
+                res.at("/query/operands/0/operands/2/classOut").asInt());
         assertEquals("d", res.at("/query/operands/1/wrap/key").asText());
         assertEquals(1, res.at("/meta/alignment/0/0").asInt());
         assertEquals(2, res.at("/meta/alignment/0/1").asInt());
@@ -1844,8 +1830,8 @@
 
 
     @Test
-    public void testSimpleQueries () throws JsonProcessingException,
-            IOException {
+    public void testSimpleQueries ()
+            throws JsonProcessingException, IOException {
         query = "Baum";
         qs.setQuery(query, "poliqarpplus");
         res = mapper.readTree(qs.toJSON());
@@ -1861,16 +1847,16 @@
         assertEquals("koral:group", res.at("/query/@type").asText());
         assertEquals("operation:sequence", res.at("/query/operation").asText());
         assertEquals("koral:token", res.at("/query/operands/0/@type").asText());
-        assertEquals("koral:term", res.at("/query/operands/0/wrap/@type")
-                .asText());
+        assertEquals("koral:term",
+                res.at("/query/operands/0/wrap/@type").asText());
         assertEquals("Der", res.at("/query/operands/0/wrap/key").asText());
         assertEquals("Baum", res.at("/query/operands/1/wrap/key").asText());
         assertEquals("orth", res.at("/query/operands/0/wrap/layer").asText());
-        assertEquals("match:eq", res.at("/query/operands/0/wrap/match")
-                .asText());
+        assertEquals("match:eq",
+                res.at("/query/operands/0/wrap/match").asText());
         assertEquals("orth", res.at("/query/operands/1/wrap/layer").asText());
-        assertEquals("match:eq", res.at("/query/operands/1/wrap/match")
-                .asText());
+        assertEquals("match:eq",
+                res.at("/query/operands/1/wrap/match").asText());
 
         query = "Der große Baum";
         qs.setQuery(query, "poliqarpplus");
@@ -1885,29 +1871,29 @@
         assertEquals("Der", res.at("/query/operands/0/wrap/key").asText());
         assertEquals("operation:disjunction",
                 res.at("/query/operands/1/operation").asText());
-        assertEquals("große", res.at("/query/operands/1/operands/0/wrap/key")
-                .asText());
-        assertEquals("kleine", res.at("/query/operands/1/operands/1/wrap/key")
-                .asText());
+        assertEquals("große",
+                res.at("/query/operands/1/operands/0/wrap/key").asText());
+        assertEquals("kleine",
+                res.at("/query/operands/1/operands/1/wrap/key").asText());
         assertEquals("Baum", res.at("/query/operands/2/wrap/key").asText());
 
         query = "der große Baum | der kleine Baum";
         qs.setQuery(query, "poliqarpplus");
         res = mapper.readTree(qs.toJSON());
-        assertEquals("operation:disjunction", res.at("/query/operation")
-                .asText());
-        assertEquals("der", res.at("/query/operands/0/operands/0/wrap/key")
-                .asText());
-        assertEquals("große", res.at("/query/operands/0/operands/1/wrap/key")
-                .asText());
-        assertEquals("Baum", res.at("/query/operands/0/operands/2/wrap/key")
-                .asText());
-        assertEquals("der", res.at("/query/operands/1/operands/0/wrap/key")
-                .asText());
-        assertEquals("kleine", res.at("/query/operands/1/operands/1/wrap/key")
-                .asText());
-        assertEquals("Baum", res.at("/query/operands/1/operands/2/wrap/key")
-                .asText());
+        assertEquals("operation:disjunction",
+                res.at("/query/operation").asText());
+        assertEquals("der",
+                res.at("/query/operands/0/operands/0/wrap/key").asText());
+        assertEquals("große",
+                res.at("/query/operands/0/operands/1/wrap/key").asText());
+        assertEquals("Baum",
+                res.at("/query/operands/0/operands/2/wrap/key").asText());
+        assertEquals("der",
+                res.at("/query/operands/1/operands/0/wrap/key").asText());
+        assertEquals("kleine",
+                res.at("/query/operands/1/operands/1/wrap/key").asText());
+        assertEquals("Baum",
+                res.at("/query/operands/1/operands/2/wrap/key").asText());
 
         query = "Der [p=ADJA] Baum";
         qs.setQuery(query, "poliqarpplus");
@@ -1932,8 +1918,8 @@
 
 
     @Test
-    public void testSpanSerialization () throws JsonProcessingException,
-            IOException {
+    public void testSpanSerialization ()
+            throws JsonProcessingException, IOException {
 
         // Both constructs should be serialized identically
         query = "contains(<s>, der)";
@@ -1977,7 +1963,8 @@
         assertEquals("x", res.at("/query/wrap/key").asText());
         assertEquals("koral:docGroup", res.at("/collection/@type").asText());
         assertEquals("operation:and", res.at("/collection/operation").asText());
-        assertEquals("textClass", res.at("/collection/operands/0/key").asText());
+        assertEquals("textClass",
+                res.at("/collection/operands/0/key").asText());
         assertEquals("Sport", res.at("/collection/operands/0/value").asText());
         assertEquals("author", res.at("/collection/operands/1/key").asText());
         assertEquals("Smith", res.at("/collection/operands/1/value").asText());