deletion of deprecated classes
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/JsonGenerator.java b/src/main/java/de/ids_mannheim/korap/query/serialize/JsonGenerator.java
index a3921e3..8cd4d48 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/JsonGenerator.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/JsonGenerator.java
@@ -15,15 +15,13 @@
*/
public class JsonGenerator {
- ObjectMapper mapper;
- AbstractSyntaxTree ast;
- private Serializer serializer;
+ private ObjectMapper mapper;
+ private AbstractSyntaxTree ast;
private org.slf4j.Logger log = LoggerFactory
.getLogger(JsonGenerator.class);
public JsonGenerator() {
mapper = new ObjectMapper();
- serializer = new Serializer();
}
/**
@@ -118,7 +116,7 @@
throws IllegalArgumentException{
if (ql.toLowerCase().equals("poliqarp")) {
ast = new PoliqarpPlusTree(query);
-// } else if (queryLanguage.equals("cosmas")) {
+// } else if (ql.toLowerCase().equals("cosmas")) {
// ast = new CosmasTree(query);
} else if (ql.toLowerCase().equals("poliqarpplus")) {
ast = new PoliqarpPlusTree(query);
@@ -131,7 +129,7 @@
try {
requestMap.put("meta", metaQuery.raw());
- requestMap = serializer.addParameters(requestMap, page, num,
+ requestMap = MetaQuery.addParameters(requestMap, page, num,
cli, cri, cls, crs);
String res = mapper.writeValueAsString(requestMap);
return res;
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/MetaCollectionSerializer.java b/src/main/java/de/ids_mannheim/korap/query/serialize/MetaCollectionSerializer.java
deleted file mode 100644
index 4b74ce4..0000000
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/MetaCollectionSerializer.java
+++ /dev/null
@@ -1,143 +0,0 @@
-package de.ids_mannheim.korap.query.serialize;
-
-import com.fasterxml.jackson.core.JsonFactory;
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * @author hanl
- * @date 04/12/2013
- */
-@Deprecated
-public class MetaCollectionSerializer {
-
- public String meta1 = "{\n" +
- " \"@type\": \"korap:meta-filter\",\n" +
- " \"@id\": \"korap-filter#id-23\",\n" +
- " \"@value\": {\n" +
- " \"@type\": \"korap:term\",\n" +
- " \"@value\": \"wissenschaft\"\n" +
- " }\n" +
- " }\n";
- public String meta2 = "{\n" +
- " \"@type\": \"korap:meta-filter\",\n" +
- " \"@id\": \"korap-filter#id-24\",\n" +
- " \"@value\": {\n" +
- " \"@type\": \"korap:group\",\n" +
- " \"relation\": \"and\",\n" +
- " \"operands\": [\n" +
- " {\n" +
- " \"@type\": \"korap:term\",\n" +
- " \"@field\": \"korap:field#pubPlace\",\n" +
- " \"@value\": \"Erfurt\"\n" +
- " },\n" +
- " {\n" +
- " \"@type\": \"korap:term\",\n" +
- " \"@field\": \"korap:field#author\",\n" +
- " \"@value\": \"Hesse\"\n" +
- " }\n" +
- " ]\n" +
- " }\n" +
- " }\n";
- private MetaTypes types;
- private ObjectMapper mapper;
- private String meta3 = "{\n" +
- " \"@type\": \"korap:meta-extend\",\n" +
- " \"@id\": \"korap-filter#id-25\",\n" +
- " \"@value\": {\n" +
- " \"@type\": \"korap:group\",\n" +
- " \"relation\": \"and\",\n" +
- " \"operands\": [\n" +
- " {\n" +
- " \"@type\": \"korap:group\",\n" +
- " \"relation\": \"comment: other values can be 'since','until' in combination with a simple korap:term\",\n" +
- " \"relation\": \"between\",\n" +
- " \"@field\": \"korap:field#pubDate\",\n" +
- " \"operands\": [\n" +
- " {\n" +
- " \"@type\": \"korap:date\",\n" +
- " \"@value\": \"comment: either long value or String representation '2013-04-29'\",\n" +
- " \"@value\": \"2011\"\n" +
- " },\n" +
- " {\n" +
- " \"@type\": \"korap:date\",\n" +
- " \"@value\": \"2013\"\n" +
- " }\n" +
- " ]\n" +
- " },\n" +
- " {\n" +
- " \"@type\": \"korap:term\",\n" +
- " \"@field\": \"korap:field#textClass\",\n" +
- " \"@value\": \"freizeit\"\n" +
- " }\n" +
- " ]\n" +
- " }\n" +
- " }";
- private Map<String, Map> tester;
-
- public MetaCollectionSerializer() {
- this.types = new MetaTypes();
- this.mapper = new ObjectMapper();
- this.tester = tester();
- }
-
- //resources must be ordered: 0 without parent, 1 has 0 as parent, etc.
- public List<Map> serializeResource(List<String> r_queries) throws IOException {
- JsonFactory factory = mapper.getFactory();
- List parids = new ArrayList<>();
- for (String query : r_queries) {
- JsonParser jp = factory.createParser(query);
- JsonNode m = jp.readValueAsTree();
- for (JsonNode n : m)
- parids.add(mapper.treeToValue(n, Map.class));
- }
- return parids;
- }
-
- @Deprecated
- private Map<String, String> getParents(String id) {
- Map<String, String> cursor = getResource(id);
- Map<String, String> parents = new HashMap<>();
-
- parents.put(id, cursor.get("query"));
- if (cursor.get("parent") != null && !cursor.get("parent").isEmpty())
- parents.putAll(getParents(cursor.get("parent")));
- return parents;
- }
-
- //todo: connection to database module!
- public Map<String, String> getResource(String id) {
- return tester.get(id);
- }
-
- private Map<String, Map> tester() {
- Map<String, Map> l = new HashMap<>();
- Map<String, String> s = new HashMap<>();
- s.put("id", "23");
- s.put("parent", "");
- s.put("query", meta1);
-
- Map<String, String> s2 = new HashMap<>();
- s2.put("id", "24");
- s2.put("parent", "23");
- s2.put("query", meta2);
-
- Map<String, String> s3 = new HashMap<>();
- s3.put("id", "25");
- s3.put("parent", "24");
- s3.put("query", meta3);
- l.put("23", s);
- l.put("24", s2);
- l.put("25", s3);
- return l;
- }
-
-
-}
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/MetaQuery.java b/src/main/java/de/ids_mannheim/korap/query/serialize/MetaQuery.java
index 310c5e4..aad96b6 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/MetaQuery.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/MetaQuery.java
@@ -23,7 +23,6 @@
private List<Map> rq;
private List<Map> mfil;
private List<Map> mext;
- private Multimap<Integer, Integer> track;
public MetaQuery() {
this.serialzer = new ObjectMapper();
@@ -32,7 +31,25 @@
this.mext = new ArrayList<>();
this.factory = serialzer.getFactory();
this.types = new MetaTypes();
- this.track = ArrayListMultimap.create();
+ }
+
+ public static Map addParameters(Map request, int page, int num, String cli, String cri,
+ int cls, int crs) {
+ Map ctx = new LinkedHashMap();
+ List left = new ArrayList();
+ left.add(cli);
+ left.add(cls);
+ List right = new ArrayList();
+ right.add(cri);
+ right.add(crs);
+ ctx.put("left", left);
+ ctx.put("right", right);
+
+ request.put("startPage", page);
+ request.put("count", num);
+ request.put("context", ctx);
+
+ return request;
}
public MetaQuery addResource(String query) {
@@ -54,6 +71,7 @@
return this;
}
+ // map can only have one key, value pair. thus, text class can only be added once. Multiple types are not possible!
public MetaQuery addMetaFilter(Map<String, String> queries) {
//single is redundant!
boolean single = true;
@@ -162,7 +180,6 @@
value.add(group);
}
-
for (int i = idx; i < proc.length; i++) {
if (proc[i] != null) {
Map term1 = types.createTerm(proc[i], "korap:date");
@@ -181,8 +198,6 @@
group = types.createGroup("and", null, value);
Collections.addAll(this.mext, types.createMetaExtend(group));
}
- track.put(this.mfil.size() - 1, this.mext.size() - 1);
-
return this;
}
@@ -230,27 +245,6 @@
this.rq.clear();
this.mfil.clear();
this.mext.clear();
- this.track.clear();
- }
-
- @Deprecated
- //todo: ordering irrelevant
- private List<Map> joinO() {
- List<Map> cursor = new ArrayList<>(this.rq);
- List<Map> copy = new ArrayList<>();
- if (!this.mext.isEmpty()) {
- for (int idx = 0; idx < this.mfil.size(); idx++) {
- copy.add(idx, this.mfil.get(idx));
- if (!this.track.get(idx).isEmpty()) {
- Collection<Integer> ext = this.track.get(idx);
- for (Integer i : ext)
- copy.add(this.mext.get(i));
- }
- }
- } else
- copy = this.mfil;
- cursor.addAll(copy);
- return cursor;
}
private List<Map> join() {
@@ -268,6 +262,7 @@
/**
* returns the meta query only and does not contain parent dependencies
+ *
* @return
*/
public String stringify() {
@@ -286,6 +281,7 @@
/**
* returns the List<Map> that contains all the meta queries and resource queries
* added to the meta query container
+ *
* @return
*/
public List<Map> raw() {
@@ -310,5 +306,18 @@
}
}
+ private Multimap resEq(String queries) {
+ Multimap qmap = ArrayListMultimap.create();
+ String[] spl = queries.split(" AND ");
+ for (String query : spl) {
+ String[] q = query.split(":");
+ String attr = q[0];
+ String val = q[1];
+ qmap.put(attr, val);
+ }
+ return qmap;
+
+ }
+
}
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/MetaQuerySerializer.java b/src/main/java/de/ids_mannheim/korap/query/serialize/MetaQuerySerializer.java
deleted file mode 100644
index 5cca176..0000000
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/MetaQuerySerializer.java
+++ /dev/null
@@ -1,219 +0,0 @@
-package de.ids_mannheim.korap.query.serialize;
-
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-
-import java.io.IOException;
-import java.util.*;
-
-/**
- * serializes a map of meta queries to JSON-LD. Currently this only works for simple mode queries (simple AND relation, except for date ranges)
- * Expert mode requires a full blown parser (since different combinations of OR and AND relations are possible)
- * also normalizes dates to year-month-day
- * <p/>
- * <p/>
- * User: hanl
- * Date: 11/14/13
- * Time: 2:03 PM
- */
-@Deprecated
-public class MetaQuerySerializer {
-
-
- private String metaString = "{\n" +
- " \"meta\": [\n" +
- " {\n" +
- " \"@type\": \"korap:meta-filter\",\n" +
- " \"@value\": {\n" +
- " \"@type\": \"korap:group\",\n" +
- " \"relation\": \"and\",\n" +
- " \"operands\": [\n" +
- " {\n" +
- " \"@type\": \"korap:term\",\n" +
- " \"field\": \"korap:field#author\",\n" +
- " \"@value\": \"Goethe\"\n" +
- " },\n" +
- " {\n" +
- " \"@type\": \"korap:group\",\n" +
- " \"field\": \"korap:field#pubDate\",\n" +
- " \"relation\": \"between\",\n" +
- " \"operands\": [\n" +
- " {\n" +
- " \"@type\": \"korap:date\",\n" +
- " \"@value\": \"2013-12-5\"\n" +
- " },\n" +
- " {\n" +
- " \"@type\": \"korap:date\",\n" +
- " \"@value\": \"2013-12-5\"\n" +
- " }\n" +
- " ]\n" +
- " }\n" +
- " ]\n" +
- " }\n" +
- " }\n" +
- " ]\n" +
- "}";
- private ObjectMapper mapper;
- private MetaTypes types;
-
- public MetaQuerySerializer() {
- this.mapper = new ObjectMapper();
- this.types = new MetaTypes();
- }
-
- // construct pubdate range query as "pubDate:'<date>' ~ pubDate:'<date>'"
- //todo: how to handle regex types?
- // only handles AND relation between query attributes and values!
- // value pair : pubdate=<date>, pubPlace=<place>, etc.
- public List<Map> serializeQueries(Map<String, String> queries, TYPE type) {
- //single is redundant!
- boolean extend, single = true; //single = true;
- boolean multypes = queries.keySet().size() > 1;
- List<Map> metavalue = new ArrayList<>();
- String def_key = null;
- if (queries.size() > 1)
- single = false;
- switch (type) {
- case EXTEND:
- extend = true;
- break;
- default:
- extend = false;
- break;
- }
-
- List value = new ArrayList<>();
- List<String> dates = new ArrayList<>();
- for (String key : queries.keySet()) {
- if (!multypes)
- def_key = key;
- if (queries.get(key).contains("~") | queries.get(key).contains(">") |
- queries.get(key).contains("<")) {
- dates.add(queries.get(key));
- continue;
- }
-
-// if (queries.get(key).contains("~")) {
-// dr = queries.get(key).split("~");
-// Map fd = types.createTerm(dr[0].trim(), "korap:date");
-// Map td = types.createTerm(dr[1].trim(), "korap:date");
-// Map dg = types.createGroup("between", key, Arrays.asList(fd, td));
-// value.add(dg);
-// continue;
-// } else if (queries.get(key).contains(">")) {
-// dr = queries.get(key).split(">");
-// Map fd = types.createTerm(dr[0].trim(), "korap:date");
-// Map td = types.createTerm(dr[1].trim(), "korap:date");
-// Map dg = types.createGroup("between", key, Arrays.asList(fd, td));
-// value.add(dg);
-// continue;
-// } else if (queries.get(key).contains("<")) {
-// dr = queries.get(key).split("<");
-// Map fd = types.createTerm(dr[0].trim(), "korap:date");
-// Map td = types.createTerm(dr[1].trim(), "korap:date");
-// Map dg = types.createGroup("between", key, Arrays.asList(fd, td));
-// value.add(dg);
-// continue;
-// }
-
- Map term;
- term = types.createTerm(key, null, queries.get(key).trim(), null);
- value.add(term);
- }
-
- String[] proc = processDates(dates);
- int idx = 3;
- if (proc[0] != null && proc[0].equals("r")) {
- Map term1 = types.createTerm(proc[1], "korap:date");
- Map term2 = types.createTerm(proc[2], "korap:date");
- Map group = types.createGroup("between", "pubDate", Arrays.asList(term1, term2));
- value.add(group);
- } else if (proc[1] != null) {
- Map term1 = types.createTerm(proc[1], "korap:date");
- Map group = types.createGroup("since", "pubDate", Arrays.asList(term1));
- value.add(group);
- } else if (proc[2] != null) {
- Map term1 = types.createTerm(proc[2], "korap:date");
- Map group = types.createGroup("until", "pubDate", Arrays.asList(term1));
- value.add(group);
- }
-
-
- for (int i = idx; i < proc.length; i++) {
- if (proc[i] != null) {
- Map term1 = types.createTerm(proc[i], "korap:date");
- Map group = types.createGroup("until", "pubDate", Arrays.asList(term1));
- value.add(group);
- }
- }
-
-
- // todo: missing: - takes only one resource, but resources can be chained!
- if (single) {
- if (extend)
- Collections.addAll(metavalue, types.createMetaExtend((Map) value.get(0)));
- else
- Collections.addAll(metavalue, types.createMetaFilter((Map) value.get(0)));
- } else {
- Map group;
- if (!multypes)
- group = types.createGroup("and", def_key, value);
- else
- group = types.createGroup("and", null, value);
- // metavalue = Arrays.asList(types.createMetaExtend(group));
- if (extend)
- Collections.addAll(metavalue, types.createMetaExtend(group));
- else
- Collections.addAll(metavalue, types.createMetaFilter(group));
- }
- return metavalue;
- }
-
- //fixme: only allows for one until and since entry!!
- private String[] processDates(List<String> dates) {
- if (dates.isEmpty())
- return new String[3];
- boolean range = false;
- String[] el = new String[dates.size() + 3];
- int idx = 3;
- for (String value : dates) {
- if (value.contains("<")) {
- String[] sp = value.split("<");
- el[1] = types.formatDate(Long.valueOf(sp[1]), MetaTypes.YMD);
- } else if (value.contains(">")) {
- String[] sp = value.split(">");
- el[2] = types.formatDate(Long.valueOf(sp[1]), MetaTypes.YMD);
- } else if (value.contains("~")) {
- range = true;
- String[] sp = value.split("~");
- el[1] = types.formatDate(Long.valueOf(sp[0]), MetaTypes.YMD);
- el[2] = types.formatDate(Long.valueOf(sp[1]), MetaTypes.YMD);
- } else {
- el[idx] = types.formatDate(Long.valueOf(value), MetaTypes.YMD);
- idx++;
- }
- }
- if (range)
- el[0] = "r";
- return el;
- }
-
- public JsonNode jsonify(Map<String, String> queries) {
- List s = serializeQueries(queries, TYPE.FILTER);
- return mapper.valueToTree(s);
- }
-
- //todo: resource id must be added!
- public String stringify(Map<String, String> queries, TYPE type) throws IOException {
- Map f = new HashMap();
- f.put("meta", serializeQueries(queries, type));
- return mapper.writeValueAsString(f);
- }
-
-
- public enum TYPE {
- EXTEND, FILTER
- }
-
-
-}
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/Serializer.java b/src/main/java/de/ids_mannheim/korap/query/serialize/Serializer.java
deleted file mode 100644
index f800e68..0000000
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/Serializer.java
+++ /dev/null
@@ -1,73 +0,0 @@
-package de.ids_mannheim.korap.query.serialize;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-
-import java.io.IOException;
-import java.util.*;
-
-/**
- * @author hanl
- * @date 05/12/2013
- */
-@Deprecated
-public class Serializer {
-
-
- private MetaQuerySerializer qs;
- private MetaCollectionSerializer cs;
- private ObjectMapper mapper;
-
-
- public Serializer() {
- this.qs = new MetaQuerySerializer();
- this.cs = new MetaCollectionSerializer();
- this.mapper = new ObjectMapper();
- }
-
- public String serializeToMeta(List m_queries) throws JsonProcessingException {
- Map metas = new HashMap();
- metas.put("meta", m_queries);
- return mapper.writeValueAsString(metas);
- }
-
- public String stringify(Object object) throws JsonProcessingException {
- return mapper.writeValueAsString(object);
- }
-
- public List<Map> serializeResources(List<String> r_queries) throws IOException {
- return cs.serializeResource(r_queries);
- }
-
- public String queryToMeta(String s) throws IOException {
- Map f = new HashMap();
- List e = mapper.readValue(s, ArrayList.class);
- f.put("meta", e);
- return mapper.writeValueAsString(f);
- }
-
- public List<Map> serializeQueries(Map<String, String> queries, MetaQuerySerializer.TYPE type) {
- return qs.serializeQueries(queries, type);
- }
-
- public Map addParameters(Map request, int page, int num, String cli, String cri,
- int cls, int crs) {
- Map ctx = new LinkedHashMap();
- List left = new ArrayList();
- left.add(cli);
- left.add(cls);
- List right = new ArrayList();
- right.add(cri);
- right.add(crs);
- ctx.put("left", left);
- ctx.put("right", right);
-
- request.put("startPage", page);
- request.put("count", num);
- request.put("context", ctx);
-
- return request;
-
- }
-
-}
diff --git a/src/test/java/MetaQuerySerializationTest.java b/src/test/java/MetaQuerySerializationTest.java
index b32b8f6..4c3b355 100644
--- a/src/test/java/MetaQuerySerializationTest.java
+++ b/src/test/java/MetaQuerySerializationTest.java
@@ -1,14 +1,17 @@
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.*;
+import de.ids_mannheim.korap.query.serialize.JsonGenerator;
+import de.ids_mannheim.korap.query.serialize.MetaQuery;
import org.joda.time.DateTime;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import java.io.IOException;
-import java.util.*;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
/**
* @author hanl
@@ -18,15 +21,6 @@
@RunWith(JUnit4.class)
public class MetaQuerySerializationTest {
- private MetaQuerySerializer querySerializer;
- private MetaCollectionSerializer collSerializer;
- private Serializer ser;
-
- public MetaQuerySerializationTest() {
- querySerializer = new MetaQuerySerializer();
- collSerializer = new MetaCollectionSerializer();
- ser = new Serializer();
- }
@Test
public void test() throws IOException {
@@ -34,16 +28,17 @@
j.put("author", "Goethe");
j.put("pubPlace", "Erfurt");
j.put("textClass", "wissenschaft");
- String s = querySerializer.stringify(j, MetaQuerySerializer.TYPE.FILTER);
-// System.out.println("value reference " + s);
+ MetaQuery qu = new MetaQuery().addMetaFilter(j);
+ System.out.println("value reference " + qu.stringify());
+ System.out.println();
}
@Test
public void testSingle() throws IOException {
Map<String, String> j = new HashMap();
j.put("textClass", "wissenschaft");
- String s = querySerializer.stringify(j, MetaQuerySerializer.TYPE.FILTER);
- System.out.println("------ TEXT SINGLE " + s);
+ MetaQuery query = new MetaQuery().addMetaFilter("textClass", "wissenschaft");
+ System.out.println("------ TEXT SINGLE " + query.stringify());
System.out.println();
}
@@ -53,8 +48,8 @@
queries.put("pubDate", String.valueOf(new DateTime().getMillis()) + "~"
+ String.valueOf(new DateTime().getMillis() + 2));
queries.put("author", "Goethe");
- String f = querySerializer.stringify(queries, MetaQuerySerializer.TYPE.FILTER);
- System.out.println("value until/since : " + f);
+ MetaQuery query = new MetaQuery().addMetaFilter(queries);
+ System.out.println("value until/since : " + query.stringify());
System.out.println();
}
@@ -63,8 +58,8 @@
Map<String, String> queries = new LinkedHashMap<>();
queries.put("pubDate", ">" + String.valueOf(new DateTime().getMillis()));
queries.put("author", "Hesse");
- String f = querySerializer.stringify(queries, MetaQuerySerializer.TYPE.FILTER);
- System.out.println("value until : " + f);
+ MetaQuery query = new MetaQuery().addMetaFilter(queries);
+ System.out.println("value until : " + query.stringify());
System.out.println();
}
@@ -73,8 +68,8 @@
Map<String, String> queries = new LinkedHashMap<>();
queries.put("pubDate", "<" + String.valueOf(new DateTime().getMillis()));
queries.put("author", "Kafka");
- String f = querySerializer.stringify(queries, MetaQuerySerializer.TYPE.FILTER);
- System.out.println("value since : " + f);
+ MetaQuery query = new MetaQuery().addMetaFilter(queries);
+ System.out.println("value since : " + query.stringify());
System.out.println();
}
@@ -117,14 +112,11 @@
Map<String, String> queries = new LinkedHashMap<>();
queries.put("pubDate", "<" + String.valueOf(new DateTime().getMillis()));
queries.put("author", "Kafka");
- List s = querySerializer.serializeQueries(queries, MetaQuerySerializer.TYPE.FILTER);
+ MetaQuery query = new MetaQuery().addMetaFilter(queries);
- queries.clear();
- queries.put("author", "Hesse");
+ query.addMetaExtend("author", "Hesse");
- List f = querySerializer.serializeQueries(queries, MetaQuerySerializer.TYPE.EXTEND);
- s.addAll(f);
- System.out.println("--- ALL " + s);
+ System.out.println("--- ALL " + query.stringify());
System.out.println();
}
@@ -134,94 +126,49 @@
Map<String, String> queries = new LinkedHashMap<>();
queries.put("pubDate", "<" + String.valueOf(new DateTime().getMillis()));
queries.put("author", "Kafka");
- List s = querySerializer.serializeQueries(queries, MetaQuerySerializer.TYPE.FILTER);
- System.out.println("array repres " + ser.serializeToMeta(s));
+ MetaQuery q = new MetaQuery().addMetaExtend(queries);
+ System.out.println("array repres " + q.toMeta());
System.out.println();
}
@Test
public void testCollections() throws IOException {
- Map<String, String> query = new LinkedHashMap<>();
- Serializer ser = new Serializer();
- query.put("corpusID", "A00");
- List<Map> l = ser.serializeQueries(query, MetaQuerySerializer.TYPE.FILTER);
- query.clear();
- query.put("corpusID", "A01");
- List<Map> u = ser.serializeQueries(query, MetaQuerySerializer.TYPE.EXTEND);
- l.addAll(u);
- String val = ser.stringify(l);
- System.out.println("results " + val);
+ MetaQuery q = new MetaQuery().addMetaFilter("corpusID", "A00");
+ q.addMetaExtend("corpusID", "A01");
+
+ System.out.println("results stringified " + q.stringify());
+ System.out.println("results to meta" + q.toMeta());
System.out.println();
-
-
- String meta = ser.queryToMeta(val);
-
- System.out.println("meta query " + meta);
-// List<String> list = new ArrayList<>();
-// list.add(val);
-// List s = collSerializer.serializeResource(list);
- System.out.println("printable list ");
- 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\"}}]";
- List s = new ArrayList();
- s.add(meta);
- List fin = ser.serializeResources(s);
-
- String string = ser.serializeToMeta(fin);
- System.out.println("meta string " + string);
-
+ MetaQuery q = new MetaQuery().addResource(meta);
+ org.junit.Assert.assertEquals("String should be empty", "", q.stringify());
+ System.out.println("meta string " + q.toMeta());
+ org.junit.Assert.assertEquals(meta, q.toMeta());
}
@Test
public void testA00() throws IOException {
- Map<String, String> query = new LinkedHashMap<>();
- Serializer ser = new Serializer();
- query.put("corpusID", "A00");
- List<Map> l = ser.serializeQueries(query, MetaQuerySerializer.TYPE.FILTER);
- query.clear();
- query.put("corpusID", "A01");
- List<Map> u = ser.serializeQueries(query, MetaQuerySerializer.TYPE.EXTEND);
- l.addAll(u);
- String val = ser.stringify(l);
- List s = new ArrayList();
- s.add(val);
-
- List fin = ser.serializeResources(s);
- System.out.println("A00 meta: " + fin);
-
+ MetaQuery q = new MetaQuery().addMetaExtend("corpusID", "A00").addMetaExtend("corpusID", "A01");
+ System.out.println("A meta: " + q.stringify());
+ System.out.println();
}
-
@Test
public void testnewMetaQuery() throws IOException {
- Map<String, String> qu = new LinkedHashMap<>();
- Serializer ser = new Serializer();
- qu.put("corpusID", "A00");
- List<Map> l = ser.serializeQueries(qu, MetaQuerySerializer.TYPE.FILTER);
- qu.clear();
- qu.put("corpusID", "A01");
- List<Map> u = ser.serializeQueries(qu, MetaQuerySerializer.TYPE.EXTEND);
- l.addAll(u);
- String val = ser.stringify(l);
- List s = new ArrayList();
- s.add(val);
-
- List fin = ser.serializeResources(s);
-
-
- System.out.println("======= METAQUERY TESTING BEGIN =======");
-
- MetaQuery query = new MetaQuery();
- query.addMetaFilter("textClass", "wissenschaft");
- query.addResources(s);
- System.out.println("query "+ query.toMeta());
- System.out.println("string "+ query.stringify());
- System.out.println("======= METAQUERY TESTING END =======");
+ String meta = "[{\"@type\":\"korap:meta-filter\",\"@value\":{\"@type\":\"korap:term\",\"@field\":\"korap:field#corpusID\",\"@value\":\"WPD\"}}]";
+ MetaQuery q = new MetaQuery().addResource(meta);
+ q.addMetaFilter("textClass", "wissenschaft");
+ System.out.println("meta string " + q.toMeta());
}
}