Added Span expansion query with exclusion
diff --git a/src/main/java/de/ids_mannheim/korap/query/SpanAttributeQuery.java b/src/main/java/de/ids_mannheim/korap/query/SpanAttributeQuery.java
index c752776..150f060 100644
--- a/src/main/java/de/ids_mannheim/korap/query/SpanAttributeQuery.java
+++ b/src/main/java/de/ids_mannheim/korap/query/SpanAttributeQuery.java
@@ -54,9 +54,10 @@
 	public String toString(String field) {
 		StringBuilder sb = new StringBuilder();
 		sb.append("spanAttribute(");
-		sb.append(firstClause.toString(field));
-		sb.append(",");
-		sb.append(isNegation ? "negated)" : "notNegated)");		
+		sb.append(firstClause.toString(field));		
+		if (isNegation)
+			sb.append( ", not");		
+		sb.append(")");
 		sb.append(ToStringUtils.boost(getBoost()));
 		return sb.toString();
 	}
diff --git a/src/main/java/de/ids_mannheim/korap/query/SpanExpansionQuery.java b/src/main/java/de/ids_mannheim/korap/query/SpanExpansionQuery.java
index cab5683..654cb52 100644
--- a/src/main/java/de/ids_mannheim/korap/query/SpanExpansionQuery.java
+++ b/src/main/java/de/ids_mannheim/korap/query/SpanExpansionQuery.java
@@ -10,49 +10,95 @@
 import org.apache.lucene.search.spans.Spans;
 import org.apache.lucene.util.Bits;
 
+import de.ids_mannheim.korap.query.spans.ExpandedExclusionSpans;
 import de.ids_mannheim.korap.query.spans.ExpandedSpans;
 
-/** Query to make a span longer by stretching out the start or 
- * 	the end position of the span.
+/** Query to make a span longer by stretching out the start or the end 
+ * 	position of the span. The constraints of the expansion, such as how 
+ * 	large the expansion should be (min and max position) and the 
+ * 	direction of the expansion with respect to the "main" span, are 
+ * 	specified in ExpansionConstraint.
+ * 
+ * 	The expansion can be specified to not contain any direct/immediate
+ * 	/adjacent occurrence(s) of another span. Examples:
+ * 		[orth=der][orth!=Baum] 		"der" cannot be followed by "Baum" 
+ * 		[pos!=ADJ]{1,2}[orth=Baum]	one or two adjectives cannot precedes 
+ * 									"Baum"
+ * 
+ *  The offsets of the expansion parts can be collected by using a class 
+ *  number. 
  * 
  * 	@author margaretha
  * */
 public class SpanExpansionQuery extends SimpleSpanQuery{
-
-	int min, max; 
-	byte classNumber;
-	boolean isBefore;
+	 
+	private int min, max; // min, max expansion position
 	
-	public SpanExpansionQuery(SpanQuery firstClause, int min, int max,  
-			boolean isBefore, boolean collectPayloads) {		
+	// if > 0, collect expansion offsets using this label
+	private byte classNumber;
+	
+	// expansion direction with regard to the main span: 
+	// < 0 	to the left of main span 
+	// >= 0  to the right of main span
+	private int direction;	
+	
+	// if true, no occurrence of another span
+	final boolean isExclusion; 
+	
+	/** Simple expansion for any/empty token. Use 
+	 * 	{@link #SpanExpansionQuery(SpanQuery, SpanQuery, ExpansionConstraint, 
+	 * 	boolean)} for expansion with exclusions of a specific spanquery. 
+	 * */
+	public SpanExpansionQuery(SpanQuery firstClause, int min, int max, int direction, 
+			boolean collectPayloads) {
 		super(firstClause, collectPayloads);
 		this.min = min;
 		this.max = max;
-		this.isBefore = isBefore;
+		this.direction = direction;
+		this.isExclusion = false;
 	}
 	
-	public SpanExpansionQuery(SpanQuery firstClause, int min, int max, 
-			byte classNumber, boolean isBefore, boolean collectPayloads) {		
-		this(firstClause, min,max,isBefore,collectPayloads);
+	public SpanExpansionQuery(SpanQuery firstClause, int min, int max, int direction, 
+			byte classNumber, boolean collectPayloads) {
+		this(firstClause, min, max, direction, collectPayloads);		
 		this.classNumber = classNumber;
 	}
-
+	
+	/** Expansion with exclusions of the spanquery specified as the second 
+	 * 	parameter.
+	 * */
+	public SpanExpansionQuery(SpanQuery firstClause, SpanQuery notClause, int min, 
+			int max, int direction, boolean collectPayloads) {
+		super(firstClause, notClause, collectPayloads);
+		this.min = min;
+		this.max = max;
+		this.direction = direction;
+		this.isExclusion = true;
+	}
+		
+	
 	@Override
 	public SimpleSpanQuery clone() {
-		SpanExpansionQuery sq = new SpanExpansionQuery(
-				firstClause, 
-				min, 
-				max, 
-				isBefore,
-				collectPayloads);
+		SpanExpansionQuery sq = null;
+		if (isExclusion){
+			sq = new SpanExpansionQuery(firstClause, secondClause, min, max, 
+					direction, collectPayloads);
+		}
+		else{
+			sq = new SpanExpansionQuery(firstClause, min, max, direction, classNumber,
+					collectPayloads);
+		}
 		//sq.setBoost(sq.getBoost());
 		return sq;
 	}
 
 	@Override
 	public Spans getSpans(AtomicReaderContext context, Bits acceptDocs,
-			Map<Term, TermContext> termContexts) throws IOException {
-		return new ExpandedSpans(this, context, acceptDocs, termContexts);
+			Map<Term, TermContext> termContexts) throws IOException {		 
+		if (isExclusion)
+			return new ExpandedExclusionSpans(this, context, acceptDocs, termContexts);		
+		else
+			return new ExpandedSpans(this, context, acceptDocs, termContexts);
 	}
 
 	@Override
@@ -60,14 +106,26 @@
 		StringBuilder sb = new StringBuilder();
 		sb.append("spanExpansion(");
 		sb.append(firstClause.toString());
-		sb.append(",[");
+		if (isExclusion && secondClause != null){
+			sb.append(", !");
+			sb.append(secondClause.toString());
+		}
+		else{
+			sb.append(", []");
+		}
+		sb.append("{");
 		sb.append(min);
-		sb.append(",");
+		sb.append(", ");
 		sb.append(max);
-		sb.append("],");		
-		if (isBefore)
-			sb.append("left)");
-		else sb.append("right)");
+		sb.append("}, ");		
+		if (direction < 0)
+			sb.append("left");
+		else sb.append("right");
+		if (classNumber > 0){
+			sb.append(", class:");
+			sb.append(classNumber);			
+		}
+		sb.append(")");
 		return sb.toString();
 	}
 
@@ -87,14 +145,6 @@
 		this.max = max;
 	}
 
-	public boolean isBefore() {
-		return isBefore;
-	}
-
-	public void setBefore(boolean isBefore) {
-		this.isBefore = isBefore;
-	}
-
 	public byte getClassNumber() {
 		return classNumber;
 	}
@@ -102,4 +152,12 @@
 	public void setClassNumber(byte classNumber) {
 		this.classNumber = classNumber;
 	}
+
+	public int getDirection() {
+		return direction;
+	}
+
+	public void setDirection(int direction) {
+		this.direction = direction;
+	}
 }
diff --git a/src/main/java/de/ids_mannheim/korap/query/SpanRepetitionQuery.java b/src/main/java/de/ids_mannheim/korap/query/SpanRepetitionQuery.java
index 97ecd0a..94b273b 100644
--- a/src/main/java/de/ids_mannheim/korap/query/SpanRepetitionQuery.java
+++ b/src/main/java/de/ids_mannheim/korap/query/SpanRepetitionQuery.java
@@ -50,13 +50,13 @@
 	@Override
 	public String toString(String field) {
 		StringBuilder sb = new StringBuilder();		
-		sb.append("spanQuantifier(");
+		sb.append("spanRepetition(");
 		sb.append(firstClause.toString(field));
-		sb.append("[");
+		sb.append("{");
 		sb.append(min);
-		sb.append(":");
+		sb.append(",");
 		sb.append(max);
-		sb.append("])");
+		sb.append("})");
 		sb.append(ToStringUtils.boost(getBoost()));
 		return sb.toString();
 	}
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/ElementAttributeSpans.java b/src/main/java/de/ids_mannheim/korap/query/spans/ElementAttributeSpans.java
index 9a1c13b..a378e1a 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/ElementAttributeSpans.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/ElementAttributeSpans.java
@@ -122,7 +122,8 @@
 	 * */
 	private boolean checkNotElementRef() throws IOException{
 		for (AttributeSpans notAttribute: notAttributeList){
-			if (elements.start() == notAttribute.start() &&
+			if (!notAttribute.isFinish() && 
+					elements.start() == notAttribute.start() &&
 					elements.getElementRef() == notAttribute.getElementRef()){
 			        if (DEBUG)
 				    logger.info("not attribute ref exists");
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/ExpandedSpans.java b/src/main/java/de/ids_mannheim/korap/query/spans/ExpandedSpans.java
index 2f8ebed..68ae7f2 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/ExpandedSpans.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/ExpandedSpans.java
@@ -20,7 +20,7 @@
 	
 	private int min, max;
 	private byte classNumber;
-	private boolean isBefore;	
+	private int direction;	
 	private List<CandidateSpan> candidateSpans;
 	private long matchCost;
 	
@@ -30,8 +30,8 @@
 		super(spanExpansionQuery, context, acceptDocs, termContexts);
 		this.min = spanExpansionQuery.getMin();
 		this.max = spanExpansionQuery.getMax();
+		this.direction = spanExpansionQuery.getDirection();
 		this.classNumber = spanExpansionQuery.getClassNumber();
-		this.isBefore = spanExpansionQuery.isBefore();
 		
 		candidateSpans = new ArrayList<CandidateSpan>();		
 		hasMoreSpans = true;		
@@ -63,7 +63,7 @@
 		CandidateSpan cs;
 		int counter, start, end;
 		
-		if (isBefore){
+		if (direction < 0 ){
 			counter = max;
 			while (counter >= min ){
 				start =  Math.max(0,firstSpans.start() - counter);			
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestAttributeIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestAttributeIndex.java
index 8a00787..5749746 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestAttributeIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestAttributeIndex.java
@@ -233,6 +233,4 @@
 		assertEquals(1,kr.getMatch(0).getStartPos());
 		assertEquals(5,kr.getMatch(0).getEndPos());		
 	}
-	
-	
 }
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestMultipleDistanceIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestMultipleDistanceIndex.java
index 038b157..a3e649b 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestMultipleDistanceIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestMultipleDistanceIndex.java
@@ -179,7 +179,7 @@
 		constraints.add(createConstraint("p", 0, 0, false, false));
 		mdq = createQuery("s:b", "s:c", constraints,false);
 		kr = ki.search(mdq, (short) 10);		
-		assertEquals(3, kr.getTotalResults());		
+		assertEquals(3, kr.getTotalResults());	
 
 	}
     
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestRepetitionIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestRepetitionIndex.java
index 02df26c..243627c 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestRepetitionIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestRepetitionIndex.java
@@ -11,6 +11,7 @@
 import org.junit.Test;
 
 import de.ids_mannheim.korap.KorapIndex;
+import de.ids_mannheim.korap.KorapMatch;
 import de.ids_mannheim.korap.KorapResult;
 import de.ids_mannheim.korap.query.SpanNextQuery;
 import de.ids_mannheim.korap.query.SpanRepetitionQuery;
@@ -43,15 +44,15 @@
         fd.addString("ID", "doc-1");
         fd.addTV("base",
             "text",             
-            "[(0-1)s:b|_1#0-1|<>:s#0-2$<i>1]" +
-            "[(1-2)s:e|_2#1-2|<>:s#1-2$<i>4]" +             
+            "[(0-1)s:b|_1#0-1]" +
+            "[(1-2)s:e|_2#1-2]" +             
             "[(2-3)s:c|_3#2-3]" +
-            "[(3-4)s:c|s:d|_4#3-4]" + 
-            "[(4-5)s:d|_5#4-5|<>:s#4-5$<i>7]" +             
-            "[(5-6)s:e|_6#5-6]" +
+            "[(3-4)s:c|s:d]" + 
+            "[(4-5)s:d|s:c|_5#4-5]" +             
+            "[(5-6)s:e|s:c|_6#5-6]" +
     		"[(6-7)s:e|_7#6-7]" +	
-	        "[(7-8)s:c|_8#7-8|<>:x#7-9$<i>9]" + 
-	        "[(8-9)s:d|_9#8-9|<>:x#8-10$<i>10]" + 
+	        "[(7-8)s:c|_8#7-8]" + 
+	        "[(8-9)s:d|_9#8-9]" + 
 	        "[(9-10)s:d|_10#9-10]");
         return fd;
 	}
@@ -81,8 +82,7 @@
             "[(2-3)s:e|_3#2-3]");	
         return fd;
 	}
-	
-	
+
 	@Test
 	public void testCase1() throws IOException{
 		ki = new KorapIndex();
@@ -91,6 +91,7 @@
         
         SpanQuery sq, sq2;
         // Quantifier only
+        // c{1,2}
         sq = new SpanRepetitionQuery(new SpanTermQuery(new Term("base","s:c")),1,2, true);
         kr = ki.search(sq, (short) 10);
         // 0-1, 2-3, 2-4, 3-4, 5-6
@@ -133,10 +134,13 @@
         ki.commit();
         
         SpanQuery sq;
+        // c{2,2}
         sq = new SpanRepetitionQuery(new SpanTermQuery(new Term("base","s:c")),2,2, true);
         kr = ki.search(sq, (short) 10);
-        assertEquals(4,kr.getTotalResults());
-		
+        // doc1 2-4, 3-5, 4-6
+        assertEquals(6,kr.getTotalResults());
+        
+        // ec{2,2}
         kr = ki.search(sq, (short) 10); 
         sq = new SpanNextQuery(
         		new SpanTermQuery(new Term("base", "s:e")),
@@ -173,6 +177,26 @@
         assertEquals(6, kr.getMatch(1).endPos);
         assertEquals(7, kr.getMatch(2).startPos);
         assertEquals(9, kr.getMatch(2).endPos);
+
+	}
+	
+	@Test
+	public void testCase4() throws IOException {
+		ki = new KorapIndex();
+        ki.addDoc(createFieldDoc1());
+        ki.commit();
+        
+		SpanQuery sq;
+        // c{2,2}
+        sq = new SpanRepetitionQuery(new SpanTermQuery(new Term("base","s:c")),1,3, true);
+        kr = ki.search(sq, (short) 10);
+        // 2-3, 2-4, 2-5, 3-4, 3-5, 3-6, 4-5, 4-6, 5-6, 7-8  
+        assertEquals(10,kr.getTotalResults());
+        
+        sq = new SpanRepetitionQuery(new SpanTermQuery(new Term("base","s:c")),2,3, true);
+        kr = ki.search(sq, (short) 10);
+        // 2-4, 2-5, 3-5, 3-6, 4-6 
+        assertEquals(5,kr.getTotalResults());
         
 //        System.out.print(kr.getTotalResults()+"\n");
 //		for (int i=0; i< kr.getTotalResults(); i++){
@@ -180,7 +204,45 @@
 //				kr.match(i).getLocalDocID()+" "+
 //				kr.match(i).startPos + " " +
 //				kr.match(i).endPos
-//		    );
+//			);
 //		}
 	}
+	
+	@Test
+	public void testCase5() throws IOException {
+		ki = new KorapIndex();
+		for (String i : new String[] {"AAA-12402"}) {
+		    ki.addDocFile(
+		        getClass().getResource("/wiki/" + i + ".json.gz").getFile(), true
+	            );
+		};
+		ki.commit();
+		
+		SpanQuery sq0, sq1, sq2;
+		sq0 = new SpanTermQuery(new Term("tokens", "s:Mann"));
+		sq1 = new SpanRepetitionQuery(new SpanTermQuery(new Term("tokens","cnx/p:A")),2,3, true);
+        sq2 = new SpanNextQuery(sq1,sq0);        
+        kr = ki.search(sq2, (short) 10);
+        
+        assertEquals(2,kr.getTotalResults());
+        assertEquals(672, kr.getMatch(0).getStartPos());
+        assertEquals(676, kr.getMatch(0).getEndPos());
+        assertEquals(673, kr.getMatch(1).getStartPos());
+        assertEquals(676, kr.getMatch(1).getEndPos());
+        
+        
+        sq2 = new SpanNextQuery(
+        		new SpanTermQuery(new Term("tokens", "s:scheinbar")),
+        		sq2);
+        kr = ki.search(sq2, (short) 10);
+        
+        assertEquals(1,kr.getTotalResults());
+        assertEquals(672, kr.getMatch(0).getStartPos());
+        assertEquals(676, kr.getMatch(0).getEndPos());
+        
+      /*  for (KorapMatch km : kr.getMatches()){
+        	System.out.println(km.getSnippetBrackets());
+        	System.out.println(km.getStartPos() +","+km.getEndPos());
+        }*/
+	}
 }
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestSpanExpansionIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestSpanExpansionIndex.java
index 4c1704e..1a9524a 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestSpanExpansionIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestSpanExpansionIndex.java
@@ -34,7 +34,7 @@
 	public void testCase1() throws IOException {
 		
 		SpanTermQuery stq = new SpanTermQuery(new Term("tokens","s:Kaiser")	);
-		SpanExpansionQuery seq = new SpanExpansionQuery(stq, 0, 2, true, true);		
+		SpanExpansionQuery seq = new SpanExpansionQuery(stq, 0, 2, -1, true);		
 		kr = ki.search(seq, (short) 10);
 		
 		assertEquals(72,kr.getTotalResults());
@@ -45,7 +45,7 @@
         assertEquals(7, kr.getMatch(2).getStartPos());
         assertEquals(8, kr.getMatch(2).getEndPos());
         
-        seq = new SpanExpansionQuery(stq, 3, 4, false, true);
+        seq = new SpanExpansionQuery(stq, 3, 4, 0, true);
         kr = ki.search(seq, (short) 10);
         
         assertEquals(7, kr.getMatch(0).getStartPos());
@@ -57,11 +57,11 @@
         assertEquals(15, kr.getMatch(3).getStartPos());
         assertEquals(20, kr.getMatch(3).getEndPos());
         
-//		for (KorapMatch km : kr.getMatches()){
-//			System.out.println(km.getStartPos() +","+km.getEndPos()+" "
-//					+km.getSnippetBrackets());
-//		}	
-		
+		/*for (KorapMatch km : kr.getMatches()){
+			System.out.println(km.getStartPos() +","+km.getEndPos()+" "
+					+km.getSnippetBrackets());
+		}	
+		*/
 	}
 	
 	/** Classnumber
@@ -73,12 +73,12 @@
 		
 		// create new payload for the expansion offsets
 		SpanTermQuery stq = new SpanTermQuery(new Term("tokens","s:Kaiser")	);
-		SpanExpansionQuery sq = new SpanExpansionQuery(stq, 0, 2, classNumber, true, true);		
+		SpanExpansionQuery sq = new SpanExpansionQuery(stq, 0, 2, -1, classNumber, true);		
 		kr = ki.search(sq, (short) 10);
 				
 		// add expansion offsets to the existing payload
 		SpanElementQuery seq = new SpanElementQuery("tokens", "cnx/c:np");
-		sq = new SpanExpansionQuery(seq, 1, 2, classNumber, false, true);		
+		sq = new SpanExpansionQuery(seq, 1, 2, 0, classNumber, true);		
 		kr = ki.search(sq, (short) 10);
 		
 		/*for (KorapMatch km : kr.getMatches()){		
@@ -87,4 +87,39 @@
 		}*/
 	}
 	
+	
+	/** Expansion with exclusion
+	 * */
+	@Test
+	public void testCase3() throws IOException {
+		
+		SpanTermQuery stq = new SpanTermQuery(new Term("tokens","cnx/p:N")	);
+		SpanTermQuery notQuery = new SpanTermQuery(new Term("tokens","s:September"));
+		
+		SpanExpansionQuery seq = new SpanExpansionQuery(stq, notQuery, 2, 3, 0, true);		
+		kr = ki.search(seq, (short) 20);
+		
+		/*for (KorapMatch km : kr.getMatches()){
+			System.out.println(km.getStartPos() +","+km.getEndPos()+" "
+					+km.getSnippetBrackets());
+		}*/
+	}
+	
+	/** Expansion with exclusion
+	 * */
+	@Test
+	public void testCase4() throws IOException {
+		
+		SpanTermQuery stq = new SpanTermQuery(new Term("tokens","cnx/p:N")	);
+		SpanTermQuery notQuery = new SpanTermQuery(new Term("tokens","cnx/p:A"));
+		
+		SpanExpansionQuery seq = new SpanExpansionQuery(stq, notQuery, 0, 2, -1, true);		
+		kr = ki.search(seq, (short) 10);
+		
+		for (KorapMatch km : kr.getMatches()){
+			System.out.println(km.getStartPos() +","+km.getEndPos()+" "
+					+km.getSnippetBrackets());
+		}
+	}
+	
 }
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestSubSpanIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestSubSpanIndex.java
index ae2cef4..179effa 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestSubSpanIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestSubSpanIndex.java
@@ -54,7 +54,7 @@
 		kr = ki.search(ssq, (short) 10);
 		
 		assertEquals(34, kr.getMatch(0).getStartPos());
-        assertEquals(35, kr.getMatch(0).getEndPos());
+        assertEquals(36, kr.getMatch(0).getEndPos());
         assertEquals(85, kr.getMatch(1).getStartPos());
         assertEquals(87, kr.getMatch(1).getEndPos());
 	}
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestUnorderedDistanceIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestUnorderedDistanceIndex.java
index b9f7065..ddff51d 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestUnorderedDistanceIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestUnorderedDistanceIndex.java
@@ -283,7 +283,7 @@
 		        getClass().getResource("/a00/" + i + ".json.gz").getFile(), true
 	            );
 		};
-		ki.commit();	    	
+		ki.commit();
 		
 		SpanQuery sq = new SpanDistanceQuery(
         		new SpanTermQuery(new Term("tokens","s:in")),
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestWPDIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestWPDIndex.java
index a5a945e..4f6226d 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestWPDIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestWPDIndex.java
@@ -84,6 +84,12 @@
 		ks = new KorapSearch(sq);
 		kr = ks.run(ki);
 		assertEquals(11, kr.getTotalResults());
+		//System.out.println(kr.getTotalResults());
+		//for (KorapMatch km : kr.getMatches()){
+			//System.out.println(km.getDocID() +" "+km.getStartPos() +" "+ km.getEndPos());
+        	//System.out.println(km.getSnippetBrackets());
+        	//System.out.println(km.toJSON());
+        //}	
 	}
 	
 	/** Token exclusion distance spans */
@@ -107,12 +113,6 @@
 		ks = new KorapSearch(sq);
 		kr = ks.run(ki);
 		assertEquals(1896, kr.getTotalResults());	
-		
-//		System.out.println(kr.getTotalResults());
-//		for (KorapMatch km : kr.getMatches()){
-//			System.out.println(km.getDocID() +" "+km.getStartPos() +" "+ km.getEndPos());
-//        	System.out.println(km.getSnippetBrackets());
-//        }
 	}
 	
 	/** Element distance spans */
@@ -169,7 +169,7 @@
 		assertEquals(451,kr.getMatch(1).getEndPos());		
 	}
 			
-	/** Quantifier */
+	/** Repetition */
 	@Test
 	public void testCase5() throws IOException{
 		SpanQuery sq;
@@ -191,7 +191,7 @@
 		//0.65s
 	}
 	
-	/** Next and quantifier */
+	/** Next and repetition */
 	@Test
 	public void testCase6() throws IOException{
 		SpanQuery sq = new SpanNextQuery(
diff --git a/src/test/java/de/ids_mannheim/korap/query/TestKorapQueryJSON.java b/src/test/java/de/ids_mannheim/korap/query/TestKorapQueryJSON.java
index da0d5d7..0d99899 100644
--- a/src/test/java/de/ids_mannheim/korap/query/TestKorapQueryJSON.java
+++ b/src/test/java/de/ids_mannheim/korap/query/TestKorapQueryJSON.java
@@ -1,3 +1,5 @@
+package de.ids_mannheim.korap.query;
+
 import java.util.*;
 import java.io.*;
 
@@ -25,7 +27,7 @@
 	// There is a repetition in here
 	// ([base=foo]|[base=bar])[base=foobar]
 	assertEquals(sqwi.toQuery().toString(),
-            "spanOr([tokens:base:foo, spanQuantifier(spanNext(tokens:base:foo, tokens:base:bar)[1:100])])");
+            "spanOr([tokens:base:foo, spanRepetition(spanNext(tokens:base:foo, tokens:base:bar){1,100})])");
 	assertTrue(sqwi.isOptional());
     };
 
@@ -269,7 +271,7 @@
 	SpanQueryWrapperInterface sqwi = jsonQuery(getClass().getResource("/queries/bsp-repetition.jsonld").getFile());
 
 	// der[cnx/p=A]{0,2}[tt/p=NN]
-	assertEquals(sqwi.toQuery().toString(), "spanNext(spanOr([tokens:s:der, spanNext(tokens:s:der, spanQuantifier(tokens:cnx/p:A[1:2]))]), tokens:tt/p:NN)");
+	assertEquals(sqwi.toQuery().toString(), "spanNext(spanOr([tokens:s:der, spanNext(tokens:s:der, spanRepetition(tokens:cnx/p:A{1,2}))]), tokens:tt/p:NN)");
     };
 
     public static String getString (String path) {