Support for arbitrary left/right contexts

Change-Id: I3f9efd8f9d0619d1fb43637373d7ecde5494313f
diff --git a/Changes b/Changes
index ef54526..aa58d1a 100644
--- a/Changes
+++ b/Changes
@@ -1,4 +1,4 @@
-0.34 2019-08-26
+0.34 2019-08-27
     - [bugfix] Ignore min:max order in distance operators
       (#67; diewald)
     - [feature] Support #COND() operator alias in C2 (#70; diewald)
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 3da5313..f672f08 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
@@ -12,8 +12,8 @@
  */
 public class MetaQueryBuilder {
 
-    private static Pattern p = Pattern
-            .compile("\\s*(\\d+)-(c(?:hars?)?|t(?:okens?)?)\\s*,\\s*(\\d+)-(c(?:hars?)?|t(?:okens?)?)\\s*");
+    private static Pattern p = Pattern.compile("\\s*(\\d+)-([^,\\s]+?)\\s*,\\s*(\\d+)-([^,\\s]+?)\\s*");
+
     private Map meta;
     private SpanContext spanContext;
 
@@ -67,15 +67,15 @@
                 int rcLen = Integer.valueOf(m.group(3));
                 String rcType = m.group(4);
 
-                if (lcType.startsWith("t")) {
+                if (lcType.equals("t") || lcType.equals("token") || lcType.equals("tokens")) {
                     lcType = "token";
-                } else if (lcType.startsWith("c")) {
+                } else if (lcType.equals("c") || lcType.equals("char") || lcType.equals("chars")) {
                     lcType = "char";
                 }
 
-                if (rcType.startsWith("t")) {
+                if (rcType.equals("t") || rcType.equals("token") || rcType.equals("tokens")) {
                     rcType = "token";
-                } else if (rcType.startsWith("c")) {
+                } else if (rcType.equals("c") || rcType.equals("char") || rcType.equals("chars")) {
                     rcType = "char";
                 }
                 
diff --git a/src/test/java/de/ids_mannheim/korap/query/test/MetaQueryTest.java b/src/test/java/de/ids_mannheim/korap/query/test/MetaQueryTest.java
index e384482..b5d81fb 100644
--- a/src/test/java/de/ids_mannheim/korap/query/test/MetaQueryTest.java
+++ b/src/test/java/de/ids_mannheim/korap/query/test/MetaQueryTest.java
@@ -63,6 +63,13 @@
 
         mqb.setSpanContext("2-r,4-r");
         node = mapper.valueToTree(mqb.getSpanContext().raw());
-        assertEquals(node.at("/context").asText(),"2-r,4-r");
+        assertEquals(node.at("/context/left/0").asText(),"r");
+        assertEquals(node.at("/context/right/0").asText(),"r");
+        assertEquals(node.at("/context/left/1").asInt(),2);
+        assertEquals(node.at("/context/right/1").asInt(),4);       
+
+        mqb.setSpanContext("element");
+        node = mapper.valueToTree(mqb.getSpanContext().raw());
+        assertEquals(node.at("/context").asText(),"element");
     }
 }