Spans now always wrap terms

Change-Id: I9f2685aaeb8bb916fb4df211044ad24e381bef07
diff --git a/Changes b/Changes
index 8cc2db8..ffea7ec 100644
--- a/Changes
+++ b/Changes
@@ -1,7 +1,14 @@
-0.2 2015-10-27
-        - Switch to "koral:" prefix.
+0.22 2016-06-03
+        - Spans now always wrap terms (diewald)
+
+0.21 2015-10-27
+        - Improved meta query builder (hanl)
+
+0.2 2015-06-25
+        - Switch to "koral:" prefix (bingel)
 	- Coverage of KoralQuery 0.3
 	  (see http://korap.github.io/Koral/)
+          (bingel)
 
 0.1 2015-02-10
-        - First version published to GitHub.
+        - First version published to GitHub (bingel)
diff --git a/pom.xml b/pom.xml
index 77bbae3..76d29f5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
 
   <groupId>de.ids_mannheim.korap</groupId>
   <artifactId>Koral</artifactId>
-  <version>0.21</version>
+  <version>0.22</version>
   <packaging>jar</packaging>
   <name>Koral</name>
   <url>http://maven.apache.org</url>
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/MetaQueryBuilder.java b/src/main/java/de/ids_mannheim/korap/query/serialize/MetaQueryBuilder.java
index 3726a56..93aa5f7 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/MetaQueryBuilder.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/MetaQueryBuilder.java
@@ -1,10 +1,5 @@
 package de.ids_mannheim.korap.query.serialize;
 
-import lombok.AccessLevel;
-import lombok.Data;
-import lombok.Getter;
-import lombok.Setter;
-
 import java.util.LinkedHashMap;
 import java.util.LinkedList;
 import java.util.List;
@@ -83,7 +78,6 @@
         return meta;
     }
 
-    @Data
     public class SpanContext {
         private String left_type;
         private String right_type;
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusQueryProcessor.java b/src/main/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusQueryProcessor.java
index 3ff73df..03117dd 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusQueryProcessor.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusQueryProcessor.java
@@ -654,6 +654,7 @@
         ArrayList<Object> operands = (ArrayList<Object>) contains
                 .get("operands");
         operands.add(span);
+
         operands.add(queryObj);
         requestMap.put("query", contains);
         visited.add(node.getChild(0));
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/util/KoralObjectGenerator.java b/src/main/java/de/ids_mannheim/korap/query/serialize/util/KoralObjectGenerator.java
index 20de50c..8381176 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/util/KoralObjectGenerator.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/util/KoralObjectGenerator.java
@@ -27,7 +27,9 @@
     public static LinkedHashMap<String, Object> makeSpan (String key) {
         LinkedHashMap<String, Object> span = new LinkedHashMap<String, Object>();
         span.put("@type", "koral:span");
-        span.put("key", key);
+        LinkedHashMap<String, Object> term = makeTerm();
+        term.put("key", key);
+        span.put("wrap", term);
         return span;
     }
 
@@ -334,4 +336,4 @@
         }
         return number;
     }
-}
\ No newline at end of file
+}
diff --git a/src/test/java/de/ids_mannheim/korap/query/serialize/Cosmas2QueryProcessorTest.java b/src/test/java/de/ids_mannheim/korap/query/serialize/Cosmas2QueryProcessorTest.java
index fa3adc8..802ba9e 100644
--- a/src/test/java/de/ids_mannheim/korap/query/serialize/Cosmas2QueryProcessorTest.java
+++ b/src/test/java/de/ids_mannheim/korap/query/serialize/Cosmas2QueryProcessorTest.java
@@ -18,7 +18,8 @@
  * Tests for JSON-LD serialization of Cosmas II queries.
  * 
  * @author Joachim Bingel (bingel@ids-mannheim.de)
- * @version 1.0
+ * @author Nils Diewald
+ * @version 1.1
  */
 public class Cosmas2QueryProcessorTest {
 
@@ -685,7 +686,7 @@
                         .asText());
         assertEquals(
                 "s",
-                res.at("/query/operands/0/operands/0/operands/0/operands/0/key")
+                res.at("/query/operands/0/operands/0/operands/0/operands/0/wrap/key")
                         .asText());
         assertEquals("koral:group",
                 res.at("/query/operands/0/operands/0/operands/1/@type")
@@ -727,7 +728,7 @@
         assertEquals("koral:span",
                 res.at("/query/operands/0/operands/0/operands/0/@type")
                         .asText());
-        assertEquals("s", res.at("/query/operands/0/operands/0/operands/0/key")
+        assertEquals("s", res.at("/query/operands/0/operands/0/operands/0/wrap/key")
                 .asText());
         assertEquals("koral:group", res
                 .at("/query/operands/0/operands/1/@type").asText());
@@ -859,7 +860,7 @@
                         .asText());
         assertEquals(
                 "s",
-                res.at("/query/operands/0/operands/0/operands/0/operands/0/key")
+                res.at("/query/operands/0/operands/0/operands/0/operands/0/wrap/key")
                         .asText());
         assertEquals("koral:group",
                 res.at("/query/operands/0/operands/0/operands/1/@type")
@@ -1400,7 +1401,7 @@
                         .asText());
         assertEquals("koral:span", res.at("/query/operands/0/operands/0/@type")
                 .asText());
-        assertEquals("s", res.at("/query/operands/0/operands/0/key").asText());
+        assertEquals("s", res.at("/query/operands/0/operands/0/wrap/key").asText());
 
         query = "#BED(der Mann , +pe)";
         qs.setQuery(query, "cosmas2");
@@ -1424,7 +1425,7 @@
         assertEquals("koral:span",
                 res.at("/query/operands/0/operands/0/operands/0/@type")
                         .asText());
-        assertEquals("p", res.at("/query/operands/0/operands/0/operands/0/key")
+        assertEquals("p", res.at("/query/operands/0/operands/0/operands/0/wrap/key")
                 .asText());
         assertEquals("koral:reference",
                 res.at("/query/operands/0/operands/1/@type").asText());
@@ -1477,7 +1478,7 @@
         assertEquals("koral:span",
                 res.at("/query/operands/0/operands/0/operands/0/@type")
                         .asText());
-        assertEquals("s", res.at("/query/operands/0/operands/0/operands/0/key")
+        assertEquals("s", res.at("/query/operands/0/operands/0/operands/0/wrap/key")
                 .asText());
         assertEquals("koral:group",
                 res.at("/query/operands/0/operands/0/operands/1/@type")
@@ -1512,7 +1513,7 @@
         assertEquals("koral:span",
                 res.at("/query/operands/0/operands/1/operands/0/@type")
                         .asText());
-        assertEquals("p", res.at("/query/operands/0/operands/1/operands/0/key")
+        assertEquals("p", res.at("/query/operands/0/operands/1/operands/0/wrap/key")
                 .asText());
         assertEquals("koral:group",
                 res.at("/query/operands/0/operands/1/operands/1/@type")
@@ -1566,7 +1567,7 @@
                         .asText());
         assertEquals("koral:span", res.at("/query/operands/0/operands/0/@type")
                 .asText());
-        assertEquals("s", res.at("/query/operands/0/operands/0/key").asText());
+        assertEquals("s", res.at("/query/operands/0/operands/0/wrap/key").asText());
 
         query = "der:sa,-pa";
         qs.setQuery(query, "cosmas2");
@@ -1588,7 +1589,7 @@
         assertEquals("koral:span",
                 res.at("/query/operands/0/operands/0/operands/0/@type")
                         .asText());
-        assertEquals("s", res.at("/query/operands/0/operands/0/operands/0/key")
+        assertEquals("s", res.at("/query/operands/0/operands/0/operands/0/wrap/key")
                 .asText());
         assertEquals("koral:group",
                 res.at("/query/operands/0/operands/0/operands/1/@type")
@@ -1614,7 +1615,7 @@
         assertEquals("koral:span",
                 res.at("/query/operands/0/operands/1/operands/0/@type")
                         .asText());
-        assertEquals("p", res.at("/query/operands/0/operands/1/operands/0/key")
+        assertEquals("p", res.at("/query/operands/0/operands/1/operands/0/wrap/key")
                 .asText());
         assertEquals("koral:group",
                 res.at("/query/operands/0/operands/1/operands/1/@type")
@@ -1650,7 +1651,7 @@
         assertEquals("koral:span",
                 res.at("/query/operands/0/operands/0/operands/0/@type")
                         .asText());
-        assertEquals("s", res.at("/query/operands/0/operands/0/operands/0/key")
+        assertEquals("s", res.at("/query/operands/0/operands/0/operands/0/wrap/key")
                 .asText());
         assertEquals("koral:group",
                 res.at("/query/operands/0/operands/0/operands/1/@type")
@@ -1702,7 +1703,7 @@
                         .asText());
         assertEquals(
                 "p",
-                res.at("/query/operands/0/operands/1/operands/0/operands/0/operands/0/key")
+                res.at("/query/operands/0/operands/1/operands/0/operands/0/operands/0/wrap/key")
                         .asText());
         assertEquals(
                 "koral:group",
@@ -1754,7 +1755,7 @@
                         .asText());
         assertEquals(
                 "t",
-                res.at("/query/operands/0/operands/1/operands/0/operands/1/operands/0/operands/0/key")
+                res.at("/query/operands/0/operands/1/operands/0/operands/1/operands/0/operands/0/wrap/key")
                         .asText());
         assertEquals(
                 "koral:reference",
diff --git a/src/test/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusQueryProcessorTest.java b/src/test/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusQueryProcessorTest.java
index b918649..7e3c9f3 100644
--- a/src/test/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusQueryProcessorTest.java
+++ b/src/test/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusQueryProcessorTest.java
@@ -1699,10 +1699,37 @@
         res = mapper.readTree(qs.toJSON());
         assertEquals("operation:position", res.at("/query/operation").asText());
         assertEquals("frames:isAround", res.at("/query/frames/0").asText());
-        assertEquals("s", res.at("/query/operands/0/key").asText());
+        assertEquals("s", res.at("/query/operands/0/wrap/key").asText());
         assertEquals("VVFIN", res.at("/query/operands/1/wrap/key").asText());
     }
 
+    @Test
+    public void testSpanSerialization () throws JsonProcessingException, IOException {
+
+        // Both constructs should be serialized identically
+        query = "contains(<s>, der)";
+        qs.setQuery(query, "poliqarpplus");
+        res = mapper.readTree(qs.toJSON());
+        assertEquals("koral:group", res.at("/query/@type").asText());
+        assertEquals("operation:position", res.at("/query/operation").asText());
+        assertEquals("frames:isAround", res.at("/query/frames/0").asText());
+        assertEquals(true, res.at("/query/frames/1").isMissingNode());
+        assertEquals("koral:span", res.at("/query/operands/0/@type").asText());
+        assertEquals("s", res.at("/query/operands/0/wrap/key").asText());
+        assertEquals("koral:token", res.at("/query/operands/1/@type").asText());
+
+        query = "der within s";
+        qs.setQuery(query, "poliqarpplus");
+        res = mapper.readTree(qs.toJSON());
+        assertEquals("koral:group", res.at("/query/@type").asText());
+        assertEquals("operation:position", res.at("/query/operation").asText());
+        assertEquals("frames:isAround", res.at("/query/frames/0").asText());
+        assertEquals(true, res.at("/query/frames/1").isMissingNode());
+        assertEquals("koral:span", res.at("/query/operands/0/@type").asText());
+        assertEquals("s", res.at("/query/operands/0/wrap/key").asText());
+        assertEquals("koral:token", res.at("/query/operands/1/@type").asText());
+    }
+
 
     @Test
     public void testMeta () throws JsonProcessingException, IOException {