Broken test for query rewrite in nested repetition/expansion query
diff --git a/CHANGES b/CHANGES
index 770142d..32c6468 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,6 @@
+0.49 2014-11-08
+ - [bugfix-todo] Rewrite bug when repeating expansions (margaretha)
+
0.48 2014-11-07
- [feature] Retrieval of token lists (diewald)
- [bugfix] Classes can now be highlighted to 127.
diff --git a/pom.xml b/pom.xml
index 14293f9..de888a1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -24,7 +24,7 @@
<groupId>KorAP-modules</groupId>
<artifactId>KorAP-lucene-index</artifactId>
- <version>0.48</version>
+ <version>0.49</version>
<packaging>jar</packaging>
<name>KorAP-lucene-index</name>
diff --git a/src/main/java/de/ids_mannheim/korap/KorapQuery.java b/src/main/java/de/ids_mannheim/korap/KorapQuery.java
index b409599..582e2a0 100644
--- a/src/main/java/de/ids_mannheim/korap/KorapQuery.java
+++ b/src/main/java/de/ids_mannheim/korap/KorapQuery.java
@@ -812,6 +812,11 @@
return ssq;
};
+ // Create an empty segment
+ public SpanRepetitionQueryWrapper empty () {
+ return new SpanRepetitionQueryWrapper();
+ };
+
// SpanSegmentAlterQueries
/**
* Create a segment alternation query object.
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestSpanExpansionIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestSpanExpansionIndex.java
index 7f2e658..6173ad6 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestSpanExpansionIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestSpanExpansionIndex.java
@@ -1,11 +1,15 @@
package de.ids_mannheim.korap.index;
-import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.*;
import java.io.IOException;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.spans.SpanTermQuery;
+import org.apache.lucene.search.spans.SpanMultiTermQueryWrapper;
+import org.apache.lucene.util.automaton.RegExp;
+import org.apache.lucene.search.RegexpQuery;
+
import org.junit.Test;
import de.ids_mannheim.korap.KorapIndex;
@@ -13,6 +17,7 @@
import de.ids_mannheim.korap.KorapResult;
import de.ids_mannheim.korap.query.SpanElementQuery;
import de.ids_mannheim.korap.query.SpanExpansionQuery;
+import de.ids_mannheim.korap.query.SpanRepetitionQuery;
public class TestSpanExpansionIndex {
@@ -248,6 +253,38 @@
assertEquals(1, kr.getMatch(4).getStartPos());
assertEquals(4, kr.getMatch(4).getEndPos());
}
+
+
+ /**
+ * Query rewrite bug
+ * @throws IOException
+ * */
+ @Test
+ public void testQueryRewriteBug() throws IOException {
+ KorapIndex ki = new KorapIndex();
+ ki.addDoc(createFieldDoc0()); // same doc
+ ki.addDoc(createFieldDoc1()); // only not clause
+ ki.addDoc(createFieldDoc2()); // only main clause
+ ki.commit();
+
+ // See /queries/bugs/repetition_group_rewrite
+ // spanRepetition(spanExpansion(
+ // SpanMultiTermQueryWrapper(tokens:/cnx/p:A/), []{1, 1}, right){2,2}
+ // )
+ RegexpQuery requery = new RegexpQuery(new Term("base", "s:[ac]"), RegExp.ALL);
+ SpanMultiTermQueryWrapper<RegexpQuery> query =
+ new SpanMultiTermQueryWrapper<RegexpQuery>( requery );
+ SpanExpansionQuery seq = new SpanExpansionQuery(query, 1, 1, 1, true);
+ SpanRepetitionQuery rep = new SpanRepetitionQuery(seq, 2, 2, true);
+
+ try {
+ ki.search(rep, (short) 20);
+ }
+ catch (Exception e) {
+ fail(e.getMessage());
+ };
+ };
+
private FieldDocument createFieldDoc0(){
FieldDocument fd = new FieldDocument();
diff --git a/src/test/java/de/ids_mannheim/korap/query/TestKorapQueryJSON.java b/src/test/java/de/ids_mannheim/korap/query/TestKorapQueryJSON.java
index 01c94be..4ac40d9 100644
--- a/src/test/java/de/ids_mannheim/korap/query/TestKorapQueryJSON.java
+++ b/src/test/java/de/ids_mannheim/korap/query/TestKorapQueryJSON.java
@@ -307,6 +307,13 @@
};
+ @Test
+ public void queryJSONrepetitionGroupRewriteBug () throws QueryException {
+ // ([cnx/p="A"][]){2}
+ SpanQueryWrapper sqwi = jsonQuery(getClass().getResource("/queries/bugs/repetition_group_rewrite.jsonld").getFile());
+
+ assertEquals(sqwi.toQuery().toString(), "spanRepetition(spanExpansion(SpanMultiTermQueryWrapper(tokens:/cnx/p:A/), []{1, 1}, right){2,2})");
+ };
public static String getString (String path) {
StringBuilder contentBuilder = new StringBuilder();
diff --git a/src/test/resources/queries/bugs/repetition_group_rewrite.jsonld b/src/test/resources/queries/bugs/repetition_group_rewrite.jsonld
new file mode 100644
index 0000000..914fc95
--- /dev/null
+++ b/src/test/resources/queries/bugs/repetition_group_rewrite.jsonld
@@ -0,0 +1,36 @@
+{
+ "@context" : "http://ids-mannheim.de/ns/KorAP/json-ld/v0.2/context.jsonld",
+ "query" : {
+ "@type" : "korap:group",
+ "boundary" : {
+ "@type" : "korap:boundary",
+ "max" : 2,
+ "min" : 2
+ },
+ "max" : 2,
+ "min" : 2,
+ "operands" : [
+ {
+ "@type" : "korap:group",
+ "operands" : [
+ {
+ "@type" : "korap:token",
+ "wrap" : {
+ "@type" : "korap:term",
+ "foundry" : "cnx",
+ "key" : "A",
+ "layer" : "p",
+ "match" : "match:eq",
+ "type" : "type:regex"
+ }
+ },
+ {
+ "@type" : "korap:token"
+ }
+ ],
+ "operation" : "operation:sequence"
+ }
+ ],
+ "operation" : "operation:repetition"
+ }
+}