Skip to content

Commit

Permalink
Use operation:override in query reference rewrite (#783)
Browse files Browse the repository at this point in the history
Change-Id: Iaaaefcb325a4062fac7ef0e8adc243ffa70f5e95
  • Loading branch information
margaretha committed Dec 4, 2024
1 parent d59b34d commit d5799ae
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 29 deletions.
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,14 @@ else if (koralNode.has("operands")) {

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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -103,7 +102,7 @@ private void removeOwner (String koralQuery, String vcOwner,
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");
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -15,7 +16,7 @@
/**
* @author diewald
*/
public class QueryRewriteTest extends SpringJerseyTest {
public class QueryReferenceRewriteTest extends SpringJerseyTest {

@Test
public void testRewriteRefNotFound () throws KustvaktException, Exception {
Expand All @@ -37,18 +38,13 @@ public void testRewriteSystemQuery () throws KustvaktException, Exception {
.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
Expand All @@ -64,16 +60,13 @@ public void testRewriteRefRewrite () throws KustvaktException, Exception {
JsonNode node = JsonUtils.readTree(ent);
assertEquals(node.at("/query/operands/1/@type").asText(),
"koral:token");

node = node.at("/query/operands/1/rewrites");
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("dory/dory-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("dory/dory-q", node.at("/0/source/ref").asText());
assertTrue(node.at("/0/scope").isMissingNode());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
/**
* @author margaretha
*/
public class VirtualCorpusRewriteTest extends SpringJerseyTest {
public class VirtualCorpusReferenceRewriteTest extends SpringJerseyTest {

@Autowired
private NamedVCLoader vcLoader;
Expand Down

0 comments on commit d5799ae

Please sign in to comment.