test case refactoring
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/IdWriter.java b/src/main/java/de/ids_mannheim/korap/query/serialize/IdWriter.java
index 70d6a31..966b3d3 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/IdWriter.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/IdWriter.java
@@ -1,24 +1,26 @@
package de.ids_mannheim.korap.query.serialize;
+import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
-import de.ids_mannheim.korap.utils.JsonUtils;
import java.util.Iterator;
/**
* @author hanl
* @date 04/06/2014
- * <p/>
- * create idn for korap:token
+ * <p/>
+ * create idn for korap:token
*/
public class IdWriter {
private JsonNode node;
private int counter;
+ private ObjectMapper mapper = new ObjectMapper();
- public IdWriter (String json) {
- node = JsonUtils.readTree(json);
+ public IdWriter(String json) {
+ node = mapper.valueToTree(json);
counter = 0;
}
@@ -63,13 +65,17 @@
}
- @Deprecated
- public JsonNode getFinalNode() {
+ @Deprecated public JsonNode getFinalNode() {
return this.node;
}
public String toJSON() {
- return JsonUtils.toJSON(node);
+ try {
+ return mapper.writeValueAsString(node);
+ }
+ catch (JsonProcessingException e) {
+ return "";
+ }
}
}
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 d62b622..b0af534 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
@@ -65,7 +65,6 @@
try {
System.out.println(q);
String ql = "cosmas2";
- jg.setCollection("pubDate=2014");
jg.run(q, ql);
System.out.println();
}
@@ -253,12 +252,12 @@
return this;
}
- @Deprecated public QuerySerializer setCollectionSimple(String collection) {
- CollectionQueryBuilder qobj = new CollectionQueryBuilder();
- qobj.addResource(collection);
- this.collection = (Map<String, Object>) qobj.raw();
- return this;
- }
+// @Deprecated public QuerySerializer setCollectionSimple(String collection) {
+// CollectionQueryBuilder qobj = new CollectionQueryBuilder();
+// qobj.addResource(collection);
+// this.collection = (Map<String, Object>) qobj.raw();
+// return this;
+// }
public QuerySerializer setCollection(String collection) {
CollectionQueryProcessor tree = new CollectionQueryProcessor();
@@ -272,14 +271,14 @@
return this;
}
- public QuerySerializer setCollection(CollectionQueryBuilder2 collections) {
- this.collection = (Map<String, Object>) collections.raw();
- return this;
- }
-
- public QuerySerializer setDeprCollection(
- CollectionQueryBuilder collections) {
- this.collection = (Map<String, Object>) collections.raw();
- return this;
- }
+// public QuerySerializer setCollection(CollectionQueryBuilder2 collections) {
+ // this.collection = (Map<String, Object>) collections.raw();
+ // return this;
+ // }
+ //
+ // public QuerySerializer setDeprCollection(
+ // CollectionQueryBuilder collections) {
+ // this.collection = (Map<String, Object>) collections.raw();
+ // return this;
+ // }
}
diff --git a/src/test/java/MetaQuerySerializationTest.java b/src/test/java/MetaQuerySerializationTest.java
deleted file mode 100644
index a2e6442..0000000
--- a/src/test/java/MetaQuerySerializationTest.java
+++ /dev/null
@@ -1,200 +0,0 @@
-import com.fasterxml.jackson.core.JsonGenerationException;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.JsonMappingException;
-import de.ids_mannheim.korap.query.serialize.CollectionQueryBuilder;
-import de.ids_mannheim.korap.query.serialize.QuerySerializer;
-import de.ids_mannheim.korap.query.serialize.util.QueryException;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-import java.io.IOException;
-
-/**
- * @author hanl
- * @date 04/12/2013
- */
-
-@RunWith(JUnit4.class)
-public class MetaQuerySerializationTest {
-
-
- @Test
- public void test() throws IOException {
- StringBuffer b = new StringBuffer();
- b.append("author:Goethe");
- b.append(" AND ");
- b.append("pubPlace:Erfurt");
- b.append(" AND ");
- b.append("textClass:wissenschaft");
-// CollectionQuery qu = new CollectionQuery().addMetaFilterQuery(b.toString());
- CollectionQueryBuilder query = new CollectionQueryBuilder().addMetaFilterQuery(b.toString());
- System.out.println(query.toJSON());
- System.out.println(query.toCollections());
-// System.out.println("value reference " + qu.stringify());
-// System.out.println();
- }
-
- @Test
- public void testSingle() throws IOException {
- CollectionQueryBuilder query = new CollectionQueryBuilder().addMetaFilter("textClass", "wissenschaft");
-// System.out.println("------ TEXT SINGLE " + query.stringify());
- System.out.println(query.toJSON());
- }
-
-// @Test
- public void testDates() throws IOException {
- StringBuffer b = new StringBuffer();
- b.append("pubDate:>2013-04-01");
- b.append(" AND ");
- b.append("pubDate:<2012-04-01");
- b.append(" AND ");
- b.append("author:Goethe");
- CollectionQueryBuilder query = new CollectionQueryBuilder().addMetaFilterQuery(b.toString());
- 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.toJSON());
-// System.out.println();
- }
-
-// @Test
- public void testUntil() throws IOException {
- StringBuffer b = new StringBuffer();
- b.append("pubDate:>2013-12-10");
- b.append(" AND ");
- 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.toJSON());
-// System.out.println("value until : " + query.stringify());
-// System.out.println();
- }
-
-// @Test
- public void testSince() throws IOException {
- StringBuffer b = new StringBuffer();
- b.append("pubDate:<2013-12-10");
- b.append(" AND ");
- b.append("author:Kafka");
- CollectionQueryBuilder query = new CollectionQueryBuilder().addMetaFilterQuery(b.toString());
- 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.toJSON());
- }
-
-
- @Test
- public void testMeta() {
- QuerySerializer s = new QuerySerializer();
- try {
- s.setQuery("shrink({[base=foo]})", "poliqarp");
- s.addMeta("2-token, 2-token", 10, 0);
- } catch (QueryException e) {
- e.printStackTrace();
- }
- System.out.println("THE RESULTING QUERY: " + s.toJSON());
- }
-
-// // @Test
-// public void testGenerator() throws QueryException {
-// /*
-// * just for testing...
-// */
-// QuerySerializer jg = new QuerySerializer();
-// int i = 0;
-// String[] queries;
-// queries = new String[]{
-// "shrink({[base=foo]})",
-// "shrink({[base=foo]}[orth=bar])",
-// "shrink(1:[base=Der]{1:[base=Mann]})",
-// };
-//
-// for (String q : queries) {
-// i++;
-// try {
-// System.out.println(q);
-// jg.run(q, "poliqarp", System.getProperty("user.home") + "/bsp" + i + ".json");
-// System.out.println();
-// } catch (NullPointerException npe) {
-// npe.printStackTrace();
-// System.out.println("null\n");
-// System.out.println();
-// } catch (JsonGenerationException e) {
-// e.printStackTrace();
-// } catch (JsonMappingException e) {
-// e.printStackTrace();
-// } catch (IOException e) {
-// e.printStackTrace();
-// }
-// }
-// }
-
- @Test
- public void testLists() {
- StringBuffer b = new StringBuffer();
- b.append("pubDate:<2013-12-10");
- b.append(" AND ");
- b.append("author:Kafka");
- CollectionQueryBuilder q = new CollectionQueryBuilder().addMetaFilterQuery(b.toString());
- q.addMetaExtend("author", "Hesse");
-
- System.out.println("--- ALL " + q.toJSON());
- System.out.println();
-
- }
-
- @Test
- public void testJSONArray() throws JsonProcessingException {
- StringBuffer b = new StringBuffer();
- b.append("pubDate:<2013-12-10");
- b.append(" AND ");
- b.append("author:Kafka");
- CollectionQueryBuilder q = new CollectionQueryBuilder().addMetaExtendQuery(b.toString());
- System.out.println("array repres " + q.toJSON());
- System.out.println();
- }
-
- @Test
- public void testCollections() throws IOException {
- CollectionQueryBuilder q = new CollectionQueryBuilder().addMetaFilter("corpusID", "A00");
- q.addMetaExtend("corpusID", "A01");
-
- System.out.println("results stringified " + q.toJSON());
- System.out.println("results to meta" + q.toCollections());
- System.out.println();
- }
-
- /**
- * asserts equality. input should be equal to output,
- * since there is no other metadata added to the meta query
- *
- * @throws IOException
- */
- @Test
- public void testResources() throws IOException {
- String meta = "[{\"@type\":\"korap:meta-filter\",\"@value\":{\"@type\":\"korap:term\",\"@field\":\"korap:field#corpusID\",\"@value\":\"WPD\"}}]";
- CollectionQueryBuilder q = new CollectionQueryBuilder().addResource(meta);
- System.out.println("Testing Resource Meta data");
- org.junit.Assert.assertEquals("{\"collections\":" + meta + "}", q.toCollections());
- }
-
- @Test
- public void testA00() throws IOException {
- CollectionQueryBuilder q = new CollectionQueryBuilder().addMetaExtend("corpusID", "A00").addMetaExtend("corpusID", "A01");
- System.out.println("A meta: " + q.toJSON());
- System.out.println();
- }
-
- @Test
- public void testResources2() throws IOException {
- 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.toJSON());
- System.out.println("meta string " + q.toCollections());
- }
-
-}