Added SpanWithAttributeQueryWrapper.
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 49e3cb6..5f4c262 100644
--- a/src/main/java/de/ids_mannheim/korap/query/SpanAttributeQuery.java
+++ b/src/main/java/de/ids_mannheim/korap/query/SpanAttributeQuery.java
@@ -6,6 +6,7 @@
 import org.apache.lucene.index.AtomicReaderContext;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermContext;
+import org.apache.lucene.search.spans.SpanQuery;
 import org.apache.lucene.search.spans.SpanTermQuery;
 import org.apache.lucene.search.spans.Spans;
 import org.apache.lucene.util.Bits;
@@ -95,9 +96,8 @@
     public String toString(String field) {
         StringBuilder sb = new StringBuilder();
         sb.append("spanAttribute(");
+		if (negation) sb.append("!");
         sb.append(firstClause.toString(field));
-        if (negation)
-            sb.append(", not");
         sb.append(")");
         sb.append(ToStringUtils.boost(getBoost()));
         return sb.toString();
diff --git a/src/main/java/de/ids_mannheim/korap/query/wrap/SpanAttributeQueryWrapper.java b/src/main/java/de/ids_mannheim/korap/query/wrap/SpanAttributeQueryWrapper.java
index 07ca212..87c9d90 100644
--- a/src/main/java/de/ids_mannheim/korap/query/wrap/SpanAttributeQueryWrapper.java
+++ b/src/main/java/de/ids_mannheim/korap/query/wrap/SpanAttributeQueryWrapper.java
@@ -6,15 +6,26 @@
 import de.ids_mannheim.korap.query.SpanAttributeQuery;
 import de.ids_mannheim.korap.util.QueryException;
 
+/**
+ * @author margaretha
+ * */
 public class SpanAttributeQueryWrapper extends SpanQueryWrapper {
 
-    boolean isNegation = false;
     private SpanQueryWrapper subquery;
 
-    public SpanAttributeQueryWrapper (SpanQueryWrapper sqw, boolean inclusion) {
+	public SpanAttributeQueryWrapper(SpanQueryWrapper sqw) {
+		if (sqw == null) {
+			isNull = true;
+			return;
+		}
+		if (sqw.isEmpty()) {
+			isEmpty = true;
+			return;
+		}
+
         this.subquery = sqw;
-        if (!inclusion) {
-            this.isNegation = true;
+		if (sqw.isNegative) {
+			this.isNegative = true;
         };
 
         if (sqw.maybeUnsorted())
@@ -22,13 +33,20 @@
     };
 
     @Override
-    public SpanQuery toQuery() throws QueryException {
-
+	public SpanQuery toQuery() throws QueryException {
+    	if (isNull || isEmpty) return null;
+    		
         SpanQuery sq = subquery.retrieveNode(this.retrieveNode).toQuery();
+		if (sq == null) {
+			isNull = true;
+			return null;
+		}
+		
         if (sq instanceof SpanTermQuery) {
-            return new SpanAttributeQuery((SpanTermQuery) sq, isNegation, true);
+			return new SpanAttributeQuery((SpanTermQuery) sq, isNegative, true);
         }
-
-        return null; // or exception??
+        else {
+        	throw new IllegalArgumentException("The subquery is not a SpanTermQuery.");
+        }		
     }
 }
diff --git a/src/main/java/de/ids_mannheim/korap/query/wrap/SpanSimpleQueryWrapper.java b/src/main/java/de/ids_mannheim/korap/query/wrap/SpanSimpleQueryWrapper.java
index 39c1a7d..ad72570 100644
--- a/src/main/java/de/ids_mannheim/korap/query/wrap/SpanSimpleQueryWrapper.java
+++ b/src/main/java/de/ids_mannheim/korap/query/wrap/SpanSimpleQueryWrapper.java
@@ -12,6 +12,11 @@
         this.query = new SpanTermQuery(new Term(field, term));
     };
 
+	public SpanSimpleQueryWrapper(String field, String term, boolean value) {
+		this(field, term);
+		this.isNegative = !value;
+	}
+
     public SpanSimpleQueryWrapper (SpanQuery query) {
         this.isNull = false;
         this.query = query;
diff --git a/src/main/java/de/ids_mannheim/korap/query/wrap/SpanSubspanQueryWrapper.java b/src/main/java/de/ids_mannheim/korap/query/wrap/SpanSubspanQueryWrapper.java
index 1b3d160..2126ee0 100644
--- a/src/main/java/de/ids_mannheim/korap/query/wrap/SpanSubspanQueryWrapper.java
+++ b/src/main/java/de/ids_mannheim/korap/query/wrap/SpanSubspanQueryWrapper.java
@@ -9,9 +9,6 @@
 import de.ids_mannheim.korap.util.QueryException;
 
 /**
- * Automatically handle the length parameter if it is less than 0, then no
- * SpanSubspanQuery is created, but a SpanQuery for the subquery ?
- * 
  * @author margaretha, diewald
  * 
  */
@@ -102,15 +99,10 @@
 
 	@Override
 	public SpanQuery toQuery() throws QueryException {
-
-		if (this.isNull()) {
-			// if (DEBUG) log.warn("Subquery of SpanSubspanquery is null.");
-			return null;
-		}
+		if (this.isNull()) { return null; }
 
 		SpanQuery sq = subquery.retrieveNode(this.retrieveNode).toQuery();
-		if (sq == null)
-			return null;
+		if (sq == null) return null;
 		if (sq instanceof SpanTermQuery) {
 			if (subquery.isNegative()) {
 				return sq;
diff --git a/src/main/java/de/ids_mannheim/korap/query/wrap/SpanWithAttributeQueryWrapper.java b/src/main/java/de/ids_mannheim/korap/query/wrap/SpanWithAttributeQueryWrapper.java
new file mode 100644
index 0000000..517e4c6
--- /dev/null
+++ b/src/main/java/de/ids_mannheim/korap/query/wrap/SpanWithAttributeQueryWrapper.java
@@ -0,0 +1,120 @@
+package de.ids_mannheim.korap.query.wrap;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.lucene.search.spans.SpanQuery;
+import org.apache.lucene.search.spans.SpanTermQuery;
+
+import de.ids_mannheim.korap.query.SpanAttributeQuery;
+import de.ids_mannheim.korap.query.SpanWithAttributeQuery;
+import de.ids_mannheim.korap.query.SpanWithIdQuery;
+import de.ids_mannheim.korap.util.QueryException;
+
+public class SpanWithAttributeQueryWrapper extends SpanQueryWrapper {
+
+	private SpanQueryWrapper withIdQueryWrapper = null;
+	private SpanQueryWrapper attrQueryWrapper = null;
+	private List<SpanQueryWrapper> queryWrapperList = null;
+
+	public SpanWithAttributeQueryWrapper(SpanQueryWrapper withIdQuery,
+			SpanQueryWrapper attrQuery) {
+
+		if (withIdQuery != null || attrQuery != null) {
+			isNull = false;
+		}
+		if (withIdQuery.isEmpty || attrQuery.isEmpty()) {
+			isEmpty = true;
+			return;
+		}
+
+		this.attrQueryWrapper = attrQuery;
+		this.withIdQueryWrapper = withIdQuery;
+	}
+
+	public SpanWithAttributeQueryWrapper(SpanQueryWrapper withIdQuery,
+			List<SpanQueryWrapper> attrList) {
+
+		if (withIdQuery != null || attrList != null) {
+			isNull = false;
+		}
+		if (withIdQuery.isEmpty) {
+			isEmpty = true;
+			return;
+		}
+
+		for (SpanQueryWrapper sqw : attrList) {
+			if (sqw == null) {
+				isNull = true;
+				return;
+			}
+			if (sqw.isEmpty) {
+				isEmpty = true;
+				return;
+			}
+		}
+		if (attrList.isEmpty()) {
+			// not withattribute query, just a normal query
+		}
+		this.queryWrapperList = attrList;
+		this.withIdQueryWrapper = withIdQuery;
+	}
+
+	public SpanAttributeQuery createSpanAttributeQuery(
+			SpanQueryWrapper attrQueryWrapper) throws QueryException {
+		SpanQuery sq = attrQueryWrapper.toQuery();
+		if (sq == null) {
+			isNull = true;
+			return null;
+		}
+		if (sq instanceof SpanTermQuery) {
+			return new SpanAttributeQuery(
+					(SpanTermQuery) sq,
+					attrQueryWrapper.isNegative, true);
+		} 
+		else {
+			throw new IllegalArgumentException(
+					"The subquery is not a SpanTermQuery.");
+		}
+	}
+
+	@Override
+	public SpanQuery toQuery() throws QueryException {
+
+		if (isNull || isEmpty) return null;
+		
+		SpanWithIdQuery withIdQuery = (SpanWithIdQuery) withIdQueryWrapper
+				.toQuery();
+		if (withIdQuery == null) {
+			isNull = true;
+			return null;
+		}
+		
+		if (attrQueryWrapper != null){
+			SpanAttributeQuery attrQuery = createSpanAttributeQuery(attrQueryWrapper);
+			if (attrQuery == null) {
+				isNull = true;
+				return null;
+			}
+			return new SpanWithAttributeQuery(withIdQuery, attrQuery, true);
+		}
+		else if (queryWrapperList != null) {
+			if (queryWrapperList.isEmpty()) {
+				return withIdQuery;
+			}
+
+			List<SpanQuery> attrQueries = new ArrayList<SpanQuery>();
+			SpanQuery attrQuery;
+			for (SpanQueryWrapper sqw : queryWrapperList) {
+				attrQuery = createSpanAttributeQuery(sqw);
+				if (attrQuery == null) {
+					isNull = true;
+					return null;
+				}
+				attrQueries.add(attrQuery);
+			}
+			return new SpanWithAttributeQuery(withIdQuery, attrQueries, true);
+		}
+		return null;		
+	}
+}