- interpret ambiguous {n} segments (where n is a number, could be repetition or word form 'n' inside a class) as repetition by default
- issue warning to user: "use {[orth=n]} if you want a class containing 'n'"
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusTree.java b/src/main/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusTree.java
index c0c175f..c3bb60e 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusTree.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusTree.java
@@ -459,7 +459,14 @@
// min is optional: if not specified, min = max
if (minNode!=null) min = Integer.parseInt(minNode.getText());
else if (hasChild(repetitionTypeNode, ",")) min = 0;
- else min = max;
+ else {
+ min = max;
+ warnings.add("Your query contains a segment of the form {n}, where n is some number. This expression is ambiguous. "
+ + "It could mean a repetition (\"Repeat the previous element n times!\") or a word form that equals the number, "
+ + "enclosed by a \"class\" (which is denoted by braces like '{x}', see the documentation on classes)."
+ + "KorAP has by default interpreted the segment as a repetition statement. If you want to express the"
+ + "number as a word form inside a class, use the non-shorthand form {[orth=n]}.");
+ }
}
if (maxInfinite) {
max = null;
@@ -691,6 +698,8 @@
throw new QueryException("The query you specified could not be processed. Please make sure it is well-formed.");
}
// Return the generated tree
+ log.info("ANTLR parse tree: "+tree.toStringTree(parser));
+ System.out.println("ANTLR parse tree: "+tree.toStringTree(parser));
return tree;
}
}
diff --git a/src/test/java/PoliqarpPlusTreeTest.java b/src/test/java/PoliqarpPlusTreeTest.java
index 07df5c3..fa9fda0 100644
--- a/src/test/java/PoliqarpPlusTreeTest.java
+++ b/src/test/java/PoliqarpPlusTreeTest.java
@@ -520,6 +520,18 @@
ppt = new PoliqarpPlusTree(query);
map = ppt.getRequestMap().get("query").toString();
assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
+
+ query = "[base=Mann][]{2}";
+ expected =
+ "{@type=korap:group, operation=operation:sequence, operands=[" +
+ "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," +
+ "{@type=korap:group, operation=operation:repetition, operands=[" +
+ "{@type=korap:token}" +
+ "], boundary={@type=korap:boundary, min=2, max=2}, min=2, max=2}" +
+ "]}";
+ ppt = new PoliqarpPlusTree(query);
+ map = ppt.getRequestMap().get("query").toString();
+ assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
}
@Test