foundry mapper fix for nested queries
diff --git a/src/main/java/de/ids_mannheim/korap/resource/LayerProcessor.java b/src/main/java/de/ids_mannheim/korap/resource/LayerProcessor.java
index 71d30b1..90b6319 100644
--- a/src/main/java/de/ids_mannheim/korap/resource/LayerProcessor.java
+++ b/src/main/java/de/ids_mannheim/korap/resource/LayerProcessor.java
@@ -28,15 +28,23 @@
}
}else if (node.at("/query/wrap/@type").asText()
.equals("koral:termGroup")) {
- Iterator<JsonNode> nodes = node.at("/query/wrap/operands")
- .elements();
- while (nodes.hasNext()) {
- JsonNode n = nodes.next();
- if (n.path("foundry").isMissingNode()) {
- String layer = n.path("layer").asText();
- ObjectNode obj = (ObjectNode) n;
- obj.put("foundry", mapper.findFoundry(layer));
- }
+ processTermGroup(node.at("/query/wrap/operands"));
+ }
+ return node;
+ }
+
+ private JsonNode processTermGroup(JsonNode node) {
+ Iterator<JsonNode> nodes = node.elements();
+ while (nodes.hasNext()) {
+ JsonNode n = nodes.next();
+ if (n.path("@type").asText().equals("koral:termGroup"))
+ n = processTermGroup(n.path("operands"));
+
+ if (n.path("@type").asText().equals("koral:term") && n
+ .path("foundry").isMissingNode()) {
+ String layer = n.path("layer").asText();
+ ObjectNode obj = (ObjectNode) n;
+ obj.put("foundry", mapper.findFoundry(layer));
}
}
return node;
diff --git a/src/test/java/RewriteTest.java b/src/test/java/RewriteTest.java
index db33a1a..92e61fd 100644
--- a/src/test/java/RewriteTest.java
+++ b/src/test/java/RewriteTest.java
@@ -16,6 +16,7 @@
private static String simple_rewrite_query = "[base=Haus]";
private static String complex_rewrite_query = "<c=INFC>";
private static String complex_rewrite_query2 = "[orth=laufe/i & base!=Lauf]";
+ private static String complex_rewrite_query3 = "[(base=laufen | base=gehen) & tt/pos=VVFIN]";
public RewriteTest() {
@@ -51,7 +52,7 @@
RewriteProcessor processor = new RewriteProcessor();
QuerySerializer s = new QuerySerializer();
- s.setQuery(complex_rewrite_query2, "poliqarp");
+ s.setQuery(complex_rewrite_query3, "poliqarp");
System.out.println("query " + s.toJSON());
System.out.println("finished node " + processor.process(s.toJSON()));
}