fixed parsing of infinite quantifiers +/* for empty segments
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 02d4e0d..e6ef5cd 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
@@ -880,6 +880,7 @@
String[] minmax = new String[2];
Integer min = 1;
Integer max = 1;
+ boolean infinite = false;
ParseTree child;
for (int i = 0; i < emptySegments.getChildCount() - 1; i++) {
child = emptySegments.getChild(i);
@@ -888,7 +889,13 @@
if (child.toStringTree().equals("[]")) {
if (nextSiblingString.equals("?")) {
max++;
- } else if (nextSiblingString.startsWith("{")) {
+ } else if (nextSiblingString.equals("+")) {
+ min++;
+ infinite = true;
+ } else if (nextSiblingString.equals("*")) {
+ infinite = true;
+ }
+ else if (nextSiblingString.startsWith("{")) {
String occ = nextSiblingString.substring(1, nextSiblingString.length() - 1);
System.out.println(occ);
if (occ.contains(",")) {
@@ -910,6 +917,7 @@
min++;
max++;
}
+ if (infinite) max = MAXIMUM_DISTANCE;
minmax[0] = min.toString();
minmax[1] = max.toString();
return minmax;
@@ -984,7 +992,7 @@
"contains(<cnx/c=np>, [mate/pos=NE])",
"matches(<A>,[pos=N]*)",
"[base=Auto]matches(<A>,[][pos=N]{4})",
- "[base=der][][base=Mann]"
+ "[base=der][]*[base=Mann]"
};
// PoliqarpPlusTree.verbose=true;
for (String q : queries) {
@@ -993,6 +1001,7 @@
// System.out.println(PoliqarpPlusTree.parsePoliqarpQuery(q).toStringTree(PoliqarpPlusTree.parser));
@SuppressWarnings("unused")
PoliqarpPlusTree pt = new PoliqarpPlusTree(q);
+ System.out.println(pt.parsePoliqarpQuery(q).toStringTree(pt.parser));
System.out.println(q);
System.out.println();
diff --git a/src/test/java/PoliqarpPlusTreeTest.java b/src/test/java/PoliqarpPlusTreeTest.java
index 3fab91f..2c6eeaf 100644
--- a/src/test/java/PoliqarpPlusTreeTest.java
+++ b/src/test/java/PoliqarpPlusTreeTest.java
@@ -172,6 +172,31 @@
map = ppt.getRequestMap().get("query").toString();
assertEquals(et5.replaceAll(" ", ""), map.replaceAll(" ", ""));
+ // [base=der][]*[base=Mann]
+ String et6 =
+ "{@type=korap:group, operation=operation:sequence, inOrder=true, distances=[" +
+ "{@type=korap:distance, key=w, min=1, max=100}" +
+ "], " +
+ "operands=[" +
+ "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
+ "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}" +
+ "]}";
+ ppt = new PoliqarpPlusTree("[base=der][]*[base=Mann]");
+ map = ppt.getRequestMap().get("query").toString();
+ assertEquals(et6.replaceAll(" ", ""), map.replaceAll(" ", ""));
+
+ // [base=der][]*[base=Mann]
+ String et7 =
+ "{@type=korap:group, operation=operation:sequence, inOrder=true, distances=[" +
+ "{@type=korap:distance, key=w, min=2, max=100}" +
+ "], " +
+ "operands=[" +
+ "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
+ "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}" +
+ "]}";
+ ppt = new PoliqarpPlusTree("[base=der][]+[base=Mann]");
+ map = ppt.getRequestMap().get("query").toString();
+ assertEquals(et7.replaceAll(" ", ""), map.replaceAll(" ", ""));
}
@Test