use of de.ids_mannheim.korap.KrillIndex in project Krill by KorAP.
the class TestKrill method queryJSONzeroRepetitionBug.
@Test
public void queryJSONzeroRepetitionBug() throws IOException {
// der{0}
KrillIndex ki = new KrillIndex();
ki.addDoc(getClass().getResourceAsStream("/wiki/00001.json.gz"), true);
ki.commit();
String json = getJsonString(getClass().getResource("/queries/bugs/zero_repetition_bug.jsonld").getFile());
Result kr = new Krill(json).apply(ki);
assertEquals(783, kr.getError(0).getCode());
assertEquals("This query can't match anywhere", kr.getError(0).getMessage());
}
use of de.ids_mannheim.korap.KrillIndex in project Krill by KorAP.
the class TestKrill method searchLongMatch.
@Test
public void searchLongMatch() throws IOException {
// Construct index
KrillIndex ki = new KrillIndex();
// Indexing test files
ki.addDoc(getClass().getResourceAsStream("/goe/AGX-00002.json"), false);
ki.commit();
Krill k = new Krill(new QueryBuilder("tokens").tag("xy/z:long"));
assertEquals(k.getSpanQuery().toString(), "<tokens:xy/z:long />");
Result kr = k.apply(ki);
assertEquals(kr.getTotalResults(), 1);
assertEquals(2, kr.getMatch(0).getStartPos());
assertEquals(52, kr.getMatch(0).getEndPos());
assertEquals(kr.getMatch(0).getSnippetBrackets(), "Maximen und [[Reflexionen Religion und Christentum. wir sind naturforschend Pantheisten, dichtend Polytheisten, sittlich Monotheisten. Gott, wenn wir hoch stehen, ist alles; stehen wir niedrig, so ist er ein Supplement unsrer Armseligkeit. die Kreatur ist sehr schwach; denn sucht sie etwas, findet sie's nicht. stark aber ist Gott; denn sucht er die Kreatur]<!>], so hat er sie gleich in ...");
assertEquals(kr.getMatch(0).getSnippetHTML(), "<span class=\"context-left\">Maximen und </span><span class=\"match\"><mark>Reflexionen Religion und Christentum. wir sind naturforschend Pantheisten, dichtend Polytheisten, sittlich Monotheisten. Gott, wenn wir hoch stehen, ist alles; stehen wir niedrig, so ist er ein Supplement unsrer Armseligkeit. die Kreatur ist sehr schwach; denn sucht sie etwas, findet sie's nicht. stark aber ist Gott; denn sucht er die Kreatur</mark><span class=\"cutted\"></span></span><span class=\"context-right\">, so hat er sie gleich in<span class=\"more\"></span></span>");
assertEquals(kr.getMatch(0).getTextSigle(), "GOE_AGX.00002");
}
use of de.ids_mannheim.korap.KrillIndex in project Krill by KorAP.
the class TestSpanExpansionIndex method indexExpansionWithNegationDifferentFragments.
@Test
public void indexExpansionWithNegationDifferentFragments() throws Exception {
KrillIndex ki = new KrillIndex();
// Add to the index in a single fragment
FieldDocument fd = new FieldDocument();
fd.addTV("base", "a B c", "[(0-1)s:a|i:a|_1$<i>0<i>1]" + "[(1-2)s:B|i:b|_2$<i>1<i>2|]" + "[(2-3)s:c|i:c|_3$<i>2<i>3]");
ki.addDoc(fd);
ki.commit();
fd.addTV("base", "a b c", "[(0-1)s:a|i:a|_1$<i>0<i>1]" + "[(1-2)s:b|i:b|_2$<i>1<i>2|]" + "[(2-3)s:c|i:c|_3$<i>2<i>3]");
ki.addDoc(fd);
ki.commit();
QueryBuilder kq = new QueryBuilder("base");
SpanQuery sq = kq.seq(kq.seg("s:a")).append(kq.seg().without("s:B")).append(kq.seg("s:c")).toQuery();
assertEquals("spanNext(base:s:a, spanExpansion(base:s:c, !base:s:B{1, 1}, left))", sq.toString());
Krill ks = new Krill(sq);
ks.getMeta().getContext().left.setToken(true).setLength(0);
ks.getMeta().getContext().right.setToken(true).setLength(0);
Result kr = ki.search(ks);
assertEquals((long) 1, kr.getTotalResults());
}
use of de.ids_mannheim.korap.KrillIndex in project Krill by KorAP.
the class TestSpanExpansionIndex method testRightExpansionWithWrongSorting.
@Test
public void testRightExpansionWithWrongSorting() throws IOException {
KrillIndex ki = new KrillIndex();
ki.addDoc(simpleFieldDoc("abccef"));
ki.commit();
SpanTermQuery stq = new SpanTermQuery(new Term("base", "s:c"));
SpanExpansionQuery seqL = new SpanExpansionQuery(stq, 0, 2, -1, true);
kr = ki.search(seqL, (short) 20);
// for (Match km : kr.getMatches()) {
// System.out.println(km.getStartPos() + "," + km.getEndPos() + " " +
// km.getSnippetBrackets());
// };
SpanExpansionQuery seqR = new SpanExpansionQuery(seqL, 0, 2, 0, true);
assertEquals("spanExpansion(spanExpansion(base:s:c, []{0, 2}, left), []{0, 2}, right)", seqR.toString());
kr = ki.search(seqR, (short) 20);
// for (Match km : kr.getMatches()) {
// System.out.println(km.getStartPos() + "," + km.getEndPos() + " " +
// km.getSnippetBrackets());
// };
assertEquals("a[[bcc]]ef", kr.getMatch(5).getSnippetBrackets());
assertEquals("a[[bcce]]f", kr.getMatch(6).getSnippetBrackets());
assertEquals(18, kr.getTotalResults());
}
use of de.ids_mannheim.korap.KrillIndex in project Krill by KorAP.
the class TestSpanExpansionIndex method testExpansionQueryBug3.
/**
* Query rewrite bug
*
* @throws IOException
*/
@Test
public void testExpansionQueryBug3() throws IOException, QueryException {
KrillIndex ki = new KrillIndex();
ki.addDoc(createFieldDoc3());
ki.addDoc(createFieldDoc4());
ki.commit();
String jsonPath = getClass().getResource("/queries/bugs/expansion_bug_3.jsonld").getFile();
String json = getJsonString(jsonPath);
KrillQuery kq = new KrillQuery("base");
SpanQuery sq = kq.fromKoral(json).toQuery();
assertEquals(sq.toString(), "focus(254: spanContain(<base:base/s:t />, {254: spanExpansion(base:s:c, []{0, 4}, right)}))");
kr = ki.search(sq, (short) 10);
assertEquals("[[c]]ab", kr.getMatch(0).getSnippetBrackets());
assertEquals("[[ca]]b", kr.getMatch(1).getSnippetBrackets());
assertEquals("[[cab]]", kr.getMatch(2).getSnippetBrackets());
assertEquals("[[c]]e", kr.getMatch(3).getSnippetBrackets());
assertEquals("[[ce]]", kr.getMatch(4).getSnippetBrackets());
assertEquals(5, kr.getTotalResults());
sq = kq.builder().tag("base/s:t").toQuery();
assertEquals(sq.toString(), "<base:base/s:t />");
kr = ki.search(sq, (short) 5);
assertEquals("[[cab]]", kr.getMatch(0).getSnippetBrackets());
assertEquals("[[ce]]", kr.getMatch(1).getSnippetBrackets());
assertEquals(2, kr.getTotalResults());
}
Aggregations