Search in sources :

Example 46 with KrillIndex

use of de.ids_mannheim.korap.KrillIndex in project Krill by KorAP.

the class TestSegmentNegationIndex method testcaseWarnings.

@Test
public void testcaseWarnings() throws Exception {
    ki = new KrillIndex();
    ki.addDoc(createFieldDoc0());
    ki.addDoc(createFieldDoc1());
    ki.addDoc(createFieldDoc2());
    ki.addDoc(createFieldDoc3());
    ki.commit();
    kr = ki.search(new Krill("{\"query\" : { \"@type\" : \"koral:token\", \"wrap\" : { \"@type\" : \"koral:term\", \"key\" : \"a\", \"flags\" : [\"caseInsensitive\"], \"layer\" : \"orth\", \"match\" : \"match:eq\" }}}"));
    assertEquals("totalResults", kr.getTotalResults(), 6);
    assertEquals("Warning", kr.hasWarnings(), true);
    assertEquals("Warning text", kr.getWarning(0).getMessage(), "Flag is unknown");
    assertEquals("Warning text", kr.getWarning(0).toJsonString(), "[748,\"Flag is unknown\",\"caseInsensitive\"]");
    // Negation of segment
    kr = ki.search(new Krill("{\"query\" : { \"@type\" : \"koral:token\", \"wrap\" : { \"@type\" : \"koral:term\", \"key\" : \"a\", \"flags\" : [\"flags:caseInsensitive\"], \"layer\" : \"orth\", \"match\" : \"match:ne\" }}}"));
    assertEquals("totalResults", kr.getTotalResults(), 4);
    assertEquals("Warning", kr.hasWarnings(), true);
    assertEquals("Warning text", kr.getWarning(0).getMessage(), "Exclusivity of query is ignored");
    // Flag parameter injection
    kr = ki.search(new Krill("{\"query\" : { \"@type\" : \"koral:token\", \"wrap\" : { \"@type\" : \"koral:term\", \"key\" : \"a\", \"flags\" : [{ \"injection\" : true }], \"layer\" : \"orth\", \"match\" : \"match:ne\" }}}"));
    assertEquals("totalResults", kr.getTotalResults(), 6);
    assertEquals("Warning", kr.hasWarnings(), true);
    assertEquals("Warning text", kr.getWarning(0).getMessage(), "Flag is unknown");
    assertEquals("Warning text", kr.getWarning(0).toJsonString(), "[748,\"Flag is unknown\"]");
}
Also used : Krill(de.ids_mannheim.korap.Krill) KrillIndex(de.ids_mannheim.korap.KrillIndex) Test(org.junit.Test)

Example 47 with KrillIndex

use of de.ids_mannheim.korap.KrillIndex in project Krill by KorAP.

the class TestSegmentNegationIndex method testcaseNegation.

@Test
public void testcaseNegation() throws Exception {
    ki = new KrillIndex();
    ki.addDoc(createFieldDoc0());
    ki.addDoc(createFieldDoc1());
    ki.addDoc(createFieldDoc2());
    ki.addDoc(createFieldDoc3());
    ki.commit();
    SpanSegmentQueryWrapper ssqw = new SpanSegmentQueryWrapper("tokens", "s:b");
    ssqw.with("s:c");
    SpanSequenceQueryWrapper sqw = new SpanSequenceQueryWrapper("tokens", ssqw).append("s:d");
    kr = ki.search(sqw.toQuery(), (short) 10);
    assertEquals("totalResults", kr.getTotalResults(), 2);
    // Match #0
    assertEquals("doc-number", 0, kr.getMatch(0).getLocalDocID());
    assertEquals("StartPos (0)", 4, kr.getMatch(0).startPos);
    assertEquals("EndPos (0)", 6, kr.getMatch(0).endPos);
    // Match #1 in the other atomic index
    assertEquals("doc-number", 3, kr.getMatch(1).getLocalDocID());
    assertEquals("StartPos (0)", 0, kr.getMatch(1).startPos);
    assertEquals("EndPos (0)", 2, kr.getMatch(1).endPos);
    ssqw = new SpanSegmentQueryWrapper("tokens", "s:b");
    ssqw.without("s:c");
    sqw = new SpanSequenceQueryWrapper("tokens", ssqw).append("s:a");
    kr = ki.search(sqw.toQuery(), (short) 10);
    assertEquals("doc-number", 0, kr.getMatch(0).getLocalDocID());
    assertEquals("StartPos (0)", 2, kr.getMatch(0).startPos);
    assertEquals("EndPos (0)", 4, kr.getMatch(0).endPos);
    assertEquals("doc-number", 1, kr.getMatch(1).getLocalDocID());
    assertEquals("StartPos (1)", 1, kr.getMatch(1).startPos);
    assertEquals("EndPos (1)", 3, kr.getMatch(1).endPos);
    assertEquals("doc-number", 1, kr.getMatch(2).getLocalDocID());
    assertEquals("StartPos (2)", 2, kr.getMatch(2).startPos);
    assertEquals("EndPos (2)", 4, kr.getMatch(2).endPos);
    assertEquals("doc-number", 2, kr.getMatch(3).getLocalDocID());
    assertEquals("StartPos (3)", 1, kr.getMatch(3).startPos);
    assertEquals("EndPos (3)", 3, kr.getMatch(3).endPos);
}
Also used : SpanSegmentQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanSegmentQueryWrapper) KrillIndex(de.ids_mannheim.korap.KrillIndex) SpanSequenceQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanSequenceQueryWrapper) Test(org.junit.Test)

Example 48 with KrillIndex

use of de.ids_mannheim.korap.KrillIndex in project Krill by KorAP.

the class TestSpanExpansionIndex method indexRegexSequence.

@Test
public void indexRegexSequence() throws Exception {
    KrillIndex ki = new KrillIndex();
    ki.addDoc(createFieldDoc5());
    ki.commit();
    QueryBuilder kq = new QueryBuilder("base");
    SpanQueryWrapper sq = kq.seq(kq.or("s:baumgarten", "s:steingarten")).append(kq.seg().without(kq.or("s:franz", "s:hans")));
    // Expected to find [baumgarten steingarten]
    Krill ks = _newKrill(sq);
    Result kr = ki.search(ks);
    assertEquals((long) 1, kr.getTotalResults());
    assertEquals("... baum [[baumgarten steingarten]] franz ...", kr.getMatch(0).getSnippetBrackets());
    // The same result should be shown for:
    sq = kq.seq(kq.re("s:.*garten")).append(kq.seg().without(kq.re("s:.*an.*")));
    ks = _newKrill(sq);
    kr = ki.search(ks);
    assertEquals((long) 1, kr.getTotalResults());
    assertEquals("... baum [[baumgarten steingarten]] franz ...", kr.getMatch(0).getSnippetBrackets());
}
Also used : Krill(de.ids_mannheim.korap.Krill) QueryBuilder(de.ids_mannheim.korap.query.QueryBuilder) SpanQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanQueryWrapper) KrillIndex(de.ids_mannheim.korap.KrillIndex) Result(de.ids_mannheim.korap.response.Result) Test(org.junit.Test)

Example 49 with KrillIndex

use of de.ids_mannheim.korap.KrillIndex in project Krill by KorAP.

the class TestSpanExpansionIndex method testExpansionOverStart.

/**
 * Expansion over start and end documents start => cut to 0
 * TODO: end => to be handled in rendering process
 *
 * @throws IOException
 */
@Test
public void testExpansionOverStart() throws IOException {
    KrillIndex ki = new KrillIndex();
    ki.addDoc(createFieldDoc0());
    ki.commit();
    SpanTermQuery stq = new SpanTermQuery(new Term("base", "s:e"));
    // left expansion precedes 0
    SpanExpansionQuery seq = new SpanExpansionQuery(stq, 2, 2, -1, true);
    kr = ki.search(seq, (short) 10);
    assertEquals((long) 3, kr.getTotalResults());
    assertEquals(2, kr.getMatch(0).getStartPos());
    assertEquals(5, kr.getMatch(0).getEndPos());
    // right expansion exceeds end position
    seq = new SpanExpansionQuery(stq, 3, 3, 0, true);
    kr = ki.search(seq, (short) 10);
    assertEquals((long) 4, kr.getTotalResults());
    assertEquals(7, kr.getMatch(2).getStartPos());
    assertEquals(11, kr.getMatch(2).getEndPos());
    assertEquals(8, kr.getMatch(3).getStartPos());
    assertEquals(12, kr.getMatch(3).getEndPos());
/*
         * for (Match km : kr.getMatches()){
         * System.out.println(km.getStartPos() +","+km.getEndPos()+" "
         * //+km.getSnippetBrackets() ); }
         */
}
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 50 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)

Aggregations

KrillIndex (de.ids_mannheim.korap.KrillIndex)321 Test (org.junit.Test)310 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