Added a broken test for the ticket #134 (WithinSpans problem)
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/WithinSpans.java b/src/main/java/de/ids_mannheim/korap/query/spans/WithinSpans.java
index 56724b4..609dcdc 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/WithinSpans.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/WithinSpans.java
@@ -1,34 +1,21 @@
package de.ids_mannheim.korap.query.spans;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.Map;
+
import org.apache.lucene.index.AtomicReaderContext;
import org.apache.lucene.index.Term;
import org.apache.lucene.index.TermContext;
-import org.apache.lucene.util.ArrayUtil;
-import org.apache.lucene.util.Bits;
-import org.apache.lucene.search.spans.Spans;
-import org.apache.lucene.search.spans.SpanQuery;
import org.apache.lucene.search.DocIdSetIterator;
-
-import java.nio.ByteBuffer;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Comparator;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Collection;
-import java.util.Map;
-import java.util.Set;
-
-import de.ids_mannheim.korap.query.SpanWithinQuery;
-import de.ids_mannheim.korap.query.spans.KorapLongSpan;
-
+import org.apache.lucene.search.spans.Spans;
+import org.apache.lucene.util.Bits;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.*;
-import java.io.*;
+import de.ids_mannheim.korap.query.SpanWithinQuery;
/*
TODO: Use the flag in KorapQuery!
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestWithinIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestWithinIndex.java
index 2af8786..853d886 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestWithinIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestWithinIndex.java
@@ -8,18 +8,22 @@
import org.apache.lucene.util.Bits;
import static org.junit.Assert.*;
+
import org.junit.Test;
import org.junit.Ignore;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import de.ids_mannheim.korap.KorapIndex;
+import de.ids_mannheim.korap.KorapMatch;
import de.ids_mannheim.korap.KorapQuery;
import de.ids_mannheim.korap.KorapResult;
import de.ids_mannheim.korap.query.SpanElementQuery;
import de.ids_mannheim.korap.query.SpanWithinQuery;
import de.ids_mannheim.korap.query.SpanNextQuery;
import de.ids_mannheim.korap.query.SpanClassQuery;
+import de.ids_mannheim.korap.query.wrap.SpanQueryWrapper;
+import de.ids_mannheim.korap.util.QueryException;
import de.ids_mannheim.korap.index.FieldDocument;
import de.ids_mannheim.korap.analysis.MultiTermTokenStream;
import org.apache.lucene.search.spans.SpanQuery;
@@ -1069,4 +1073,58 @@
ki.addDoc(fd);
};
+ /**
+ * @throws IOException */
+ @Test
+ public void queryJSONpoly2() throws QueryException, IOException {
+
+ String jsonPath = getClass().getResource("/queries/poly2.json").getFile();
+ String jsonPQuery = readFile(jsonPath);
+ SpanQueryWrapper sqwi = new KorapQuery("tokens").fromJSON(
+ jsonPQuery
+ );
+
+ SpanWithinQuery sq = (SpanWithinQuery) sqwi.toQuery();
+// System.out.println(sq.toString());
+
+ KorapIndex ki = new KorapIndex();
+ ki.addDocFile(
+ getClass().getResource("/wiki/DDD-08370.json.gz").getFile(),true);
+ ki.addDocFile(
+ getClass().getResource("/wiki/PPP-02924.json.gz").getFile(),true);
+ ki.commit();
+ KorapResult kr = ki.search(sq, (short) 10);
+// for (KorapMatch km : kr.getMatches()){
+// System.out.println(km.getStartPos() +","+km.getEndPos()+" "
+// +km.getSnippetBrackets());
+// }
+
+ assertEquals(2, kr.getTotalResults());
+ assertEquals(0, kr.getMatch(0).getLocalDocID());
+ assertEquals(76, kr.getMatch(0).getStartPos());
+ assertEquals(93, kr.getMatch(0).getEndPos());
+ assertEquals(1, kr.getMatch(0).getLocalDocID());
+ assertEquals(237, kr.getMatch(1).getStartPos());
+ assertEquals(252, kr.getMatch(1).getEndPos());
+
+
+
+ }
+
+
+ private String readFile(String path) {
+ StringBuilder sb = new StringBuilder();
+ try {
+ BufferedReader in = new BufferedReader(new FileReader(path));
+ String str;
+ while ((str = in.readLine()) != null) {
+ sb.append(str);
+ };
+ in.close();
+ } catch (IOException e) {
+ fail(e.getMessage());
+ }
+ return sb.toString();
+ }
+
};
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 4d5256b..c0ad9d9 100644
--- a/src/test/java/de/ids_mannheim/korap/query/TestKorapQueryJSON.java
+++ b/src/test/java/de/ids_mannheim/korap/query/TestKorapQueryJSON.java
@@ -196,8 +196,7 @@
// within(<np>,[base=Mann])
assertEquals(sqwi.toQuery().toString(), "{0: spanNext(tokens:tt/p:ADJA, tokens:mate/p:NN)}");
};
-
-
+
@Test
public void queryJSONcosmas3 () throws QueryException {
SpanQueryWrapper sqwi = jsonQuery(getClass().getResource("/queries/cosmas3.json").getFile());
diff --git a/src/test/resources/queries/poly2.json b/src/test/resources/queries/poly2.json
new file mode 100644
index 0000000..68bcadc
--- /dev/null
+++ b/src/test/resources/queries/poly2.json
@@ -0,0 +1,91 @@
+{
+ "@context" : "http://ids-mannheim.de/ns/KorAP/json-ld/v0.2/context.jsonld",
+ "announcements" : [
+ "Deprecated 2014-09-22: 'frame' only to be supported until 3 months from deprecation date. Position frames are now expressed through 'frames'."
+ ],
+ "collection" : {},
+ "collections" : [
+ {
+ "@type" : "korap:meta-filter",
+ "@value" : {
+ "@field" : "korap:field#corpusID",
+ "@type" : "korap:term",
+ "@value" : "WPD"
+ }
+ }
+ ],
+ "errors" : [],
+ "meta" : {},
+ "query" : {
+ "@type" : "korap:group",
+ "frame" : "frame:contains",
+ "frames" : [
+ "frames:contains"
+ ],
+ "operands" : [
+ {
+ "@type" : "korap:span",
+ "key" : "s"
+ },
+ {
+ "@type" : "korap:group",
+ "operands" : [
+ {
+ "@type" : "korap:group",
+ "operands" : [
+ {
+ "@type" : "korap:token",
+ "wrap" : {
+ "@type" : "korap:term",
+ "caseInsensitive" : true,
+ "key" : "es",
+ "layer" : "orth",
+ "match" : "match:eq"
+ }
+ },
+ {
+ "@type" : "korap:token",
+ "wrap" : {
+ "@type" : "korap:term",
+ "key" : "wird",
+ "layer" : "orth",
+ "match" : "match:eq"
+ }
+ }
+ ],
+ "operation" : "operation:sequence"
+ },
+ {
+ "@type" : "korap:group",
+ "operands" : [
+ {
+ "@type" : "korap:token",
+ "wrap" : {
+ "@type" : "korap:term",
+ "caseInsensitive" : true,
+ "key" : "wird",
+ "layer" : "orth",
+ "match" : "match:eq"
+ }
+ },
+ {
+ "@type" : "korap:token",
+ "wrap" : {
+ "@type" : "korap:term",
+ "key" : "es",
+ "layer" : "orth",
+ "match" : "match:eq"
+ }
+ }
+ ],
+ "operation" : "operation:sequence"
+ }
+ ],
+ "operation" : "operation:or"
+ }
+ ],
+ "operation" : "operation:position"
+ },
+ "warnings" : []
+}
+
\ No newline at end of file
diff --git a/src/test/resources/wiki/DDD-08370.json.gz b/src/test/resources/wiki/DDD-08370.json.gz
new file mode 100644
index 0000000..2d7ef2e
--- /dev/null
+++ b/src/test/resources/wiki/DDD-08370.json.gz
Binary files differ
diff --git a/src/test/resources/wiki/PPP-02924.json.gz b/src/test/resources/wiki/PPP-02924.json.gz
new file mode 100644
index 0000000..45e0712
--- /dev/null
+++ b/src/test/resources/wiki/PPP-02924.json.gz
Binary files differ