layer mapping for query serializations!
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQueryBuilder.java b/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQueryBuilder.java
index fb1a0e3..fa9f3fc 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQueryBuilder.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQueryBuilder.java
@@ -240,7 +240,7 @@
return JsonUtils.valueToTree(join());
}
- public String buildString() {
+ public String toJSON() {
return JsonUtils.toJSON(join());
}
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 e6ef5cd..eef19e4 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
@@ -2,6 +2,7 @@
import de.ids_mannheim.korap.query.PoliqarpPlusLexer;
import de.ids_mannheim.korap.query.PoliqarpPlusParser;
+import de.ids_mannheim.korap.query.serialize.util.ResourceMapper;
import de.ids_mannheim.korap.util.QueryException;
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.tree.ParseTree;
@@ -480,6 +481,10 @@
}
if (layer.equals("base")) layer = "lemma";
+
+ // fixme: injected layer mapping:
+ layer = ResourceMapper.descriptor2policy(layer);
+
fieldMap.put("layer", layer);
if (foundry != null) fieldMap.put("foundry", foundry);
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/QuerySerializer.java b/src/main/java/de/ids_mannheim/korap/query/serialize/QuerySerializer.java
index 68173c3..cde7b8b 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/QuerySerializer.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/QuerySerializer.java
@@ -146,6 +146,10 @@
return this;
}
+ public QuerySerializer setQuery(String query, String ql) throws QueryException {
+ return setQuery(query, ql, "");
+ }
+
public final String build() {
return JsonUtils.toJSON(raw());
}
diff --git a/src/test/java/CosmasTreeTest.java b/src/test/java/CosmasTreeTest.java
index e8d8d3b..55d2c8e 100644
--- a/src/test/java/CosmasTreeTest.java
+++ b/src/test/java/CosmasTreeTest.java
@@ -28,7 +28,7 @@
ct = new CosmasTree(query);
map = ct.getRequestMap().get("query").toString();
assertEquals(single1.replaceAll(" ", ""), map.replaceAll(" ", ""));
-
+
query="Mann";
String single2 =
"{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}";
diff --git a/src/test/java/MetaQuerySerializationTest.java b/src/test/java/MetaQuerySerializationTest.java
index 7bf8784..50b65ca 100644
--- a/src/test/java/MetaQuerySerializationTest.java
+++ b/src/test/java/MetaQuerySerializationTest.java
@@ -30,7 +30,7 @@
b.append("textClass:wissenschaft");
// CollectionQuery qu = new CollectionQuery().addMetaFilterQuery(b.toString());
CollectionQueryBuilder query = new CollectionQueryBuilder().addMetaFilterQuery(b.toString());
- System.out.println(query.buildString());
+ System.out.println(query.toJSON());
System.out.println(query.toCollections());
// System.out.println("value reference " + qu.stringify());
// System.out.println();
@@ -40,7 +40,7 @@
public void testSingle() throws IOException {
CollectionQueryBuilder query = new CollectionQueryBuilder().addMetaFilter("textClass", "wissenschaft");
// System.out.println("------ TEXT SINGLE " + query.stringify());
- System.out.println(query.buildString());
+ System.out.println(query.toJSON());
}
@Test
@@ -52,9 +52,9 @@
b.append(" AND ");
b.append("author:Goethe");
CollectionQueryBuilder query = new CollectionQueryBuilder().addMetaFilterQuery(b.toString());
- System.out.println("value until/since : " + query.buildString());
+ System.out.println("value until/since : " + query.toJSON());
System.out.println("meta value until/since " + query.toCollections());
- Assert.assertEquals("[{\"@type\":\"korap:meta-filter\",\"@value\":{\"@type\":\"korap:group\",\"relation\":\"and\",\"operands\":[{\"@type\":\"korap:term\",\"@field\":\"korap:field#author\",\"@value\":\"Goethe\"},{\"@type\":\"korap:group\",\"@field\":\"korap:field#pubDate\",\"relation\":\"between\",\"operands\":[{\"@type\":\"korap:date\",\"@value\":\"2012-04-01\"},{\"@type\":\"korap:date\",\"@value\":\"2013-04-01\"}]}]}}]", query.buildString());
+ Assert.assertEquals("[{\"@type\":\"korap:meta-filter\",\"@value\":{\"@type\":\"korap:group\",\"relation\":\"and\",\"operands\":[{\"@type\":\"korap:term\",\"@field\":\"korap:field#author\",\"@value\":\"Goethe\"},{\"@type\":\"korap:group\",\"@field\":\"korap:field#pubDate\",\"relation\":\"between\",\"operands\":[{\"@type\":\"korap:date\",\"@value\":\"2012-04-01\"},{\"@type\":\"korap:date\",\"@value\":\"2013-04-01\"}]}]}}]", query.toJSON());
// System.out.println();
}
@@ -66,7 +66,7 @@
b.append("author:Hesse");
CollectionQueryBuilder query = new CollectionQueryBuilder().addMetaFilterQuery(b.toString());
System.out.println("Running date check (until) with additional attribute author");
- Assert.assertEquals("[{\"@type\":\"korap:meta-filter\",\"@value\":{\"@type\":\"korap:group\",\"relation\":\"and\",\"operands\":[{\"@type\":\"korap:term\",\"@field\":\"korap:field#author\",\"@value\":\"Hesse\"},{\"@type\":\"korap:group\",\"@field\":\"korap:field#pubDate\",\"relation\":\"until\",\"operands\":[{\"@type\":\"korap:date\",\"@value\":\"2013-12-10\"}]}]}}]", query.buildString());
+ Assert.assertEquals("[{\"@type\":\"korap:meta-filter\",\"@value\":{\"@type\":\"korap:group\",\"relation\":\"and\",\"operands\":[{\"@type\":\"korap:term\",\"@field\":\"korap:field#author\",\"@value\":\"Hesse\"},{\"@type\":\"korap:group\",\"@field\":\"korap:field#pubDate\",\"relation\":\"until\",\"operands\":[{\"@type\":\"korap:date\",\"@value\":\"2013-12-10\"}]}]}}]", query.toJSON());
// System.out.println("value until : " + query.stringify());
// System.out.println();
}
@@ -78,11 +78,11 @@
b.append(" AND ");
b.append("author:Kafka");
CollectionQueryBuilder query = new CollectionQueryBuilder().addMetaFilterQuery(b.toString());
- System.out.println("value since : " + query.buildString());
+ System.out.println("value since : " + query.toJSON());
System.out.println("meta value since " + query.toCollections());
// System.out.println();
System.out.println("Running date check (since) with additional attribute author");
- Assert.assertEquals("[{\"@type\":\"korap:meta-filter\",\"@value\":{\"@type\":\"korap:group\",\"relation\":\"and\",\"operands\":[{\"@type\":\"korap:term\",\"@field\":\"korap:field#author\",\"@value\":\"Kafka\"},{\"@type\":\"korap:group\",\"@field\":\"korap:field#pubDate\",\"relation\":\"since\",\"operands\":[{\"@type\":\"korap:date\",\"@value\":\"2013-12-10\"}]}]}}]", query.buildString());
+ Assert.assertEquals("[{\"@type\":\"korap:meta-filter\",\"@value\":{\"@type\":\"korap:group\",\"relation\":\"and\",\"operands\":[{\"@type\":\"korap:term\",\"@field\":\"korap:field#author\",\"@value\":\"Kafka\"},{\"@type\":\"korap:group\",\"@field\":\"korap:field#pubDate\",\"relation\":\"since\",\"operands\":[{\"@type\":\"korap:date\",\"@value\":\"2013-12-10\"}]}]}}]", query.toJSON());
}
@Test
@@ -128,7 +128,7 @@
CollectionQueryBuilder q = new CollectionQueryBuilder().addMetaFilterQuery(b.toString());
q.addMetaExtend("author", "Hesse");
- System.out.println("--- ALL " + q.buildString());
+ System.out.println("--- ALL " + q.toJSON());
System.out.println();
}
@@ -140,7 +140,7 @@
b.append(" AND ");
b.append("author:Kafka");
CollectionQueryBuilder q = new CollectionQueryBuilder().addMetaExtendQuery(b.toString());
- System.out.println("array repres " + q.buildString());
+ System.out.println("array repres " + q.toJSON());
System.out.println();
}
@@ -149,7 +149,7 @@
CollectionQueryBuilder q = new CollectionQueryBuilder().addMetaFilter("corpusID", "A00");
q.addMetaExtend("corpusID", "A01");
- System.out.println("results stringified " + q.buildString());
+ System.out.println("results stringified " + q.toJSON());
System.out.println("results to meta" + q.toCollections());
System.out.println();
}
@@ -171,7 +171,7 @@
@Test
public void testA00() throws IOException {
CollectionQueryBuilder q = new CollectionQueryBuilder().addMetaExtend("corpusID", "A00").addMetaExtend("corpusID", "A01");
- System.out.println("A meta: " + q.buildString());
+ System.out.println("A meta: " + q.toJSON());
System.out.println();
}
@@ -180,7 +180,7 @@
String meta = "[{\"@type\":\"korap:meta-filter\",\"@value\":{\"@type\":\"korap:term\",\"@field\":\"korap:field#corpusID\",\"@value\":\"WPD\"}}]";
CollectionQueryBuilder q = new CollectionQueryBuilder().addResource(meta);
q.addMetaFilter("textClass", "wissenschaft");
- System.out.println("stringified meta " + q.buildString());
+ System.out.println("stringified meta " + q.toJSON());
System.out.println("meta string " + q.toCollections());
}