PQ alignment
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 6f471e4..2eaff8b 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
@@ -440,8 +440,8 @@
 			submatchgroup.put("@operands", submatchoperands);
 			submatchoperands.add(posgroup);
 			posgroup.put("@type", "korap:group");
-			String relation = nodeCat.equals("OPIN") ? "position" : "overlaps";
-			posgroup.put("@relation", relation);
+//			String relation = nodeCat.equals("OPIN") ? "position" : "overlaps";
+			posgroup.put("@relation", "position");
 			
 			if (nodeCat.equals("OPIN")) {
 				parseOPINOptions(node, posgroup);
@@ -616,7 +616,7 @@
 		String position = "";
 		if (posnode != null) {
 			String value = posnode.getChild(0).toStringTree();
-			position = translateTextAreaArgument(value);
+			position = translateTextAreaArgument(value, "in");
 			if (value.equals("N")) {
 				negatePosition = !negatePosition;
 			}
@@ -656,12 +656,9 @@
 		String position = "";
 		if (posnode != null) {
 			String value = posnode.getChild(0).toStringTree();
-			position = translateTextAreaArgument(value);
-		} else {
-			position = "any";
+			position = "-"+translateTextAreaArgument(value, "ov");
 		}
-		posgroup.put("@position", position);
-		position = openNodeCats.get(1).equals("OPIN") ? "contains" : "full";
+		posgroup.put("@position", "overlaps"+position);
 		
 		if (exclnode != null) {
 			if (exclnode.getChild(0).toStringTree().equals("YES")) {
@@ -681,22 +678,23 @@
 	 * http://www.ids-mannheim.de/cosmas2/win-app/hilfe/suchanfrage/eingabe-grafisch/syntax/ARGUMENT_I.html or
 	 * http://www.ids-mannheim.de/cosmas2/win-app/hilfe/suchanfrage/eingabe-grafisch/syntax/ARGUMENT_O.html, respectively.
 	 * @param argument
+	 * @param mode 
 	 * @return
 	 */
-	private String translateTextAreaArgument(String argument) {
+	private String translateTextAreaArgument(String argument, String mode) {
 		String position = "";
 		switch (argument) {
 		case "L":
-			position = "startswith";
+			position = mode.equals("in") ? "startswith" : "left";
 			break;
 		case "R":
-			position = "endswith";
+			position = mode.equals("in") ? "endswith" : "right";
 			break;
 		case "F":
 			position = "leftrightmatch";
 			break;
 		case "FE":
-			position = "ident";
+			position = "matches";
 			break;
 		case "FI":
 			position = "leftrightmatch-noident";
@@ -767,7 +765,8 @@
 				"wegen #IN(%, L) <s>",
 				"wegen #IN(%) <s>",
 				"(Mann oder Frau) #IN <s>",
-				"#BEG(der /w3:5 Mann) /+w10 kommt"
+				"#BEG(der /w3:5 Mann) /+w10 kommt",
+				"&würde /w0 MORPH(V)"
 				};
 		CosmasTree.debug=true;
 		for (String q : queries) {
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusTree.java b/src/main/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusTree.java
index 530f597..6679466 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusTree.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusTree.java
@@ -260,7 +260,8 @@
 			ignoreCq_segment = (node.getChildCount() == 1 && (node.getChild(0).toStringTree(poliqarpParser).equals(" ") || QueryUtils.getNodeCat(node.getChild(0)).equals("spanclass") || QueryUtils.getNodeCat(node.getChild(0)).equals("position")));
 			// ignore this node if it only serves as an aligned sequence container
 			if (node.getChildCount()>1) {
-				if (QueryUtils.getNodeCat(node.getChild(1)).equals("cq_segments") && QueryUtils.hasChild(node.getChild(1), "align")) {
+				if (QueryUtils.getNodeCat(node.getChild(1)).equals("cq_segments") && QueryUtils.hasChild(node.getChild(1), "alignment")) {
+//				if (QueryUtils.getNodeCat(node.getChild(0)).equals("align")) {	
 					ignoreCq_segment = true;
 				}
 			}
@@ -594,7 +595,7 @@
 			} 
 		}
 		
-		if (nodeCat.equals("align")) {
+		if (nodeCat.equals("alignment")) {
 			alignNext = true;
 			LinkedHashMap<String,Object> alignGroup = new LinkedHashMap<String,Object>();
 			// push but don't increase the stackedObjects counter in order to keep this
@@ -602,16 +603,17 @@
 			// operands are siblings of this align node rather than children, i.e. the group
 			// would be removed from the stack before seeing its operands.
 			objectStack.push(alignGroup);
+			stackedObjects++;
 			// Step I: get info
 			// fill group
 			alignGroup.put("@type", "korap:group");
-			alignGroup.put("@relation", "left-align");
+			alignGroup.put("@alignment", "left");
 			alignGroup.put("@operands", new ArrayList<Object>());
 			// Step II: decide where to put the group
 			// add group to sequence only if it is not an only child (in that case, sq_segments has already added the info and is just waiting for the relevant info)
 			if (node.getParent().getChildCount()>1) {
 				ArrayList<Object> topSequenceOperands = (ArrayList<Object>) objectStack.get(1).get("@operands");
-				topSequenceOperands.add(alignGroup); 
+				topSequenceOperands.add(alignGroup);
 			} else if (openNodeCats.get(2).equals("query")) {
 				requestMap.put("query", alignGroup);	
 			} else {
@@ -801,10 +803,10 @@
 		}
 		
 		// pop the align group that was introduced by previous 'align' but never closed
-		if (isAligned) {
-			isAligned=false;
-			objectStack.pop();
-		}
+//		if (isAligned) {
+//			isAligned=false;
+//			objectStack.pop();
+//		}
 		
 		// Stuff that happens when leaving a node (taking items off the stacks)
 		for (int i=0; i<objectsToPop.get(0); i++) {
@@ -935,13 +937,25 @@
 		/*
 		 * For testing
 		 */
+		
+		PoliqarpPlusTree pt1 = new PoliqarpPlusTree("[base=Hund] | [base=Katze][base=Maus]");
+		PoliqarpPlusTree pt2 = new PoliqarpPlusTree("[base=Hund] | [base=Katze] [base=Maus]");
+		System.err.println(pt1.getRequestMap().equals(pt2.getRequestMap()));
+		
 		String[] queries = new String[] {
-				"startswith(<s>,[][base=der][base=Mann])",
-//				"[][base=Mann]",
-				"[base=Hund][][base=Katze][][][base=Maus]",
-				"[base=Hund][]?[][base=Katze]",
-				"split([base=der]{[base=Mann]})",
-				"[base=Mann&gen=m&cas=N]"
+//				"startswith(<s>,[][base=der][base=Mann])",
+////				"[][base=Mann]",
+//				"[base=Hund][][base=Katze][][][base=Maus]",
+//				"[base=Hund][]?[][base=Katze]",
+//				"split([base=der]{[base=Mann]})",
+//				"[base=Mann&gen=m&cas=N]",
+//				"[base=Hund] | [base=Katze][base=Maus]",
+//				"Baum | Haus",
+//				"Baum | Stein Haus",
+//				"^contains(<s>,<np>)",
+//				"([base=a]^[base=b][base=c])|[base=d]",
+				"[orth=der]^[orth=große][orth=Mann]",
+				"([base=a]^[base=b]^[base=c])|[base=d]"
 		};
 		PoliqarpPlusTree.debug=true;
 		for (String q : queries) {
diff --git a/src/test/java/CosmasTreeTest.java b/src/test/java/CosmasTreeTest.java
index efe86f6..fac29e7 100644
--- a/src/test/java/CosmasTreeTest.java
+++ b/src/test/java/CosmasTreeTest.java
@@ -332,7 +332,7 @@
 		query="wegen #IN('FE,ALL,%,MIN') <s>";
 		String opin4 = 
 					"{@type=korap:group, @relation=submatch, @classRef=1, @operands=[" +
-						"{@type=korap:group, @relation=position, @position=ident, range=all, @exclude=true, grouping=false, @operands=[" +
+						"{@type=korap:group, @relation=position, @position=matches, range=all, @exclude=true, grouping=false, @operands=[" +
 							"{@type=korap:span, @value=s}," +
 							"{@type=korap:group, class=1, @operands=[" +
 								"{@type=korap:token, @value={@type=korap:term, @value=wegen, @attr=orth, @relation==}}" +
@@ -349,7 +349,7 @@
 		query="wegen #OV <s>";
 		String opov1 = 
 					"{@type=korap:group, @relation=submatch, @classRef=1, @operands=[" +
-						"{@type=korap:group, @relation=overlaps, @position=any, @operands=[" +
+						"{@type=korap:group, @relation=position, @position=overlaps, @operands=[" +
 							"{@type=korap:span, @value=s}," +
 							"{@type=korap:group, class=1, @operands=[" +
 								"{@type=korap:token, @value={@type=korap:term, @value=wegen, @attr=orth, @relation==}}" +
@@ -363,7 +363,7 @@
 		query="wegen #OV(L) <s>";
 		String opov2 = 
 					"{@type=korap:group, @relation=submatch, @classRef=1, @operands=[" +
-						"{@type=korap:group, @relation=overlaps, @position=startswith, @operands=[" +
+						"{@type=korap:group, @relation=position, @position=overlaps-left, @operands=[" +
 							"{@type=korap:span, @value=s}," +
 							"{@type=korap:group, class=1, @operands=[" +
 								"{@type=korap:token, @value={@type=korap:term, @value=wegen, @attr=orth, @relation==}}" +
diff --git a/src/test/java/PoliqarpPlusTreeTest.java b/src/test/java/PoliqarpPlusTreeTest.java
index 6090867..078cf8e 100644
--- a/src/test/java/PoliqarpPlusTreeTest.java
+++ b/src/test/java/PoliqarpPlusTreeTest.java
@@ -643,7 +643,7 @@
 		String align1 = 
 				"{@type=korap:sequence, @operands=[" +
 					"{@type=korap:token, @value={@type=korap:term, @value=der, @attr=orth, @relation==}}," +
-					"{@type=korap:group, @relation=left-align, @operands=[" +
+					"{@type=korap:group, @alignment=left, @operands=[" +
 						"{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=orth, @relation==}}" +
 					"]}" +
 				"]}";
@@ -651,12 +651,28 @@
 		map = ppt.getRequestMap().get("query").toString();
 		assertEquals(align1.replaceAll(" ", ""), map.replaceAll(" ", ""));
 		
+		// [orth=der]^[orth=große][orth=Mann]
+		String query = "[orth=der]^[orth=große][orth=Mann]";
+		String align1b = 
+				"{@type=korap:sequence, @operands=[" +
+					"{@type=korap:token, @value={@type=korap:term, @value=der, @attr=orth, @relation==}}," +
+					"{@type=korap:group, @alignment=left, @operands=[" +
+						"{@type=korap:sequence, @operands=[" +
+							"{@type=korap:token, @value={@type=korap:term, @value=große, @attr=orth, @relation==}}," +
+							"{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=orth, @relation==}}" +
+						"]}" +
+					"]}" +
+				"]}";
+		ppt = new PoliqarpPlusTree(query);
+		map = ppt.getRequestMap().get("query").toString();
+		assertEquals(align1b.replaceAll(" ", ""), map.replaceAll(" ", ""));
+		
 		// "([base=a]^[base=b])|[base=c]",
 		String align2 = 
 				"{@type=korap:group, @relation=or, @operands=[" +
 						"{@type=korap:sequence, @operands=[" +
 							"{@type=korap:token, @value={@type=korap:term, @value=a, @attr=base, @relation==}}," +
-							"{@type=korap:group, @relation=left-align, @operands=[" +
+							"{@type=korap:group, @alignment=left, @operands=[" +
 								"{@type=korap:token, @value={@type=korap:term, @value=b, @attr=base, @relation==}}" +
 							"]}" +
 						"]}," +
@@ -671,10 +687,12 @@
 				"{@type=korap:group, @relation=or, @operands=[" +
 						"{@type=korap:sequence, @operands=[" +
 							"{@type=korap:token, @value={@type=korap:term, @value=a, @attr=base, @relation==}}," +
-							"{@type=korap:group, @relation=left-align, @operands=[" +
-								"{@type=korap:token, @value={@type=korap:term, @value=b, @attr=base, @relation==}}" +
-							"]}," +
-							"{@type=korap:token, @value={@type=korap:term, @value=c, @attr=base, @relation==}}" +
+							"{@type=korap:group, @alignment=left, @operands=[" +
+								"{@type=korap:sequence, @operands=[" +
+									"{@type=korap:token, @value={@type=korap:term, @value=b, @attr=base, @relation==}}," +
+									"{@type=korap:token, @value={@type=korap:term, @value=c, @attr=base, @relation==}}" +
+								"]}" +
+							"]}" +
 						"]}," +
 						"{@type=korap:token, @value={@type=korap:term, @value=d, @attr=base, @relation==}}" +
 				"]}";
@@ -687,11 +705,13 @@
 				"{@type=korap:group, @relation=or, @operands=[" +
 						"{@type=korap:sequence, @operands=[" +
 							"{@type=korap:token, @value={@type=korap:term, @value=a, @attr=base, @relation==}}," +
-							"{@type=korap:group, @relation=left-align, @operands=[" +
-								"{@type=korap:token, @value={@type=korap:term, @value=b, @attr=base, @relation==}}" +
-							"]}," +
-							"{@type=korap:group, @relation=left-align, @operands=[" +
-								"{@type=korap:token, @value={@type=korap:term, @value=c, @attr=base, @relation==}}" +
+							"{@type=korap:group, @alignment=left, @operands=[" +
+								"{@type=korap:sequence, @operands=[" +
+									"{@type=korap:token, @value={@type=korap:term, @value=b, @attr=base, @relation==}}," +
+									"{@type=korap:group, @alignment=left, @operands=[" +
+										"{@type=korap:token, @value={@type=korap:term, @value=c, @attr=base, @relation==}}" +
+									"]}" +
+								"]}" +
 							"]}" +
 						"]}," +
 						"{@type=korap:token, @value={@type=korap:term, @value=d, @attr=base, @relation==}}" +
@@ -742,6 +762,20 @@
 		ppt = new PoliqarpPlusTree("Baum | Stein");
 		map = ppt.getRequestMap().get("query").toString();
 		assertEquals(simple4.replaceAll(" ", ""), map.replaceAll(" ", ""));		
+		
+		// Baum | Stein Haus
+		String query = "(Baum | Stein) Haus";
+		String simple5 = 
+				"{@type=korap:sequence, @operands=[" +
+					"{@type=korap:group, @relation=or, @operands=[" +
+						"{@type=korap:token, @value={@type=korap:term, @value=Baum, @attr=orth, @relation==}}, " +						
+						"{@type=korap:token, @value={@type=korap:term, @value=Stein, @attr=orth, @relation==}}" +
+					"]}," +
+					"{@type=korap:token, @value={@type=korap:term, @value=Haus, @attr=orth, @relation==}} " +			
+				"]}";
+		ppt = new PoliqarpPlusTree(query);
+		map = ppt.getRequestMap().get("query").toString();
+		assertEquals(simple5.replaceAll(" ", ""), map.replaceAll(" ", ""));		
 	}
 }