- Jsonify CosmasTreeTest
- fix single terms in #ELEM attrs
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/CosmasTree.java b/src/main/java/de/ids_mannheim/korap/query/serialize/CosmasTree.java
index eec2cf2..c3c72ca 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/CosmasTree.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/CosmasTree.java
@@ -222,35 +222,30 @@
 
 		if (nodeCat.equals("OPMORPH")) {
 			//Step I: get info
-			String[] morphterms = node.getChild(0).toStringTree().split("&");
+			String[] morphterms = node.getChild(0).toStringTree().replace(" ", "").split("&");
 			LinkedHashMap<String, Object> token = new LinkedHashMap<String, Object>();
 			token.put("@type", "korap:token");
 			ArrayList<Object> terms = new ArrayList<Object>();
 			LinkedHashMap<String, Object> fieldMap = null;
 			for (String morphterm : morphterms) {
+				// regex group #2 is foundry, #4 layer, #5 operator #6 key, #8 value
+				Pattern p = Pattern.compile("((\\w+)/)?((\\w*)(!?=))?(\\w+)(:(\\w+))?");    
+				Matcher m = p.matcher(morphterm);										  
+				if (! m.matches()) {
+					throw new QueryException();
+				}
+				
 				fieldMap = new LinkedHashMap<String, Object>();
 				fieldMap.put("@type", "korap:term");
-				String[] attrval = morphterm.split("=");
-				if (attrval.length == 1) {
-					fieldMap.put("key", morphterm);
-				} else {
-					if (attrval[0].endsWith("!")) {
-						negate = !negate;
-						attrval[0] = attrval[0].replace("!", "");
-					}
-					String[] foundrylayer = attrval[0].split("/");
-					//     			fieldMap.put("key", "morph:"+node.getChild(0).toString().replace(" ", "_"));
-					fieldMap.put("key", attrval[1]);
-					if (foundrylayer.length==1) {
-						fieldMap.put("layer", foundrylayer[0]);
-					} else {
-						fieldMap.put("foundry", foundrylayer[0]);
-						fieldMap.put("layer", foundrylayer[1]);
-					}
+				
+				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 (m.group(6) != null) fieldMap.put("key", m.group(6));
+				if (m.group(8) != null) fieldMap.put("value", m.group(8));
 
-
-				// make category-specific fieldMap entry
 				// negate field (see above)
 				if (negate) {
 					fieldMap.put("match", "match:ne");
@@ -338,6 +333,10 @@
 						}
 						if (getNodeCat(attrNode).equals("NOTEQ")) negate = true;
 					}
+					// possibly only one term was present throughout all nodes: extract it from the group
+					if (termGroupOperands.size()==1) {
+						termGroup = (LinkedHashMap<String, Object>) termGroupOperands.get(0);
+					}
 					span.put("attr", termGroup);
 				}
 			}
@@ -1082,8 +1081,20 @@
 		 */
 		String[] queries = new String[]{
 				/* COSMAS 2 */
-				"Mann:sa,-pa,+te,se",
-				"d*r ($Baum oder $Wald)"
+//				"Mann:sa,-pa,+te,se",
+//				"d*r ($Baum oder $Wald)",
+//				"MORPH(mate/m=temp:pres)",
+//				"MORPH(V)",
+//				"MORPH(p!=V)",
+//				"MORPH(tt/p=V)",
+//				"MORPH(temp:pres)",
+//				"MORPH(a/m=temp:pres)",
+//				"Sonne nicht Mond nicht Sterne",
+//				"(Sonne nicht Mond) nicht Sterne",
+//				"Sonne nicht (Mond oder Sterne)",
+				"#ELEM(W ANA=N)",
+				 "#ELEM(W ANA=N FOO=BAR)",
+				 "#ELEM(W ANA='N V')",
 		};
 //		CosmasTree.verbose=true;
 		for (String q : queries) {
diff --git a/src/test/java/CosmasTreeTest.java b/src/test/java/CosmasTreeTest.java
index ecf0cfc..6085218 100644
--- a/src/test/java/CosmasTreeTest.java
+++ b/src/test/java/CosmasTreeTest.java
@@ -1,1457 +1,1145 @@
 import static org.junit.Assert.*;
 
+import java.io.IOException;
+import java.util.ArrayList;
+
 import org.junit.Test;
 
 import de.ids_mannheim.korap.query.serialize.CosmasTree;
+import de.ids_mannheim.korap.query.serialize.QuerySerializer;
 import de.ids_mannheim.korap.util.QueryException;
 
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+/**
+ * Tests for JSON-LD serialization of Cosmas II queries. 
+ * @author Joachim Bingel (bingel@ids-mannheim.de)
+ * @version 1.0
+ */
+
 public class CosmasTreeTest {
 	
-	CosmasTree ct;
-	String map;
-	String query;
-	String expected;
-	
-	@Test
-	public void testContext() throws QueryException {
-		String contextString = "http://ids-mannheim.de/ns/KorAP/json-ld/v0.2/context.jsonld";
-		ct = new CosmasTree("Test");
-		assertEquals(contextString.replaceAll(" ", ""), ct.getRequestMap().get("@context").toString().replaceAll(" ", ""));
-	}
-	
-	
-	@Test
-	public void testSingleToken() throws QueryException {
-		query="der";
-		String single1 = 
-					"{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-		assertEquals(single1.replaceAll(" ", ""), map.replaceAll(" ", ""));
 
-		query="Mann";
-		String single2 = 
-				"{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-		assertEquals(single2.replaceAll(" ", ""), map.replaceAll(" ", ""));
+	String query;
+	ArrayList<JsonNode> operands;
+
+	QuerySerializer qs = new QuerySerializer();
+	ObjectMapper mapper = new ObjectMapper();
+	JsonNode res;
+	
+	@Test
+	public void testContext() throws QueryException, JsonProcessingException, IOException {
+		String contextString = "http://ids-mannheim.de/ns/KorAP/json-ld/v0.2/context.jsonld";
+		query = "foo";
+		qs.setQuery(query, "cosmas2");
+		res = mapper.readTree(qs.toJSON());
+		assertEquals(contextString, res.get("@context").asText());
+	}
+	
+	
+	@Test
+	public void testSingleToken() throws QueryException, JsonProcessingException, IOException {
+		query = "der";
+		qs.setQuery(query, "cosmas2");
+		res = mapper.readTree(qs.toJSON());
+		assertEquals("korap:token", 		res.at("/query/@type").asText());
+		assertEquals("korap:term", 			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="&Mann";
-		String single3 = 
-				"{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-		assertEquals(single3.replaceAll(" ", ""), map.replaceAll(" ", ""));
+		query = "&Mann";
+		qs.setQuery(query, "cosmas2");
+		res = mapper.readTree(qs.toJSON());
+		assertEquals("korap:token", 		res.at("/query/@type").asText());
+		assertEquals("korap:term", 			res.at("/query/wrap/@type").asText());
+		assertEquals("Mann", 				res.at("/query/wrap/key").asText());
+		assertEquals("lemma", 				res.at("/query/wrap/layer").asText());
+		assertEquals("match:eq",			res.at("/query/wrap/match").asText());
+	}
+		
+
+	
+	@Test
+	public void testWildcardToken() throws QueryException, JsonProcessingException, IOException {
+		query = "*der";
+		qs.setQuery(query, "cosmas2");
+		res = mapper.readTree(qs.toJSON());
+		assertEquals("korap: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("orth", 				res.at("/query/wrap/layer").asText());
+		assertEquals("match:eq",			res.at("/query/wrap/match").asText());
+		
+		query = "*de*?r";
+		qs.setQuery(query, "cosmas2");
+		res = mapper.readTree(qs.toJSON());
+		assertEquals("*de*?r", 				res.at("/query/wrap/key").asText());
+	}
+//	
+	@Test
+	public void testCaseSensitivityFlag() throws QueryException, JsonProcessingException, IOException {
+		query = "$deutscher";
+		qs.setQuery(query, "cosmas2");
+		res = mapper.readTree(qs.toJSON());
+		assertEquals("korap:term", 			res.at("/query/wrap/@type").asText());
+		assertEquals("deutscher",			res.at("/query/wrap/key").asText());
+		assertEquals(true,					res.at("/query/wrap/caseInsensitive").asBoolean());
+		assertEquals("orth", 				res.at("/query/wrap/layer").asText());
+		assertEquals("match:eq",			res.at("/query/wrap/match").asText());
+		
+		query = "$deutscher Bundestag";
+		qs.setQuery(query, "cosmas2");
+		res = mapper.readTree(qs.toJSON());
+		assertEquals("korap:group",			res.at("/query/@type").asText());
+		assertEquals("operation:sequence",	res.at("/query/operation").asText());
+		assertEquals("korap:term", 			res.at("/query/operands/0/wrap/@type").asText());
+		assertEquals("deutscher",			res.at("/query/operands/0/wrap/key").asText());
+		assertEquals(true,					res.at("/query/operands/0/wrap/caseInsensitive").asBoolean());
+		assertEquals("orth", 				res.at("/query/operands/0/wrap/layer").asText());
+		assertEquals("match:eq",			res.at("/query/operands/0/wrap/match").asText());
+		assertEquals("Bundestag",			res.at("/query/operands/1/wrap/key").asText());
+		assertEquals(true,					res.at("/query/operands/1/wrap/caseInsensitive").isMissingNode());
 	}
 	
 	@Test
-	public void testWildcardToken() throws QueryException {
-		query="*der";
-		String wc1 = 
-					"{@type=korap:token, wrap={@type=korap:term, type=type:wildcard, key=*der, layer=orth, match=match:eq}}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-		assertEquals(wc1.replaceAll(" ", ""), map.replaceAll(" ", ""));
+	public void testMORPH() throws QueryException, JsonProcessingException, IOException {
+		query = "MORPH(p=V)";
+		qs.setQuery(query, "cosmas2");
+		res = mapper.readTree(qs.toJSON());
+		assertEquals("korap:token",			res.at("/query/@type").asText());
+		assertEquals("korap:term", 			res.at("/query/wrap/@type").asText());
+		assertEquals("V",					res.at("/query/wrap/key").asText());
+		assertEquals("p",					res.at("/query/wrap/layer").asText());
+		assertEquals("match:eq",			res.at("/query/wrap/match").asText());
+		
+		query = "MORPH(V)";
+		qs.setQuery(query, "cosmas2");
+		res = mapper.readTree(qs.toJSON());
+		assertEquals("korap:token",			res.at("/query/@type").asText());
+		assertEquals("korap:term", 			res.at("/query/wrap/@type").asText());
+		assertEquals("V",					res.at("/query/wrap/key").asText());
+		assertEquals("match:eq",			res.at("/query/wrap/match").asText());
+		
+		query = "MORPH(tt/p=V)";
+		qs.setQuery(query, "cosmas2");
+		res = mapper.readTree(qs.toJSON());
+		assertEquals("korap:token",			res.at("/query/@type").asText());
+		assertEquals("korap:term", 			res.at("/query/wrap/@type").asText());
+		assertEquals("V",					res.at("/query/wrap/key").asText());
+		assertEquals("p",					res.at("/query/wrap/layer").asText());
+		assertEquals("tt",					res.at("/query/wrap/foundry").asText());
+		assertEquals("match:eq",			res.at("/query/wrap/match").asText());
+		
+		query = "MORPH(mate/m=temp:pres)";
+		qs.setQuery(query, "cosmas2");
+		res = mapper.readTree(qs.toJSON());
+		assertEquals("korap:token",			res.at("/query/@type").asText());
+		assertEquals("korap:term", 			res.at("/query/wrap/@type").asText());
+		assertEquals("temp",				res.at("/query/wrap/key").asText());
+		assertEquals("pres",				res.at("/query/wrap/value").asText());
+		assertEquals("m",					res.at("/query/wrap/layer").asText());
+		assertEquals("mate",				res.at("/query/wrap/foundry").asText());
+		assertEquals("match:eq",			res.at("/query/wrap/match").asText());
+		
+		query = "MORPH(tt/p=V & mate/m!=temp:pres)";
+		qs.setQuery(query, "cosmas2");
+		res = mapper.readTree(qs.toJSON());
+		assertEquals("korap:token",			res.at("/query/@type").asText());
+		assertEquals("korap:termGroup",		res.at("/query/wrap/@type").asText());
+		assertEquals("V",					res.at("/query/wrap/operands/0/key").asText());
+		assertEquals("p",					res.at("/query/wrap/operands/0/layer").asText());
+		assertEquals("tt",					res.at("/query/wrap/operands/0/foundry").asText());
+		assertEquals("match:eq",			res.at("/query/wrap/operands/0/match").asText());
+		assertEquals("temp",				res.at("/query/wrap/operands/1/key").asText());
+		assertEquals("pres",				res.at("/query/wrap/operands/1/value").asText());
+		assertEquals("m",					res.at("/query/wrap/operands/1/layer").asText());
+		assertEquals("mate",				res.at("/query/wrap/operands/1/foundry").asText());
+		assertEquals("match:ne",			res.at("/query/wrap/operands/1/match").asText());
 	}
 	
 	@Test
-	public void testCaseSensitivityFlag() throws QueryException {
-		query="$deutscher";
-		String cs1 = 
-				"{@type=korap:token, wrap={@type=korap:term, caseInsensitive=true, key=deutscher, layer=orth, match=match:eq}}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-		assertEquals(cs1.replaceAll(" ", ""), map.replaceAll(" ", ""));
+	public void testSequence() throws QueryException, JsonProcessingException, IOException {
+		query = "der Mann";
+		qs.setQuery(query, "cosmas2");
+		res = mapper.readTree(qs.toJSON());
+		assertEquals("korap:group",			res.at("/query/@type").asText());
+		assertEquals("operation:sequence",	res.at("/query/operation").asText());
+		assertEquals("der",					res.at("/query/operands/0/wrap/key").asText());
+		assertEquals("Mann",				res.at("/query/operands/1/wrap/key").asText());
+		assertEquals(true,					res.at("/query/operands/2").isMissingNode());
 		
-		query="$deutscher Bundestag";
-		String cs2 = 
-				"{@type=korap:group, operation=operation:sequence, operands=[" +
-						"{@type=korap:token, wrap={@type=korap:term, caseInsensitive=true, key=deutscher, layer=orth, match=match:eq}}," +
-						"{@type=korap:token, wrap={@type=korap:term, key=Bundestag, layer=orth, match=match:eq}}" +
-					"]}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-		assertEquals(cs2.replaceAll(" ", ""), map.replaceAll(" ", ""));
+		query = "der Mann schläft";
+		qs.setQuery(query, "cosmas2");
+		res = mapper.readTree(qs.toJSON());
+		assertEquals("korap:group",			res.at("/query/@type").asText());
+		assertEquals("operation:sequence",	res.at("/query/operation").asText());
+		assertEquals("der",					res.at("/query/operands/0/wrap/key").asText());
+		assertEquals("Mann",				res.at("/query/operands/1/wrap/key").asText());
+		assertEquals("schläft",				res.at("/query/operands/2/wrap/key").asText());
+		assertEquals(true,					res.at("/query/operands/3").isMissingNode());
+		
+		query = "der Mann schläft lang";
+		qs.setQuery(query, "cosmas2");
+		res = mapper.readTree(qs.toJSON());
+		assertEquals("korap:group",			res.at("/query/@type").asText());
+		assertEquals("operation:sequence",	res.at("/query/operation").asText());
+		assertEquals("der",					res.at("/query/operands/0/wrap/key").asText());
+		assertEquals("Mann",				res.at("/query/operands/1/wrap/key").asText());
+		assertEquals("schläft",				res.at("/query/operands/2/wrap/key").asText());
+		assertEquals("lang",				res.at("/query/operands/3/wrap/key").asText());
+		assertEquals(true,					res.at("/query/operands/4").isMissingNode());
+		
+		query = "der #ELEM(W)";
+		qs.setQuery(query, "cosmas2");
+		res = mapper.readTree(qs.toJSON());
+		assertEquals("korap:group",			res.at("/query/@type").asText());
+		assertEquals("operation:sequence",	res.at("/query/operation").asText());
+		assertEquals("der",					res.at("/query/operands/0/wrap/key").asText());
+		assertEquals("w",					res.at("/query/operands/1/key").asText());
+		assertEquals("korap:span",			res.at("/query/operands/1/@type").asText());
+		assertEquals(true,					res.at("/query/operands/2").isMissingNode());
+		
+		query = "der #ELEM(W) Mann";
+		qs.setQuery(query, "cosmas2");
+		res = mapper.readTree(qs.toJSON());
+		assertEquals("korap:group",			res.at("/query/@type").asText());
+		assertEquals("operation:sequence",	res.at("/query/operation").asText());
+		assertEquals("der",					res.at("/query/operands/0/wrap/key").asText());
+		assertEquals("w",					res.at("/query/operands/1/key").asText());
+		assertEquals("korap:span",			res.at("/query/operands/1/@type").asText());
+		assertEquals("Mann",				res.at("/query/operands/2/wrap/key").asText());
+		assertEquals(true,					res.at("/query/operands/3").isMissingNode());
+		
+		query = "der MORPH(p=ADJA) Mann";
+		qs.setQuery(query, "cosmas2");
+		res = mapper.readTree(qs.toJSON());
+		assertEquals("korap:group",			res.at("/query/@type").asText());
+		assertEquals("operation:sequence",	res.at("/query/operation").asText());
+		assertEquals("der",					res.at("/query/operands/0/wrap/key").asText());
+		assertEquals("ADJA",				res.at("/query/operands/1/wrap/key").asText());
+		assertEquals("p",					res.at("/query/operands/1/wrap/layer").asText());
+		assertEquals("Mann",				res.at("/query/operands/2/wrap/key").asText());
+		assertEquals(true,					res.at("/query/operands/3").isMissingNode());
+	}
+
+	@Test
+	public void testOPOR() throws QueryException, JsonProcessingException, IOException {
+		query = "Sonne oder Mond";
+		qs.setQuery(query, "cosmas2");
+		res = mapper.readTree(qs.toJSON());
+		assertEquals("korap:group",			res.at("/query/@type").asText());
+		assertEquals("operation:or",		res.at("/query/operation").asText());
+		assertEquals("Sonne",				res.at("/query/operands/0/wrap/key").asText());
+		assertEquals("Mond",				res.at("/query/operands/1/wrap/key").asText());
+		assertEquals(true,					res.at("/query/operands/2").isMissingNode());
+		
+		query = "(Sonne scheint) oder Mond";
+		qs.setQuery(query, "cosmas2");
+		res = mapper.readTree(qs.toJSON());
+		assertEquals("korap:group",			res.at("/query/@type").asText());
+		assertEquals("operation:or",		res.at("/query/operation").asText());
+		assertEquals("korap:group",			res.at("/query/operands/0/@type").asText());
+		assertEquals("operation:sequence",	res.at("/query/operands/0/operation").asText());
+		assertEquals("Sonne",				res.at("/query/operands/0/operands/0/wrap/key").asText());
+		assertEquals("scheint",				res.at("/query/operands/0/operands/1/wrap/key").asText());
+		assertEquals("Mond",				res.at("/query/operands/1/wrap/key").asText());
+		assertEquals(true,					res.at("/query/operands/2").isMissingNode());
+		
+		query = "(Sonne scheint) oder (Mond scheint)";
+		qs.setQuery(query, "cosmas2");
+		res = mapper.readTree(qs.toJSON());
+		assertEquals("korap:group",			res.at("/query/@type").asText());
+		assertEquals("operation:or",		res.at("/query/operation").asText());
+		assertEquals("korap:group",			res.at("/query/operands/0/@type").asText());
+		assertEquals("operation:sequence",	res.at("/query/operands/0/operation").asText());
+		assertEquals("korap:group",			res.at("/query/operands/1/@type").asText());
+		assertEquals("operation:sequence",	res.at("/query/operands/1/operation").asText());
+		assertEquals("Sonne",				res.at("/query/operands/0/operands/0/wrap/key").asText());
+		assertEquals("scheint",				res.at("/query/operands/0/operands/1/wrap/key").asText());
+		assertEquals("Mond",				res.at("/query/operands/1/operands/0/wrap/key").asText());
+		assertEquals("scheint",				res.at("/query/operands/1/operands/1/wrap/key").asText());
+		assertEquals(true,					res.at("/query/operands/2").isMissingNode());
+	}
+
+	@Test
+	public void testOPORAND() throws QueryException, JsonProcessingException, IOException {
+		query = "(Sonne oder Mond) und scheint";
+		qs.setQuery(query, "cosmas2");
+		res = mapper.readTree(qs.toJSON());
+		assertEquals("korap:group",			res.at("/query/@type").asText());
+		assertEquals("operation:sequence",	res.at("/query/operation").asText());
+		assertEquals("cosmas:distance",		res.at("/query/distances/0/@type").asText());
+		assertEquals("t",					res.at("/query/distances/0/key").asText());
+		assertEquals(0,						res.at("/query/distances/0/min").asInt());
+		assertEquals(0,						res.at("/query/distances/0/max").asInt());
+		assertEquals("korap:group",			res.at("/query/operands/0/@type").asText());
+		assertEquals("operation:or",		res.at("/query/operands/0/operation").asText());
+		assertEquals("Sonne",				res.at("/query/operands/0/operands/0/wrap/key").asText());
+		assertEquals("Mond",				res.at("/query/operands/0/operands/1/wrap/key").asText());
+		assertEquals("korap:token",			res.at("/query/operands/1/@type").asText());
+		assertEquals("scheint",				res.at("/query/operands/1/wrap/key").asText());
+		
+		query = "scheint und (Sonne oder Mond)";
+		qs.setQuery(query, "cosmas2");
+		res = mapper.readTree(qs.toJSON());
+		assertEquals("korap:group",			res.at("/query/@type").asText());
+		assertEquals("operation:sequence",	res.at("/query/operation").asText());
+		assertEquals("cosmas:distance",		res.at("/query/distances/0/@type").asText());
+		assertEquals("t",					res.at("/query/distances/0/key").asText());
+		assertEquals(0,						res.at("/query/distances/0/min").asInt());
+		assertEquals(0,						res.at("/query/distances/0/max").asInt());
+		assertEquals("korap:token",			res.at("/query/operands/0/@type").asText());
+		assertEquals("scheint",				res.at("/query/operands/0/wrap/key").asText());
+		assertEquals("korap:group",			res.at("/query/operands/1/@type").asText());
+		assertEquals("operation:or",		res.at("/query/operands/1/operation").asText());
+		assertEquals("Sonne",				res.at("/query/operands/1/operands/0/wrap/key").asText());
+		assertEquals("Mond",				res.at("/query/operands/1/operands/1/wrap/key").asText());
+		
+		query = "Regen und scheint und (Sonne oder Mond)";
+		qs.setQuery(query, "cosmas2");
+		res = mapper.readTree(qs.toJSON());
+		assertEquals("korap:group",			res.at("/query/@type").asText());
+		assertEquals("operation:sequence",	res.at("/query/operation").asText());
+		assertEquals("cosmas:distance",		res.at("/query/distances/0/@type").asText());
+		assertEquals("t",					res.at("/query/distances/0/key").asText());
+		assertEquals(0,						res.at("/query/distances/0/min").asInt());
+		assertEquals(0,						res.at("/query/distances/0/max").asInt());
+		assertEquals("korap:token",			res.at("/query/operands/0/@type").asText());
+		assertEquals("Regen",				res.at("/query/operands/0/wrap/key").asText());
+		assertEquals("korap:group",			res.at("/query/@type").asText());
+		assertEquals("operation:sequence",	res.at("/query/operation").asText());
+		assertEquals("cosmas:distance",		res.at("/query/operands/1/distances/0/@type").asText());
+		assertEquals("t",					res.at("/query/operands/1/distances/0/key").asText());
+		assertEquals(0,						res.at("/query/operands/1/distances/0/min").asInt());
+		assertEquals(0,						res.at("/query/operands/1/distances/0/max").asInt());
+		assertEquals("scheint",				res.at("/query/operands/1/operands/0/wrap/key").asText());
+		assertEquals("korap:group",			res.at("/query/operands/1/operands/1/@type").asText());
+		assertEquals("operation:or",		res.at("/query/operands/1/operands/1/operation").asText());
+		assertEquals("Sonne",				res.at("/query/operands/1/operands/1/operands/0/wrap/key").asText());
+		assertEquals("Mond",				res.at("/query/operands/1/operands/1/operands/1/wrap/key").asText());
 	}
 	
 	@Test
-	public void testMORPH() throws QueryException {
-		query="MORPH(pos=V)";
-		String morph1 = 
-					"{@type=korap:token, wrap={@type=korap:term, key=V, layer=pos, match=match:eq}}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-		assertEquals(morph1.replaceAll(" ", ""), map.replaceAll(" ", ""));
+	public void testOPNOT() throws QueryException, JsonProcessingException, IOException {
+		query = "Sonne nicht Mond";
+		qs.setQuery(query, "cosmas2");
+		res = mapper.readTree(qs.toJSON());
+		assertEquals("korap:group",			res.at("/query/@type").asText());
+		assertEquals("operation:sequence",	res.at("/query/operation").asText());
+		assertEquals("cosmas:distance",		res.at("/query/distances/0/@type").asText());
+		assertEquals("t",					res.at("/query/distances/0/key").asText());
+		assertEquals(0,						res.at("/query/distances/0/min").asInt());
+		assertEquals(0,						res.at("/query/distances/0/max").asInt());
+		assertEquals(true,					res.at("/query/distances/0/exclude").asBoolean());
+		assertEquals("korap:token",			res.at("/query/operands/0/@type").asText());
+		assertEquals("Sonne",				res.at("/query/operands/0/wrap/key").asText());
+		assertEquals("Mond",				res.at("/query/operands/1/wrap/key").asText());
 		
-		query="MORPH(V)";
-		expected = 
-					"{@type=korap:token, wrap={@type=korap:term, key=V, match=match:eq}}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-		assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
+		query = "Sonne nicht Mond nicht Sterne";
+		qs.setQuery(query, "cosmas2");
+		res = mapper.readTree(qs.toJSON());
+		assertEquals("korap:group",			res.at("/query/@type").asText());
+		assertEquals("operation:sequence",	res.at("/query/operation").asText());
+		assertEquals("cosmas:distance",		res.at("/query/distances/0/@type").asText());
+		assertEquals("t",					res.at("/query/distances/0/key").asText());
+		assertEquals(0,						res.at("/query/distances/0/min").asInt());
+		assertEquals(0,						res.at("/query/distances/0/max").asInt());
+		assertEquals(true,					res.at("/query/distances/0/exclude").asBoolean());
+		assertEquals("korap:token",			res.at("/query/operands/0/@type").asText());
+		assertEquals("Sonne",				res.at("/query/operands/0/wrap/key").asText());
+		assertEquals("korap:group",			res.at("/query/operands/1/@type").asText());
+		assertEquals("operation:sequence",	res.at("/query/operands/1/operation").asText());
+		assertEquals("cosmas:distance",		res.at("/query/operands/1/distances/0/@type").asText());
+		assertEquals("t",					res.at("/query/operands/1/distances/0/key").asText());
+		assertEquals(0,						res.at("/query/operands/1/distances/0/min").asInt());
+		assertEquals(0,						res.at("/query/operands/1/distances/0/max").asInt());
+		assertEquals(true,					res.at("/query/operands/1/distances/0/exclude").asBoolean());
+		assertEquals("Mond",				res.at("/query/operands/1/operands/0/wrap/key").asText());
+		assertEquals("Sterne",				res.at("/query/operands/1/operands/1/wrap/key").asText());
+		
+		query = "(Sonne nicht Mond) nicht Sterne";
+		qs.setQuery(query, "cosmas2");
+		res = mapper.readTree(qs.toJSON());
+		assertEquals("korap:group",			res.at("/query/@type").asText());
+		assertEquals("operation:sequence",	res.at("/query/operation").asText());
+		assertEquals("cosmas:distance",		res.at("/query/distances/0/@type").asText());
+		assertEquals("t",					res.at("/query/distances/0/key").asText());
+		assertEquals(0,						res.at("/query/distances/0/min").asInt());
+		assertEquals(0,						res.at("/query/distances/0/max").asInt());
+		assertEquals(true,					res.at("/query/distances/0/exclude").asBoolean());
+		assertEquals("korap:group",			res.at("/query/operands/0/@type").asText());
+		assertEquals("operation:sequence",	res.at("/query/operands/0/operation").asText());
+		assertEquals("cosmas:distance",		res.at("/query/operands/0/distances/0/@type").asText());
+		assertEquals("t",					res.at("/query/operands/0/distances/0/key").asText());
+		assertEquals(0,						res.at("/query/operands/0/distances/0/min").asInt());
+		assertEquals(0,						res.at("/query/operands/0/distances/0/max").asInt());
+		assertEquals(true,					res.at("/query/operands/0/distances/0/exclude").asBoolean());
+		assertEquals("Sonne",				res.at("/query/operands/0/operands/0/wrap/key").asText());
+		assertEquals("Mond",				res.at("/query/operands/0/operands/1/wrap/key").asText());
+		assertEquals("korap:token",			res.at("/query/operands/1/@type").asText());
+		assertEquals("Sterne",				res.at("/query/operands/1/wrap/key").asText());
 	}
 	
 	@Test
-	public void testSequence() throws QueryException {
-		query="der Mann";
-		String seq1 = 
-				"{@type=korap:group, operation=operation:sequence, operands=[" +
-					"{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
-					"{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
-				"]}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-		assertEquals(seq1.replaceAll(" ", ""), map.replaceAll(" ", ""));
+	public void testOPPROX() throws QueryException, JsonProcessingException, IOException {
+		query = "Sonne /+w1:4 Mond";
+		qs.setQuery(query, "cosmas2");
+		res = mapper.readTree(qs.toJSON());
+		assertEquals("korap:reference",		res.at("/query/@type").asText());
+		assertEquals("operation:focus",		res.at("/query/operation").asText());
+		assertEquals(129,					res.at("/query/classRef/0").asInt());
+		assertEquals("korap:group",			res.at("/query/operands/0/@type").asText());
+		assertEquals("operation:sequence",	res.at("/query/operands/0/operation").asText());
+		assertEquals("korap:distance",		res.at("/query/operands/0/distances/0/@type").asText());
+		assertEquals("w",					res.at("/query/operands/0/distances/0/key").asText());
+		assertEquals(1,						res.at("/query/operands/0/distances/0/boundary/min").asInt());
+		assertEquals(4,						res.at("/query/operands/0/distances/0/boundary/max").asInt());
+		assertEquals(true,					res.at("/query/operands/0/inOrder").asBoolean());
+		assertEquals("korap:group",			res.at("/query/operands/0/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(129,					res.at("/query/operands/0/operands/1/classOut").asInt());
+		assertEquals("korap:token",			res.at("/query/operands/0/operands/0/operands/0/@type").asText());
+		assertEquals("Sonne",				res.at("/query/operands/0/operands/0/operands/0/wrap/key").asText());
+		assertEquals("Mond",				res.at("/query/operands/0/operands/1/operands/0/wrap/key").asText());
 		
-		query="der Mann schläft";
-		String seq2 = 
-				"{@type=korap:group, operation=operation:sequence, operands=[" +
-					"{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
-					"{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}," +
-					"{@type=korap:token, wrap={@type=korap:term, key=schläft, layer=orth, match=match:eq}}" +
-				"]}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-		assertEquals(seq2.replaceAll(" ", ""), map.replaceAll(" ", ""));
+		query = "Sonne /+w1:4,s0,p1:3 Mond";
+		qs.setQuery(query, "cosmas2");
+		res = mapper.readTree(qs.toJSON());
+		assertEquals("korap:reference",		res.at("/query/@type").asText());
+		assertEquals("operation:focus",		res.at("/query/operation").asText());
+		assertEquals(129,					res.at("/query/classRef/0").asInt());
+		assertEquals("korap:group",			res.at("/query/operands/0/@type").asText());
+		assertEquals("operation:sequence",	res.at("/query/operands/0/operation").asText());
+		assertEquals("korap:distance",		res.at("/query/operands/0/distances/0/@type").asText());
+		assertEquals("w",					res.at("/query/operands/0/distances/0/key").asText());
+		assertEquals(1,						res.at("/query/operands/0/distances/0/boundary/min").asInt());
+		assertEquals(4,						res.at("/query/operands/0/distances/0/boundary/max").asInt());
+		assertEquals("s",					res.at("/query/operands/0/distances/1/key").asText());
+		assertEquals(0,						res.at("/query/operands/0/distances/1/boundary/min").asInt());
+		assertEquals("p",					res.at("/query/operands/0/distances/2/key").asText());
+		assertEquals(1,						res.at("/query/operands/0/distances/2/boundary/min").asInt());
+		assertEquals(3,						res.at("/query/operands/0/distances/2/boundary/max").asInt());
+		assertEquals(true,					res.at("/query/operands/0/inOrder").asBoolean());
+		assertEquals("korap:group",			res.at("/query/operands/0/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(129,					res.at("/query/operands/0/operands/1/classOut").asInt());
+		assertEquals("korap:token",			res.at("/query/operands/0/operands/0/operands/0/@type").asText());
+		assertEquals("Sonne",				res.at("/query/operands/0/operands/0/operands/0/wrap/key").asText());
+		assertEquals("Mond",				res.at("/query/operands/0/operands/1/operands/0/wrap/key").asText());
 		
-		query="der Mann schläft lang";
-		String seq3 = 
-				"{@type=korap:group, operation=operation:sequence, operands=[" +
-					"{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
-					"{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}," +
-					"{@type=korap:token, wrap={@type=korap:term, key=schläft, layer=orth, match=match:eq}}," +
-					"{@type=korap:token, wrap={@type=korap:term, key=lang, layer=orth, match=match:eq}}" +
-				"]}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-		assertEquals(seq3.replaceAll(" ", ""), map.replaceAll(" ", ""));
+		query = "Sonne /+w4 Mond";
+		qs.setQuery(query, "cosmas2");
+		res = mapper.readTree(qs.toJSON());
+		assertEquals("korap:distance",		res.at("/query/operands/0/distances/0/@type").asText());
+		assertEquals("w",					res.at("/query/operands/0/distances/0/key").asText());
+		assertEquals(0,						res.at("/query/operands/0/distances/0/boundary/min").asInt());
+		assertEquals(4,						res.at("/query/operands/0/distances/0/boundary/max").asInt());
 		
-		query="der #ELEM(S)";
-		expected = 
-				"{@type=korap:group, operation=operation:sequence, operands=[" +
-					"{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
-					"{@type=korap:span, key=s}" +
-				"]}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-		assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
+		query = "Sonne /-w4 Mond";
+		qs.setQuery(query, "cosmas2");
+		res = mapper.readTree(qs.toJSON());
+		assertEquals("korap:distance",		res.at("/query/operands/0/distances/0/@type").asText());
+		assertEquals("w",					res.at("/query/operands/0/distances/0/key").asText());
+		assertEquals(0,						res.at("/query/operands/0/distances/0/boundary/min").asInt());
+		assertEquals(4,						res.at("/query/operands/0/distances/0/boundary/max").asInt());
+		assertEquals("Mond",				res.at("/query/operands/0/operands/0/operands/0/wrap/key").asText());
+		assertEquals("Sonne",				res.at("/query/operands/0/operands/1/operands/0/wrap/key").asText());
 		
-		query="der MORPH(mate/p=ADJA)";
-		expected = 
-				"{@type=korap:group, operation=operation:sequence, operands=[" +
-					"{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
-					"{@type=korap:token, wrap={@type=korap:term, key=ADJA, foundry=mate, layer=p, match=match:eq}}" +
-				"]}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-		assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
+		query = "Sonne /w4 Mond";
+		qs.setQuery(query, "cosmas2");
+		res = mapper.readTree(qs.toJSON());
+		assertEquals("korap:distance",		res.at("/query/operands/0/distances/0/@type").asText());
+		assertEquals("w",					res.at("/query/operands/0/distances/0/key").asText());
+		assertEquals(0,						res.at("/query/operands/0/distances/0/boundary/min").asInt());
+		assertEquals(4,						res.at("/query/operands/0/distances/0/boundary/max").asInt());
+		assertEquals("Sonne",				res.at("/query/operands/0/operands/0/operands/0/wrap/key").asText());
+		assertEquals("Mond",				res.at("/query/operands/0/operands/1/operands/0/wrap/key").asText());
+		assertEquals(false,					res.at("/query/operands/0/inOrder").asBoolean());
 	}
 	
 	@Test
-	public void testOPOR() throws QueryException {
-		query="Sonne oder Mond";
-		String disj1 = 
-					"{@type=korap:group, operation=operation:or, operands=[" +
-						"{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}," +
-						"{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
-					"]}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-		assertEquals(disj1.replaceAll(" ", ""), map.replaceAll(" ", ""));
+	public void testOPPROXNested() throws QueryException, JsonProcessingException, IOException {	
+		query = "Sonne /+w1:4 Mond /+w1:7 Sterne";
+		qs.setQuery(query, "cosmas2");
+		res = mapper.readTree(qs.toJSON());
+		assertEquals("korap:reference",		res.at("/query/@type").asText());
+		assertEquals("operation:focus",		res.at("/query/operation").asText());
+		assertEquals(129,					res.at("/query/classRef/0").asInt());
+		assertEquals("korap:group",			res.at("/query/operands/0/@type").asText());
+		assertEquals("operation:sequence",	res.at("/query/operands/0/operation").asText());
+		assertEquals("korap:distance",		res.at("/query/operands/0/distances/0/@type").asText());
+		assertEquals("w",					res.at("/query/operands/0/distances/0/key").asText());
+		assertEquals(1,						res.at("/query/operands/0/distances/0/boundary/min").asInt());
+		assertEquals(4,						res.at("/query/operands/0/distances/0/boundary/max").asInt());
+		assertEquals(true,					res.at("/query/operands/0/inOrder").asBoolean());
+		assertEquals("korap:group",			res.at("/query/operands/0/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("Sonne",				res.at("/query/operands/0/operands/0/operands/0/wrap/key").asText());
+		assertEquals(129,					res.at("/query/operands/0/operands/1/classOut").asInt());
+		assertEquals("korap:reference",		res.at("/query/operands/0/operands/1/operands/0/@type").asText());
+		assertEquals(130,					res.at("/query/operands/0/operands/1/operands/0/classRef/0").asInt());
+		assertEquals("operation:focus",		res.at("/query/operands/0/operands/1/operands/0/operation").asText());
+		assertEquals("operation:sequence",	res.at("/query/operands/0/operands/1/operands/0/operands/0/operation").asText());
+		assertEquals("w",					res.at("/query/operands/0/operands/1/operands/0/operands/0/distances/0/key").asText());
+		assertEquals(1,						res.at("/query/operands/0/operands/1/operands/0/operands/0/distances/0/boundary/min").asInt());
+		assertEquals(7,						res.at("/query/operands/0/operands/1/operands/0/operands/0/distances/0/boundary/max").asInt());
+		assertEquals(130,					res.at("/query/operands/0/operands/1/operands/0/operands/0/operands/0/classOut").asInt());
+		assertEquals("Mond",				res.at("/query/operands/0/operands/1/operands/0/operands/0/operands/0/operands/0/wrap/key").asText());
+		assertEquals(130,					res.at("/query/operands/0/operands/1/operands/0/operands/0/operands/1/classOut").asInt());
+		assertEquals("Sterne",				res.at("/query/operands/0/operands/1/operands/0/operands/0/operands/1/operands/0/wrap/key").asText());
 		
-		query="(Sonne scheint) oder Mond";
-		String disj2 = 
-					"{@type=korap:group, operation=operation:or, operands=[" +
-						"{@type=korap:group, operation=operation:sequence, operands=[" +
-							"{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}," +
-							"{@type=korap:token, wrap={@type=korap:term, key=scheint, layer=orth, match=match:eq}}" +
-						"]}," +
-						"{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
-					"]}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-		assertEquals(disj2.replaceAll(" ", ""), map.replaceAll(" ", ""));
+		query = "Sonne /+w1:4 Mond /-w1:7 Sterne";
+		qs.setQuery(query, "cosmas2");
+		res = mapper.readTree(qs.toJSON());
+		assertEquals("Sonne",				res.at("/query/operands/0/operands/0/operands/0/wrap/key").asText());
+		assertEquals("Sterne",				res.at("/query/operands/0/operands/1/operands/0/operands/0/operands/0/operands/0/wrap/key").asText());
+		assertEquals("Mond",				res.at("/query/operands/0/operands/1/operands/0/operands/0/operands/1/operands/0/wrap/key").asText());
 		
-		query="(Sonne scheint) oder (Mond scheint)";
-		String disj3 = 
-				"{@type=korap:group, operation=operation:or, operands=[" +
-						"{@type=korap:group, operation=operation:sequence, operands=[" +
-							"{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}," +
-							"{@type=korap:token, wrap={@type=korap:term, key=scheint, layer=orth, match=match:eq}}" +
-						"]}," +
-						"{@type=korap:group, operation=operation:sequence, operands=[" +
-							"{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}," +
-							"{@type=korap:token, wrap={@type=korap:term, key=scheint, layer=orth, match=match:eq}}" +
-						"]}" +
-					"]}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-		assertEquals(disj3.replaceAll(" ", ""), map.replaceAll(" ", ""));
+		query = "Sonne /-w4 Mond /+w2 Sterne";
+		qs.setQuery(query, "cosmas2");
+		res = mapper.readTree(qs.toJSON());
+		assertEquals("korap:reference",		res.at("/query/@type").asText());
+		assertEquals("operation:focus",		res.at("/query/operation").asText());
+		assertEquals(129,					res.at("/query/classRef/0").asInt());
+		assertEquals("korap:group",			res.at("/query/operands/0/@type").asText());
+		assertEquals("operation:sequence",	res.at("/query/operands/0/operation").asText());
+		assertEquals("korap:distance",		res.at("/query/operands/0/distances/0/@type").asText());
+		assertEquals("w",					res.at("/query/operands/0/distances/0/key").asText());
+		assertEquals(0,						res.at("/query/operands/0/distances/0/boundary/min").asInt());
+		assertEquals(4,						res.at("/query/operands/0/distances/0/boundary/max").asInt());
+		assertEquals(true,					res.at("/query/operands/0/inOrder").asBoolean());
+		assertEquals("korap:group",			res.at("/query/operands/0/operands/1/@type").asText());
+		assertEquals("operation:class",		res.at("/query/operands/0/operands/1/operation").asText());
+		assertEquals(129,					res.at("/query/operands/0/operands/1/classOut").asInt());
+		assertEquals("Sonne",				res.at("/query/operands/0/operands/1/operands/0/wrap/key").asText());
+		assertEquals(129,					res.at("/query/operands/0/operands/0/classOut").asInt());
+		assertEquals("korap:reference",		res.at("/query/operands/0/operands/0/operands/0/@type").asText());
+		assertEquals(130,					res.at("/query/operands/0/operands/0/operands/0/classRef/0").asInt());
+		assertEquals("operation:focus",		res.at("/query/operands/0/operands/0/operands/0/operation").asText());
+		assertEquals("operation:sequence",	res.at("/query/operands/0/operands/0/operands/0/operands/0/operation").asText());
+		assertEquals("w",					res.at("/query/operands/0/operands/0/operands/0/operands/0/distances/0/key").asText());
+		assertEquals(0,						res.at("/query/operands/0/operands/0/operands/0/operands/0/distances/0/boundary/min").asInt());
+		assertEquals(2,						res.at("/query/operands/0/operands/0/operands/0/operands/0/distances/0/boundary/max").asInt());
+		assertEquals(130,					res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/0/classOut").asInt());
+		assertEquals("Mond",				res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/0/operands/0/wrap/key").asText());
+		assertEquals(130,					res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/1/classOut").asInt());
+		assertEquals("Sterne",				res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/1/operands/0/wrap/key").asText());
+
+	}
+	
+	@Test
+	public void testOPIN() throws QueryException, JsonProcessingException, IOException {
+		query = "wegen #IN <s>";
+		qs.setQuery(query, "cosmas2");
+		res = mapper.readTree(qs.toJSON());
+		assertEquals("korap:reference",				res.at("/query/@type").asText());
+		assertEquals("operation:focus",				res.at("/query/operation").asText());
+		assertEquals(130,							res.at("/query/classRef/0").asInt());
+		assertEquals("korap: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").asText());
+		assertEquals("korap: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("korap: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("korap: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/key").asText());
+		assertEquals("korap: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("korap: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());
+		
+		query = "wegen #IN(L) <s>";
+		qs.setQuery(query, "cosmas2");
+		res = mapper.readTree(qs.toJSON());
+		assertEquals("classRefCheck:includes",		res.at("/query/operands/0/classRefCheck").asText());
+		assertEquals("frames:startswith",			res.at("/query/operands/0/operands/0/frames/0").asText());
+		assertEquals(true,							res.at("/query/operands/0/operands/0/frames/1").isMissingNode());
+		
+		query = "wegen #IN(F) <s>";
+		qs.setQuery(query, "cosmas2");
+		res = mapper.readTree(qs.toJSON());
+		assertEquals("classRefCheck:includes",		res.at("/query/operands/0/classRefCheck").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());
+		
+		query = "wegen #IN(FI) <s>";
+		qs.setQuery(query, "cosmas2");
+		res = mapper.readTree(qs.toJSON());
+		assertEquals("classRefCheck:unequals",		res.at("/query/operands/0/classRefCheck/0").asText());
+		assertEquals("classRefCheck:includes",		res.at("/query/operands/0/classRefCheck/1").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());
+		
+		query = "wegen #IN(FE) <s>";
+		qs.setQuery(query, "cosmas2");
+		res = mapper.readTree(qs.toJSON());
+		assertEquals("classRefCheck:equals",		res.at("/query/operands/0/classRefCheck").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());
+		
+		query = "wegen #IN(%, L) <s>";
+		qs.setQuery(query, "cosmas2");
+		res = mapper.readTree(qs.toJSON());
+		assertEquals("classRefCheck:includes",		res.at("/query/operands/0/classRefCheck").asText());
+		assertEquals("frames:startswith",			res.at("/query/operands/0/operands/0/frames/0").asText());
+		assertEquals(true,							res.at("/query/operands/0/operands/0/frames/1").isMissingNode());
+		assertEquals(true,							res.at("/query/operands/0/operands/0/exclude").asBoolean());
+		
+		query = "wegen #IN(FE,ALL,%,MIN) <s>";
+		qs.setQuery(query, "cosmas2");
+		res = mapper.readTree(qs.toJSON());
+		assertEquals(true,							res.at("/query/reset").asBoolean());
+		assertEquals("classRefCheck:equals",		res.at("/query/operands/0/classRefCheck").asText());
+		assertEquals("frames:matches",				res.at("/query/operands/0/operands/0/frames/0").asText());
+		assertEquals(true,							res.at("/query/operands/0/operands/0/exclude").asBoolean());
 		
 	}
 	
 	@Test
-	public void testOPORAND() throws QueryException {
-		query="(Sonne oder Mond) und scheint";
-		String orand1 = 
-				"{@type=korap:group, operation=operation:sequence, distances=[" +
-					"{@type=cosmas:distance, key=t, min=0, max=0}" +
-					"], operands=[" +
-						"{@type=korap:group, operation=operation:or, operands=[" +
-							"{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}," +
-							"{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
-						"]}," +
-						"{@type=korap:token, wrap={@type=korap:term, key=scheint, layer=orth, match=match:eq}}" +
-				"]}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-		assertEquals(orand1.replaceAll(" ", ""), map.replaceAll(" ", ""));
+	public void testOPOV() throws QueryException, JsonProcessingException, IOException {
+		query = "wegen #OV <s>";
+		qs.setQuery(query, "cosmas2");
+		res = mapper.readTree(qs.toJSON());
+		assertEquals("korap:reference",				res.at("/query/@type").asText());
+		assertEquals("operation:focus",				res.at("/query/operation").asText());
+		assertEquals(130,							res.at("/query/classRef/0").asInt());
+		assertEquals("korap:group",					res.at("/query/operands/0/@type").asText());
+		assertEquals("operation:class",				res.at("/query/operands/0/operation").asText());
+		assertEquals("classRefCheck:intersects",	res.at("/query/operands/0/classRefCheck").asText());
+		assertEquals("korap: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("korap: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("korap: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/key").asText());
+		assertEquals("korap: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("korap: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());
 		
-		query="scheint und (Sonne oder Mond)";
-		String orand2 = 
-				"{@type=korap:group, operation=operation:sequence, distances=[" +
-						"{@type=cosmas:distance, key=t, min=0, max=0}" +
-					"], operands=[" +
-						"{@type=korap:token, wrap={@type=korap:term, key=scheint, layer=orth, match=match:eq}}," +
-						"{@type=korap:group, operation=operation:or, operands=[" +
-							"{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}," +
-							"{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
-					"]}" +
-				"]}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-		assertEquals(orand2.replaceAll(" ", ""), map.replaceAll(" ", ""));
+		query = "wegen #OV(L) <s>";
+		qs.setQuery(query, "cosmas2");
+		res = mapper.readTree(qs.toJSON());
+		assertEquals("classRefCheck:intersects",	res.at("/query/operands/0/classRefCheck").asText());
+		assertEquals("frames:startswith",			res.at("/query/operands/0/operands/0/frames/0").asText());
+		assertEquals("frames:overlapsLeft",			res.at("/query/operands/0/operands/0/frames/1").asText());
 		
-		query="Regen und scheint und (Sonne oder Mond)";
-		String orand3 = 
-				"{@type=korap:group, operation=operation:sequence, distances=[" +
-						"{@type=cosmas:distance, key=t, min=0, max=0}" +
-				"], operands=[" +
-					"{@type=korap:token, wrap={@type=korap:term, key=Regen, layer=orth, match=match:eq}}," +
-					"{@type=korap:group, operation=operation:sequence, distances=[" +
-							"{@type=cosmas:distance, key=t, min=0, max=0}" +
-						"], operands=[" +
-							"{@type=korap:token, wrap={@type=korap:term, key=scheint, layer=orth, match=match:eq}}," +
-							"{@type=korap:group, operation=operation:or, operands=[" +
-								"{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}," +
-								"{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
-						"]}" +
-					"]}" +
-				"]}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-		assertEquals(orand3.replaceAll(" ", ""), map.replaceAll(" ", ""));
+		query = "wegen #OV(F) <s>";
+		qs.setQuery(query, "cosmas2");
+		res = mapper.readTree(qs.toJSON());
+		assertEquals("classRefCheck:intersects",	res.at("/query/operands/0/classRefCheck").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());
+		
+		query = "wegen #OV(FI) <s>";
+		qs.setQuery(query, "cosmas2");
+		res = mapper.readTree(qs.toJSON());
+		assertEquals("classRefCheck:unequals",		res.at("/query/operands/0/classRefCheck").asText());
+		assertEquals("frames:matches",				res.at("/query/operands/0/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").asText());
+		assertEquals("frames:matches",				res.at("/query/operands/0/operands/0/frames/0").asText());
+	}
+
+	
+	@Test
+	public void testBEG_END() throws QueryException, JsonProcessingException, IOException {
+		query = "#BEG(der /w3:5 Mann)";
+		qs.setQuery(query, "cosmas2");
+		res = mapper.readTree(qs.toJSON());
+		assertEquals("korap:reference",		res.at("/query/@type").asText());
+		assertEquals("operation:focus",		res.at("/query/operation").asText());
+		assertEquals(0,						res.at("/query/spanRef/0").asInt());
+		assertEquals(1,						res.at("/query/spanRef/1").asInt());
+		assertEquals("korap:group",			res.at("/query/operands/0/@type").asText());
+		assertEquals("operation:sequence",	res.at("/query/operands/0/operation").asText());
+		assertEquals("korap:distance",		res.at("/query/operands/0/distances/0/@type").asText());
+		assertEquals("w",					res.at("/query/operands/0/distances/0/key").asText());
+		assertEquals(3,						res.at("/query/operands/0/distances/0/boundary/min").asInt());
+		assertEquals(5,						res.at("/query/operands/0/distances/0/boundary/max").asInt());
+		assertEquals(false,					res.at("/query/operands/0/inOrder").asBoolean());
+		assertEquals("korap:token",			res.at("/query/operands/0/operands/0/@type").asText());
+		assertEquals("der",					res.at("/query/operands/0/operands/0/wrap/key").asText());
+		assertEquals("Mann",				res.at("/query/operands/0/operands/1/wrap/key").asText());
+		
+		query = "#BEG(der /w3:5 Mann) /+w10 kommt";
+		qs.setQuery(query, "cosmas2");
+		res = mapper.readTree(qs.toJSON());
+		assertEquals("korap:reference",		res.at("/query/@type").asText());
+		assertEquals("operation:focus",		res.at("/query/operation").asText());
+		assertEquals(129,					res.at("/query/classRef/0").asInt());
+		assertEquals("korap:group",			res.at("/query/operands/0/@type").asText());
+		assertEquals("operation:sequence",	res.at("/query/operands/0/operation").asText());
+		assertEquals("korap:distance",		res.at("/query/operands/0/distances/0/@type").asText());
+		assertEquals("w",					res.at("/query/operands/0/distances/0/key").asText());
+		assertEquals(0,						res.at("/query/operands/0/distances/0/boundary/min").asInt());
+		assertEquals(10,					res.at("/query/operands/0/distances/0/boundary/max").asInt());
+		assertEquals(true,					res.at("/query/operands/0/inOrder").asBoolean());
+		assertEquals("korap:group",			res.at("/query/operands/0/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("korap:reference",		res.at("/query/operands/0/operands/0/operands/0/@type").asText());
+		assertEquals("operation:focus",		res.at("/query/operands/0/operands/0/operands/0/operation").asText());
+		assertEquals(0,						res.at("/query/operands/0/operands/0/operands/0/spanRef/0").asInt());
+		assertEquals(1,						res.at("/query/operands/0/operands/0/operands/0/spanRef/1").asInt());
+		assertEquals("korap:group",			res.at("/query/operands/0/operands/0/operands/0/operands/0/@type").asText());
+		assertEquals("operation:sequence",	res.at("/query/operands/0/operands/0/operands/0/operands/0/operation").asText());
+		assertEquals("korap:distance",		res.at("/query/operands/0/operands/0/operands/0/operands/0/distances/0/@type").asText());
+		assertEquals("w",					res.at("/query/operands/0/operands/0/operands/0/operands/0/distances/0/key").asText());
+		assertEquals(3,						res.at("/query/operands/0/operands/0/operands/0/operands/0/distances/0/boundary/min").asInt());
+		assertEquals(5,						res.at("/query/operands/0/operands/0/operands/0/operands/0/distances/0/boundary/max").asInt());
+		assertEquals(false,					res.at("/query/operands/0/operands/0/operands/0/operands/0/inOrder").asBoolean());
+		assertEquals("korap:token",			res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/0/@type").asText());
+		assertEquals("der",					res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/0/wrap/key").asText());
+		assertEquals("Mann",				res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/1/wrap/key").asText());
+		assertEquals("operation:class",		res.at("/query/operands/0/operands/1/operation").asText());
+		assertEquals(129,					res.at("/query/operands/0/operands/1/classOut").asInt());
+		assertEquals("korap:token",			res.at("/query/operands/0/operands/1/operands/0/@type").asText());
+		assertEquals("kommt",				res.at("/query/operands/0/operands/1/operands/0/wrap/key").asText());
+		
+		query = "kommt /+w10 #BEG(der /w3:5 Mann)";
+		qs.setQuery(query, "cosmas2");
+		res = mapper.readTree(qs.toJSON());
+		assertEquals("korap:reference",		res.at("/query/@type").asText());
+		assertEquals("operation:focus",		res.at("/query/operation").asText());
+		assertEquals(129,					res.at("/query/classRef/0").asInt());
+		assertEquals("korap:group",			res.at("/query/operands/0/@type").asText());
+		assertEquals("operation:sequence",	res.at("/query/operands/0/operation").asText());
+		assertEquals("korap:distance",		res.at("/query/operands/0/distances/0/@type").asText());
+		assertEquals("w",					res.at("/query/operands/0/distances/0/key").asText());
+		assertEquals(0,						res.at("/query/operands/0/distances/0/boundary/min").asInt());
+		assertEquals(10,					res.at("/query/operands/0/distances/0/boundary/max").asInt());
+		assertEquals(true,					res.at("/query/operands/0/inOrder").asBoolean());
+		assertEquals("korap:group",			res.at("/query/operands/0/operands/1/@type").asText());
+		assertEquals("operation:class",		res.at("/query/operands/0/operands/1/operation").asText());
+		assertEquals(129,					res.at("/query/operands/0/operands/1/classOut").asInt());
+		assertEquals("korap:reference",		res.at("/query/operands/0/operands/1/operands/0/@type").asText());
+		assertEquals("operation:focus",		res.at("/query/operands/0/operands/1/operands/0/operation").asText());
+		assertEquals(0,						res.at("/query/operands/0/operands/1/operands/0/spanRef/0").asInt());
+		assertEquals(1,						res.at("/query/operands/0/operands/1/operands/0/spanRef/1").asInt());
+		assertEquals("korap:group",			res.at("/query/operands/0/operands/1/operands/0/operands/0/@type").asText());
+		assertEquals("operation:sequence",	res.at("/query/operands/0/operands/1/operands/0/operands/0/operation").asText());
+		assertEquals("korap:distance",		res.at("/query/operands/0/operands/1/operands/0/operands/0/distances/0/@type").asText());
+		assertEquals("w",					res.at("/query/operands/0/operands/1/operands/0/operands/0/distances/0/key").asText());
+		assertEquals(3,						res.at("/query/operands/0/operands/1/operands/0/operands/0/distances/0/boundary/min").asInt());
+		assertEquals(5,						res.at("/query/operands/0/operands/1/operands/0/operands/0/distances/0/boundary/max").asInt());
+		assertEquals(false,					res.at("/query/operands/0/operands/1/operands/0/operands/0/inOrder").asBoolean());
+		assertEquals("korap:token",			res.at("/query/operands/0/operands/1/operands/0/operands/0/operands/0/@type").asText());
+		assertEquals("der",					res.at("/query/operands/0/operands/1/operands/0/operands/0/operands/0/wrap/key").asText());
+		assertEquals("Mann",				res.at("/query/operands/0/operands/1/operands/0/operands/0/operands/1/wrap/key").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("korap:token",			res.at("/query/operands/0/operands/0/operands/0/@type").asText());
+		assertEquals("kommt",				res.at("/query/operands/0/operands/0/operands/0/wrap/key").asText());
+		
+		query = "#END(der /w3:5 Mann)";
+		qs.setQuery(query, "cosmas2");
+		res = mapper.readTree(qs.toJSON());
+		assertEquals("korap:reference",		res.at("/query/@type").asText());
+		assertEquals("operation:focus",		res.at("/query/operation").asText());
+		assertEquals(-1,					res.at("/query/spanRef/0").asInt());
+		assertEquals(1,						res.at("/query/spanRef/1").asInt());
+		assertEquals("korap:group",			res.at("/query/operands/0/@type").asText());
+		assertEquals("operation:sequence",	res.at("/query/operands/0/operation").asText());
+		assertEquals("korap:distance",		res.at("/query/operands/0/distances/0/@type").asText());
+		assertEquals("w",					res.at("/query/operands/0/distances/0/key").asText());
+		assertEquals(3,						res.at("/query/operands/0/distances/0/boundary/min").asInt());
+		assertEquals(5,						res.at("/query/operands/0/distances/0/boundary/max").asInt());
+		assertEquals(false,					res.at("/query/operands/0/inOrder").asBoolean());
+		assertEquals("korap:token",			res.at("/query/operands/0/operands/0/@type").asText());
+		assertEquals("der",					res.at("/query/operands/0/operands/0/wrap/key").asText());
+		assertEquals("Mann",				res.at("/query/operands/0/operands/1/wrap/key").asText());
 	}
 	
 	@Test
-	public void testOPPROX() throws QueryException {
-		query="Sonne /+w1:4 Mond";
-		String prox1 = 
-					"{@type=korap:reference, operation=operation:focus, classRef=[129], operands=[" +
-						"{@type=korap:group, operation=operation:sequence, " +
-							"operands=[" +
-								"{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +
-									"{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
-								"]}," +
-								"{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +	
-									"{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
-								"]}" +
-							"], inOrder=true, " +
-							"distances=[" +
-								"{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=4}, min=1, max=4}" +
-							"]" +
-						"}" +
-					"]}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-		assertEquals(prox1.replaceAll(" ", ""), map.replaceAll(" ", ""));
+	public void testELEM() throws QueryException, JsonProcessingException, IOException {
+		query = "#ELEM(S)";
+		qs.setQuery(query, "cosmas2");
+		res = mapper.readTree(qs.toJSON());
+		assertEquals("korap:span",		res.at("/query/@type").asText());
+		assertEquals("s",				res.at("/query/key").asText());
 		
-		query="Sonne /+w1:4,s0,p1:3 Mond";
-		String prox2 = 
-				"{@type=korap:reference, operation=operation:focus, classRef=[129], operands=[" +
-					"{@type=korap:group, operation=operation:sequence, " +
-						"operands=[" +
-							"{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +	
-								"{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
-							"]}," +
-							"{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +	
-								"{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
-							"]}" +
-						"], inOrder=true, " +
-						"distances=[" +
-							"{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=4}, min=1, max=4}," +
-							"{@type=cosmas:distance, key=s, boundary={@type=korap:boundary, min=0, max=0}, min=0, max=0}," +
-							"{@type=cosmas:distance, key=p, boundary={@type=korap:boundary, min=1, max=3}, min=1, max=3}" +
-						"]" +
-					"}" +
-				"]}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-		assertEquals(prox2.replaceAll(" ", ""), map.replaceAll(" ", ""));
+		query = "#ELEM(W ANA=N)";
+		qs.setQuery(query, "cosmas2");
+		res = mapper.readTree(qs.toJSON());
+		assertEquals("korap:span",		res.at("/query/@type").asText());
+		assertEquals("w",				res.at("/query/key").asText());
+		assertEquals("korap:term",		res.at("/query/attr/@type").asText());
+		assertEquals("N",				res.at("/query/attr/key").asText());
+		assertEquals("p",				res.at("/query/attr/layer").asText());
+		assertEquals("match:eq",		res.at("/query/attr/match").asText());
 		
-		query="Sonne %+w1:4,s0,p1:3 Mond";
-		String prox3 = 
-				"{@type=korap:reference, operation=operation:focus, classRef=[129], operands=[" +
-					"{@type=korap:group, operation=operation:sequence, " +
-						"operands=[" +
-							"{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +	
-								"{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
-							"]}," +
-							"{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +	
-								"{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
-							"]}" +
-						"], inOrder=true, " +
-						"distances=[" +
-							"{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=4}, min=1, max=4, exclude=true}," +
-							"{@type=cosmas:distance, key=s, boundary={@type=korap:boundary, min=0, max=0}, min=0, max=0, exclude=true}," +
-							"{@type=cosmas:distance, key=p, boundary={@type=korap:boundary, min=1, max=3}, min=1, max=3, exclude=true}" +
-						"]" +
-					"}" +
-				"]}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-//		assertEquals(prox3.replaceAll(" ", ""), map.replaceAll(" ", ""));
+		query = "#ELEM(W ANA != 'N V')";
+		qs.setQuery(query, "cosmas2");
+		res = mapper.readTree(qs.toJSON());
+		assertEquals("korap:span",		res.at("/query/@type").asText());
+		assertEquals("w",				res.at("/query/key").asText());
+		assertEquals("korap:termGroup",	res.at("/query/attr/@type").asText());
+		assertEquals("relation:and",	res.at("/query/attr/relation").asText());
+		assertEquals("korap:term",		res.at("/query/attr/operands/0/@type").asText());
+		assertEquals("N",				res.at("/query/attr/operands/0/key").asText());
+		assertEquals("p",				res.at("/query/attr/operands/0/layer").asText());
+		assertEquals("match:ne",		res.at("/query/attr/operands/0/match").asText());
+		assertEquals("korap:term",		res.at("/query/attr/operands/1/@type").asText());
+		assertEquals("V",				res.at("/query/attr/operands/1/key").asText());
+		assertEquals("p",				res.at("/query/attr/operands/1/layer").asText());
+		assertEquals("match:ne",		res.at("/query/attr/operands/1/match").asText());
 		
-		query="Sonne /+w4 Mond";
-		String prox4 = 
-						"{@type=korap:reference, operation=operation:focus, classRef=[129], operands=[" +
-							"{@type=korap:group, operation=operation:sequence, " +
-								"operands=[" +
-									"{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +	
-										"{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
-									"]}," +
-									"{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +	
-										"{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
-									"]}" +
-								"], inOrder=true, " +
-								"distances=[" +
-									"{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=4}, min=0, max=4}" +
-								"]" +
-							"}" +
-						"]}";
-//					"{@type=korap:group, operation=operation:or, operands=[" +
-//						"{@type=korap:group, operation=operation:position, frames=[frames:], sharedClasses=[sharedClasses:intersects], operands=[" +
-//							"{@type=korap:group, operation=operation:class, class= , classOut=128, operands=[" +	
-//								"{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
-//							"]}," +
-//							"{@type=korap:group, operation=operation:class, class= , classOut=128, operands=[" +	
-//								"{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
-//							"]}" +
-//						"], frame=frame:overlaps}," +
-//						"{@type=korap:reference, operation=operation:focus, classRef=[128], operands=[" +
-//							"{@type=korap:group, operation=operation:sequence, " +
-//								"operands=[" +
-//									"{@type=korap:group, operation=operation:class, class= , classOut=128, operands=[" +	
-//										"{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
-//									"]}," +
-//									"{@type=korap:group, operation=operation:class, class= , classOut=128, operands=[" +	
-//										"{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
-//									"]}" +
-//								"], inOrder=true, " +
+		query = "#ELEM(W ANA != 'N A V' Genre = Sport)";
+		qs.setQuery(query, "cosmas2");
+		res = mapper.readTree(qs.toJSON());
+		assertEquals("korap:span",		res.at("/query/@type").asText());
+		assertEquals("w",				res.at("/query/key").asText());
+		assertEquals("korap:termGroup",	res.at("/query/attr/@type").asText());
+		assertEquals("relation:and",	res.at("/query/attr/relation").asText());
+		assertEquals("korap:termGroup",	res.at("/query/attr/operands/0/@type").asText());
+		assertEquals("relation:and",	res.at("/query/attr/operands/0/relation").asText());
+		assertEquals("N",				res.at("/query/attr/operands/0/operands/0/key").asText());
+		assertEquals("A",				res.at("/query/attr/operands/0/operands/1/key").asText());
+		assertEquals("V",				res.at("/query/attr/operands/0/operands/2/key").asText());
+		assertEquals("Genre",			res.at("/query/attr/operands/1/layer").asText());
+		assertEquals("Sport",			res.at("/query/attr/operands/1/key").asText());
+		
+		query = "#ELEM(W ANA != 'N A V' Genre != 'Sport Politik')";
+		qs.setQuery(query, "cosmas2");
+		res = mapper.readTree(qs.toJSON());
+		assertEquals("korap:span",		res.at("/query/@type").asText());
+		assertEquals("w",				res.at("/query/key").asText());
+		assertEquals("korap:termGroup",	res.at("/query/attr/@type").asText());
+		assertEquals("relation:and",	res.at("/query/attr/relation").asText());
+		assertEquals("korap:termGroup",	res.at("/query/attr/operands/0/@type").asText());
+		assertEquals("relation:and",	res.at("/query/attr/operands/0/relation").asText());
+		assertEquals("korap:termGroup",	res.at("/query/attr/operands/1/@type").asText());
+		assertEquals("relation:and",	res.at("/query/attr/operands/1/relation").asText());
+		assertEquals("N",				res.at("/query/attr/operands/0/operands/0/key").asText());
+		assertEquals("A",				res.at("/query/attr/operands/0/operands/1/key").asText());
+		assertEquals("V",				res.at("/query/attr/operands/0/operands/2/key").asText());
+		assertEquals("match:ne",		res.at("/query/attr/operands/0/operands/2/match").asText());
+		assertEquals("Genre",			res.at("/query/attr/operands/1/operands/0/layer").asText());
+		assertEquals("Sport",			res.at("/query/attr/operands/1/operands/0/key").asText());
+		assertEquals("Genre",			res.at("/query/attr/operands/1/operands/1/layer").asText());
+		assertEquals("Politik",			res.at("/query/attr/operands/1/operands/1/key").asText());
+		assertEquals("match:ne",		res.at("/query/attr/operands/1/operands/1/match").asText());
+	}
+//	@Test
+//	public void testOPALL() throws QueryException {
+//		query="#ALL(gehen /w1:10 voran)";
+//		String all1 =
+//				"{@type=korap:group, operation=operation:sequence, " +
+//					"operands=[" +
+//						"{@type=korap:token, wrap={@type=korap:term, key=gehen, layer=orth, match=match:eq}}," +
+//						"{@type=korap:token, wrap={@type=korap:term, key=voran, layer=orth, match=match:eq}}" +
+//					"], inOrder=false, " +
+//					"distances=[" +
+//						"{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=10}, min=1, max=10}" +
+//					"]" +
+//				"}";
+//		ct = new CosmasTree(query);
+//		map = ct.getRequestMap().get("query").toString();
+//		assertEquals(all1.replaceAll(" ", ""), map.replaceAll(" ", ""));
+//		
+//		query="#ALL(gehen /w1:10 (voran /w1:4 schnell))";
+//		String all2 =
+//				"{@type=korap:group, operation=operation:sequence, " +
+//					"operands=[" +
+//						"{@type=korap:token, wrap={@type=korap:term, key=gehen, layer=orth, match=match:eq}}," +
+//							"{@type=korap:group, operation=operation:sequence, operands=[" +
+//									"{@type=korap:token, wrap={@type=korap:term, key=voran, layer=orth, match=match:eq}}," +
+//									"{@type=korap:token, wrap={@type=korap:term, key=schnell, layer=orth, match=match:eq}}" +
+//								"], inOrder=false, " +
 //								"distances=[" +
 //									"{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=4}, min=1, max=4}" +
 //								"]" +
 //							"}" +
-//						"]}" +
-//					"]}";
-		
-		
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-		assertEquals(prox4.replaceAll(" ", ""), map.replaceAll(" ", ""));
-		
-		query="Sonne /-w4 Mond";
-		String prox5 = 
-					"{@type=korap:reference, operation=operation:focus, classRef=[129], operands=[" +
-						"{@type=korap:group, operation=operation:sequence, " +
-							"operands=[" +
-								"{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +	
-									"{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
-								"]}," +
-								"{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +	
-									"{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
-								"]}" +
-							"], inOrder=true, " +
-							"distances=[" +
-								"{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=4}, min=0, max=4}" +
-							"]" +
-						"}" +
-					"]}";
-//				"{@type=korap:group, operation=operation:or, operands=[" +
-//					"{@type=korap:group, operation=operation:position, frames=[frames:], sharedClasses=[sharedClasses:intersects], operands=[" +
-//						"{@type=korap:group, operation=operation:class, class= , classOut=128, operands=[" +	
-//							"{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
-//						"]}," +
-//						"{@type=korap:group, operation=operation:class, class= , classOut=128, operands=[" +	
-//							"{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
-//						"]}" +
-//					"], frame=frame:overlaps}," +
-//					"{@type=korap:reference, operation=operation:focus, classRef=[128], operands=[" +
+//					"], inOrder=false, " +
+//					"distances=[" +
+//						"{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=10}, min=1, max=10}" +
+//					"]" +
+//				"}";
+//		ct = new CosmasTree(query);
+//		map = ct.getRequestMap().get("query").toString();
+//		assertEquals(all2.replaceAll(" ", ""), map.replaceAll(" ", ""));
+//	}
+//	
+//	@Test
+//	public void testOPNHIT() throws QueryException {
+//		query="#NHIT(gehen /w1:10 voran)";
+//		String nhit1 = 
+//				"{@type=korap:reference, operation=operation:focus, classRef=[129], operands=[" +
+//					"{@type=korap:group, operation=operation:class, classRefOp=classRefOp:inversion, classIn=[130,131], classOut=129, operands=[" +
 //						"{@type=korap:group, operation=operation:sequence, " +
 //							"operands=[" +
-//								"{@type=korap:group, operation=operation:class, class= , classOut=128, operands=[" +	
-//									"{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
+//								"{@type=korap:group, operation=operation:class, class=130 , classOut=130, operands=[" +
+//									"{@type=korap:token, wrap={@type=korap:term, key=gehen, layer=orth, match=match:eq}}" +
+//								"]}," +	
+//								"{@type=korap:group, operation=operation:class, class=131 , classOut=131, operands=[" +
+//									"{@type=korap:token, wrap={@type=korap:term, key=voran, layer=orth, match=match:eq}}" +
+//								"]}" +	
+//							"], inOrder=false, " +
+//							"distances=[" +
+//								"{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=10}, min=1, max=10}" +
+//							"]" +
+//						"}" +
+//					"]}" +
+//				"]}";
+//		ct = new CosmasTree(query);
+//		map = ct.getRequestMap().get("query").toString();
+//		assertEquals(nhit1.replaceAll(" ", ""), map.replaceAll(" ", ""));
+//
+////		query="#NHIT(gehen %w1:10 voran)";
+////		String nhit2 = 
+////				"{@type=korap:reference, operation=operation:focus, classRef=129, operands=[" +
+////					"{@type=korap:group, operation=operation:sequence, " +
+////						"operands=[" +
+////							"{@type=korap:token, wrap={@type=korap:term, key=gehen, layer=orth, match=match:eq}}" +
+////							"{@type=korap:group, operation=operation:class, class= , classOut=129, operands=[" +
+////								"{@type=korap:group, operation=operation:repetition, operands=[" +
+////									"{@type=korap:token}" +
+////								"], boundary={@type=korap:boundary, min=1, max=10}, min=1, max=10}}" +
+////							"]}," +	
+////							"{@type=korap:token, wrap={@type=korap:term, key=voran, layer=orth, match=match:eq}}" +
+////						"], inOrder=false, " +
+////						"distances=[" +
+////							"{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=10}, min=1, max=10}" +
+////						"]" +
+////					"}" +
+////				"]}";
+////		ct = new CosmasTree(query);
+////		map = ct.getRequestMap().get("query").toString();
+////		assertEquals(nhit2.replaceAll(" ", ""), map.replaceAll(" ", ""));
+//		
+//		query="#NHIT(gehen /+w1:10 voran /w1:10 Beispiel)";
+//		String nhit3 = 
+//				"{@type=korap:reference, operation=operation:focus, classRef=[129], operands=[" +
+//					"{@type=korap:group, operation=operation:class, classRefOp=classRefOp:inversion, classIn=[130,131], classOut=129, operands=[" +
+//						"{@type=korap:group, operation=operation:sequence, " +
+//							"operands=[" +
+//								"{@type=korap:group, operation=operation:class, class=130, classOut=130, operands=[" +
+//									"{@type=korap:token, wrap={@type=korap:term, key=gehen, layer=orth, match=match:eq}}" +
 //								"]}," +
-//								"{@type=korap:group, operation=operation:class, class= , classOut=128, operands=[" +	
-//									"{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
+//								"{@type=korap:group, operation=operation:class, class=131, classOut=131, operands=[" +
+//									"{@type=korap:reference, operation=operation:focus, classRef=[132], operands=[" +
+//										"{@type=korap:group, operation=operation:sequence, " +
+//											"operands=[" +
+//												"{@type=korap:group, operation=operation:class, class=132, classOut=132, operands=[" +
+//													"{@type=korap:token, wrap={@type=korap:term, key=voran, layer=orth, match=match:eq}}" +
+//												"]}," +
+//												"{@type=korap:group, operation=operation:class, class=132, classOut=132, operands=[" +	
+//													"{@type=korap:token, wrap={@type=korap:term, key=Beispiel, layer=orth, match=match:eq}}" +
+//												"]}" +
+//											"], inOrder=false, " +
+//											"distances=[" +
+//												"{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=10}, min=1, max=10}" +
+//											"]" +
+//										"}" +
+//									"]}" +
 //								"]}" +
 //							"], inOrder=true, " +
 //							"distances=[" +
-//								"{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=4}, min=1, max=4}" +
+//								"{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=10}, min=1, max=10}" +
 //							"]" +
 //						"}" +
 //					"]}" +
 //				"]}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-		assertEquals(prox5.replaceAll(" ", ""), map.replaceAll(" ", ""));
-		
-		query="Sonne /w4 Mond";
-		String prox6 = 
-					"{@type=korap:reference, operation=operation:focus, classRef=[129], operands=[" +
-						"{@type=korap:group, operation=operation:sequence, " +
-							"operands=[" +
-								"{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +	
-									"{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
-								"]}," +
-								"{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +	
-									"{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
-								"]}" +
-							"], inOrder=false, " +
-							"distances=[" +
-								"{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=4}, min=0, max=4}" +
-							"]" +
-						"}" +
-					"]}";
-//				"{@type=korap:group, operation=operation:or, operands=[" +
-//					"{@type=korap:group, operation=operation:position, frames=[frames:], sharedClasses=[sharedClasses:intersects], operands=[" +
-//						"{@type=korap:group, operation=operation:class, class= , classOut=128, operands=[" +	
-//							"{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
-//						"]}," +
-//						"{@type=korap:group, operation=operation:class, class= , classOut=128, operands=[" +	
-//							"{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
+//		ct = new CosmasTree(query);
+//		map = ct.getRequestMap().get("query").toString();
+//		assertEquals(nhit3.replaceAll(" ", ""), map.replaceAll(" ", ""));
+//	}
+//	
+//	@Test
+//	public void testOPBED() throws QueryException {
+//		query = "#BED(der , sa)";
+//		String bed1 = 
+//				"{@type=korap:reference, operation=operation:focus, classRef=[129], operands= [" +
+//					"{@type=korap:group, operation=operation:position, frames=[frames:startswith], operands=[" +
+//						"{@type=korap:span, key=s}," +
+//						"{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +
+//							"{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}" +
 //						"]}" +
-//					"], frame=frame:overlaps}," +
-//					"{@type=korap:reference, operation=operation:focus, classRef=[128], operands=[" +
-//						"{@type=korap:group, operation=operation:sequence, " +
-//							"operands=[" +
-//								"{@type=korap:group, operation=operation:class, class= , classOut=128, operands=[" +	
-//									"{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
-//								"]}," +
-//								"{@type=korap:group, operation=operation:class, class= , classOut=128, operands=[" +	
-//									"{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
-//								"]}" +
-//							"], inOrder=false, " +
-//							"distances=[" +
-//								"{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=4}, min=1, max=4}" +
-//							"]" +
-//						"}" +
-//					"]}" +
+//					"], frame=frame:startswith}" +
 //				"]}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-		assertEquals(prox6.replaceAll(" ", ""), map.replaceAll(" ", ""));
-	}
-	
-	@Test
-	public void testOPPROXNested() throws QueryException {	
-		query="Sonne /+w1:4 Mond /-w1:7 Sterne";
-		expected = 
-					"{@type=korap:reference, operation=operation:focus, classRef=[129], operands=[" +
-						"{@type=korap:group, operation=operation:sequence, " +
-							"operands=[" +
-								"{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +
-									"{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
-								"]}," +
-								"{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +	
-									"{@type=korap:reference, operation=operation:focus, classRef=[130], operands=[" +
-										"{@type=korap:group, operation=operation:sequence, " +
-											"operands=[" +
-												"{@type=korap:group, operation=operation:class, class=130, classOut=130, operands=[" +
-													"{@type=korap:token, wrap={@type=korap:term, key=Sterne, layer=orth, match=match:eq}}" +
-												"]}," +
-												"{@type=korap:group, operation=operation:class, class=130, classOut=130, operands=[" +	
-													"{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
-												"]}" +
-											"], inOrder=true, " +
-											"distances=[" +
-												"{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=7}, min=1, max=7}" +
-											"]" +
-										"}" +
-									"]}" +
-								"]}" +
-							"], inOrder=true, " +
-							"distances=[" +
-								"{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=4}, min=1, max=4}" +
-							"]" +
-						"}" +
-					"]}" +
-					""	;
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-		assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
-		
-		query="Sonne /-w4 Mond /+w2 Sterne";
-		
-//		String mondsterne = 
-//					"{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}," +
-//					"{@type=korap:token, wrap={@type=korap:term, key=Sterne, layer=orth, match=match:eq}}" ;
-		
-		String mondsterneClasses = 
-					"{@type=korap:group, operation=operation:class, class=128 , classOut=128, operands=[" +	
-						"{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
-					"]}," +
-					"{@type=korap:group, operation=operation:class, class=128 , classOut=128, operands=[" +	
-						"{@type=korap:token, wrap={@type=korap:term, key=Sterne, layer=orth, match=match:eq}}" +
-					"]}";
-//		String mondsterneSeq = 
-//					"{@type=korap:group, operation=operation:sequence, operands=[" +
-//						mondsterne +
-//					"], inOrder=true, distances=[" +
-//						"{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=2}, min=1, max=2}" +
-//					"]}" ;
-		String mondsterneClassesSeq = 
-				"{@type=korap:reference, operation=operation:focus, classRef=[128], operands=[" +
-					"{@type=korap:group, operation=operation:sequence, operands=[" +
-						mondsterneClasses +
-					"], inOrder=true, distances=[" +
-						"{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=2}, min=1, max=2}" +
-					"]}" +
-				"]}" ;
-//		String mondsterneOv =
-//					"{@type=korap:group, operation=operation:position, frames=[frames:], sharedClasses=[sharedClasses:intersects], operands=[" +
-//						mondsterne +
-//					"]}";
-		String mondsterneClassesOv =
-				"{@type=korap:group, operation=operation:position, frames=[frames:], sharedClasses=[sharedClasses:intersects], operands=[" +
-					mondsterneClasses +
-				"], frame=frame:overlaps}";
-//		String mondsterneAll =
-//					"{@type=korap:group, operation=operation:or, operands=[" +
-//						mondsterneOv + "," + mondsterneClassesSeq +
-//					"]}";
-		String mondsterneAllClasses = 
-					"{@type=korap:group, operation=operation:or, operands=[" +
-						mondsterneClassesOv + "," + mondsterneClassesSeq +
-					"]}";
-		
-		
-		String prox6 = 
-				"{@type=korap:reference, operation=operation:focus, classRef=[129], operands=[" +
-						"{@type=korap:group, operation=operation:sequence, " +
-							"operands=[" +
-								"{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +	
-									"{@type=korap:reference, operation=operation:focus, classRef=[130], operands=[" +
-										"{@type=korap:group, operation=operation:sequence, " +
-											"operands=[" +
-												"{@type=korap:group, operation=operation:class, class=130, classOut=130, operands=[" +
-													"{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
-												"]}," +
-												"{@type=korap:group, operation=operation:class, class=130, classOut=130, operands=[" +	
-													"{@type=korap:token, wrap={@type=korap:term, key=Sterne, layer=orth, match=match:eq}}" +
-												"]}" +
-											"], inOrder=true, " +
-											"distances=[" +
-												"{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=2}, min=0, max=2}" +
-											"]" +
-										"}" +
-									"]}" +
-								"]}," +
-								"{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +
-									"{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
-								"]}" +
-							"], inOrder=true, " +
-							"distances=[" +
-								"{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=4}, min=0, max=4}" +
-							"]" +
-						"}" +
-					"]}" +
-					""	;
-//			"{@type=korap:group, operation=operation:or, operands=[" +
-//				"{@type=korap:group, operation=operation:position, frames=[frames:], sharedClasses=[sharedClasses:intersects], operands=[" +
-//					"{@type=korap:group, operation=operation:class, class= , classOut=128, operands=[" +	
-//						mondsterneAllClasses  + 
-//					"]}," +
-//					"{@type=korap:group, operation=operation:class, class= , classOut=128, operands=[" +	
-//						"{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
-//					"]}" +
-//				"], frame=frame:overlaps}," +
-//				"{@type=korap:reference, operation=operation:focus, classRef=[128], operands=[" +
-//					"{@type=korap:group, operation=operation:sequence, " +
-//						"operands=[" +
-//							"{@type=korap:group, operation=operation:class, class= , classOut=128, operands=[" +	
-//								mondsterneAllClasses  + 
+//		ct = new CosmasTree(query);
+//		map = ct.getRequestMap().get("query").toString();
+//		assertEquals(bed1.replaceAll(" ", ""), map.replaceAll(" ", ""));
+//		
+//		query = "#BED(der Mann , +pe)";
+//		String bed2 = 
+//				"{@type=korap:reference, operation=operation:focus, classRef=[129], operands= [" +
+//						"{@type=korap:group, operation=operation:position, frames=[frames:matches], operands=[" +
+//							"{@type=korap:reference, operation=operation:focus, spanRef=[-1,1], operands=[" +
+//								"{@type=korap:span, key=p}" +
 //							"]}," +
-//							"{@type=korap:group, operation=operation:class, class= , classOut=128, operands=[" +
-//								"{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
-//							"]}" +
-//						"], inOrder=true, " +
-//						"distances=[" +
-//							"{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=4}, min=1, max=4}" +
-//						"]" +
-//					"}" +
-//				"]}" +
-//			"]}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-		assertEquals(prox6.replaceAll(" ", ""), map.replaceAll(" ", ""));
-	}
-	
-	@Test
-	public void testOPIN() throws QueryException {
-		query="wegen #IN <s>";
-		String opin1 = 
-					"{@type=korap:reference, operation=operation:focus, classRef=[130], operands=[" +
-						"{@type=korap:group, operation=operation:class, classRefCheck=classRefCheck:includes, classIn=[129,130], classOut=131, class=131, operands=[" +
-							"{@type=korap:group, operation=operation:position, operands=[" +
-								"{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +
-									"{@type=korap:span, key=s}" +
-								"]}," +
-								"{@type=korap:group, operation=operation:class, class=130, classOut=130, operands=[" +
-									"{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
-								"]}" +
-							"], frames=[], frame=frame:contains}" +
-						"]}" +
-					"]}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-		assertEquals(opin1.replaceAll(" ", ""), map.replaceAll(" ", ""));
-		
-		query="wegen #IN(L) <s>"; 
-		String opin2 = 
-				"{@type=korap:reference, operation=operation:focus, classRef=[130], operands=[" +
-						"{@type=korap:group, operation=operation:class, classRefCheck=classRefCheck:includes, classIn=[129,130], classOut=131, class=131, operands=[" +
-							"{@type=korap:group, operation=operation:position, operands=[" +
-								"{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +
-									"{@type=korap:span, key=s}" +
-								"]}," +
-								"{@type=korap:group, operation=operation:class, class=130, classOut=130, operands=[" +
-									"{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
-								"]}" +
-						"], frames=[frames:startswith], frame=frame:startswith}" +
-					"]}" +
-				"]}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-		assertEquals(opin2.replaceAll(" ", ""), map.replaceAll(" ", ""));
-		
-		
-		query="wegen #IN(F) <s>";
-		String opin3= 
-				"{@type=korap:reference, operation=operation:focus, classRef=[130], operands=[" +
-						"{@type=korap:group, operation=operation:class, classRefCheck=classRefCheck:includes, classIn=[129,130], classOut=131, class=131, operands=[" +
-							"{@type=korap:group, operation=operation:position, operands=[" +
-								"{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +
-									"{@type=korap:span, key=s}" +
-								"]}," +
-								"{@type=korap:group, operation=operation:class, class=130, classOut=130, operands=[" +
-									"{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
-								"]}" +
-						"], frames=[frames:matches], frame=frame:matches}" +
-					"]}" +
-				"]}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-		assertEquals(opin3.replaceAll(" ", ""), map.replaceAll(" ", ""));
-		
-		query="wegen #IN(FI) <s>";
-		String opin4= 
-				"{@type=korap:reference, operation=operation:focus, classRef=[130], operands=[" +
-						"{@type=korap:group, operation=operation:class, classRefCheck=[classRefCheck:unequals,classRefCheck:includes], classIn=[129,130], classOut=131, class=131, operands=[" +
-							"{@type=korap:group, operation=operation:position, operands=[" +
-								"{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +
-									"{@type=korap:span, key=s}" +
-								"]}," +
-								"{@type=korap:group, operation=operation:class, class=130, classOut=130, operands=[" +
-									"{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
-								"]}" +
-						"], frames=[frames:matches], frame=frame:matches-noident}" +
-					"]}" +
-				"]}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-		assertEquals(opin4.replaceAll(" ", ""), map.replaceAll(" ", ""));
-		
-		query="wegen #IN(FE) <s>";
-		String opin5= 
-				"{@type=korap:reference, operation=operation:focus, classRef=[130], operands=[" +
-						"{@type=korap:group, operation=operation:class, classRefCheck=classRefCheck:equals, classIn=[129,130], classOut=131, class=131, operands=[" +
-							"{@type=korap:group, operation=operation:position, operands=[" +
-								"{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +
-									"{@type=korap:span, key=s}" +
-								"]}," +
-								"{@type=korap:group, operation=operation:class, class=130, classOut=130, operands=[" +
-									"{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
-								"]}" +
-						"], frames=[frames:matches], frame=frame:matches}" +
-					"]}" +
-				"]}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-		assertEquals(opin5.replaceAll(" ", ""), map.replaceAll(" ", ""));
-		
-		query="wegen #IN(%, L) <s>";
-		String opin6 = 
-				"{@type=korap:reference, operation=operation:focus, classRef=[130], operands=[" +
-						"{@type=korap:group, operation=operation:class, classRefCheck=classRefCheck:includes, classIn=[129,130], classOut=131, class=131, operands=[" +
-							"{@type=korap:group, operation=operation:position, operands=[" +
-								"{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +
-									"{@type=korap:span, key=s}" +
-								"]}," +
-								"{@type=korap:group, operation=operation:class, class=130, classOut=130, operands=[" +
-									"{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
-								"]}" +
-						"], frames=[frames:startswith], frame=frame:startswith, exclude=true}" +
-					"]}" +
-				"]}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-		assertEquals(opin6.replaceAll(" ", ""), map.replaceAll(" ", ""));
-		
-		query="wegen #IN(FE,ALL,%,MIN) <s>";
-		String opin7 = 
-				"{@type=korap:reference, operation=operation:focus, reset=true, operands=[" +	
-					"{@type=korap:group, operation=operation:class, classRefCheck=classRefCheck:equals, classIn=[129,130], classOut=131, class=131, operands=[" +
-						"{@type=korap:group, operation=operation:position, operands=[" +
-							"{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +
-								"{@type=korap:span, key=s}" +
-							"]}," +
-							"{@type=korap:group, operation=operation:class, class=130, classOut=130, operands=[" +
-								"{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
-							"]}" +
-				
-						"], frames=[frames:matches], frame=frame:matches, exclude=true, grouping=false}" +
-					"]}" +
-				"]}" +
-				"";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-		assertEquals(opin7.replaceAll(" ", ""), map.replaceAll(" ", ""));
-	}
-	
-	@Test
-	public void testOPOV() throws QueryException {
-		query="wegen #OV <s>";
-		String opov1 = 
-					"{@type=korap:reference, operation=operation:focus, classRef=[130], operands=[" +
-						"{@type=korap:group, operation=operation:class, classRefCheck=classRefCheck:intersects, classIn=[129,130], classOut=131, class=131, operands=[" +
-							"{@type=korap:group, operation=operation:position, operands=[" +
-								"{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +
-									"{@type=korap:span, key=s}" +
-								"]}," +
-								"{@type=korap:group, operation=operation:class, class=130, classOut=130, operands=[" +
-									"{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
-								"]}" +
-							"], frames=[], frame=frame:overlaps}" +
-						"]}" +
-					"]}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-		assertEquals(opov1.replaceAll(" ", ""), map.replaceAll(" ", ""));
-		
-		query="wegen #OV(L) <s>";
-		String opov2 = 
-				"{@type=korap:reference, operation=operation:focus, classRef=[130], operands=[" +
-						"{@type=korap:group, operation=operation:class, classRefCheck=classRefCheck:intersects, classIn=[129,130], classOut=131, class=131, operands=[" +
-							"{@type=korap:group, operation=operation:position, operands=[" +
-								"{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +
-									"{@type=korap:span, key=s}" +
-								"]}," +
-								"{@type=korap:group, operation=operation:class, class=130, classOut=130, operands=[" +
-									"{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
-								"]}" +
-							"], frames=[frames:startswith,frames:overlapsLeft], frame=frame:overlapsLeft}" +
-						"]}" +
-					"]}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-		assertEquals(opov2.replaceAll(" ", ""), map.replaceAll(" ", ""));
-		
-		query="wegen #OV(F) <s>";
-		String opov3= 
-				
-					"{@type=korap:reference, operation=operation:focus, classRef=[130], operands=[" +
-						"{@type=korap:group, operation=operation:class, classRefCheck=classRefCheck:intersects, classIn=[129,130], classOut=131, class=131, operands=[" +
-							"{@type=korap:group, operation=operation:position, operands=[" +
-								"{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +
-									"{@type=korap:span, key=s}" +
-								"]}," +
-								"{@type=korap:group, operation=operation:class, class=130, classOut=130, operands=[" +
-									"{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
-								"]}" +
-							"], frames=[frames:matches], frame=frame:matches}" +
-						"]}" +
-					"]}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-		assertEquals(opov3.replaceAll(" ", ""), map.replaceAll(" ", ""));
-		
-		query="wegen #OV(FI) <s>";
-		String opov4= 
-					"{@type=korap:reference, operation=operation:focus, classRef=[130], operands=[" +
-						"{@type=korap:group, operation=operation:class, classRefCheck=classRefCheck:unequals, classIn=[129,130], classOut=131, class=131, operands=[" +
-							"{@type=korap:group, operation=operation:position, operands=[" +
-								"{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +
-									"{@type=korap:span, key=s}" +
-								"]}," +
-								"{@type=korap:group, operation=operation:class, class=130, classOut=130, operands=[" +
-									"{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
-								"]}" +
-							"], frames=[frames:matches], frame=frame:matches-noident}" +
-						"]}" +
-					"]}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-		assertEquals(opov4.replaceAll(" ", ""), map.replaceAll(" ", ""));
-		
-		query="wegen #OV(FE) <s>";
-		String opov5= 
-				"{@type=korap:reference, operation=operation:focus, classRef=[130], operands=[" +
-						"{@type=korap:group, operation=operation:class, classRefCheck=classRefCheck:equals, classIn=[129,130], classOut=131, class=131, operands=[" +
-							"{@type=korap:group, operation=operation:position, operands=[" +
-								"{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +
-									"{@type=korap:span, key=s}" +
-								"]}," +
-								"{@type=korap:group, operation=operation:class, class=130, classOut=130, operands=[" +
-									"{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
-								"]}" +
-							"], frames=[frames:matches], frame=frame:matches}" +
-						"]}" +
-					"]}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-		assertEquals(opov5.replaceAll(" ", ""), map.replaceAll(" ", ""));
-	}
-	
-	@Test
-	public void testOPNOT() throws QueryException {
-		query="Sonne nicht Mond";
-		String opnot1 = 
-					"{@type=korap:group, operation=operation:sequence, distances=[" +
-						"{@type=cosmas:distance, key=t, min=0, max=0, exclude=true}" +
-					"], operands=[" +
-						"{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}," +
-						"{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
-					"]}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-		assertEquals(opnot1.replaceAll(" ", ""), map.replaceAll(" ", ""));
-	}
-	
-	@Test
-	public void testBEG_END() throws QueryException {
-		// BEG and END operators
-		// http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/syntax/links.html
-		// http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/syntax/rechts.html
-		// http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/thematische-bsp/bsp-satzlaenge.html
-		query="#BEG(der /w3:5 Mann)";
-		String beg1 = 
-				"{@type=korap:reference, operation=operation:focus, spanRef=[0,1], operands=[" +
-					"{@type=korap:group, operation=operation:sequence," +
-					"operands = [" +
-						"{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
-						"{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
-					"], inOrder=false, distances=[" +
-						"{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=3, max=5}, min=3, max=5}" +
-					"]}" +
-				"]}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-		assertEquals(beg1.replaceAll(" ", ""), map.replaceAll(" ", ""));
-		
-		
-//		String dermannSeq = "{@type=korap:group, operation=operation:sequence," +
-//								"operands = [" +
-//									"{@type=korap:group, operation=operation:class, class= , classOut=128, operands=[" +
-//										"{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}" +
-//									"]}," +
-//									"{@type=korap:group, operation=operation:class, class= , classOut=128, operands=[" +
+//							"{@type=korap:reference, operation=operation:focus, spanRef=[0,1], operands=[" +
+//								"{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +
+//									"{@type=korap:group, operation=operation:sequence, operands=[" +
+//										"{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
 //										"{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
 //									"]}" +
-//									
-//								"], inOrder=false, distances=[" +
-//									"{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=3, max=5}, min=3, max=5}" +
-//								"]}";
-//		
-//		String begDermannSeq = 
-////							"{@type=korap:group, operation=operation:class, class= , classOut=128, operands=[" +
-//								"{@type=korap:reference, operation=operation:focus, spanRef=[0,1], operands=[" +
-//									dermannSeq +
 //								"]}" +
-////							"]}" +
-//							"";
-		
-		String kommt = "{@type=korap:token, wrap={@type=korap:term, key=kommt, layer=orth, match=match:eq}}";
-		
-		query="#BEG(der /w3:5 Mann) /+w10 kommt"; // nesting #BEG() in a distance group
-		String beg2 = 
-//					"{@type=korap:group, operation=operation:or, operands=[" +
-//						"{@type=korap:group, operation=operation:position, frames=[frames:], sharedClasses=[sharedClasses:intersects], operands=[" +
-//							"{@type=korap:group, operation=operation:class, class= , classOut=128, operands=[" +
-//								beg1 +
-//							"]}" + "," +
-//							"{@type=korap:group, operation=operation:class, class= , classOut=128, operands=[" +
-//								kommt +
 //							"]}" +
-//						"], frame=frame:overlaps}," +
-//						"{@type=korap:reference, operation=operation:focus, classRef=[128], operands=[" +
-//							"{@type=korap:group, operation=operation:sequence, operands=[" +
-//								"{@type=korap:group, operation=operation:class, class= , classOut=128, operands=[" +
-//									beg1 + 
-//								"]}," +
-//								"{@type=korap:group, operation=operation:class, class= , classOut=128, operands=[" +
-//									kommt +
-//								"]}" +
-//							"], inOrder=true, distances=[" +
-//								"{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=10}, min=1, max=10}" +
-//							"]}" +
-//						"]}" +
+//						"], frame=frame:matches}" +
 //					"]}";
-//		
-						"{@type=korap:reference, operation=operation:focus, classRef=[129], operands=[" +
-							"{@type=korap:group, operation=operation:sequence, operands=[" +
-								"{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +
-									beg1 + 
-								"]}," +
-								"{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +
-									kommt +
-								"]}" +
-							"], inOrder=true, distances=[" +
-								"{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=10}, min=0, max=10}" +
-							"]}" +
-						"]}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-		assertEquals(beg2.replaceAll(" ", ""), map.replaceAll(" ", ""));
-		
-		query="kommt /+w10 #BEG(der /w3:5 Mann)";
-		String beg3 = 
-//				"{@type=korap:group, operation=operation:or, operands=[" +
-//						"{@type=korap:group, operation=operation:position, frames=[frames:], sharedClasses=[sharedClasses:intersects], operands=[" +
-//							"{@type=korap:group, operation=operation:class, class= , classOut=128, operands=[" +
-//								kommt + 
-////							"," +
-//							"]}," +
-//							"{@type=korap:group, operation=operation:class, class= , classOut=128, operands=[" +
-//								beg1+
-//							"]}" +
-//						"], frame=frame:overlaps}," +
-//						"{@type=korap:reference, operation=operation:focus, classRef=[128], operands=[" +
-//							"{@type=korap:group, operation=operation:sequence, operands=[" +
-//								"{@type=korap:group, operation=operation:class, class= , classOut=128, operands=[" +
-//									kommt +
-//								"]}," +
-//								"{@type=korap:group, operation=operation:class, class= , classOut=128, operands=[" +
-//									beg1+
-//								"]}" +
-//							"], inOrder=true, distances=[" +
-//								"{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=10}, min=1, max=10}" +
-//							"]}" +
-//						"]}" +
-//					"]}";
-				
-						"{@type=korap:reference, operation=operation:focus, classRef=[129], operands=[" +
-							"{@type=korap:group, operation=operation:sequence, operands=[" +
-								"{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +
-									kommt +
-								"]}," +
-								"{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +
-									beg1+
-								"]}" +
-							"], inOrder=true, distances=[" +
-								"{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=10}, min=0, max=10}" +
-							"]}" +
-						"]}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-		assertEquals(beg3.replaceAll(" ", ""), map.replaceAll(" ", ""));
-		
-		query="#END(der /w3:5 Mann)";
-		String end1 = 
-				"{@type=korap:reference, operation=operation:focus, spanRef=[-1,1], operands=[" +
-					"{@type=korap:group, operation=operation:sequence, " +
-					"operands = [" +
-						"{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
-						"{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
-					"], inOrder=false, distances=[" +
-						"{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=3, max=5}, min=3, max=5}" +
-					"]}" +
-				"]}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-		assertEquals(end1.replaceAll(" ", ""), map.replaceAll(" ", ""));
-	}
-	
-	/*
-	 * YET UNCLEAR HOW TO SERIALIZE SPAN DISTANCES. BEING DISCUSSED.
-	 * 
-	@Test
-	public void testSentenceDistance() throws QueryException {
-		query="Sonne /s0 Mond";   // contains(focus(1:contains({1:<s>},Sonne)),Mond)
-		expected = 
-					"{@type=korap:group, operation=operation:position, frame=frame:frame:contains, operands=[" +
-						"{@type=korap:reference, operation=operation:focus, classRef=[129], operands=[" +
-							"{@type=korap:group, operation=operation:position, frame=frame:frame:contains, operands=[" +
-								"{@type=korap:group, operation=operation:class, class= , classOut=129, operands=[" +
-									"{@type=korap:span, key=s}" +
-								"]}," +
-								"{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
-							"]}" +
-						"]}," +
-						"{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
-					"]}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-		assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
-		
-		query="Sonne /s0,w5 Mond";   
-		expected = 
-					"{@type=korap:group, operation=operation:position, frame=frame:frame:contains, operands=[" +
-						"{@type=korap:reference, operation=operation:focus, classRef=[129], operands=[" +
-							"{@type=korap:group, operation=operation:position, frame=frame:frame:contains, operands=[" +
-								"{@type=korap:group, operation=operation:class, class= , classOut=129, operands=[" +
-									"{@type=korap:span, key=s}" +
-								"]}," +
-								"{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
-							"]}" +
-						"]}," +
-						"{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
-					"]}";
 //		ct = new CosmasTree(query);
 //		map = ct.getRequestMap().get("query").toString();
-//		assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
-		
-		query="Sonne /s2:2 Mond";   // contains(<s>,Sonne)<s>contains(<s>,Mond)
-		expected = 
-						"{@type=korap:group, operation=operation:sequence, operands=[" +
-							"{@type=korap:group, operation=operation:position, frame=frame:frame:contains, operands=[" +
-								"{@type=korap:span, key=s}," +
-								"{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
-							"]}," +
-							"{@type=korap:span, key=s}," +
-							"{@type=korap:group, operation=operation:position, frame=frame:frame:contains, operands=[" +
-								"{@type=korap:span, key=s}," +
-								"{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
-							"]}" +
-						"]}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-//		assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
-		
-		query="Sonne /s2:3 Mond";   // contains(<s>,Sonne)<s>contains(<s>,Mond)
-		expected = 
-						"{@type=korap:group, operation=operation:sequence, operands=[" +
-							"{@type=korap:group, operation=operation:position, frame=frame:frame:contains, operands=[" +
-								"{@type=korap:span, key=s}," +
-								"{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
-							"]}," +
-							"{@type=korap:group, operation=operation:repetition, operands=[" +
-								"{@type=korap:span, key=s}" +
-							"], boundary={@type=korap:boundary, min=1, max=2}, min=1, max=2}," +
-							"{@type=korap:group, operation=operation:position, frame=frame:frame:contains, operands=[" +
-								"{@type=korap:span, key=s}," +
-								"{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
-							"]}" +
-						"]}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-//		assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
-		
-		query="Sonne /s2 Mond";   // contains(focus(1:contains({1:<s>},Sonne)),Mond) | contains(<s>,Sonne)<s>?contains(<s>,Mond)
-		expected = 
-					"{@type=korap:group, operation=operation:or, operands=[" +
-						"{@type=korap:group, operation=operation:position, frame=frame:frame:contains, operands=[" +
-							"{@type=korap:reference, operation=operation:focus, classRef=[129], operands=[" +
-								"{@type=korap:group, operation=operation:position, frame=frame:frame:contains, operands=[" +
-									"{@type=korap:group, operation=operation:class, class= , classOut=129, operands=[" +
-										"{@type=korap:span, key=s}" +
-									"]}," +
-									"{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
-								"]}" +
-							"]}," +
-							"{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
-						"]}," +
-						"{@type=korap:group, operation=operation:sequence, operands=[" +
-							"{@type=korap:group, operation=operation:position, frame=frame:frame:contains, operands=[" +
-								"{@type=korap:span, key=s}," +
-								"{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
-							"]}," +
-							"{@type=korap:group, operation=operation:repetition, operands=[" +
-								"{@type=korap:span, key=s}" +
-							"], boundary={@type=korap:boundary, min=0, max=1}, min=0, max=1}," +
-							"{@type=korap:group, operation=operation:position, frame=frame:frame:contains, operands=[" +
-								"{@type=korap:span, key=s}," +
-								"{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
-							"]}" +
-						"]}" +
-					"]}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-//		assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
-	}
-	*/
-	
-
-	@Test
-	public void testELEM() throws QueryException {
-		// http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/syntax/elem.html
-		query="#ELEM(S)";
-		String elem1 = "{@type=korap:span, key=s}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-		assertEquals(elem1.replaceAll(" ", ""), map.replaceAll(" ", ""));
-		
-		query="#ELEM(W ANA=N)";
-		String elem2 = 
-			"{@type=korap:span, key=w, attr=" +
-				"{@type=korap:termGroup, relation=relation:and, operands=[" +
-					"{@type=korap:term, layer=p, key=N, match=match:eq}" +
-				"]}" +
-			"}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-		assertEquals(elem2.replaceAll(" ", ""), map.replaceAll(" ", ""));
-		
-		query="#ELEM(W ANA != 'N V')";
-		String elem3 = 
-			"{@type=korap:span, key=w, attr=" +
-				"{@type=korap:termGroup, relation=relation:and, operands=[" +
-					"{@type=korap:term, layer=p, key=N, match=match:ne}," +
-					"{@type=korap:term, layer=p, key=V, match=match:ne}" +
-				"]}" +
-			"}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-		assertEquals(elem3.replaceAll(" ", ""), map.replaceAll(" ", ""));
-		
-		query="#ELEM(W ANA != 'N A V' Genre = Sport)";
-		String elem4 = 
-			"{@type=korap:span, key=w, attr=" +
-				"{@type=korap:termGroup, relation=relation:and, operands=[" +
-					"{@type=korap:termGroup, relation=relation:and, operands=[" +
-						"{@type=korap:term, layer=p, key=N, match=match:ne}," +
-						"{@type=korap:term, layer=p, key=A, match=match:ne}," +
-						"{@type=korap:term, layer=p, key=V, match=match:ne}" +
-					"]}," +
-					"{@type=korap:term, layer=Genre, key=Sport, match=match:eq}" +
-				"]}" +
-			"}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-		assertEquals(elem4.replaceAll(" ", ""), map.replaceAll(" ", ""));
-		
-		query="#ELEM(W ANA != 'N V' Genre != 'Sport Politik')";
-		String elem5 = 
-			"{@type=korap:span, key=w, attr=" +
-				"{@type=korap:termGroup, relation=relation:and, operands=[" +
-					"{@type=korap:termGroup, relation=relation:and, operands=[" +
-						"{@type=korap:term, layer=p, key=N, match=match:ne}," +
-						"{@type=korap:term, layer=p, key=V, match=match:ne}" +
-					"]}," +
-					"{@type=korap:termGroup, relation=relation:and, operands=[" +
-						"{@type=korap:term, layer=Genre, key=Sport, match=match:ne}," +
-						"{@type=korap:term, layer=Genre, key=Politik, match=match:ne}" +
-					"]}" +
-				"]}" +
-			"}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-		assertEquals(elem5.replaceAll(" ", ""), map.replaceAll(" ", ""));
-	}
-	
-	@Test
-	public void testOPALL() throws QueryException {
-		query="#ALL(gehen /w1:10 voran)";
-		String all1 =
-				"{@type=korap:group, operation=operation:sequence, " +
-					"operands=[" +
-						"{@type=korap:token, wrap={@type=korap:term, key=gehen, layer=orth, match=match:eq}}," +
-						"{@type=korap:token, wrap={@type=korap:term, key=voran, layer=orth, match=match:eq}}" +
-					"], inOrder=false, " +
-					"distances=[" +
-						"{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=10}, min=1, max=10}" +
-					"]" +
-				"}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-		assertEquals(all1.replaceAll(" ", ""), map.replaceAll(" ", ""));
-		
-		query="#ALL(gehen /w1:10 (voran /w1:4 schnell))";
-		String all2 =
-				"{@type=korap:group, operation=operation:sequence, " +
-					"operands=[" +
-						"{@type=korap:token, wrap={@type=korap:term, key=gehen, layer=orth, match=match:eq}}," +
-							"{@type=korap:group, operation=operation:sequence, operands=[" +
-									"{@type=korap:token, wrap={@type=korap:term, key=voran, layer=orth, match=match:eq}}," +
-									"{@type=korap:token, wrap={@type=korap:term, key=schnell, layer=orth, match=match:eq}}" +
-								"], inOrder=false, " +
-								"distances=[" +
-									"{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=4}, min=1, max=4}" +
-								"]" +
-							"}" +
-					"], inOrder=false, " +
-					"distances=[" +
-						"{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=10}, min=1, max=10}" +
-					"]" +
-				"}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-		assertEquals(all2.replaceAll(" ", ""), map.replaceAll(" ", ""));
-	}
-	
-	@Test
-	public void testOPNHIT() throws QueryException {
-		query="#NHIT(gehen /w1:10 voran)";
-		String nhit1 = 
-				"{@type=korap:reference, operation=operation:focus, classRef=[129], operands=[" +
-					"{@type=korap:group, operation=operation:class, classRefOp=classRefOp:inversion, classIn=[130,131], classOut=129, operands=[" +
-						"{@type=korap:group, operation=operation:sequence, " +
-							"operands=[" +
-								"{@type=korap:group, operation=operation:class, class=130 , classOut=130, operands=[" +
-									"{@type=korap:token, wrap={@type=korap:term, key=gehen, layer=orth, match=match:eq}}" +
-								"]}," +	
-								"{@type=korap:group, operation=operation:class, class=131 , classOut=131, operands=[" +
-									"{@type=korap:token, wrap={@type=korap:term, key=voran, layer=orth, match=match:eq}}" +
-								"]}" +	
-							"], inOrder=false, " +
-							"distances=[" +
-								"{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=10}, min=1, max=10}" +
-							"]" +
-						"}" +
-					"]}" +
-				"]}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-		assertEquals(nhit1.replaceAll(" ", ""), map.replaceAll(" ", ""));
-
-//		query="#NHIT(gehen %w1:10 voran)";
-//		String nhit2 = 
-//				"{@type=korap:reference, operation=operation:focus, classRef=129, operands=[" +
-//					"{@type=korap:group, operation=operation:sequence, " +
-//						"operands=[" +
-//							"{@type=korap:token, wrap={@type=korap:term, key=gehen, layer=orth, match=match:eq}}" +
-//							"{@type=korap:group, operation=operation:class, class= , classOut=129, operands=[" +
-//								"{@type=korap:group, operation=operation:repetition, operands=[" +
-//									"{@type=korap:token}" +
-//								"], boundary={@type=korap:boundary, min=1, max=10}, min=1, max=10}}" +
-//							"]}," +	
-//							"{@type=korap:token, wrap={@type=korap:term, key=voran, layer=orth, match=match:eq}}" +
-//						"], inOrder=false, " +
-//						"distances=[" +
-//							"{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=10}, min=1, max=10}" +
-//						"]" +
-//					"}" +
+//		assertEquals(bed2.replaceAll(" ", ""), map.replaceAll(" ", ""));
+//		
+//		query = "#BED(der Mann , sa,-pa)";
+//		String bed3 = 
+//				"{@type=korap:reference, operation=operation:focus, classRef=[129], operands=[" +
+//					"{@type=korap:group, operation=operation:position, frames=[frames:matches], operands=[" +
+//						"{@type=korap:group, operation=operation:position, frames=[frames:startswith], operands=[" +
+//							"{@type=korap:span, key=s}," +
+//							"{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +
+//								"{@type=korap:group, operation=operation:sequence, operands=[" +
+//									"{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
+//									"{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
+//								"]}" +
+//							"]}" +
+//						"], frame=frame:startswith}," +
+//						"{@type=korap:group, operation=operation:position, frames=[frames:startswith], operands=[" +
+//							"{@type=korap:span, key=p}," +
+//							"{@type=korap:group, operation=operation:class, class=130, classOut=130, operands=[" +
+//								"{@type=korap:group, operation=operation:sequence, operands=[" +
+//									"{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
+//									"{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
+//								"]}" +
+//							"]}" +
+//						"], frame=frame:startswith, exclude=true}" +
+//					"], frame=frame:matches}" +
 //				"]}";
 //		ct = new CosmasTree(query);
 //		map = ct.getRequestMap().get("query").toString();
-//		assertEquals(nhit2.replaceAll(" ", ""), map.replaceAll(" ", ""));
-		
-		query="#NHIT(gehen /+w1:10 voran /w1:10 Beispiel)";
-		String nhit3 = 
-				"{@type=korap:reference, operation=operation:focus, classRef=[129], operands=[" +
-					"{@type=korap:group, operation=operation:class, classRefOp=classRefOp:inversion, classIn=[130,131], classOut=129, operands=[" +
-						"{@type=korap:group, operation=operation:sequence, " +
-							"operands=[" +
-								"{@type=korap:group, operation=operation:class, class=130, classOut=130, operands=[" +
-									"{@type=korap:token, wrap={@type=korap:term, key=gehen, layer=orth, match=match:eq}}" +
-								"]}," +
-								"{@type=korap:group, operation=operation:class, class=131, classOut=131, operands=[" +
-									"{@type=korap:reference, operation=operation:focus, classRef=[132], operands=[" +
-										"{@type=korap:group, operation=operation:sequence, " +
-											"operands=[" +
-												"{@type=korap:group, operation=operation:class, class=132, classOut=132, operands=[" +
-													"{@type=korap:token, wrap={@type=korap:term, key=voran, layer=orth, match=match:eq}}" +
-												"]}," +
-												"{@type=korap:group, operation=operation:class, class=132, classOut=132, operands=[" +	
-													"{@type=korap:token, wrap={@type=korap:term, key=Beispiel, layer=orth, match=match:eq}}" +
-												"]}" +
-											"], inOrder=false, " +
-											"distances=[" +
-												"{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=10}, min=1, max=10}" +
-											"]" +
-										"}" +
-									"]}" +
-								"]}" +
-							"], inOrder=true, " +
-							"distances=[" +
-								"{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=10}, min=1, max=10}" +
-							"]" +
-						"}" +
-					"]}" +
-				"]}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-		assertEquals(nhit3.replaceAll(" ", ""), map.replaceAll(" ", ""));
-	}
-	
-	@Test
-	public void testOPBED() throws QueryException {
-		query = "#BED(der , sa)";
-		String bed1 = 
-				"{@type=korap:reference, operation=operation:focus, classRef=[129], operands= [" +
-					"{@type=korap:group, operation=operation:position, frames=[frames:startswith], operands=[" +
-						"{@type=korap:span, key=s}," +
-						"{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +
-							"{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}" +
-						"]}" +
-					"], frame=frame:startswith}" +
-				"]}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-		assertEquals(bed1.replaceAll(" ", ""), map.replaceAll(" ", ""));
-		
-		query = "#BED(der Mann , +pe)";
-		String bed2 = 
-				"{@type=korap:reference, operation=operation:focus, classRef=[129], operands= [" +
-						"{@type=korap:group, operation=operation:position, frames=[frames:matches], operands=[" +
-							"{@type=korap:reference, operation=operation:focus, spanRef=[-1,1], operands=[" +
-								"{@type=korap:span, key=p}" +
-							"]}," +
-							"{@type=korap:reference, operation=operation:focus, spanRef=[0,1], operands=[" +
-								"{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +
-									"{@type=korap:group, operation=operation:sequence, operands=[" +
-										"{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
-										"{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
-									"]}" +
-								"]}" +
-							"]}" +
-						"], frame=frame:matches}" +
-					"]}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-		assertEquals(bed2.replaceAll(" ", ""), map.replaceAll(" ", ""));
-		
-		query = "#BED(der Mann , sa,-pa)";
-		String bed3 = 
-				"{@type=korap:reference, operation=operation:focus, classRef=[129], operands=[" +
-					"{@type=korap:group, operation=operation:position, frames=[frames:matches], operands=[" +
-						"{@type=korap:group, operation=operation:position, frames=[frames:startswith], operands=[" +
-							"{@type=korap:span, key=s}," +
-							"{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +
-								"{@type=korap:group, operation=operation:sequence, operands=[" +
-									"{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
-									"{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
-								"]}" +
-							"]}" +
-						"], frame=frame:startswith}," +
-						"{@type=korap:group, operation=operation:position, frames=[frames:startswith], operands=[" +
-							"{@type=korap:span, key=p}," +
-							"{@type=korap:group, operation=operation:class, class=130, classOut=130, operands=[" +
-								"{@type=korap:group, operation=operation:sequence, operands=[" +
-									"{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
-									"{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
-								"]}" +
-							"]}" +
-						"], frame=frame:startswith, exclude=true}" +
-					"], frame=frame:matches}" +
-				"]}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-		assertEquals(bed3.replaceAll(" ", ""), map.replaceAll(" ", ""));
-	}
-	
-	@Test
-	public void testColonSeparatedConditions() throws QueryException {
-		
-		query = "Der:sa";
-		String col1 = 
-				"{@type=korap:reference, operation=operation:focus, classRef=[129], operands=[" +
-					"{@type=korap:group, operation=operation:position, frames=[frames:startswith], operands=[" +
-						"{@type=korap:span, key=s}," +
-						"{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +
-							"{@type=korap:token, wrap={@type=korap:term, key=Der, layer=orth, match=match:eq}}" +
-						"]}" +
-					"], frame=frame:startswith}" +
-				"]}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-		assertEquals(col1.replaceAll(" ", ""), map.replaceAll(" ", ""));
-		
-		query = "Mann:sa,-pa,+te";
-		String col2 = 
-				"{@type=korap:reference, operation=operation:focus, classRef=[129], operands=[" +
-					"{@type=korap:group, operation=operation:position, frames=[frames:matches], operands=[" +
-						"{@type=korap:group, operation=operation:position, frames=[frames:startswith], operands=[" +
-							"{@type=korap:span, key=s}," +
-							"{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +
-									"{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
-							"]}" +
-						"], frame=frame:startswith}," +
-						"{@type=korap:reference, operation=operation:focus, classRef=[130], operands=[" +
-							"{@type=korap:group, operation=operation:position, frames=[frames:matches], operands=[" +	
-								"{@type=korap:group, operation=operation:position, frames=[frames:startswith], operands=[" +
-									"{@type=korap:span, key=p}," +
-									"{@type=korap:group, operation=operation:class, class=130, classOut=130, operands=[" +
-											"{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
-									"]}" +
-								"], frame=frame:startswith, exclude=true}," +
-								"{@type=korap:group, operation=operation:position, frames=[frames:matches], operands=[" +
-									"{@type=korap:reference, operation=operation:focus, spanRef=[-1,1], operands=[" +
-										"{@type=korap:span, key=t}" +
-									"]}," +
-									"{@type=korap:reference, operation=operation:focus, spanRef=[0,1], operands=[" +
-										"{@type=korap:group, operation=operation:class, class=131, classOut=131, operands=[" +
-												"{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
-										"]}" +
-									"]}" +
-								"], frame=frame:matches}" +
-							"], frame=frame:matches}" +
-						"]}" +
-					"], frame=frame:matches}" +
-				"]}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-		assertEquals(col2.replaceAll(" ", ""), map.replaceAll(" ", ""));
-		
-		query = "Mann:sa,-pa,+te,se";
-		expected = 
-				"{@type=korap:reference, operation=operation:focus, classRef=[129], operands=[" +
-					"{@type=korap:group, operation=operation:position, frames=[frames:matches], operands=[" +
-						"{@type=korap:group, operation=operation:position, frames=[frames:startswith], operands=[" +
-							"{@type=korap:span, key=s}," +
-							"{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +
-									"{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
-							"]}" +
-						"], frame=frame:startswith}," +
-						"{@type=korap:reference, operation=operation:focus, classRef=[130], operands=[" +
-							"{@type=korap:group, operation=operation:position, frames=[frames:matches], operands=[" +	
-								"{@type=korap:group, operation=operation:position, frames=[frames:startswith], operands=[" +
-									"{@type=korap:span, key=p}," +
-									"{@type=korap:group, operation=operation:class, class=130, classOut=130, operands=[" +
-											"{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
-									"]}" +
-								"], frame=frame:startswith, exclude=true}," +
-								"{@type=korap:reference, operation=operation:focus, classRef=[131], operands=[" +
-									"{@type=korap:group, operation=operation:position, frames=[frames:matches], operands=[" +	
-										"{@type=korap:group, operation=operation:position, frames=[frames:matches], operands=[" +
-											"{@type=korap:reference, operation=operation:focus, spanRef=[-1,1], operands=[" +
-												"{@type=korap:span, key=t}" +
-											"]}," +
-											"{@type=korap:reference, operation=operation:focus, spanRef=[0,1], operands=[" +
-												"{@type=korap:group, operation=operation:class, class=131, classOut=131, operands=[" +
-														"{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
-												"]}" +
-											"]}" +
-										"], frame=frame:matches}," +
-										"{@type=korap:group, operation=operation:position, frames=[frames:matches], operands=[" +
-											"{@type=korap:reference, operation=operation:focus, spanRef=[-1,1], operands=[" +
-												"{@type=korap:span, key=s}" +
-											"]}," +
-											"{@type=korap:reference, operation=operation:focus, spanRef=[0,1], operands=[" +
-												"{@type=korap:group, operation=operation:class, class=132, classOut=132, operands=[" +
-														"{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
-												"]}" +
-											"]}" +
-										"], frame=frame:matches}" +
-									"], frame=frame:matches}" +
-								"]}" +
-							"], frame=frame:matches}" +
-						"]}" +
-					"], frame=frame:matches}" +
-				"]}";
-		ct = new CosmasTree(query);
-		map = ct.getRequestMap().get("query").toString();
-		assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
-	}
+//		assertEquals(bed3.replaceAll(" ", ""), map.replaceAll(" ", ""));
+//	}
+//	
+//	@Test
+//	public void testColonSeparatedConditions() throws QueryException {
+//		
+//		query = "Der:sa";
+//		String col1 = 
+//				"{@type=korap:reference, operation=operation:focus, classRef=[129], operands=[" +
+//					"{@type=korap:group, operation=operation:position, frames=[frames:startswith], operands=[" +
+//						"{@type=korap:span, key=s}," +
+//						"{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +
+//							"{@type=korap:token, wrap={@type=korap:term, key=Der, layer=orth, match=match:eq}}" +
+//						"]}" +
+//					"], frame=frame:startswith}" +
+//				"]}";
+//		ct = new CosmasTree(query);
+//		map = ct.getRequestMap().get("query").toString();
+//		assertEquals(col1.replaceAll(" ", ""), map.replaceAll(" ", ""));
+//		
+//		query = "Mann:sa,-pa,+te";
+//		String col2 = 
+//				"{@type=korap:reference, operation=operation:focus, classRef=[129], operands=[" +
+//					"{@type=korap:group, operation=operation:position, frames=[frames:matches], operands=[" +
+//						"{@type=korap:group, operation=operation:position, frames=[frames:startswith], operands=[" +
+//							"{@type=korap:span, key=s}," +
+//							"{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +
+//									"{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
+//							"]}" +
+//						"], frame=frame:startswith}," +
+//						"{@type=korap:reference, operation=operation:focus, classRef=[130], operands=[" +
+//							"{@type=korap:group, operation=operation:position, frames=[frames:matches], operands=[" +	
+//								"{@type=korap:group, operation=operation:position, frames=[frames:startswith], operands=[" +
+//									"{@type=korap:span, key=p}," +
+//									"{@type=korap:group, operation=operation:class, class=130, classOut=130, operands=[" +
+//											"{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
+//									"]}" +
+//								"], frame=frame:startswith, exclude=true}," +
+//								"{@type=korap:group, operation=operation:position, frames=[frames:matches], operands=[" +
+//									"{@type=korap:reference, operation=operation:focus, spanRef=[-1,1], operands=[" +
+//										"{@type=korap:span, key=t}" +
+//									"]}," +
+//									"{@type=korap:reference, operation=operation:focus, spanRef=[0,1], operands=[" +
+//										"{@type=korap:group, operation=operation:class, class=131, classOut=131, operands=[" +
+//												"{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
+//										"]}" +
+//									"]}" +
+//								"], frame=frame:matches}" +
+//							"], frame=frame:matches}" +
+//						"]}" +
+//					"], frame=frame:matches}" +
+//				"]}";
+//		ct = new CosmasTree(query);
+//		map = ct.getRequestMap().get("query").toString();
+//		assertEquals(col2.replaceAll(" ", ""), map.replaceAll(" ", ""));
+//		
+//		query = "Mann:sa,-pa,+te,se";
+//		expected = 
+//				"{@type=korap:reference, operation=operation:focus, classRef=[129], operands=[" +
+//					"{@type=korap:group, operation=operation:position, frames=[frames:matches], operands=[" +
+//						"{@type=korap:group, operation=operation:position, frames=[frames:startswith], operands=[" +
+//							"{@type=korap:span, key=s}," +
+//							"{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +
+//									"{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
+//							"]}" +
+//						"], frame=frame:startswith}," +
+//						"{@type=korap:reference, operation=operation:focus, classRef=[130], operands=[" +
+//							"{@type=korap:group, operation=operation:position, frames=[frames:matches], operands=[" +	
+//								"{@type=korap:group, operation=operation:position, frames=[frames:startswith], operands=[" +
+//									"{@type=korap:span, key=p}," +
+//									"{@type=korap:group, operation=operation:class, class=130, classOut=130, operands=[" +
+//											"{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
+//									"]}" +
+//								"], frame=frame:startswith, exclude=true}," +
+//								"{@type=korap:reference, operation=operation:focus, classRef=[131], operands=[" +
+//									"{@type=korap:group, operation=operation:position, frames=[frames:matches], operands=[" +	
+//										"{@type=korap:group, operation=operation:position, frames=[frames:matches], operands=[" +
+//											"{@type=korap:reference, operation=operation:focus, spanRef=[-1,1], operands=[" +
+//												"{@type=korap:span, key=t}" +
+//											"]}," +
+//											"{@type=korap:reference, operation=operation:focus, spanRef=[0,1], operands=[" +
+//												"{@type=korap:group, operation=operation:class, class=131, classOut=131, operands=[" +
+//														"{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
+//												"]}" +
+//											"]}" +
+//										"], frame=frame:matches}," +
+//										"{@type=korap:group, operation=operation:position, frames=[frames:matches], operands=[" +
+//											"{@type=korap:reference, operation=operation:focus, spanRef=[-1,1], operands=[" +
+//												"{@type=korap:span, key=s}" +
+//											"]}," +
+//											"{@type=korap:reference, operation=operation:focus, spanRef=[0,1], operands=[" +
+//												"{@type=korap:group, operation=operation:class, class=132, classOut=132, operands=[" +
+//														"{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
+//												"]}" +
+//											"]}" +
+//										"], frame=frame:matches}" +
+//									"], frame=frame:matches}" +
+//								"]}" +
+//							"], frame=frame:matches}" +
+//						"]}" +
+//					"], frame=frame:matches}" +
+//				"]}";
+//		ct = new CosmasTree(query);
+//		map = ct.getRequestMap().get("query").toString();
+//		assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
+//	}
 }
+	
+
+
+
+
+