Removed frames:matches in OPIN and OPOV with L/R.

Change-Id: I366c59d1aa100794c304005f7058463fe7566a4b
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 6ff2a4e..7c30e56 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
@@ -1241,7 +1241,7 @@
     private void checkINOptions (String posOption,
             ArrayList<KoralFrame> positions,
             ArrayList<ClassRefCheck> classRefCheck) {
-        positions.add(KoralFrame.MATCHES);
+        
         switch (posOption) {
             case "L":
                 positions.add(KoralFrame.ALIGNS_LEFT);
@@ -1250,21 +1250,24 @@
                 positions.add(KoralFrame.ALIGNS_RIGHT);
                 break;
             case "F":
+                positions.add(KoralFrame.MATCHES);
                 break;
             case "FE":
                 classRefCheck.add(ClassRefCheck.EQUALS);
+                positions.add(KoralFrame.MATCHES);
                 break;
             case "FI":
                 classRefCheck.add(ClassRefCheck.UNEQUALS);
+                positions.add(KoralFrame.MATCHES);
                 break;
             case "N":
                 positions.add(KoralFrame.IS_WITHIN);
-                positions.remove(KoralFrame.MATCHES);
                 break;
             default:
                 positions.add(KoralFrame.ALIGNS_LEFT);
                 positions.add(KoralFrame.ALIGNS_RIGHT);
                 positions.add(KoralFrame.IS_WITHIN);
+                positions.add(KoralFrame.MATCHES);
         }
         
     }
@@ -1284,19 +1287,23 @@
             positions.add(KoralFrame.ALIGNS_RIGHT);
         }
         else if (CosmasPosition.FE.name().equals(posOption)) {
+            positions.add(KoralFrame.MATCHES);
             classRefCheck.add(ClassRefCheck.UNEQUALS);
         }
         else if (CosmasPosition.FI.name().equals(posOption)) {
+            positions.add(KoralFrame.MATCHES);
             classRefCheck.add(ClassRefCheck.EQUALS);
         }
-        else if (CosmasPosition.F.name().equals(posOption)) {}
+        else if (CosmasPosition.F.name().equals(posOption)) {
+            positions.add(KoralFrame.MATCHES);
+        }
         else {
             positions.add(KoralFrame.ALIGNS_LEFT);
             positions.add(KoralFrame.ALIGNS_RIGHT);
             positions.add(KoralFrame.IS_WITHIN);
+            positions.add(KoralFrame.MATCHES);
         }
 
-        positions.add(KoralFrame.MATCHES);
     }
 
 
@@ -1367,7 +1374,7 @@
     private void checkOVExclusionOptions (String posOption,
             ArrayList<KoralFrame> positions,
             ArrayList<ClassRefCheck> classRefCheck) {
-        positions.add(KoralFrame.MATCHES);
+        
         switch (posOption) {
             case "L":
                 positions.add(KoralFrame.ALIGNS_LEFT);
@@ -1381,15 +1388,19 @@
                 classRefCheck.add(ClassRefCheck.INTERSECTS);
                 classRefCheck.add(ClassRefCheck.DISJOINT);
                 break;
+            case "F":
+                positions.add(KoralFrame.MATCHES);
+                break;
             case "FE":
                 classRefCheck.add(ClassRefCheck.UNEQUALS);
+                positions.add(KoralFrame.MATCHES);
                 break;
             case "FI":
                 classRefCheck.add(ClassRefCheck.EQUALS);
+                positions.add(KoralFrame.MATCHES);
                 break;
             case "X":
                 positions.add(KoralFrame.IS_WITHIN);
-                positions.remove(KoralFrame.MATCHES);
                 break;
         }
         
@@ -1400,7 +1411,6 @@
             ArrayList<KoralFrame> positions, 
             ArrayList<ClassRefCheck> classRefCheck) {
         classRefCheck.add(ClassRefCheck.INTERSECTS);
-        positions.add(KoralFrame.MATCHES);
         switch (posOption) {
             case "L":
                 positions.add(KoralFrame.ALIGNS_LEFT);
@@ -1411,12 +1421,15 @@
                 positions.add(KoralFrame.OVERLAPS_RIGHT);
                 break;
             case "F":
+                positions.add(KoralFrame.MATCHES);
                 break;
             case "FE":
+                positions.add(KoralFrame.MATCHES);
                 classRefCheck.add(ClassRefCheck.EQUALS);
                 classRefCheck.remove(ClassRefCheck.INTERSECTS);
                 break;
             case "FI":
+                positions.add(KoralFrame.MATCHES);
                 classRefCheck.add(ClassRefCheck.UNEQUALS);
                 break;
             case "X":
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 7677f98..7b89902 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
@@ -68,9 +68,6 @@
         assertEquals("operation:position", res.at("/query/operation").asText());
         assertEquals(1, res.at("/query/frames").size());
 
-		// ND: Matches seems to violate the L-rule:
-		//     "rechtes Wort von X und Y stimmen nicht überein."
-        // assertEquals("frames:matches", res.at("/query/frames/0").asText());
         assertEquals("frames:alignsLeft", res.at("/query/frames/0").asText());
 
         assertEquals("wegen", res.at("/query/operands/0/wrap/key").asText());
@@ -88,9 +85,6 @@
 
         assertEquals("operation:position", res.at("/query/operation").asText());
 
-		// ND: Matches seems to violate the L-rule:
-		//     "linkes Wort von X und Y stimmen nicht überein."
-        // assertEquals("frames:matches", res.at("/query/frames/0").asText());
         assertEquals("frames:alignsRight", res.at("/query/frames/0").asText());
         assertEquals(1, res.at("/query/frames").size());
 
@@ -108,6 +102,7 @@
         res = mapper.readTree(qs.toJSON());
         assertEquals(true,
                 res.at("/query/operands/0/classRefCheck").isMissingNode());
+        //EM: should include classRefCheck:include
         assertEquals("frames:matches", res.at("/query/frames/0").asText());
         assertEquals(true, res.at("/query/frames/1").isMissingNode());
     }
@@ -119,6 +114,7 @@
         query = "wegen #IN(FI) <s>";
         qs.setQuery(query, "cosmas2");
         res = mapper.readTree(qs.toJSON());
+//        System.out.println(res.toString());
 		assertEquals("classRefCheck:unequals",
                 res.at("/query/classRefCheck/0").asText());
         assertEquals("frames:matches",
@@ -129,17 +125,27 @@
 		// ND: unequals is not a defined value for classRefCheck, so it is unclear
 		//     what it means. I think classRefCheck "differs" is correct here.
 		//     Or did we agree on changing this in KoralQuery? I can't remember.
+        
+        // EM: Yes, I think it was unequals in the code, and differs in the documentation. 
+        //     So I picked unequals.
+        
 		//     I talked to @bodmo about the interpretation of
 		//     FI: "Linkes und rechtes Wort von X und Y stimmen überein,
 		//          aber nicht alle anderen Wörter"
 		//     and it means we satisfy the first constraint with match and
 		//     the second constraint means, there is at least one word in X
 		//     that is not in Y - so it's "differs".
-		// ND: The classOut seems to be useless here
+        // EM: Ok.
+		
+        // ND: The classOut seems to be useless here
+        // EM: Yes, it is always generated for classRefCheck. 
+        //     What is the criteria that a classOut is needed?
+        
 		// ND: This should fail with a focus requirement on the first operand!
 		// ND: The serialization is correct, though the query optimizer
 		//     should be able to see that no match can satisfy this query when
 		//     X and Y are non-complex operands
+        // EM: You mean query optimizer in Krill?
     }
 
 
@@ -169,6 +175,9 @@
 		// ND: We may not be able to switch defaults, I guess,
 		//     and in the tests above, if I understand correctly, you are already
 		//     using HIT implicitely
+        
+        //EM: right, the implementation assumes HIT as default. should I switch this?
+        
         query = "sich #IN(N,ALL) (&gelten /w5:10 zurecht)";
         qs.setQuery(query, "cosmas2");
         res = mapper.readTree(qs.toJSON());
@@ -239,6 +248,7 @@
         assertEquals("operation:class", res.at("/query/operation").asText());
 
 		// ND: Why did you mark "equals" as wrong?
+        // EM: because you said includes implicitly equals. Is it the other way around?
         assertEquals("classRefCheck:equals",
                 res.at("/query/classRefCheck/0").asText());
         //        assertEquals("classRefCheck:includes",
@@ -284,6 +294,11 @@
 		// ND: I don't think 'includes' is necessary here
         // assertEquals("classRefCheck:includes",
         //        res.at("/query/classRefCheck/1").asText());
+        // EM: now I think includes is always need for F because we need to check 
+        // the the left and the right words, so in this case:
+        // - gilt has to be the identical to &gelten and 
+        // - gilt has to be identical to zurecht.
+        // besides you have a discussion in the position frames doc regarding IN(FI).
         assertEquals(1, res.at("/query/classRefCheck").size());
 
 		// ND: The class 130, in my opinion, somehow invalidates the HIT constraint, right?
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 fca1848..c9a7ab2 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
@@ -58,6 +58,9 @@
 		// ND: I think, this requires
 		//     ["frames:alignsLeft","frames:alignsRight", "frames:matches"]
 		//     and not ["frames:within"] ..
+        
+        // EM: I thought exclusion of ["frames:alignsLeft","frames:alignsRight", "frames:matches"]
+        // is the same as frame:isWithin
     }
 
 
@@ -71,13 +74,13 @@
         assertEquals("koral:group", res.at("/query/@type").asText());
         assertEquals("operation:exclusion",
                 res.at("/query/operation").asText());
-        assertEquals(2, res.at("/query/frames").size());
+        assertEquals(1, 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());
 
 		// ND: I think, frames:matches is wrong here ...
+        // EM: fixed
     }
 
 
@@ -90,11 +93,10 @@
 
         assertEquals("operation:exclusion",
                 res.at("/query/operation").asText());
-        assertEquals(2, res.at("/query/frames").size());
+        assertEquals(1, res.at("/query/frames").size());
         assertEquals("frames:alignsRight", res.at("/query/frames/0").asText());
-        // assertEquals("frames:matches", res.at("/query/frames/1").asText());
-
-		// ND: I think, frames:matches is wrong here ...		
+		// ND: I think, frames:matches is wrong here ...
+        // EM: fixed
 	}
 
 
@@ -143,6 +145,9 @@
 		//       exclusion(['matches'],X,Y),
 		//       focus(1:classRefCheck(['differs',1,2],position(['matches'],{1:X},{2:Y})))
 		//     )
+        
+        // EM: hm, but the second OR operand means X matches Y which is not a correct answer 
+        // (not an exclusion, it should not match).
     }
 
 
@@ -168,6 +173,7 @@
 
     // EM: MIN, MAX does not matter with %
     
+    
     @Test
     public void testOPINwithExclusionFE_MIN ()
             throws JsonProcessingException, IOException {
diff --git a/src/test/java/de/ids_mannheim/korap/test/cosmas2/OPOVWithExclusionTest.java b/src/test/java/de/ids_mannheim/korap/test/cosmas2/OPOVWithExclusionTest.java
index 262b1a1..5a563f7 100644
--- a/src/test/java/de/ids_mannheim/korap/test/cosmas2/OPOVWithExclusionTest.java
+++ b/src/test/java/de/ids_mannheim/korap/test/cosmas2/OPOVWithExclusionTest.java
@@ -75,13 +75,11 @@
         JsonNode classRefCheckOperand = res.at("/query/operands/0");
         assertEquals("operation:exclusion",
                 classRefCheckOperand.at("/operation").asText());
-        assertEquals(3, classRefCheckOperand.at("/frames").size());
-        assertEquals("frames:matches",
-                classRefCheckOperand.at("/frames/0").asText());
+        assertEquals(2, classRefCheckOperand.at("/frames").size());
         assertEquals("frames:alignsLeft",
-                classRefCheckOperand.at("/frames/1").asText());
+                classRefCheckOperand.at("/frames/0").asText());
         assertEquals("frames:overlapsLeft",
-                classRefCheckOperand.at("/frames/2").asText());
+                classRefCheckOperand.at("/frames/1").asText());
         
         JsonNode exclusionOperands = classRefCheckOperand.at("/operands/0");
         assertEquals("operation:class", exclusionOperands.at("/operation").asText());
@@ -114,13 +112,11 @@
         JsonNode classRefCheckOperand = res.at("/query/operands/0");
         assertEquals("operation:exclusion",
                 classRefCheckOperand.at("/operation").asText());
-        assertEquals(3, classRefCheckOperand.at("/frames").size());
-        assertEquals("frames:matches",
-                classRefCheckOperand.at("/frames/0").asText());
+        assertEquals(2, classRefCheckOperand.at("/frames").size());
         assertEquals("frames:alignsRight",
-                classRefCheckOperand.at("/frames/1").asText());
+                classRefCheckOperand.at("/frames/0").asText());
         assertEquals("frames:overlapsRight",
-                classRefCheckOperand.at("/frames/2").asText());
+                classRefCheckOperand.at("/frames/1").asText());
     }
     
     @Test