Search in sources :

Example 1 with SpanRepetitionQuery

use of de.ids_mannheim.korap.query.SpanRepetitionQuery in project Krill by KorAP.

the class TestWPDIndex method testCase6.

/**
 * Next and repetition
 */
@Test
public void testCase6() throws IOException {
    SpanQuery sq = new SpanNextQuery(new SpanTermQuery(new Term("tokens", "tt/p:NN")), new SpanRepetitionQuery(new SpanTermQuery(new Term("tokens", "mate/p:ADJA")), 2, 2, true));
    ks = new Krill(sq);
    kr = ks.apply(ki);
    assertEquals(kr.getTotalResults(), 30223);
    // 1.1s
    SpanQuery sq2 = new SpanNextQuery(sq, new SpanTermQuery(new Term("tokens", "tt/p:NN")));
    ks = new Krill(sq2);
    kr = ks.apply(ki);
    assertEquals(kr.getTotalResults(), 26607);
// 1.1s
}
Also used : SpanRepetitionQuery(de.ids_mannheim.korap.query.SpanRepetitionQuery) Krill(de.ids_mannheim.korap.Krill) SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) Term(org.apache.lucene.index.Term) SpanQuery(org.apache.lucene.search.spans.SpanQuery) SpanNextQuery(de.ids_mannheim.korap.query.SpanNextQuery) Test(org.junit.Test)

Example 2 with SpanRepetitionQuery

use of de.ids_mannheim.korap.query.SpanRepetitionQuery in project Krill by KorAP.

the class TestWPDIndex method testCase5.

/**
 * Repetition
 */
@Test
public void testCase5() throws IOException {
    SpanQuery sq;
    sq = new SpanRepetitionQuery(new SpanTermQuery(new Term("tokens", "mate/p:ADJA")), 1, 2, true);
    ks = new Krill(sq);
    kr = ks.apply(ki);
    assertEquals(kr.getTotalResults(), 4116416);
    // 0.9s
    sq = new SpanRepetitionQuery(new SpanTermQuery(new Term("tokens", "mate/p:ADJA")), 1, 1, true);
    ks = new Krill(sq);
    kr = ks.apply(ki);
    assertEquals(kr.getTotalResults(), 3879671);
    sq = new SpanRepetitionQuery(new SpanTermQuery(new Term("tokens", "mate/p:ADJA")), 2, 2, true);
    ks = new Krill(sq);
    kr = ks.apply(ki);
    assertEquals(kr.getTotalResults(), 236745);
// 0.65s
}
Also used : SpanRepetitionQuery(de.ids_mannheim.korap.query.SpanRepetitionQuery) Krill(de.ids_mannheim.korap.Krill) SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) Term(org.apache.lucene.index.Term) SpanQuery(org.apache.lucene.search.spans.SpanQuery) Test(org.junit.Test)

Example 3 with SpanRepetitionQuery

use of de.ids_mannheim.korap.query.SpanRepetitionQuery in project Krill by KorAP.

the class TestRepetitionIndex method testCase3.

/**
 * OR
 */
@Test
public void testCase3() throws IOException {
    ki = new KrillIndex();
    ki.addDoc(createFieldDoc0());
    ki.commit();
    SpanQuery sq, sq2;
    // ec{1,2}
    sq = new SpanNextQuery(new SpanTermQuery(new Term("base", "s:e")), new SpanOrQuery(new SpanRepetitionQuery(new SpanTermQuery(new Term("base", "s:c")), 1, 1, true), new SpanRepetitionQuery(new SpanTermQuery(new Term("base", "s:b")), 1, 1, true)));
    kr = ki.search(sq, (short) 10);
    assertEquals((long) 3, kr.getTotalResults());
    assertEquals(1, kr.getMatch(0).startPos);
    assertEquals(3, kr.getMatch(0).endPos);
    assertEquals(4, kr.getMatch(1).startPos);
    assertEquals(6, kr.getMatch(1).endPos);
    assertEquals(7, kr.getMatch(2).startPos);
    assertEquals(9, kr.getMatch(2).endPos);
}
Also used : SpanRepetitionQuery(de.ids_mannheim.korap.query.SpanRepetitionQuery) SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) Term(org.apache.lucene.index.Term) SpanOrQuery(org.apache.lucene.search.spans.SpanOrQuery) KrillIndex(de.ids_mannheim.korap.KrillIndex) SpanQuery(org.apache.lucene.search.spans.SpanQuery) SpanNextQuery(de.ids_mannheim.korap.query.SpanNextQuery) Test(org.junit.Test)

Example 4 with SpanRepetitionQuery

use of de.ids_mannheim.korap.query.SpanRepetitionQuery in project Krill by KorAP.

the class TestRepetitionIndex method testCase5.

@Test
public void testCase5() throws IOException {
    ki = new KrillIndex();
    ki.addDoc(getClass().getResourceAsStream("/wiki/00001.json.gz"), true);
    ki.commit();
    SpanQuery sq0, sq1, sq2;
    sq0 = new SpanTermQuery(new Term("tokens", "tt/p:NN"));
    sq1 = new SpanRepetitionQuery(new SpanTermQuery(new Term("tokens", "tt/p:ADJA")), 2, 3, true);
    sq2 = new SpanNextQuery(sq1, sq0);
    kr = ki.search(sq2, (short) 10);
    assertEquals((long) 2, kr.getTotalResults());
    assertEquals(73, kr.getMatch(0).getStartPos());
    assertEquals(77, kr.getMatch(0).getEndPos());
    assertEquals(74, kr.getMatch(1).getStartPos());
    assertEquals(77, kr.getMatch(1).getEndPos());
    sq2 = new SpanNextQuery(new SpanTermQuery(new Term("tokens", "s:offenen")), sq2);
    kr = ki.search(sq2, (short) 10);
    assertEquals((long) 1, kr.getTotalResults());
    assertEquals(73, kr.getMatch(0).getStartPos());
    assertEquals(77, kr.getMatch(0).getEndPos());
/*
        for (Match km : kr.getMatches()){
        	System.out.println(km.getSnippetBrackets());
        	System.out.println(km.getStartPos() +","+km.getEndPos());
        }*/
}
Also used : SpanRepetitionQuery(de.ids_mannheim.korap.query.SpanRepetitionQuery) SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) Term(org.apache.lucene.index.Term) KrillIndex(de.ids_mannheim.korap.KrillIndex) SpanQuery(org.apache.lucene.search.spans.SpanQuery) SpanNextQuery(de.ids_mannheim.korap.query.SpanNextQuery) Test(org.junit.Test)

Example 5 with SpanRepetitionQuery

use of de.ids_mannheim.korap.query.SpanRepetitionQuery in project Krill by KorAP.

the class TestRepetitionIndex method testCase2.

/**
 * Skip to
 */
@Test
public void testCase2() throws IOException {
    ki = new KrillIndex();
    ki.addDoc(createFieldDoc0());
    ki.addDoc(createFieldDoc3());
    ki.addDoc(createFieldDoc2());
    ki.addDoc(createFieldDoc1());
    ki.commit();
    SpanQuery sq;
    // c{2,2}
    // sq = new SpanRepetitionQuery(
    // new SpanTermQuery(new Term("base", "s:c")), 2, 2, true);
    // kr = ki.search(sq, (short) 10);
    // // doc1 2-4, 3-5, 4-6
    // assertEquals((long) 6, kr.getTotalResults());
    // ec{2,2}
    sq = new SpanNextQuery(new SpanTermQuery(new Term("base", "s:e")), new SpanRepetitionQuery(new SpanTermQuery(new Term("base", "s:c")), 2, 2, true));
    kr = ki.search(sq, (short) 10);
    assertEquals((long) 2, kr.getTotalResults());
    assertEquals(3, kr.getMatch(1).getLocalDocID());
}
Also used : SpanRepetitionQuery(de.ids_mannheim.korap.query.SpanRepetitionQuery) SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) Term(org.apache.lucene.index.Term) KrillIndex(de.ids_mannheim.korap.KrillIndex) SpanQuery(org.apache.lucene.search.spans.SpanQuery) SpanNextQuery(de.ids_mannheim.korap.query.SpanNextQuery) Test(org.junit.Test)

Aggregations

SpanRepetitionQuery (de.ids_mannheim.korap.query.SpanRepetitionQuery)10 Term (org.apache.lucene.index.Term)10 Test (org.junit.Test)10 SpanQuery (org.apache.lucene.search.spans.SpanQuery)9 SpanTermQuery (org.apache.lucene.search.spans.SpanTermQuery)9 KrillIndex (de.ids_mannheim.korap.KrillIndex)8 SpanNextQuery (de.ids_mannheim.korap.query.SpanNextQuery)6 Krill (de.ids_mannheim.korap.Krill)2 SpanExpansionQuery (de.ids_mannheim.korap.query.SpanExpansionQuery)1 RegexpQuery (org.apache.lucene.search.RegexpQuery)1 SpanMultiTermQueryWrapper (org.apache.lucene.search.spans.SpanMultiTermQueryWrapper)1 SpanOrQuery (org.apache.lucene.search.spans.SpanOrQuery)1