aql position frames, include deprecation path for frame
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/AqlTree.java b/src/main/java/de/ids_mannheim/korap/query/serialize/AqlTree.java
index 22cfac2..b20bfee 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/AqlTree.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/AqlTree.java
@@ -236,8 +236,13 @@
 				if (! operandOnlyNodeRefs.contains(variableCounter.toString())) {
 					putIntoSuperObject(object);
 				}
+				ParseTree parentsFirstChild = node.getParent().getChild(0);
+				if (getNodeCat(parentsFirstChild).endsWith("#")) {
+					variableReferences.put(getNodeCat(parentsFirstChild).replaceAll("#", ""), object);
+				}
 				variableReferences.put(variableCounter.toString(), object);
 				variableCounter++;
+				System.out.println(variableReferences);
 			}
 		}
 
@@ -331,7 +336,7 @@
 				term.put("layer", "c");
 				relation.put("wrap", term);
 				// commonancestor is an indirect commonparent relation
-				if (reltype.equals("commonancestor")) relation.put("boundary", makeBoundary(1, MAXIMUM_DISTANCE));
+				if (reltype.equals("commonancestor")) relation.put("boundary", makeBoundary(1, null));
 				group.put("relation", relation);
 				innerGroup.put("relation", relation);
 				// Get operands list before possible re-assignment of 'group' (see following 'if')
@@ -367,15 +372,20 @@
 				} catch (ClassCastException | NullPointerException n) {
 					groupType = "relation";
 				}
-				group = makeGroup(groupType);
 				if (groupType.equals("relation") || groupType.equals("treeRelation")) {
+					group = makeGroup(groupType);
 					LinkedHashMap<String, Object> relation = new LinkedHashMap<String, Object>();
 					putAllButGroupType(relation, operatorGroup);
 					System.err.println(relation);
 					group.put("relation", relation);
-				} else if (groupType.equals("sequence") || groupType.equals("position")) {
+				} else if (groupType.equals("sequence")) {
+					group = makeGroup(groupType);
+					putAllButGroupType(group, operatorGroup);
+				} else if (groupType.equals("position")) {
+					group = new LinkedHashMap<String,Object>();
 					putAllButGroupType(group, operatorGroup);
 				}
+					
 				// Get operands list before possible re-assignment of 'group' (see following 'if')
 				operands  = (ArrayList<Object>) group.get("operands");
 				// Wrap in reference object in case other relations are following
@@ -483,7 +493,7 @@
 			LinkedHashMap<String,Object> term = makeTerm();
 			if (qName != null) term.putAll(parseQNameNode(qName));
 			if (edgeSpec != null) term.putAll(parseEdgeSpec(edgeSpec));
-			if (star != null) relation.put("boundary", makeBoundary(0, 100));
+			if (star != null) relation.put("boundary", makeBoundary(0, null));
 			if (rangeSpec != null) relation.put("boundary", boundaryFromRangeSpec(rangeSpec));
 			relation.put("wrap", term);
 		}
@@ -504,39 +514,41 @@
 			relation.put("inOrder", true);
 		}
 		else if (operator.equals("spanrelation")) {
-			relation = makeGroup("position");
-			relation.put("groupType", "position");
+//			relation = makeGroup("position");
+//			relation.put("groupType", "position");
 			String reltype = operatorNode.getChild(0).toStringTree(parser);
-			String frame = null;
-			boolean inOrder = true;
+			String[] frames = new String[]{};
+			String[] sharedClasses = new String[]{"sharedClasses:includes"};
 			switch (reltype) {
 			case "_=_":
-				frame = "matches"; break;
+				frames = new String[]{"frame:matches"}; 
+				sharedClasses = new String[]{"sharedClasses:equals"};
+				break;
 			case "_l_":
-				frame = "startswith"; 
-				inOrder = false;
+				frames = new String[]{"frame:startswith"};
 				break;
 			case "_r_":
-				frame = "endswith";
-				inOrder = false;
+				frames = new String[]{"frame:endswith"};
 				break;
 			case "_i_":
-				frame = "contains"; break;
+				frames = new String[]{"frame:contains"};break;
 			case "_o_":
-				frame = "overlaps"; 
-				inOrder = false;
+				frames = new String[]{"frame:overlapsLeft", "frame:overlapsRight"};
+				sharedClasses = new String[]{"sharedClasses:intersects"};
 				break;
 			case "_ol_":
-				frame = "overlapsLeft"; 
-				inOrder = false;
+				frames = new String[]{"frame:overlapsLeft"};
+				sharedClasses = new String[]{"sharedClasses:intersects"};
 				break;
 			case "_or_":
-				frame = "overlapsRight"; 
-				inOrder = false;
+				frames = new String[]{"frame:overlapsRight"};
+				sharedClasses = new String[]{"sharedClasses:intersects"};
 				break;
 			}
-			if (!inOrder) relation.put("inOrder", false);
-			relation.put("frame", "frame:"+frame);
+//			relation.put("frames", frames);
+//			relation.put("sharedClasses", sharedClasses);
+			relation = makePosition(frames, sharedClasses);
+			relation.put("groupType", "position");
 		}
 		else if (operator.equals("identity")) {
 			//TODO
@@ -711,7 +723,12 @@
 //				"cat=\"NP\" & cat=\"VP\" & cat=\"PP\" & #1 $ #2 > #3",
 //				"tok=\"Mann\" & tok=\"geht\" & #1 .* #2",
 //				"\"Sonne\"",
-				"\"so\" & \"nicht\" & #1 .1,6 #2"
+//				"\"so\" & ( \"nicht\" | \"doch\" ) & #1 .1,6 #2",
+//				
+//				"NP#cat=\"NP\" & PP1#cat=\"PP\" . PP2#cat=\"PP\" & #NP > #PP1 & #NP > #PP2 ",
+//				"cat=\"NP\" > cat=\"VP\" & #1 _l_ #2",
+//				"cat=\"NP\" > cat=\"VP\" & #1 . tok=\"foo\"",
+				"cat=\"NP\" & cat=\"VP\" & #1 > #2 & #1 _l_ #2",
 		};
 		//		AqlTree.verbose=true;
 		for (String q : queries) {
diff --git a/src/test/java/AqlTreeTest.java b/src/test/java/AqlTreeTest.java
index a0f133d..0cf0564 100644
--- a/src/test/java/AqlTreeTest.java
+++ b/src/test/java/AqlTreeTest.java
@@ -436,23 +436,44 @@
 		map = aqlt.getRequestMap().get("query").toString();
 		assertEquals(cp2.replaceAll(" ", ""), map.replaceAll(" ", ""));		
 	}
-	
+	/*
+	@Test
+	public void testMultipleOperatorsWithSameOperands() throws QueryException {
+		
+		query = "cat=\"NP\" > cat=\"VP\" & #1 _l_ #2";
+		String eq2 =
+				"{@type=korap:group, operation=operation:position, frames=[frame:startswith], sharedClasses=[sharedClasses:includes], operands=[" +
+						"{@type=korap:group, operation=operation:relation, operands=[" +
+							"{@type=korap:group, operation=operation:class, class=1, operands=[" +
+								"{@type=korap:span, layer=cat, key=NP, match=match:eq}" +
+							"]}," +
+							"{@type=korap:group, operation=operation:class, class=1, operands=[" +
+								"{@type=korap:span, layer=cat, key=VP, match=match:eq}" +
+							"]}" +
+						"], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}," +
+					"{@type=korap:reference, operation=operation:focus, classRef=[2]}" +
+				"]" +
+				"}"; // ???
+		aqlt = new AqlTree(query);
+		map = aqlt.getRequestMap().get("query").toString();
+		assertEquals(eq2.replaceAll(" ", ""), map.replaceAll(" ", ""));		
+	}
+	*/
 	@Test
 	public void testPositions() throws QueryException {
 		query = "node & node & #2 _=_ #1";
 		String pos1 = 
-				"{@type=korap:group, operation=operation:position, operands=[" +
+				"{@type=korap:group, operation=operation:position, frames=[frame:matches], sharedClasses=[sharedClasses:equals], operands=[" +
 						"{@type=korap:span}," +
 						"{@type=korap:span}" +
-				"], frame=frame:matches" +
-				"}";
+				"], frame=frame:matches}";
 		aqlt = new AqlTree(query);
 		map = aqlt.getRequestMap().get("query").toString();
 		assertEquals(pos1.replaceAll(" ", ""), map.replaceAll(" ", ""));
 		
 		query = "node & node & #2 _i_ #1";
 		String pos2 = 
-				"{@type=korap:group, operation=operation:position, operands=[" +
+				"{@type=korap:group, operation=operation:position, frames=[frame:contains], sharedClasses=[sharedClasses:includes], operands=[" +
 						"{@type=korap:span}," +
 						"{@type=korap:span}" +
 				"], frame=frame:contains" +
@@ -463,10 +484,10 @@
 		
 		query = "node & node & #2 _l_ #1";
 		String pos3 = 
-				"{@type=korap:group, operation=operation:position, operands=[" +
+				"{@type=korap:group, operation=operation:position, frames=[frame:startswith], sharedClasses=[sharedClasses:includes], operands=[" +
 						"{@type=korap:span}," +
 						"{@type=korap:span}" +
-				"], inOrder=false, frame=frame:startswith" +
+				"], frame=frame:startswith" +
 				"}";
 		aqlt = new AqlTree(query);
 		map = aqlt.getRequestMap().get("query").toString();
@@ -474,10 +495,10 @@
 		
 		query = "node & \"Mann\" & #1 _r_ #2";
 		String pos4 = 
-					"{@type=korap:group, operation=operation:position, operands=[" +
+					"{@type=korap:group, operation=operation:position, frames=[frame:endswith], sharedClasses=[sharedClasses:includes], operands=[" +
 						"{@type=korap:span}," +
 						"{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
-						"], inOrder=false, frame=frame:endswith" +
+						"], frame=frame:endswith" +
 					"}";
 		aqlt = new AqlTree(query);
 		map = aqlt.getRequestMap().get("query").toString();
@@ -485,10 +506,10 @@
 		
 		query = "node & \"Mann\" & #2 _r_ #1";
 		String pos5 = 
-					"{@type=korap:group, operation=operation:position, operands=[" +
+					"{@type=korap:group, operation=operation:position, frames=[frame:endswith], sharedClasses=[sharedClasses:includes], operands=[" +
 						"{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}," +
 						"{@type=korap:span}" +
-						"], inOrder=false, frame=frame:endswith" +
+						"], frame=frame:endswith" +
 					"}";
 		aqlt = new AqlTree(query);
 		map = aqlt.getRequestMap().get("query").toString();
@@ -688,6 +709,36 @@
 		aqlt = new AqlTree(query);
 		map = aqlt.getRequestMap().get("query").toString();
 		assertEquals(cp3.replaceAll(" ", ""), map.replaceAll(" ", ""));		
-	}
 		
+		query = "cat=\"NP\" & cat=\"VP\" & #1 $* #2";
+		String cp4 =
+				"{@type=korap:group, operation=operation:relation, operands=[" +
+						"{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
+							"{@type=korap:group, operation=operation:relation, operands=[" +
+								"{@type=korap:group, operation=operation:class, class=0, operands=[" +
+									"{@type=korap:span}" +
+								"]}," +
+								"{@type=korap:span, layer=cat, key=NP, match=match:eq}" +
+							"], relation={@type=korap:relation, wrap={@type=korap:term, layer=c},boundary={@type=korap:boundary,min=1}}}" +
+						"]}," +
+						"{@type=korap:span, layer=cat, key=VP, match=match:eq}" +
+					"], relation={@type=korap:relation, wrap={@type=korap:term, layer=c},boundary={@type=korap:boundary,min=1}}}" +
+					"";
+		aqlt = new AqlTree(query);
+		map = aqlt.getRequestMap().get("query").toString();
+		assertEquals(cp4.replaceAll(" ", ""), map.replaceAll(" ", ""));		
+	}
+	
+	/*		
+	@Test
+	public void testEqualNotequalValue() throws QueryException {
+		query = "cat=\"NP\" & cat=\"VP\" & #1 == #2";
+		String eq1 =
+				"{}"; // ???
+		aqlt = new AqlTree(query);
+		map = aqlt.getRequestMap().get("query").toString();
+		assertEquals(eq1.replaceAll(" ", ""), map.replaceAll(" ", ""));		
+	}
+	*/
+	
 }
\ No newline at end of file