Added a MultipleDistanceQuery test with KrillCollection.
Change-Id: I7b27d04fc80e97079b4f84de3a44d92287c47194
diff --git a/src/main/java/de/ids_mannheim/korap/Krill.java b/src/main/java/de/ids_mannheim/korap/Krill.java
index 5b40873..46f48cf 100644
--- a/src/main/java/de/ids_mannheim/korap/Krill.java
+++ b/src/main/java/de/ids_mannheim/korap/Krill.java
@@ -337,5 +337,11 @@
@Deprecated
public SpanQuery getSpanQuery () {
return this.spanQuery;
- };
+ }
+
+ //EM
+ public void setSpanQuery (SpanQuery sq) {
+ this.spanQuery = sq;
+
+ }
};
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestMultipleDistanceIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestMultipleDistanceIndex.java
index 1b4b4cf..85adfb7 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestMultipleDistanceIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestMultipleDistanceIndex.java
@@ -1,6 +1,7 @@
package de.ids_mannheim.korap.index;
import static de.ids_mannheim.korap.TestSimple.getJSONQuery;
+import static de.ids_mannheim.korap.TestSimple.getJsonString;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
@@ -19,7 +20,13 @@
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import de.ids_mannheim.korap.Krill;
+import de.ids_mannheim.korap.KrillCollection;
import de.ids_mannheim.korap.KrillIndex;
+import de.ids_mannheim.korap.KrillQuery;
import de.ids_mannheim.korap.query.DistanceConstraint;
import de.ids_mannheim.korap.query.SpanClassQuery;
import de.ids_mannheim.korap.query.SpanDistanceQuery;
@@ -317,11 +324,48 @@
"/home/elma/git/Kustvakt-new/src/test/resources/sample-index";
KrillIndex sample = new KrillIndex(new MMapDirectory(Paths.get(path)));
SpanQueryWrapper sqwi = getJSONQuery(
- getClass().getResource("/queries/bugs/cosmas_wildcards.jsonld")
+ getClass().getResource("/queries/bugs/cosmas_wildcards2.jsonld")
.getFile());
SpanQuery sq = sqwi.toQuery();
kr = sample.search(sq, (short) 10);
assertEquals(4, kr.getMatches().size());
+
+ // test krill apply
+ Krill krill = new Krill();
+ krill.setSpanQuery(sq);
+ krill.setIndex(sample);
+ kr = krill.apply();
+ assertEquals(4, kr.getMatches().size());
+
+ // test krill deserialization
+ String jsonString = getJsonString( getClass().getResource("/queries/bugs/cosmas_wildcards2.jsonld")
+ .getFile());
+ krill = new Krill();
+
+ ObjectMapper mapper = new ObjectMapper();
+ JsonNode jsonNode = mapper.readTree(jsonString);
+ final KrillQuery kq = new KrillQuery("tokens");
+ krill.setQuery(kq);
+
+ SpanQueryWrapper qw = kq.fromKoral(jsonNode.get("query"));
+ assertEquals(sqwi.toQuery(),qw.toQuery());
+
+ krill.setSpanQuery(qw.toQuery());
+ kr = krill.apply(sample);
+ assertEquals(4, kr.getMatches().size());
+ }
+
+ @Test
+ @Ignore
+ public void testWithKrillWithCollection () throws IOException {
+ String path =
+ "/home/elma/git/Kustvakt-new/src/test/resources/sample-index";
+ KrillIndex sample = new KrillIndex(new MMapDirectory(Paths.get(path)));
+ String json = getJsonString( getClass().getResource("/queries/bugs/cosmas_wildcards2.jsonld")
+ .getFile());
+ Krill krill = new Krill(json);
+ kr = krill.apply(sample);
+ assertEquals(4, kr.getMatches().size());
}
diff --git a/src/test/resources/queries/bugs/cosmas_wildcards2.jsonld b/src/test/resources/queries/bugs/cosmas_wildcards2.jsonld
new file mode 100644
index 0000000..d83488e
--- /dev/null
+++ b/src/test/resources/queries/bugs/cosmas_wildcards2.jsonld
@@ -0,0 +1,115 @@
+{
+ "@context": "http://korap.ids-mannheim.de/ns/koral/0.3/context.jsonld",
+ "query": {
+ "operation": "operation:sequence",
+ "operands": [
+ {
+ "operation": "operation:class",
+ "operands": [{
+ "wrap": {
+ "@type": "koral:term",
+ "layer": "orth",
+ "match": "match:eq",
+ "type": "type:wildcard",
+ "key": "meine*",
+ "foundry": "opennlp",
+ "rewrites": [{
+ "@type": "koral:rewrite",
+ "src": "Kustvakt",
+ "operation": "operation:injection",
+ "scope": "foundry"
+ }]
+ },
+ "@type": "koral:token",
+ "idn": "meine*_0",
+ "rewrites": [{
+ "@type": "koral:rewrite",
+ "src": "Kustvakt",
+ "operation": "operation:injection",
+ "scope": "idn"
+ }]
+ }],
+ "@type": "koral:group",
+ "classOut": 129
+ },
+ {
+ "operation": "operation:class",
+ "operands": [{
+ "wrap": {
+ "@type": "koral:term",
+ "layer": "lemma",
+ "match": "match:eq",
+ "key": "Erfahrung",
+ "foundry": "tt",
+ "rewrites": [{
+ "@type": "koral:rewrite",
+ "src": "Kustvakt",
+ "operation": "operation:injection",
+ "scope": "foundry"
+ }]
+ },
+ "@type": "koral:token",
+ "idn": "Erfahrung_1",
+ "rewrites": [{
+ "@type": "koral:rewrite",
+ "src": "Kustvakt",
+ "operation": "operation:injection",
+ "scope": "idn"
+ }]
+ }],
+ "@type": "koral:group",
+ "classOut": 129
+ }
+ ],
+ "inOrder": true,
+ "@type": "koral:group",
+ "distances": [
+ {
+ "@type": "cosmas:distance",
+ "boundary": {
+ "min": 1,
+ "max": 2,
+ "@type": "koral:boundary"
+ },
+ "key": "w"
+ },
+ {
+ "@type": "cosmas:distance",
+ "boundary": {
+ "min": 0,
+ "max": 0,
+ "@type": "koral:boundary"
+ },
+ "key": "s"
+ }
+ ]
+ },
+ "meta": {
+ "count": 25,
+ "cutOff": true,
+ "context": {
+ "left": [
+ "t",
+ 40
+ ],
+ "right": [
+ "t",
+ 40
+ ]
+ },
+ "startPage": 1
+ },
+ "collection": {
+ "@type": "koral:doc",
+ "value": "CC-BY.*",
+ "match": "match:eq",
+ "type": "type:regex",
+ "key": "availability",
+ "rewrites": [{
+ "@type": "koral:rewrite",
+ "src": "Kustvakt",
+ "operation": "operation:insertion",
+ "scope": "availability(FREE)"
+ }]
+ }
+}