Merge branch 'anltr-grammars'
diff --git a/Changes b/Changes
index 3a859d4..006c566 100644
--- a/Changes
+++ b/Changes
@@ -1,8 +1,13 @@
+0.27 2017-09-12
+	- Changed Cosmas2 wildcards serialization as regex (margaretha).  
+	- Updated C2 OP OV frames (margaretha).
+	
 0.26 2017-06-29
 	- Updated collection query grammar (margaretha)
 	- Updated maven dependency phase (margaretha)
     - Fixed handling of non-necessary brackets in tokens (diewald)
     - Improved error handling (margaretha)
+    - Added wrap to koral:span serialization (margaretha)
 
 0.25 2017-05-10
 	- Altered dominance and relation serialization (margaretha)
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/Cosmas2QueryProcessor.java b/src/main/java/de/ids_mannheim/korap/query/serialize/Cosmas2QueryProcessor.java
index ca88711..fd6c3c4 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/Cosmas2QueryProcessor.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/Cosmas2QueryProcessor.java
@@ -118,7 +118,11 @@
      */
     private LinkedList<ArrayList<Object>> invertedOperandsLists = new LinkedList<ArrayList<Object>>();
 
-
+    public static Pattern wildcardStarPattern = Pattern.compile("([*])");
+    public static Pattern wildcardPlusPattern = Pattern.compile("([+])");
+    public static Pattern wildcardQuestionPattern = Pattern.compile("([?])");
+    
+    
     /**
      * @param tree
      *            The syntax tree as returned by ANTLR
@@ -470,21 +474,33 @@
 
     private boolean isExclusion (Tree node) {
         Tree exclnode = getFirstChildWithCat(node, "EXCL");
-        if (exclnode != null
-                && exclnode.getChild(0).toStringTree().equals("YES")) {
-            return true;
-        }
+        if (exclnode != null && exclnode.getChild(0).toStringTree()
+                .equals("YES")) { return true; }
         return false;
     }
 
 
     private Map<String, Object> addClassRefCheck (
             ArrayList<ClassRefCheck> check, Map<String, Object> group) {
-        Integer[] classIn = new Integer[] { classCounter + 128 - 2,
-                classCounter + 128 - 1 };
+
+        int classOut = classCounter + 128;
+        ArrayList<Integer> classIn = new ArrayList<Integer>();
+        if (check.contains(ClassRefCheck.INCLUDES)) {
+            classIn.add(classCounter + 128);
+            classOut = classCounter + 128 + 1;
+        }
+        if (check.contains(ClassRefCheck.EQUALS)
+                || check.contains(ClassRefCheck.UNEQUALS)) {
+            classIn.add(classCounter + 128 - 2);
+            classIn.add(classCounter + 128 - 1);
+        }
+        else if (check.contains(ClassRefCheck.INTERSECTS)) {
+            classIn.add(classCounter + 128 - 2);
+            classIn.add(classCounter + 128 - 1);
+        }
         // wrap position in a classRefCheck
         Map<String, Object> topGroup = KoralObjectGenerator
-                .makeClassRefCheck(check, classIn, classCounter + 128);
+                .makeClassRefCheck(check, classIn, classOut);
         ((ArrayList<Object>) topGroup.get("operands")).add(group);
         return topGroup;
     }
@@ -521,15 +537,6 @@
         }
         else {
             posGroup = KoralObjectGenerator.makeGroup(KoralOperation.POSITION);
-            // mark this an inverted operands object
-            invertedOperandsLists
-                    .push((ArrayList<Object>) posGroup.get("operands"));
-            wrapOperandInClass(node, 2, 128 + classCounter++);
-            wrapOperandInClass(node, 1, 128 + classCounter++);
-            // EM: why bother inverting the operands and creating classes and focus? 
-            // can't we agree on the first operand to be the results, like in 
-            // operation:exclusion?
-
         }
 
         Map<String, Object> positionOptions;
@@ -550,30 +557,17 @@
                 .get("classRefCheck");
 
         // Step II: wrap in classRefCheck and/or focus and decide where to put
-        if (isExclusion) {
-            if (!checkList.isEmpty()) {
-                wrapOperandInClass(node, 1, 128 + classCounter++);
-                wrapOperandInClass(node, 2, 128 + classCounter++);
-
-                posGroup = addClassRefCheck(
-                        (ArrayList<ClassRefCheck>) positionOptions
-                                .get("classRefCheck"),
-                        posGroup);
-            }
-        }
-        else {
-            if (!checkList.isEmpty()) {
-                posGroup = addClassRefCheck(
-                        (ArrayList<ClassRefCheck>) positionOptions
-                                .get("classRefCheck"),
-                        posGroup);
-            }
-            posGroup = addClassFocus((boolean) positionOptions.get("matchall"),
+        if (!checkList.isEmpty()) {
+            posGroup = addClassRefCheck(
+                    (ArrayList<ClassRefCheck>) positionOptions
+                            .get("classRefCheck"),
                     posGroup);
         }
+        //            posGroup = addClassFocus((boolean) positionOptions.get("matchall"),
+        //                    posGroup);
 
         // wrap in 'merge' operation if grouping option is set
-        if (positionOptions.containsKey("grouping")
+        if (!isExclusion && positionOptions.containsKey("grouping")
                 && (boolean) positionOptions.get("grouping")) {
             Map<String, Object> mergeOperation = KoralObjectGenerator
                     .makeGroup(KoralOperation.MERGE);
@@ -746,8 +740,7 @@
         Map<String, Object> zerodistance = KoralObjectGenerator
                 .makeDistance("t", 0, 0);
         zerodistance.put("@type", "cosmas:distance"); // overwrite @type: cosmas:distance! 
-        if (nodeCat.equals("OPNOT"))
-            zerodistance.put("exclude", true);
+        if (nodeCat.equals("OPNOT")) zerodistance.put("exclude", true);
         distances.add(zerodistance);
         distgroup.put("distances", distances);
         distgroup.put("operands", new ArrayList<Object>());
@@ -795,8 +788,7 @@
                 Map<String, Object> fm = termToFieldMap(
                         elnameNode.getChild(0).toStringTree());
 
-                if (fm == null)
-                    return;
+                if (fm == null) return;
 
                 // Workaround for things like #ELEM(S) to become #ELEM(s)
                 if (fm.get("foundry") == null && fm.get("layer") == null
@@ -876,8 +868,7 @@
                             termGroupOperands.add(subTermGroup);
                         }
                     }
-                    if (getNodeCat(attrNode).equals("NOTEQ"))
-                        negate = true;
+                    if (getNodeCat(attrNode).equals("NOTEQ")) negate = true;
                 }
                 // possibly only one term was present throughout all
                 // nodes: extract it from the group
@@ -910,9 +901,7 @@
         for (String morphterm : morphterms) {
 
             fieldMap = termToFieldMap(morphterm);
-            if (fieldMap == null) {
-                return;
-            };
+            if (fieldMap == null) { return; };
 
             terms.add(fieldMap);
         }
@@ -951,11 +940,31 @@
         String attr = nodeCat.equals("OPWF") ? "orth" : "lemma";
         String value = node.getChild(0).toStringTree().replaceAll("\"", "");
         // check for wildcard string
-        Pattern p = Pattern.compile("[+*?]");
-        Matcher m = p.matcher(value);
-        if (m.find())
-            fieldMap.put("type", "type:wildcard");
 
+        // http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/syntax/platzhalter.html
+        boolean isFound = false;
+        Matcher m = wildcardStarPattern.matcher(value);
+        if (m.find()){
+            isFound = true;
+            value = m.replaceAll(".$1");
+        }
+        m.reset();
+        m = wildcardQuestionPattern.matcher(value);
+        if (m.find()){
+            isFound = true;
+            value = m.replaceAll(".");
+        }
+        m.reset();
+        m = wildcardPlusPattern.matcher(value);
+        if (m.find()){
+            isFound = true;
+            value = m.replaceAll(".?");
+        }
+        
+        if (isFound){
+            fieldMap.put("type", "type:regex");
+        }
+        
         if (value.startsWith("$")) {
             value = value.substring(1);
             ArrayList<String> flags = new ArrayList<String>();
@@ -1113,8 +1122,7 @@
         frames.add(position);
         Map<String, Object> positionGroup = KoralObjectGenerator
                 .makePosition(frames);
-        if (negated)
-            positionGroup.put("exclude", true);
+        if (negated) positionGroup.put("exclude", true);
         ArrayList<Object> posOperands = new ArrayList<Object>();
         Map<String, Object> classGroup = KoralObjectGenerator
                 .makeSpanClass(128 + classCounter++);
@@ -1154,32 +1162,45 @@
         ArrayList<ClassRefCheck> classRefCheck = new ArrayList<ClassRefCheck>();
         posOptions.put("matchall", false);
 
-        String posOption = null;
+        String posOption = "";
         if (posnode != null) {
             posOption = posnode.getChild(0).toStringTree().toUpperCase();
-            if (isExclusion) {
-                checkINWithExclusionOptions(posOption, positions,
-                        classRefCheck);
-            }
-            else {
-                checkINOptions(posOption, positions, classRefCheck);
-            }
+        }
+
+        if (isExclusion) {
+            checkINWithExclusionOptions(posOption, positions, classRefCheck);
         }
         else {
-            classRefCheck.add(ClassRefCheck.INCLUDES);
+            checkINOptions(posOption, positions, classRefCheck);
         }
 
         posOptions.put("frames", Converter.enumListToStringList(positions));
-        posOptions.put("classRefCheck", classRefCheck);
-        if (rangenode != null) {
+
+        if (!isExclusion && rangenode != null) {
             String range = rangenode.getChild(0).toStringTree().toLowerCase();
-            if (range.equals("all")) {
-                posOptions.put("matchall", true);
-                // Map<String,Object> ref =
-                // makeResetReference(); // reset all defined classes
-                // wrapOperand(node,2,ref);
+            // if (range.equals("all")) {
+
+            // posOptions.put("matchall", true);
+            // Map<String,Object> ref =
+            // makeResetReference(); // reset all defined classes
+            // wrapOperand(node,2,ref);
+            //}
+            // HIT is default in C2
+            if (!range.equals("all")) {
+                // EM: check in the arg2 is a complex query
+                Tree arg2Operator = getFirstChildWithCat(node, "ARG2")
+                        .getChild(0);
+                if (getFirstChildWithCat(arg2Operator, "ARG2") != null) {
+                    classRefCheck.add(ClassRefCheck.INCLUDES);
+                }
             }
         }
+        posOptions.put("classRefCheck", classRefCheck);
+        if (classRefCheck.contains(ClassRefCheck.EQUALS)
+                || classRefCheck.contains(ClassRefCheck.UNEQUALS)) {
+            wrapOperandInClass(node, 1, 128 + classCounter++);
+            wrapOperandInClass(node, 2, 128 + classCounter++);
+        }
 
         Boolean grouping = false;
         if (groupnode != null && groupnode.getChild(0).toStringTree()
@@ -1197,33 +1218,28 @@
             ArrayList<ClassRefCheck> classRefCheck) {
         switch (posOption) {
             case "L":
-                positions.add(KoralFrame.STARTS_WITH);
-                positions.add(KoralFrame.MATCHES);
-                //                    classRefCheck.add("classRefCheck:includes");
+                positions.add(KoralFrame.ALIGNS_LEFT);
                 break;
             case "R":
-                positions.add(KoralFrame.ENDS_WITH);
-                positions.add(KoralFrame.MATCHES);
-                //                    classRefCheck.add("classRefCheck:includes");
+                positions.add(KoralFrame.ALIGNS_RIGHT);
                 break;
             case "F":
-                positions.add(KoralFrame.MATCHES);
-                //                    classRefCheck.add("classRefCheck:includes");
                 break;
             case "FE":
-                positions.add(KoralFrame.MATCHES);
                 classRefCheck.add(ClassRefCheck.EQUALS);
                 break;
             case "FI":
-                positions.add(KoralFrame.MATCHES);
                 classRefCheck.add(ClassRefCheck.UNEQUALS);
-                //                    classRefCheck.add("classRefCheck:includes");
                 break;
             case "N":
-                positions.add(KoralFrame.IS_AROUND);
-                //                    classRefCheck.add("classRefCheck:includes");
+                positions.add(KoralFrame.IS_WITHIN);
                 break;
+            default:
+                positions.add(KoralFrame.ALIGNS_LEFT);
+                positions.add(KoralFrame.ALIGNS_RIGHT);
+                positions.add(KoralFrame.IS_WITHIN);
         }
+        positions.add(KoralFrame.MATCHES);
     }
 
 
@@ -1248,8 +1264,9 @@
         }
         else if (CosmasPosition.F.name().equals(posOption)) {}
         else {
-            // throw an error or add an exception;
-            return;
+            positions.add(KoralFrame.ALIGNS_LEFT);
+            positions.add(KoralFrame.ALIGNS_RIGHT);
+            positions.add(KoralFrame.IS_WITHIN);
         }
 
         positions.add(KoralFrame.MATCHES);
@@ -1271,13 +1288,13 @@
             posOption = posnode.getChild(0).toStringTree();
             switch (posOption) {
                 case "L":
-                    positions.add(KoralFrame.STARTS_WITH);
+                    positions.add(KoralFrame.ALIGNS_LEFT);
                     positions.add(KoralFrame.OVERLAPS_LEFT);
                     positions.add(KoralFrame.MATCHES);
                     classRefCheck.add(ClassRefCheck.INTERSECTS);
                     break;
                 case "R":
-                    positions.add(KoralFrame.ENDS_WITH);
+                    positions.add(KoralFrame.ALIGNS_RIGHT);
                     positions.add(KoralFrame.OVERLAPS_RIGHT);
                     positions.add(KoralFrame.MATCHES);
                     classRefCheck.add(ClassRefCheck.INTERSECTS);
@@ -1295,7 +1312,7 @@
                     classRefCheck.add(ClassRefCheck.UNEQUALS);
                     break;
                 case "X":
-                    positions.add(KoralFrame.IS_AROUND);
+                    positions.add(KoralFrame.IS_WITHIN);
                     classRefCheck.add(ClassRefCheck.INTERSECTS);
                     break;
             }
@@ -1306,6 +1323,10 @@
 
         posOptions.put("frames", Converter.enumListToStringList(positions));
         posOptions.put("classRefCheck", classRefCheck);
+        if (!classRefCheck.isEmpty()){
+            wrapOperandInClass(node, 1, 128 + classCounter++);
+            wrapOperandInClass(node, 2, 128 + classCounter++);
+        }
         if (exclnode != null) {
             if (exclnode.getChild(0).toStringTree().equals("YES")) {
                 negatePosition = !negatePosition;
@@ -1423,13 +1444,10 @@
         Map<String, Object> fieldMap = null;
         fieldMap = KoralObjectGenerator.makeTerm();
 
-        if (m.group(2) != null)
-            fieldMap.put("foundry", m.group(2));
-        if (m.group(4) != null)
-            fieldMap.put("layer", m.group(4));
+        if (m.group(2) != null) fieldMap.put("foundry", m.group(2));
+        if (m.group(4) != null) fieldMap.put("layer", m.group(4));
         if (m.group(5) != null) {
-            if ("!=".equals(m.group(5)))
-                negate = !negate;
+            if ("!=".equals(m.group(5))) negate = !negate;
         }
         if (m.group(6) != null) {
             String key = m.group(6);
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/util/KoralObjectGenerator.java b/src/main/java/de/ids_mannheim/korap/query/serialize/util/KoralObjectGenerator.java
index 0222864..ee592d0 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/util/KoralObjectGenerator.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/util/KoralObjectGenerator.java
@@ -142,12 +142,12 @@
 
 
     public static Map<String, Object> makeClassRefCheck (
-            ArrayList<ClassRefCheck> checks, Integer[] classIn, int classOut) {
+            ArrayList<ClassRefCheck> checks, ArrayList<Integer> classIn, int classOut) {
         Map<String, Object> group = new HashMap<String, Object>();
         group.put("@type", KoralType.GROUP.toString());
         group.put("operation", KoralOperation.CLASS.toString());
         group.put("classRefCheck", Converter.enumListToStringList(checks));
-        group.put("classIn", Arrays.asList(classIn));
+        group.put("classIn", classIn);
         group.put("classOut", classOut);
         group.put("operands", new ArrayList<Object>());
         return group;
diff --git a/src/test/java/de/ids_mannheim/korap/test/cosmas2/Cosmas2QueryProcessorTest.java b/src/test/java/de/ids_mannheim/korap/test/cosmas2/Cosmas2QueryProcessorTest.java
index 57cbc94..3396497 100644
--- a/src/test/java/de/ids_mannheim/korap/test/cosmas2/Cosmas2QueryProcessorTest.java
+++ b/src/test/java/de/ids_mannheim/korap/test/cosmas2/Cosmas2QueryProcessorTest.java
@@ -72,15 +72,25 @@
         qs.setQuery(query, "cosmas2");
         res = mapper.readTree(qs.toJSON());
         assertEquals("koral:term", res.at("/query/wrap/@type").asText());
-        assertEquals("type:wildcard", res.at("/query/wrap/type").asText());
-        assertEquals("*der", res.at("/query/wrap/key").asText());
+        assertEquals("type:regex", res.at("/query/wrap/type").asText());
+        assertEquals(".*der", res.at("/query/wrap/key").asText());
         assertEquals("orth", res.at("/query/wrap/layer").asText());
         assertEquals("match:eq", res.at("/query/wrap/match").asText());
 
-        query = "*de*?r";
+        query = "*de?r";
         qs.setQuery(query, "cosmas2");
         res = mapper.readTree(qs.toJSON());
-        assertEquals("*de*?r", res.at("/query/wrap/key").asText());
+        assertEquals(".*de.r", res.at("/query/wrap/key").asText());
+        
+        query = "*de+r";
+        qs.setQuery(query, "cosmas2");
+        res = mapper.readTree(qs.toJSON());
+        assertEquals(".*de.?r", res.at("/query/wrap/key").asText());
+
+        query = "*de+?r";
+        qs.setQuery(query, "cosmas2");
+        res = mapper.readTree(qs.toJSON());
+        assertEquals(".*de.?.r", res.at("/query/wrap/key").asText());
     }
 
 
@@ -698,77 +708,74 @@
         query = "wegen #OV <s>";
         qs.setQuery(query, "cosmas2");
         res = mapper.readTree(qs.toJSON());
-        assertEquals("koral:reference", res.at("/query/@type").asText());
-        assertEquals("operation:focus", res.at("/query/operation").asText());
-        assertEquals(130, res.at("/query/classRef/0").asInt());
-        assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
-        assertEquals("operation:class", res.at("/query/operands/0/operation")
+        assertEquals("koral:group", res.at("/query/@type").asText());
+        assertEquals("operation:class", res.at("/query/operation")
                 .asText());
         assertEquals("classRefCheck:intersects",
-                res.at("/query/operands/0/classRefCheck/0").asText());
+                res.at("/query/classRefCheck/0").asText());
         //		assertEquals("classRefOp:merge",            res.at("/query/operands/0/classRefOp").asText());
-        assertEquals(131, res.at("/query/operands/0/classOut").asInt());
-        assertEquals(129, res.at("/query/operands/0/classIn/0").asInt());
-        assertEquals(130, res.at("/query/operands/0/classIn/1").asInt());
+        assertEquals(131, res.at("/query/classOut").asInt());
+        assertEquals(129, res.at("/query/classIn/0").asInt());
+        assertEquals(130, res.at("/query/classIn/1").asInt());
         assertEquals("koral:group", res
-                .at("/query/operands/0/operands/0/@type").asText());
+                .at("/query/operands/0/@type").asText());
         assertEquals("operation:position",
-                res.at("/query/operands/0/operands/0/operation").asText());
-        assertEquals(true, res.at("/query/operands/0/operands/0/frames/0")
+                res.at("/query/operands/0/operation").asText());
+        assertEquals(true, res.at("/query/operands/0/frames/0")
                 .isMissingNode());
         assertEquals("koral:group", res
-                .at("/query/operands/0/operands/0/@type").asText());
+                .at("/query/operands/0/@type").asText());
         assertEquals("operation:class",
-                res.at("/query/operands/0/operands/0/operands/0/operation")
+                res.at("/query/operands/0/operands/0/operation")
                         .asText());
         assertEquals(129,
-                res.at("/query/operands/0/operands/0/operands/0/classOut")
-                        .asInt());
-        assertEquals(
-                "koral:span",
-                res.at("/query/operands/0/operands/0/operands/0/operands/0/@type")
-                        .asText());
-        assertEquals(
-                "s",
-                res.at("/query/operands/0/operands/0/operands/0/operands/0/wrap/key")
-                        .asText());
-        assertEquals("koral:group",
-                res.at("/query/operands/0/operands/0/operands/1/@type")
-                        .asText());
-        assertEquals("operation:class",
-                res.at("/query/operands/0/operands/0/operands/1/operation")
-                        .asText());
-        assertEquals(130,
-                res.at("/query/operands/0/operands/0/operands/1/classOut")
+                res.at("/query/operands/0/operands/0/classOut")
                         .asInt());
         assertEquals(
                 "koral:token",
-                res.at("/query/operands/0/operands/0/operands/1/operands/0/@type")
+                res.at("/query/operands/0/operands/0/operands/0/@type")
                         .asText());
         assertEquals(
                 "wegen",
-                res.at("/query/operands/0/operands/0/operands/1/operands/0/wrap/key")
+                res.at("/query/operands/0/operands/0/operands/0/wrap/key")
+                        .asText());
+        assertEquals("koral:group",
+                res.at("/query/operands/0/operands/1/@type")
+                        .asText());
+        assertEquals("operation:class",
+                res.at("/query/operands/0/operands/1/operation")
+                        .asText());
+        assertEquals(130,
+                res.at("/query/operands/0/operands/1/classOut")
+                        .asInt());
+        assertEquals(
+                "koral:span",
+                res.at("/query/operands/0/operands/1/operands/0/@type")
+                        .asText());
+        assertEquals(
+                "s",
+                res.at("/query/operands/0/operands/1/operands/0/wrap/key")
                         .asText());
 
         query = "wegen #OV(L) <s>";
         qs.setQuery(query, "cosmas2");
         res = mapper.readTree(qs.toJSON());
         assertEquals("classRefCheck:intersects",
-                res.at("/query/operands/0/classRefCheck/0").asText());
-        assertEquals("frames:startsWith",
-                res.at("/query/operands/0/operands/0/frames/0").asText());
+                res.at("/query/classRefCheck/0").asText());
+        assertEquals("frames:alignsLeft",
+                res.at("/query/operands/0/frames/0").asText());
         assertEquals("frames:overlapsLeft",
-                res.at("/query/operands/0/operands/0/frames/1").asText());
+                res.at("/query/operands/0/frames/1").asText());
         assertEquals("frames:matches",
-                res.at("/query/operands/0/operands/0/frames/2").asText());
+                res.at("/query/operands/0/frames/2").asText());
 
         query = "wegen #OV(F) <s>";
         qs.setQuery(query, "cosmas2");
         res = mapper.readTree(qs.toJSON());
         assertEquals("classRefCheck:intersects",
-                res.at("/query/operands/0/classRefCheck/0").asText());
+                res.at("/query/classRefCheck/0").asText());
         assertEquals("frames:matches",
-                res.at("/query/operands/0/operands/0/frames/0").asText());
+                res.at("/query/operands/0/frames/0").asText());
         assertEquals(true, res.at("/query/operands/0/operands/0/frames/1")
                 .isMissingNode());
 
@@ -776,17 +783,17 @@
         qs.setQuery(query, "cosmas2");
         res = mapper.readTree(qs.toJSON());
         assertEquals("classRefCheck:unequals",
-                res.at("/query/operands/0/classRefCheck/0").asText());
+                res.at("/query/classRefCheck/0").asText());
         assertEquals("frames:matches",
-                res.at("/query/operands/0/operands/0/frames/0").asText());
+                res.at("/query/operands/0/frames/0").asText());
 
         query = "wegen #OV(FE) <s>";
         qs.setQuery(query, "cosmas2");
         res = mapper.readTree(qs.toJSON());
         assertEquals("classRefCheck:equals",
-                res.at("/query/operands/0/classRefCheck/0").asText());
+                res.at("/query/classRefCheck/0").asText());
         assertEquals("frames:matches",
-                res.at("/query/operands/0/operands/0/frames/0").asText());
+                res.at("/query/operands/0/frames/0").asText());
     }
 
 
diff --git a/src/test/java/de/ids_mannheim/korap/test/cosmas2/OPINTest.java b/src/test/java/de/ids_mannheim/korap/test/cosmas2/OPINTest.java
index d32195c..35f18c5 100644
--- a/src/test/java/de/ids_mannheim/korap/test/cosmas2/OPINTest.java
+++ b/src/test/java/de/ids_mannheim/korap/test/cosmas2/OPINTest.java
@@ -13,6 +13,9 @@
 
 import de.ids_mannheim.korap.query.serialize.QuerySerializer;
 
+// EM: OPIN always returns the combination span of both operands
+// MAX groups all first operand spans that are in a same second operand span
+
 public class OPINTest {
     private String query;
 
@@ -26,113 +29,66 @@
         query = "wegen #IN <s>";
         qs.setQuery(query, "cosmas2");
         res = mapper.readTree(qs.toJSON());
-        assertEquals("koral:reference", res.at("/query/@type").asText());
-        assertEquals("operation:focus", res.at("/query/operation").asText());
-        assertEquals(130, res.at("/query/classRef/0").asInt());
-        assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
-        assertEquals("operation:class",
-                res.at("/query/operands/0/operation").asText());
-        assertEquals("classRefCheck:includes",
-                res.at("/query/operands/0/classRefCheck/0").asText());
-        assertEquals("koral:group",
-                res.at("/query/operands/0/operands/0/@type").asText());
-        assertEquals("operation:position",
-                res.at("/query/operands/0/operands/0/operation").asText());
-        assertEquals(true, res.at("/query/operands/0/operands/0/frames/0")
-                .isMissingNode());
-        assertEquals(129, res.at("/query/operands/0/classIn/0").asInt());
-        assertEquals(130, res.at("/query/operands/0/classIn/1").asInt());
-        assertEquals(131, res.at("/query/operands/0/classOut").asInt());
-        assertEquals("koral:group",
-                res.at("/query/operands/0/operands/0/@type").asText());
-        assertEquals("operation:class",
-                res.at("/query/operands/0/operands/0/operands/0/operation")
-                        .asText());
-        assertEquals(129,
-                res.at("/query/operands/0/operands/0/operands/0/classOut")
-                        .asInt());
-        assertEquals("koral:span",
-                res.at("/query/operands/0/operands/0/operands/0/operands/0/@type")
-                        .asText());
-        assertEquals("s",
-                res.at("/query/operands/0/operands/0/operands/0/operands/0/wrap/key")
-                        .asText());
-        assertEquals("koral:group", res
-                .at("/query/operands/0/operands/0/operands/1/@type").asText());
-        assertEquals("operation:class",
-                res.at("/query/operands/0/operands/0/operands/1/operation")
-                        .asText());
-        assertEquals(130,
-                res.at("/query/operands/0/operands/0/operands/1/classOut")
-                        .asInt());
-        assertEquals("koral:token",
-                res.at("/query/operands/0/operands/0/operands/1/operands/0/@type")
-                        .asText());
-        assertEquals("wegen",
-                res.at("/query/operands/0/operands/0/operands/1/operands/0/wrap/key")
-                        .asText());
+
+        assertEquals("koral:group", res.at("/query/@type").asText());
+        assertEquals("operation:position", res.at("/query/operation").asText());
+        assertEquals(4, res.at("/query/frames").size());
+        assertEquals("frames:alignsLeft", res.at("/query/frames/0").asText());
+        assertEquals("frames:alignsRight", res.at("/query/frames/1").asText());
+        assertEquals("frames:isWithin", res.at("/query/frames/2").asText());
+        assertEquals("frames:matches", res.at("/query/frames/3").asText());
+        assertEquals("koral:token", res.at("/query/operands/0/@type").asText());
+        assertEquals("koral:span", res.at("/query/operands/1/@type").asText());
     }
 
 
     @Test
-   
     public void testOPINWithOptionN ()
             throws JsonProcessingException, IOException {
         query = "wegen #IN(N) <s>";
         qs.setQuery(query, "cosmas2");
         res = mapper.readTree(qs.toJSON());
-        assertEquals("koral:reference", res.at("/query/@type").asText());
-        assertEquals("operation:focus", res.at("/query/operation").asText());
-        assertEquals(130, res.at("/query/classRef/0").asInt());
-        assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
-        assertEquals("operation:position",
-                res.at("/query/operands/0/operation").asText());
-        assertEquals("frames:isAround",
-                res.at("/query/operands/0/frames/0").asText());
+        assertEquals("koral:group", res.at("/query/@type").asText());
+        assertEquals("operation:position", res.at("/query/operation").asText());
+        assertEquals("frames:isWithin", res.at("/query/frames/0").asText());
+        assertEquals("wegen", res.at("/query/operands/0/wrap/key").asText());
+        assertEquals("s", res.at("/query/operands/1/wrap/key").asText());
     }
-    
-    
+
+
     @Test
     public void testOPINWithOptionL ()
             throws JsonProcessingException, IOException {
         query = "wegen #IN(L) <s>";
         qs.setQuery(query, "cosmas2");
         res = mapper.readTree(qs.toJSON());
-        assertEquals("koral:reference", res.at("/query/@type").asText());
-        assertEquals("operation:focus", res.at("/query/operation").asText());
-        assertEquals(130, res.at("/query/classRef/0").asInt());
-        assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
-        assertEquals("operation:position",
-                res.at("/query/operands/0/operation").asText());
-        assertEquals("frames:startsWith",
-                res.at("/query/operands/0/frames/0").asText());
-        assertEquals("frames:matches",
-                res.at("/query/operands/0/frames/1").asText());
-        assertEquals(true,
-                res.at("/query/operands/0/frames/2").isMissingNode());
-        assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
-        assertEquals("operation:class",
-                res.at("/query/operands/0/operands/0/operation").asText());
-        assertEquals(129,
-                res.at("/query/operands/0/operands/0/classOut").asInt());
-        assertEquals("koral:span", res
-                .at("/query/operands/0/operands/0/operands/0/@type").asText());
-        assertEquals("s",
-                res.at("/query/operands/0/operands/0/operands/0/wrap/key")
-                        .asText());
-        assertEquals("koral:group",
-                res.at("/query/operands/0/operands/1/@type").asText());
-        assertEquals("operation:class",
-                res.at("/query/operands/0/operands/1/operation").asText());
-        assertEquals(130,
-                res.at("/query/operands/0/operands/1/classOut").asInt());
-        assertEquals("koral:token", res
-                .at("/query/operands/0/operands/1/operands/0/@type").asText());
-        assertEquals("wegen",
-                res.at("/query/operands/0/operands/1/operands/0/wrap/key")
-                        .asText());
+
+        assertEquals("operation:position", res.at("/query/operation").asText());
+        assertEquals(2, res.at("/query/frames").size());
+        assertEquals("frames:alignsLeft", res.at("/query/frames/0").asText());
+        assertEquals("frames:matches", res.at("/query/frames/1").asText());
+
+        assertEquals("wegen", res.at("/query/operands/0/wrap/key").asText());
+        assertEquals("s", res.at("/query/operands/1/wrap/key").asText());
     }
 
+
+    @Test
+    public void testOPINWithOptionR ()
+            throws JsonProcessingException, IOException {
+        query = "wegen #IN(R) <s>";
+        qs.setQuery(query, "cosmas2");
+        res = mapper.readTree(qs.toJSON());
+
+        assertEquals("operation:position", res.at("/query/operation").asText());
+        assertEquals("frames:alignsRight", res.at("/query/frames/0").asText());
+        assertEquals("frames:matches", res.at("/query/frames/1").asText());
+        assertEquals(2, res.at("/query/frames").size());
+        assertEquals("wegen", res.at("/query/operands/0/wrap/key").asText());
+        assertEquals("s", res.at("/query/operands/1/wrap/key").asText());
+    }
+
+
     @Test
     public void testOPINwithOptionF ()
             throws JsonProcessingException, IOException {
@@ -141,10 +97,8 @@
         res = mapper.readTree(qs.toJSON());
         assertEquals(true,
                 res.at("/query/operands/0/classRefCheck").isMissingNode());
-        assertEquals("frames:matches",
-                res.at("/query/operands/0/frames/0").asText());
-        assertEquals(true,
-                res.at("/query/operands/0/frames/1").isMissingNode());
+        assertEquals("frames:matches", res.at("/query/frames/0").asText());
+        assertEquals(true, res.at("/query/frames/1").isMissingNode());
     }
 
 
@@ -155,12 +109,12 @@
         qs.setQuery(query, "cosmas2");
         res = mapper.readTree(qs.toJSON());
         assertEquals("classRefCheck:unequals",
-                res.at("/query/operands/0/classRefCheck/0").asText());
+                res.at("/query/classRefCheck/0").asText());
         assertEquals("frames:matches",
-                res.at("/query/operands/0/operands/0/frames/0").asText());
-        assertEquals(true, res.at("/query/operands/0/operands/0/frames/1")
-                .isMissingNode());
-        
+                res.at("/query/operands/0/frames/0").asText());
+        assertEquals(true,
+                res.at("/query/operands/0/frames/1").isMissingNode());
+
     }
 
 
@@ -171,47 +125,160 @@
         qs.setQuery(query, "cosmas2");
         res = mapper.readTree(qs.toJSON());
         assertEquals("classRefCheck:equals",
-                res.at("/query/operands/0/classRefCheck/0").asText());
+                res.at("/query/classRefCheck/0").asText());
         assertEquals("frames:matches",
-                res.at("/query/operands/0/operands/0/frames/0").asText());
-        assertEquals(true, res.at("/query/operands/0/operands/0/frames/1")
-                .isMissingNode());
+                res.at("/query/operands/0/frames/0").asText());
+        assertEquals(true,
+                res.at("/query/operands/0/frames/1").isMissingNode());
     }
 
+
+    @Test
+    public void testOPINWithOptionN_ALL ()
+            throws JsonProcessingException, IOException {
+        // ALL is default in KorAP
+        query = "sich #IN(N,ALL) (&gelten /w5:10 zurecht)";
+        qs.setQuery(query, "cosmas2");
+        res = mapper.readTree(qs.toJSON());
+        assertEquals("koral:group", res.at("/query/@type").asText());
+        assertEquals("operation:position", res.at("/query/operation").asText());
+        assertEquals("frames:isWithin", res.at("/query/frames/0").asText());
+        assertEquals("frames:matches", res.at("/query/frames/1").asText());
+        assertEquals("sich", res.at("/query/operands/0/wrap/key").asText());
+        assertEquals("gelten",
+                res.at("/query/operands/1/operands/0/operands/0/wrap/key")
+                        .asText());
+        assertEquals("zurecht",
+                res.at("/query/operands/1/operands/1/operands/0/wrap/key")
+                        .asText());
+    }
+
+
+    // Default
+
+    @Test
+    public void testOPINWithOptionN_HIT ()
+            throws JsonProcessingException, IOException {
+        query = "gilt #IN(N,HIT) (&gelten /w5:10 zurecht)";
+        qs.setQuery(query, "cosmas2");
+        res = mapper.readTree(qs.toJSON());
+        
+        assertEquals("koral:group", res.at("/query/@type").asText());
+        assertEquals("operation:class", res.at("/query/operation").asText());
+        assertEquals("classRefCheck:includes",
+                res.at("/query/classRefCheck/0").asText());
+        assertEquals(1, res.at("/query/classRefCheck").size());
+        assertEquals(129, res.at("/query/classIn/0").asInt());
+        assertEquals(130, res.at("/query/classOut").asInt());
+
+        assertEquals("operation:position",
+                res.at("/query/operands/0/operation").asText());
+        assertEquals("frames:isWithin",
+                res.at("/query/operands/0/frames/0").asText());
+        assertEquals("frames:matches",
+                res.at("/query/operands/0/frames/1").asText());
+        assertEquals("gilt",
+                res.at("/query/operands/0/operands/0/wrap/key").asText());
+        assertEquals("operation:sequence",
+                res.at("/query/operands/0/operands/1/operation").asText());
+
+        // sequence operands
+        res = res.at("/query/operands/0/operands/1/operands");
+        assertEquals("gelten", res.at("/0/operands/0/wrap/key").asText());
+        assertEquals(129, res.at("/0/classOut").asInt());
+        assertEquals("zurecht", res.at("/1/operands/0/wrap/key").asText());
+        assertEquals(129, res.at("/1/classOut").asInt());
+    }
+    
+    @Test
+    public void testOPINWithOptionFE_HIT ()
+            throws JsonProcessingException, IOException {
+        query = "gilt #IN(FE,HIT) (&gelten /w5:10 zurecht)";
+        qs.setQuery(query, "cosmas2");
+        res = mapper.readTree(qs.toJSON());
+        
+        assertEquals("koral:group", res.at("/query/@type").asText());
+        assertEquals("operation:class", res.at("/query/operation").asText());
+        assertEquals("classRefCheck:equals",
+                res.at("/query/classRefCheck/0").asText());
+        assertEquals("classRefCheck:includes",
+                res.at("/query/classRefCheck/1").asText());
+        assertEquals(2, res.at("/query/classRefCheck").size());
+        assertEquals(3, res.at("/query/classIn").size());
+        assertEquals(132, res.at("/query/classOut").asInt());
+
+        assertEquals("operation:position",
+                res.at("/query/operands/0/operation").asText());
+        assertEquals("frames:matches",
+                res.at("/query/operands/0/frames/0").asText());
+        // positions operands
+        res = res.at("/query/operands/0/operands");
+        assertEquals("gilt",
+                res.at("/0/operands/0/wrap/key").asText());
+        assertEquals(129, res.at("/0/classOut").asInt());
+        assertEquals(130, res.at("/1/classOut").asInt());
+        
+        // sequence operands
+        res = res.at("/1/operands/0/operands");        
+        assertEquals("gelten", res.at("/0/operands/0/wrap/key").asText());
+        assertEquals(131, res.at("/0/classOut").asInt());
+        assertEquals("zurecht", res.at("/1/operands/0/wrap/key").asText());
+        assertEquals(131, res.at("/1/classOut").asInt());
+    }
+    
+    @Test
+    public void testOPINWithOptionFI_HIT ()
+            throws JsonProcessingException, IOException {
+        query = "gilt #IN(FI,HIT) (&gelten /w5:10 zurecht)";
+        qs.setQuery(query, "cosmas2");
+        res = mapper.readTree(qs.toJSON());
+        
+        assertEquals("koral:group", res.at("/query/@type").asText());
+        assertEquals("operation:class", res.at("/query/operation").asText());
+        assertEquals("classRefCheck:unequals",
+                res.at("/query/classRefCheck/0").asText());
+        assertEquals("classRefCheck:includes",
+                res.at("/query/classRefCheck/1").asText());
+        assertEquals(2, res.at("/query/classRefCheck").size());
+        assertEquals(3, res.at("/query/classIn").size());
+        assertEquals(132, res.at("/query/classOut").asInt());
+
+        assertEquals("operation:position",
+                res.at("/query/operands/0/operation").asText());
+        assertEquals("frames:matches",
+                res.at("/query/operands/0/frames/0").asText());
+        // positions operands
+        res = res.at("/query/operands/0/operands");
+        assertEquals("gilt",
+                res.at("/0/operands/0/wrap/key").asText());
+        assertEquals(129, res.at("/0/classOut").asInt());
+        assertEquals(130, res.at("/1/classOut").asInt());
+        
+        // sequence operands
+        res = res.at("/1/operands/0/operands");        
+        assertEquals("gelten", res.at("/0/operands/0/wrap/key").asText());
+        assertEquals(131, res.at("/0/classOut").asInt());
+        assertEquals("zurecht", res.at("/1/operands/0/wrap/key").asText());
+        assertEquals(131, res.at("/1/classOut").asInt());
+    }
+
+
     @Test
     @Ignore
     public void testOPINWithOptionN_MAX ()
             throws JsonProcessingException, IOException {
+        // EM: Fix operation:merge
         query = "wegen #IN(N, MAX) <s>";
         qs.setQuery(query, "cosmas2");
         res = mapper.readTree(qs.toJSON());
-        // System.out.println(res.toString());
-        assertEquals("koral:reference", res.at("/query/@type").asText());
-        assertEquals("operation:focus", res.at("/query/operation").asText());
-        assertEquals(130, res.at("/query/classRef/0").asInt());
-        assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
-        assertEquals("operation:position",
-                res.at("/query/operands/0/operation").asText());
-        assertEquals("frames:isAround",
-                res.at("/query/operands/0/frames/0").asText());
-    }
-    
-    @Test
-    public void testOPINWithOptionN_HIT ()
-            throws JsonProcessingException, IOException {
-        query = "wegen #IN(N, HIT) <s>";
-        qs.setQuery(query, "cosmas2");
-        res = mapper.readTree(qs.toJSON());
-        // System.out.println(res.toString());
-        assertEquals("koral:reference", res.at("/query/@type").asText());
-        assertEquals("operation:focus", res.at("/query/operation").asText());
-        assertEquals(130, res.at("/query/classRef/0").asInt());
-        assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
-        assertEquals("operation:position",
-                res.at("/query/operands/0/operation").asText());
-        assertEquals("frames:isAround",
-                res.at("/query/operands/0/frames/0").asText());
-    }
-    
 
+        assertEquals("koral:reference", res.at("/query/@type").asText());
+        assertEquals("operation:focus", res.at("/query/operation").asText());
+        assertEquals(130, res.at("/query/classRef/0").asInt());
+        assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
+        assertEquals("operation:position",
+                res.at("/query/operands/0/operation").asText());
+        assertEquals("frames:isAround",
+                res.at("/query/operands/0/frames/0").asText());
+    }
 }
diff --git a/src/test/java/de/ids_mannheim/korap/test/cosmas2/OPINWithExclusionTest.java b/src/test/java/de/ids_mannheim/korap/test/cosmas2/OPINWithExclusionTest.java
index 3246141..9d410dc 100644
--- a/src/test/java/de/ids_mannheim/korap/test/cosmas2/OPINWithExclusionTest.java
+++ b/src/test/java/de/ids_mannheim/korap/test/cosmas2/OPINWithExclusionTest.java
@@ -4,7 +4,6 @@
 
 import java.io.IOException;
 
-import org.junit.Ignore;
 import org.junit.Test;
 
 import com.fasterxml.jackson.core.JsonProcessingException;
@@ -13,6 +12,8 @@
 
 import de.ids_mannheim.korap.query.serialize.QuerySerializer;
 
+// EM: exclusion always returns the first operand
+
 public class OPINWithExclusionTest {
     private String query;
 
@@ -20,6 +21,24 @@
     private ObjectMapper mapper = new ObjectMapper();
     private JsonNode res;
 
+    @Test
+    public void testOPINWithExclusion ()
+            throws JsonProcessingException, IOException {
+        query = "wegen #IN(%) <s>";
+        qs.setQuery(query, "cosmas2");
+        res = mapper.readTree(qs.toJSON());
+
+        assertEquals("koral:group", res.at("/query/@type").asText());
+        assertEquals("operation:exclusion",
+                res.at("/query/operation").asText());
+        assertEquals(4, res.at("/query/frames").size());
+        assertEquals("frames:alignsLeft", res.at("/query/frames/0").asText());
+        assertEquals("frames:alignsRight", res.at("/query/frames/1").asText());
+        assertEquals("frames:matches", res.at("/query/frames/3").asText());
+        assertEquals("frames:isWithin", res.at("/query/frames/2").asText());
+        assertEquals("koral:token", res.at("/query/operands/0/@type").asText());
+        assertEquals("koral:span", res.at("/query/operands/1/@type").asText());
+    }
 
     @Test
     public void testOPINWithExclusionN ()
@@ -125,6 +144,8 @@
     }
 
 
+    // EM: MIN, MAX does not matter with %
+    
     @Test
     public void testOPINwithExclusionFE_MIN ()
             throws JsonProcessingException, IOException {
@@ -141,23 +162,42 @@
                 res.at("/query/operands/0/frames/0").asText());
     }
 
+    @Test
+    public void testOPINwithExclusionFE_MAX ()
+            throws JsonProcessingException, IOException {
+        query = "wegen #IN(FE,%,MAX) <s>";
+        qs.setQuery(query, "cosmas2");
+        res = mapper.readTree(qs.toJSON());
+        
+        assertEquals("operation:class", res.at("/query/operation").asText());
+        assertEquals("classRefCheck:unequals",
+                res.at("/query/classRefCheck/0").asText());
+
+        JsonNode classRefCheckOperand = res.at("/query/operands/0");
+        assertEquals("operation:exclusion",
+                classRefCheckOperand.at("/operation").asText());
+        assertEquals(1, classRefCheckOperand.at("/frames").size());
+        assertEquals("frames:matches",
+                classRefCheckOperand.at("/frames/0").asText());
+    }
 
     @Test
     public void testOPINwithExclusionN_MAX ()
             throws JsonProcessingException, IOException {
+
         query = "wegen #IN(N,%,MAX) <s>";
         qs.setQuery(query, "cosmas2");
         res = mapper.readTree(qs.toJSON());
-
-        assertEquals("operation:merge", res.at("/query/operation").asText());
+        
+        assertEquals("koral:group", res.at("/query/@type").asText());
         assertEquals("operation:exclusion",
-                res.at("/query/operands/0/operation").asText());
-        assertEquals(1, res.at("/query/operands/0/frames").size());
-        assertEquals("frames:isWithin",
-                res.at("/query/operands/0/frames/0").asText());
+                res.at("/query/operation").asText());
+        assertEquals(1, res.at("/query/frames").size());
+        assertEquals("frames:isWithin", res.at("/query/frames/0").asText());
+        assertEquals("koral:token", res.at("/query/operands/0/@type").asText());
+        assertEquals("koral:span", res.at("/query/operands/1/@type").asText());
     }
 
-
     @Test
     public void testOPINwithExclusionL_MAX ()
             throws JsonProcessingException, IOException {
@@ -165,97 +205,75 @@
         qs.setQuery(query, "cosmas2");
         res = mapper.readTree(qs.toJSON());
         
-        assertEquals("operation:merge", res.at("/query/operation").asText());
+        assertEquals("koral:group", res.at("/query/@type").asText());
         assertEquals("operation:exclusion",
-                res.at("/query/operands/0/operation").asText());
-        assertEquals(2, res.at("/query/operands/0/frames").size());
-        assertEquals("frames:alignsLeft",
-                res.at("/query/operands/0/frames/0").asText());
-        assertEquals("frames:matches",
-                res.at("/query/operands/0/frames/1").asText());
+                res.at("/query/operation").asText());
+        assertEquals(2, res.at("/query/frames").size());
+        assertEquals("frames:alignsLeft", res.at("/query/frames/0").asText());
+        assertEquals("frames:matches", res.at("/query/frames/1").asText());
+        assertEquals("koral:token", res.at("/query/operands/0/@type").asText());
+        assertEquals("koral:span", res.at("/query/operands/1/@type").asText());
     }
 
-
-    @Test
-    public void testOPINwithExclusionFE_MAX ()
-            throws JsonProcessingException, IOException {
-        query = "wegen #IN(FE,%,MAX) <s>";
-        qs.setQuery(query, "cosmas2");
-        res = mapper.readTree(qs.toJSON());
-
-        assertEquals("operation:merge", res.at("/query/operation").asText());
-        assertEquals("operation:class",
-                res.at("/query/operands/0/operation").asText());
-        assertEquals("classRefCheck:unequals",
-                res.at("/query/operands/0/classRefCheck/0").asText());
-        JsonNode classOperand = res.at("/query/operands/0/operands/0");
-        assertEquals("operation:exclusion",
-                classOperand.at("/operation").asText());
-        assertEquals(1, classOperand.at("/frames").size());
-        assertEquals("frames:matches", classOperand.at("/frames/0").asText());
-    }
-
+    // EM: KorAP always do ALL by default.
     
     @Test
-    @Ignore
-    public void testOPINwithMultipleExclusionN_ALL ()
+    public void testOPINwithExclusionN_ALL ()
             throws JsonProcessingException, IOException {
+        
         query = "wegen #IN(N,ALL,%) <s>";
         qs.setQuery(query, "cosmas2");
         res = mapper.readTree(qs.toJSON());
-        // System.out.println(res.toString());
-        assertEquals("operation:class", res.at("/query/operation").asText());
-        assertEquals("classRefOp:delete", res.at("/query/classRefOp").asText());
-        assertEquals(131, res.at("/query/classIn/0").asInt());
-        assertEquals("classRefCheck:unequals",
-                res.at("/query/operands/0/classRefCheck/0").asText());
-        assertEquals("frames:matches",
-                res.at("/query/operands/0/operands/0/frames/0").asText());
+        assertEquals("koral:group", res.at("/query/@type").asText());
+        assertEquals("operation:exclusion",
+                res.at("/query/operation").asText());
+        assertEquals(1, res.at("/query/frames").size());
+        assertEquals("frames:isWithin", res.at("/query/frames/0").asText());
+        assertEquals("koral:token", res.at("/query/operands/0/@type").asText());
+        assertEquals("koral:span", res.at("/query/operands/1/@type").asText());
     }
 
     @Test
-    @Ignore
-    public void testOPINwithMultipleExclusionFE_ALL ()
+    public void testOPINwithExclusionN_ALL_MAX ()
+            throws JsonProcessingException, IOException {
+        query = "wegen #IN(N,ALL,%,MAX) <s>";
+        qs.setQuery(query, "cosmas2");
+        res = mapper.readTree(qs.toJSON());
+        
+        assertEquals("koral:group", res.at("/query/@type").asText());
+        assertEquals("operation:exclusion",
+                res.at("/query/operation").asText());
+        assertEquals(1, res.at("/query/frames").size());
+        assertEquals("frames:isWithin", res.at("/query/frames/0").asText());
+        assertEquals("koral:token", res.at("/query/operands/0/@type").asText());
+    }
+    
+    @Test
+    public void testOPINwithExclusionFE_ALL ()
             throws JsonProcessingException, IOException {
         query = "wegen #IN(FE,ALL,%) <s>";
         qs.setQuery(query, "cosmas2");
         res = mapper.readTree(qs.toJSON());
         assertEquals("operation:class", res.at("/query/operation").asText());
-        assertEquals("classRefOp:delete", res.at("/query/classRefOp").asText());
-        assertEquals(131, res.at("/query/classIn/0").asInt());
         assertEquals("classRefCheck:unequals",
-                res.at("/query/operands/0/classRefCheck/0").asText());
+                res.at("/query/classRefCheck/0").asText());
+        assertEquals(1, res.at("/query/operands/0/frames").size());
         assertEquals("frames:matches",
-                res.at("/query/operands/0/operands/0/frames/0").asText());
+                res.at("/query/operands/0/frames/0").asText());
     }
 
     @Test
-    public void testOPINwithMultipleExclusionN_ALL_MAX ()
-            throws JsonProcessingException, IOException {
-        query = "wegen #IN(N,ALL,%,MAX) <s>";
-        qs.setQuery(query, "cosmas2");
-        res = mapper.readTree(qs.toJSON());
-    }
-    
-    @Test
-    @Ignore
-    public void testOPINwithMultipleExclusionFE_ALL_MAX ()
+    public void testOPINwithExclusionFE_ALL_MAX ()
             throws JsonProcessingException, IOException {
         query = "wegen #IN(FE,ALL,%,MAX) <s>";
         qs.setQuery(query, "cosmas2");
         res = mapper.readTree(qs.toJSON());
-        assertEquals("operation:merge", res.at("/query/operation").asText());
-        assertEquals("operation:class",
-                res.at("/query/operands/0/operation").asText());
-        assertEquals("classRefOp:delete",
-                res.at("/query/operands/0/classRefOp").asText());
-        assertEquals(131, res.at("/query/operands/0/classIn/0").asInt());
-        assertEquals("classRefCheck:unequals", res
-                .at("/query/operands/0/operands/0/classRefCheck/0").asText());
+        assertEquals("operation:class", res.at("/query/operation").asText());
+        assertEquals("classRefCheck:unequals",
+                res.at("/query/classRefCheck/0").asText());
+        assertEquals(1, res.at("/query/operands/0/frames").size());
         assertEquals("frames:matches",
-                res.at("/query/operands/0/operands/0/operands/0/frames/0")
-                        .asText());
+                res.at("/query/operands/0/frames/0").asText());
     }
 
-
 }