bug fix in serializer
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 9c7677b..a582540 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
@@ -39,7 +39,7 @@
if (args.length == 0) {
queries = new String[]{
/*
- * negation
+ * negation
* elemente
* within
* regex
@@ -126,9 +126,10 @@
}
Map<String, Object> requestMap = ast.getRequestMap();
try {
- List<Map> meta_re = serializer.serializeResources(parents);
+ List meta_re = serializer.serializeResources(parents);
-
+// JsonNode node = mapper.valueToTree(parents);
+// JsonNode arr = node.get("meta");
requestMap.put("meta", meta_re);
requestMap = serializer.addParameters(requestMap, page, num,
cli, cri, cls, crs);
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
index 8655288..bd55641 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/MetaCollectionSerializer.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/MetaCollectionSerializer.java
@@ -84,25 +84,12 @@
this.tester = tester();
}
- @Deprecated
- public String serialize(String resource) throws IOException {
- Map metas = new HashMap();
- Map<String, String> pa = getParents(resource);
- List<Map> parids = new ArrayList<>();
- for (String key : pa.keySet()) {
- Map re = types.mapify(pa.get(key));
- parids.add(re);
- }
- metas.put("meta", parids);
- return mapper.writeValueAsString(metas);
- }
//resources must be ordered: 0 without parent, 1 has 0 as parent, etc.
- public List<Map> serialize(List<String> r_queries) throws IOException {
- Map metas = new HashMap();
- List<Map> parids = new ArrayList<>();
+ public List<ArrayList> serializeResource(List<String> r_queries) throws IOException {
+ List parids = new ArrayList<>();
for (String query : r_queries) {
- Map re = types.mapify(query);
- parids.add(re);
+ ArrayList m = mapper.readValue(query, ArrayList.class);
+ parids.add(m);
}
return parids;
}
@@ -145,5 +132,4 @@
}
-
}
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
index c7d31f1..ba0cd8a 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/MetaQuerySerializer.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/MetaQuerySerializer.java
@@ -167,13 +167,6 @@
return new ArrayList<>(metavalue);
}
- //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);
- }
-
//fixme: only allows for one until and since entry!!
private String[] processDates(List<String> dates) {
if (dates.isEmpty())
@@ -197,7 +190,6 @@
el[idx] = types.formatDate(Long.valueOf(value), MetaTypes.YMD);
idx++;
}
-
}
if (range)
el[0] = "r";
@@ -209,6 +201,13 @@
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/MetaTypes.java b/src/main/java/de/ids_mannheim/korap/query/serialize/MetaTypes.java
index dc47121..405dc4b 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/MetaTypes.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/MetaTypes.java
@@ -6,6 +6,7 @@
import java.io.IOException;
import java.util.LinkedHashMap;
+import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -116,6 +117,10 @@
return mapper.readValue(s, Map.class);
}
+ public List listify(String s) throws IOException {
+ return mapper.readValue(s, LinkedList.class);
+ }
+
public String stringify(Map m) throws JsonProcessingException {
return mapper.writeValueAsString(m);
}
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
index 3e24e4c..8edf09d 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/Serializer.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/Serializer.java
@@ -24,14 +24,18 @@
this.mapper = new ObjectMapper();
}
- public String serializeMeta(List m_queries) throws JsonProcessingException {
-// Map metas = new HashMap();
-// metas.put("meta", m_queries);
+ public String serializeToMeta(List m_queries) throws JsonProcessingException {
+ Map metas = new HashMap();
+ metas.put("meta", m_queries);
+ return mapper.writeValueAsString(metas);
+ }
+
+ public String stringify(List m_queries) throws JsonProcessingException {
return mapper.writeValueAsString(m_queries);
}
- public List<Map> serializeResources(List<String> r_queries) throws IOException {
- return cs.serialize(r_queries);
+ public List<ArrayList> serializeResources(List<String> r_queries) throws IOException {
+ return cs.serializeResource(r_queries);
}
public List<Map> serializeQueries(Map<String, String> queries, MetaQuerySerializer.TYPE type) {
diff --git a/src/test/java/MetaQuerySerializationTest.java b/src/test/java/MetaQuerySerializationTest.java
index b1062d8..bd40204 100644
--- a/src/test/java/MetaQuerySerializationTest.java
+++ b/src/test/java/MetaQuerySerializationTest.java
@@ -11,10 +11,7 @@
import org.junit.runners.JUnit4;
import java.io.IOException;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
/**
* @author hanl
@@ -50,12 +47,7 @@
j.put("textClass", "wissenschaft");
String s = querySerializer.stringify(j, MetaQuerySerializer.TYPE.FILTER);
System.out.println("------ TEXT SINGLE " + s);
- }
-
- @Test
- public void testResourceMeta() throws IOException {
- String s = collSerializer.serialize("25");
- System.out.println(" --- RESULT JSON " + s);
+ System.out.println();
}
@Test
@@ -66,6 +58,7 @@
queries.put("author", "Goethe");
String f = querySerializer.stringify(queries, MetaQuerySerializer.TYPE.FILTER);
System.out.println("value until/since : " + f);
+ System.out.println();
}
@Test
@@ -75,6 +68,7 @@
queries.put("author", "Hesse");
String f = querySerializer.stringify(queries, MetaQuerySerializer.TYPE.FILTER);
System.out.println("value until : " + f);
+ System.out.println();
}
@Test
@@ -84,6 +78,7 @@
queries.put("author", "Kafka");
String f = querySerializer.stringify(queries, MetaQuerySerializer.TYPE.FILTER);
System.out.println("value since : " + f);
+ System.out.println();
}
//@Test
@@ -109,6 +104,7 @@
} catch (NullPointerException npe) {
npe.printStackTrace();
System.out.println("null\n");
+ System.out.println();
} catch (JsonGenerationException e) {
e.printStackTrace();
} catch (JsonMappingException e) {
@@ -132,6 +128,8 @@
List f = querySerializer.serializeQueries(queries, MetaQuerySerializer.TYPE.EXTEND);
s.addAll(f);
System.out.println("--- ALL " + s);
+ System.out.println();
+
}
@Test
@@ -140,7 +138,25 @@
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.serializeMeta(s));
+ System.out.println("array repres " + ser.serializeToMeta(s));
+ System.out.println();
+ }
+
+ @Test
+ public void testCollections() throws IOException {
+ Map<String, String> query = new LinkedHashMap<>();
+ Serializer ser = new Serializer();
+ query.put("corpusID", "WPD");
+
+ List<Map> p = ser.serializeQueries(query, MetaQuerySerializer.TYPE.FILTER);
+ String s = ser.stringify(p);
+
+ System.out.println("results " + s);
+ System.out.println();
+ List<String> l = new ArrayList<>();
+ l.add(s);
+ collSerializer.serializeResource(l);
+
}
}