json pointer rewrite restriction parameter
diff --git a/src/main/java/de/ids_mannheim/korap/resource/rewrite/CollectionCleanupFilter.java b/src/main/java/de/ids_mannheim/korap/resource/rewrite/CollectionCleanupFilter.java
index c839afc..6f12d59 100644
--- a/src/main/java/de/ids_mannheim/korap/resource/rewrite/CollectionCleanupFilter.java
+++ b/src/main/java/de/ids_mannheim/korap/resource/rewrite/CollectionCleanupFilter.java
@@ -14,21 +14,9 @@
*/
public class CollectionCleanupFilter implements RewriteTask.RewriteNodeAt {
- // track path to operand
- @Deprecated
- private StringBuilder builder;
-
- public CollectionCleanupFilter() {
- super();
- }
-
@Override
public JsonNode preProcess(KoralNode node, KustvaktConfiguration config,
User user) {
- // if (node.has("collection")) {
- // JsonNode coll = node.rawNode().path("collection");
- // process(coll);
- // }
return process(node.rawNode());
}
@@ -46,8 +34,10 @@
}
int count = node.size();
+ // remove group element and replace with single doc
if (count == 1)
sub = node.path(0);
+ // indicate empty group
else if (count
== 0) // can't do anything here -- fixme: edge case?!
return null;
diff --git a/src/main/java/de/ids_mannheim/korap/resource/rewrite/IdWriter.java b/src/main/java/de/ids_mannheim/korap/resource/rewrite/IdWriter.java
index 102da60..737cbe4 100644
--- a/src/main/java/de/ids_mannheim/korap/resource/rewrite/IdWriter.java
+++ b/src/main/java/de/ids_mannheim/korap/resource/rewrite/IdWriter.java
@@ -1,7 +1,6 @@
package de.ids_mannheim.korap.resource.rewrite;
import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.node.ObjectNode;
import de.ids_mannheim.korap.config.KustvaktConfiguration;
import de.ids_mannheim.korap.user.User;
@@ -14,9 +13,7 @@
private int counter;
public IdWriter() {
- super();
this.counter = 0;
-
}
@Override
@@ -27,21 +24,9 @@
if (s != null && !s.isEmpty())
node.put("idn", s + "_" + counter++);
}
-
return node.rawNode();
}
- @Deprecated
- private JsonNode addId(JsonNode node) {
- if (node.isObject()) {
- ObjectNode o = (ObjectNode) node;
- String s = extractToken(node);
- if (s != null && !s.isEmpty())
- o.put("idn", s + "_" + counter++);
- }
- return node;
- }
-
// fixme: koral token --> how does grouping behave?!
private String extractToken(JsonNode token) {
JsonNode wrap = token.path("wrap");
diff --git a/src/main/java/de/ids_mannheim/korap/resource/rewrite/RewriteHandler.java b/src/main/java/de/ids_mannheim/korap/resource/rewrite/RewriteHandler.java
index 5b31fa4..b16d65c 100644
--- a/src/main/java/de/ids_mannheim/korap/resource/rewrite/RewriteHandler.java
+++ b/src/main/java/de/ids_mannheim/korap/resource/rewrite/RewriteHandler.java
@@ -22,7 +22,7 @@
private static Logger jlog = KustvaktLogger.getLogger(RewriteHandler.class);
private Collection<RewriteTask.IterableRewriteAt> node_processors;
private Collection<RewriteTask.RewriteKoralToken> token_node_processors;
- private Collection<RewriteTask.RewriteNodeAt> query_processors;
+ private Collection<RewriteTask> query_processors;
// private Collection<RewriteTask.RewriteNode2> fixed_nodes;
// private Collection<RewriteTask.IterableRewrite> iterable_nodes;
@@ -44,12 +44,12 @@
if (rewriter instanceof RewriteTask.RewriteKoralToken)
return this.token_node_processors
.add((RewriteTask.RewriteKoralToken) rewriter);
- else if (rewriter instanceof RewriteTask.RewriteNodeAt)
- return this.query_processors
- .add((RewriteTask.RewriteNodeAt) rewriter);
else if (rewriter instanceof RewriteTask.IterableRewriteAt)
return this.node_processors
.add((RewriteTask.IterableRewriteAt) rewriter);
+ else if (rewriter instanceof RewriteTask.RewriteBefore
+ | rewriter instanceof RewriteTask.RewriteAfter)
+ return this.query_processors.add(rewriter);
this.failed_task_registration.add(rewriter.getClass());
return false;
@@ -121,7 +121,7 @@
}
}else if (root.path("@type").asText().equals("koral:token")) {
// todo: koral:token nodes cannot be flagged for deletion --> creates the possibility for empty koral:token nodes
- processNode(name,KoralNode.wrapNode(root), user,
+ processNode(name, KoralNode.wrapNode(root), user,
this.token_node_processors, post);
return process(name, root.path("wrap"), user, post);
}else {
@@ -199,16 +199,22 @@
}
private void processFixedNode(JsonNode node, User user,
- Collection<RewriteTask.RewriteNodeAt> tasks, boolean post) {
- for (RewriteTask.RewriteNodeAt task : tasks) {
+ Collection<RewriteTask> tasks, boolean post) {
+ for (RewriteTask task : tasks) {
JsonNode next = node;
- if ((task.at() != null && !node.at(task.at()).isMissingNode()))
- next = node.at(task.at());
+ if (task instanceof RewriteTask.RewriteNodeAt) {
+ RewriteTask.RewriteNodeAt rwa = (RewriteTask.RewriteNodeAt) task;
+ if ((rwa.at() != null && !node.at(rwa.at()).isMissingNode()))
+ next = node.at(rwa.at());
+ }
- if (!post)
- task.preProcess(KoralNode.wrapNode(next), this.config, user);
+ if (!post && task instanceof RewriteTask.RewriteBefore)
+ ((RewriteTask.RewriteBefore) task)
+ .preProcess(KoralNode.wrapNode(next), this.config,
+ user);
else
- task.postProcess(KoralNode.wrapNode(next));
+ ((RewriteTask.RewriteAfter) task)
+ .postProcess(KoralNode.wrapNode(next));
}
}
diff --git a/src/main/java/de/ids_mannheim/korap/resource/rewrite/RewriteTask.java b/src/main/java/de/ids_mannheim/korap/resource/rewrite/RewriteTask.java
index 11e29b8..47b65ae 100644
--- a/src/main/java/de/ids_mannheim/korap/resource/rewrite/RewriteTask.java
+++ b/src/main/java/de/ids_mannheim/korap/resource/rewrite/RewriteTask.java
@@ -22,7 +22,9 @@
}
/**
- *
+ * Post processor targeted at result sets for queries
+ * {@link de.ids_mannheim.korap.resource.rewrite.RewriteTask.RewriteAfter} queries will run
+ * after {@link de.ids_mannheim.korap.resource.rewrite.RewriteTask.IterableRewriteAt} have been processed
*/
interface RewriteAfter extends RewriteTask {
JsonNode postProcess(KoralNode node);
@@ -31,7 +33,7 @@
/**
* nodes subject to rewrites at fixed json pointer location.
* Json-pointer based rewrites are processed after iterable rewrites
- * Deletion via KoralNode not allowed.
+ * Deletion via KoralNode not allowed. Supports pre- and post-processing
*/
interface RewriteNodeAt extends RewriteBefore, RewriteAfter {
String at();
@@ -46,6 +48,14 @@
}
/**
+ * koral token nodes that are subject to rewrites
+ * Be aware that node rewrites are processed before query rewrites. Thus query rewrite may override previous node rewrites
+ * {@link RewriteKoralToken} rewrite DOES NOT support the deletion of the respective node
+ */
+ interface RewriteKoralToken extends RewriteBefore {
+ }
+
+ /**
* query rewrites get injected the entire query from root containing all child nodes
* <p/>
* {@link RewriteQuery} does not allow the deletion of the root node or subnode through KoralNode.
@@ -65,11 +75,4 @@
interface RewriteNode extends RewriteBefore {
}
- /**
- * koral token nodes that are subject to rewrites
- * Be aware that node rewrites are processed before query rewrites. Thus query rewrite may override previous node rewrites
- * {@link RewriteKoralToken} rewrite DOES NOT support the deletion of the respective node
- */
- interface RewriteKoralToken extends RewriteBefore {
- }
}