Search in sources :

Example 11 with KrillIndex

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());
}
Also used : Krill(de.ids_mannheim.korap.Krill) TestSimple.getJsonString(de.ids_mannheim.korap.TestSimple.getJsonString) KrillIndex(de.ids_mannheim.korap.KrillIndex) Result(de.ids_mannheim.korap.response.Result) Test(org.junit.Test)

Example 12 with KrillIndex

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");
}
Also used : Krill(de.ids_mannheim.korap.Krill) QueryBuilder(de.ids_mannheim.korap.query.QueryBuilder) KrillIndex(de.ids_mannheim.korap.KrillIndex) Result(de.ids_mannheim.korap.response.Result) Test(org.junit.Test)

Example 13 with KrillIndex

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());
}
Also used : Krill(de.ids_mannheim.korap.Krill) QueryBuilder(de.ids_mannheim.korap.query.QueryBuilder) KrillIndex(de.ids_mannheim.korap.KrillIndex) SpanQuery(org.apache.lucene.search.spans.SpanQuery) Result(de.ids_mannheim.korap.response.Result) Test(org.junit.Test)

Example 14 with KrillIndex

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());
}
Also used : SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) SpanExpansionQuery(de.ids_mannheim.korap.query.SpanExpansionQuery) Term(org.apache.lucene.index.Term) KrillIndex(de.ids_mannheim.korap.KrillIndex) Test(org.junit.Test)

Example 15 with KrillIndex

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());
}
Also used : KrillQuery(de.ids_mannheim.korap.KrillQuery) TestSimple.getJsonString(de.ids_mannheim.korap.TestSimple.getJsonString) KrillIndex(de.ids_mannheim.korap.KrillIndex) SpanQuery(org.apache.lucene.search.spans.SpanQuery) Test(org.junit.Test)

Aggregations

KrillIndex (de.ids_mannheim.korap.KrillIndex)320 Test (org.junit.Test)309 Result (de.ids_mannheim.korap.response.Result)143 SpanQuery (org.apache.lucene.search.spans.SpanQuery)132 Term (org.apache.lucene.index.Term)93 SpanTermQuery (org.apache.lucene.search.spans.SpanTermQuery)84 Krill (de.ids_mannheim.korap.Krill)82 QueryBuilder (de.ids_mannheim.korap.query.QueryBuilder)56 SpanElementQuery (de.ids_mannheim.korap.query.SpanElementQuery)42 KrillCollection (de.ids_mannheim.korap.KrillCollection)39 TestSimple.getJsonString (de.ids_mannheim.korap.TestSimple.getJsonString)38 SpanNextQuery (de.ids_mannheim.korap.query.SpanNextQuery)37 Match (de.ids_mannheim.korap.response.Match)37 FieldDocument (de.ids_mannheim.korap.index.FieldDocument)33 JsonNode (com.fasterxml.jackson.databind.JsonNode)28 DistanceConstraint (de.ids_mannheim.korap.query.DistanceConstraint)27 SpanQueryWrapper (de.ids_mannheim.korap.query.wrap.SpanQueryWrapper)26 SpanClassQuery (de.ids_mannheim.korap.query.SpanClassQuery)25 SpanDistanceQuery (de.ids_mannheim.korap.query.SpanDistanceQuery)20 SpanWithinQuery (de.ids_mannheim.korap.query.SpanWithinQuery)18