refactoring;
metaquery for json-ld "meta" part;
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQuery.java b/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQuery.java
index ed1d5ef..296f905 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQuery.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQuery.java
@@ -18,7 +18,7 @@
public class CollectionQuery {
private JsonFactory factory;
- private MetaTypes types;
+ private CollectionsTypes types;
private ObjectMapper serialzer;
private List<Map> rq;
private List<Map> mfil;
@@ -30,7 +30,7 @@
this.mfil = new ArrayList<>();
this.mext = new ArrayList<>();
this.factory = serialzer.getFactory();
- this.types = new MetaTypes();
+ this.types = new CollectionsTypes();
}
public CollectionQuery addResource(String query) {
@@ -203,22 +203,18 @@
* @return
*/
public String stringify() {
- List meta = getCollectionsOnly();
- if (meta.isEmpty())
+ List collection = getCollectionsOnly();
+ if (collection.isEmpty())
return "";
try {
- return serialzer.writeValueAsString(meta);
+ return serialzer.writeValueAsString(collection);
} catch (JsonProcessingException e) {
e.printStackTrace();
return "";
}
}
- public JsonNode jsonify() {
- return serialzer.valueToTree(join());
- }
-
/**
* returns the List<Map> that contains all the meta queries and resource queries
* added to the meta query container
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/MetaTypes.java b/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionsTypes.java
similarity index 97%
rename from src/main/java/de/ids_mannheim/korap/query/serialize/MetaTypes.java
rename to src/main/java/de/ids_mannheim/korap/query/serialize/CollectionsTypes.java
index 1a3b07b..c75f059 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/MetaTypes.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionsTypes.java
@@ -14,11 +14,11 @@
* @author hanl
* @date 04/12/2013
*/
-public class MetaTypes {
+public class CollectionsTypes {
private ObjectMapper mapper;
- public MetaTypes() {
+ public CollectionsTypes() {
this.mapper = new ObjectMapper();
}
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
new file mode 100644
index 0000000..caf7154
--- /dev/null
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/MetaQuery.java
@@ -0,0 +1,51 @@
+package de.ids_mannheim.korap.query.serialize;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author hanl
+ * @date 07/02/2014
+ */
+public class MetaQuery {
+
+ private ObjectMapper serialier;
+ private Map meta;
+
+ public MetaQuery() {
+ this.serialier = new ObjectMapper();
+ meta = new HashMap();
+ }
+
+ public MetaQuery addContext(Object left, Object right, String type) {
+ Map map = new HashMap();
+ List l = new LinkedList();
+ List r = new LinkedList();
+ l.add(type);
+ l.add(left);
+ map.put("left", l);
+ r.add(type);
+ r.add(right);
+ map.put("right", r);
+ meta.put("context", map);
+ return this;
+ }
+
+ public MetaQuery addEntry(String name, Object value) {
+ meta.put(name, value);
+ return this;
+ }
+
+ public String toMeta() {
+ try {
+ return serialier.writeValueAsString(meta);
+ } catch (JsonProcessingException e) {
+ return "";
+ }
+ }
+}