use of de.ids_mannheim.korap.KrillQuery in project Krill by KorAP.
the class TestSimple method getJSONQuery.
// Get query wrapper based on json file
public static SpanQueryWrapper getJSONQuery(String jsonFile) throws QueryException {
SpanQueryWrapper sqwi;
// try {
String json = getJsonString(jsonFile);
sqwi = new KrillQuery("tokens").fromKoral(json);
// };
return sqwi;
}
use of de.ids_mannheim.korap.KrillQuery in project Krill by KorAP.
the class TestBenchmarkSpans method jsonQuery.
public static SpanQueryWrapper jsonQuery(String jsonFile) {
SpanQueryWrapper sqwi;
try {
String json = getString(jsonFile);
sqwi = new KrillQuery("tokens").fromKoral(json);
} catch (QueryException e) {
fail(e.getMessage());
sqwi = new QueryBuilder("tokens").seg("???");
}
;
return sqwi;
}
use of de.ids_mannheim.korap.KrillQuery in project Krill by KorAP.
the class TestWithinIndex method queryJSONpoly2.
// contains(<s>, (es wird | wird es))
@Test
public void queryJSONpoly2() throws QueryException, IOException {
String jsonPath = URLDecoder.decode(getClass().getResource("/queries/poly2.json").getFile(), "UTF-8");
String jsonPQuery = readFile(jsonPath);
SpanQueryWrapper sqwi = new KrillQuery("tokens").fromKoral(jsonPQuery);
SpanWithinQuery sq = (SpanWithinQuery) sqwi.toQuery();
KrillIndex ki = new KrillIndex();
ki.addDoc(getClass().getResourceAsStream("/wiki/DDD-08370.json.gz"), true);
ki.addDoc(getClass().getResourceAsStream("/wiki/PPP-02924.json.gz"), true);
ki.commit();
Result kr = ki.search(sq, (short) 10);
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(1).getLocalDocID());
assertEquals(237, kr.getMatch(1).getStartPos());
assertEquals(252, kr.getMatch(1).getEndPos());
}
use of de.ids_mannheim.korap.KrillQuery in project Krill by KorAP.
the class TestWithinIndex method queryJSONcomplexSpanOrTerm.
@Test
public void queryJSONcomplexSpanOrTerm() throws QueryException, IOException {
/*
at org.apache.lucene.search.spans.SpanOrQuery$1.doc(SpanOrQuery.java:234)
at de.ids_mannheim.korap.query.spans.WithinSpans.toSameDoc(WithinSpans.java:423)
at de.ids_mannheim.korap.query.spans.WithinSpans.next(WithinSpans.java:375)
at de.ids_mannheim.korap.KrillIndex.search(KrillIndex.java:1293)
at de.ids_mannheim.korap.Krill.apply(Krill.java:304)
*/
String jsonPath = URLDecoder.decode(getClass().getResource("/queries/bugs/span_or_bug.jsonld").getFile(), "UTF-8");
String jsonPQuery = readFile(jsonPath);
SpanQueryWrapper sqwi = new KrillQuery("tokens").fromKoral(jsonPQuery);
SpanWithinQuery sq = (SpanWithinQuery) sqwi.toQuery();
assertEquals("spanStartsWith(<tokens:base/s:s />, " + "spanOr([tokens:s:Er, tokens:s:Sie]))", sq.toString());
KrillIndex ki = new KrillIndex();
ki.addDoc(getClass().getResourceAsStream("/wiki/DDD-08370.json.gz"), true);
ki.addDoc(getClass().getResourceAsStream("/wiki/SSS-09803.json.gz"), true);
ki.commit();
Result kr = ki.search(sq, (short) 1);
assertEquals(1, kr.getTotalResults());
}
use of de.ids_mannheim.korap.KrillQuery in project Krill by KorAP.
the class TestWithinIndex method indexExample8.
/**
* SpanElementQueries
*/
@Test
public void indexExample8() throws QueryException, IOException {
KrillIndex ki = new KrillIndex();
FieldDocument fd = new FieldDocument();
// <a>xx <e>hi j <e>hi j</e></e></a>
fd.addTV("base", "xx hi j hi j", "[(0-1)s:x|i:x|_0$<i>0<i>1|<>:a$<b>64<i>0<i>12<i>8<b>0]" + "[(1-2)s:x|i:x|_1$<i>1<i>2]" + "[(3-4)s:h|i:h|_2$<i>3<i>4|<>:e$<b>64<i>3<i>12<i>8<b>0]" + "[(4-5)s:i|i:i|_3$<i>4<i>5]" + "[(6-7)s:j|i:j|_4$<i>6<i>7]" + "[(8-9)s:h|i:h|_5$<i>8<i>9|<>:e$<b>64<i>8<i>9<i>8<b>0]" + "[(9-10)s:i|i:i|_6$<i>9<i>10]" + "[(11-12)s:j|i:j|_7$<i>11<i>12]");
ki.addDoc(fd);
ki.commit();
assertEquals(1, ki.numberOf("documents"));
QueryBuilder qb = new KrillQuery("base").builder();
SpanQueryWrapper sqw;
Result kr;
/*
sqw = qb.seg("i:x");
kr = ki.search(sqw.toQuery(), (short) 10);
assertEquals(2, kr.getTotalResults());
sqw = qb.tag("a");
kr = ki.search(sqw.toQuery(), (short) 10);
assertEquals(1, kr.getTotalResults());
sqw = qb.startswith(qb.tag("a"), qb.seg("i:x"));
assertEquals("spanStartsWith(<base:a />, base:i:x)",
sqw.toQuery().toString());
kr = ki.search(sqw.toQuery(), (short) 10);
assertEquals(1, kr.getTotalResults());
*/
sqw = qb.startswith(qb.tag("e"), qb.seg("i:h"));
assertEquals("spanStartsWith(<base:e />, base:i:h)", sqw.toQuery().toString());
kr = ki.search(sqw.toQuery(), (short) 10);
assertEquals(2, kr.getTotalResults());
}
Aggregations