Use operation:override in query reference rewrite (#783)
Change-Id: Iaaaefcb325a4062fac7ef0e8adc243ffa70f5e95
diff --git a/Changes b/Changes
index 79ed314..4c1e608 100644
--- a/Changes
+++ b/Changes
@@ -8,6 +8,7 @@
- Update VirtualCorpusRewrite Remove Owner (#779)
- Add source to QueryReferenceRewrite (#783) and VirtualCorpusRewrite (#780)
- Use operation:override in virtual corpus (reference) rewrite (#780)
+- Use operation:override in query reference rewrite (#783)
# version 0.75
diff --git a/src/main/java/de/ids_mannheim/korap/rewrite/QueryReferenceRewrite.java b/src/main/java/de/ids_mannheim/korap/rewrite/QueryReferenceRewrite.java
index c682e1b..0f6ff8c 100644
--- a/src/main/java/de/ids_mannheim/korap/rewrite/QueryReferenceRewrite.java
+++ b/src/main/java/de/ids_mannheim/korap/rewrite/QueryReferenceRewrite.java
@@ -91,11 +91,14 @@
private void rewriteQuery (JsonNode qref, KoralNode koralNode)
throws KustvaktException {
- JsonNode jsonNode = koralNode.rawNode();
- koralNode.remove("@type",
- new RewriteIdentifier("@type", "", jsonNode.at("/@type").asText()));
- koralNode.remove("ref",
- new RewriteIdentifier("ref", "", jsonNode.at("/ref").asText()));
- koralNode.setAll((ObjectNode) qref);
+ String source = koralNode.rawNode().toString();
+ JsonNode sourceNode = JsonUtils.readTree(source);
+ koralNode.replace(qref, new RewriteIdentifier(null, "", sourceNode));
+
+// koralNode.remove("@type",
+// new RewriteIdentifier("@type", "", jsonNode.at("/@type").asText()));
+// koralNode.remove("ref",
+// new RewriteIdentifier("ref", "", jsonNode.at("/ref").asText()));
+// koralNode.setAll((ObjectNode) qref);
}
}
diff --git a/src/main/java/de/ids_mannheim/korap/rewrite/VirtualCorpusRewrite.java b/src/main/java/de/ids_mannheim/korap/rewrite/VirtualCorpusRewrite.java
index d479bb5..41da0e2 100644
--- a/src/main/java/de/ids_mannheim/korap/rewrite/VirtualCorpusRewrite.java
+++ b/src/main/java/de/ids_mannheim/korap/rewrite/VirtualCorpusRewrite.java
@@ -4,7 +4,6 @@
import org.springframework.stereotype.Component;
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.constant.QueryType;
@@ -103,7 +102,7 @@
koralNode.replace("ref", newRef, new RewriteIdentifier("ref", "", ref));
}
- private void rewriteVC (QueryDO vc, KoralNode koralNode)
+ protected void rewriteVC (QueryDO vc, KoralNode koralNode)
throws KustvaktException {
String koralQuery = vc.getKoralQuery();
JsonNode newKoralQuery = JsonUtils.readTree(koralQuery).at("/collection");
diff --git a/src/test/java/de/ids_mannheim/korap/rewrite/QueryRewriteTest.java b/src/test/java/de/ids_mannheim/korap/rewrite/QueryReferenceRewriteTest.java
similarity index 73%
rename from src/test/java/de/ids_mannheim/korap/rewrite/QueryRewriteTest.java
rename to src/test/java/de/ids_mannheim/korap/rewrite/QueryReferenceRewriteTest.java
index 5a3ee46..1fe9089 100644
--- a/src/test/java/de/ids_mannheim/korap/rewrite/QueryRewriteTest.java
+++ b/src/test/java/de/ids_mannheim/korap/rewrite/QueryReferenceRewriteTest.java
@@ -1,6 +1,7 @@
package de.ids_mannheim.korap.rewrite;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
import com.fasterxml.jackson.databind.JsonNode;
@@ -15,7 +16,7 @@
/**
* @author diewald
*/
-public class QueryRewriteTest extends SpringJerseyTest {
+public class QueryReferenceRewriteTest extends SpringJerseyTest {
@Test
public void testRewriteRefNotFound () throws KustvaktException, Exception {
@@ -37,18 +38,13 @@
.get();
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
-
node = node.at("/query/operands/1/rewrites");
- assertEquals(3,node.size());
+ assertEquals(1, node.size());
assertEquals("Kustvakt", node.at("/0/origin").asText());
- assertEquals("operation:deletion", node.at("/0/operation").asText());
- assertEquals("@type", node.at("/0/scope").asText());
- assertEquals("koral:queryRef", node.at("/0/source").asText());
-
- assertEquals("ref", node.at("/1/scope").asText());
- assertEquals("system-q", node.at("/1/source").asText());
-
- assertEquals("operation:injection", node.at("/2/operation").asText());
+ assertEquals("operation:override", node.at("/0/operation").asText());
+ assertEquals("koral:queryRef", node.at("/0/source/@type").asText());
+ assertEquals("system-q", node.at("/0/source/ref").asText());
+ assertTrue(node.at("/0/scope").isMissingNode());
}
@Test
@@ -64,16 +60,13 @@
JsonNode node = JsonUtils.readTree(ent);
assertEquals(node.at("/query/operands/1/@type").asText(),
"koral:token");
-
- node = node.at("/query/operands/1/rewrites");
- assertEquals("Kustvakt", node.at("/0/origin").asText());
- assertEquals("operation:deletion", node.at("/0/operation").asText());
- assertEquals("@type", node.at("/0/scope").asText());
- assertEquals("koral:queryRef", node.at("/0/source").asText());
- assertEquals("ref", node.at("/1/scope").asText());
- assertEquals("dory/dory-q", node.at("/1/source").asText());
-
- assertEquals("operation:injection", node.at("/2/operation").asText());
+ node = node.at("/query/operands/1/rewrites");
+ assertEquals(1, node.size());
+ assertEquals("Kustvakt", node.at("/0/origin").asText());
+ assertEquals("operation:override", node.at("/0/operation").asText());
+ assertEquals("koral:queryRef", node.at("/0/source/@type").asText());
+ assertEquals("dory/dory-q", node.at("/0/source/ref").asText());
+ assertTrue(node.at("/0/scope").isMissingNode());
}
}
diff --git a/src/test/java/de/ids_mannheim/korap/rewrite/VirtualCorpusRewriteTest.java b/src/test/java/de/ids_mannheim/korap/rewrite/VirtualCorpusReferenceRewriteTest.java
similarity index 98%
rename from src/test/java/de/ids_mannheim/korap/rewrite/VirtualCorpusRewriteTest.java
rename to src/test/java/de/ids_mannheim/korap/rewrite/VirtualCorpusReferenceRewriteTest.java
index c607ef1..f71c9fa 100644
--- a/src/test/java/de/ids_mannheim/korap/rewrite/VirtualCorpusRewriteTest.java
+++ b/src/test/java/de/ids_mannheim/korap/rewrite/VirtualCorpusReferenceRewriteTest.java
@@ -27,7 +27,7 @@
/**
* @author margaretha
*/
-public class VirtualCorpusRewriteTest extends SpringJerseyTest {
+public class VirtualCorpusReferenceRewriteTest extends SpringJerseyTest {
@Autowired
private NamedVCLoader vcLoader;