Search in sources :

Example 16 with SpanNextQuery

use of de.ids_mannheim.korap.query.SpanNextQuery 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 17 with SpanNextQuery

use of de.ids_mannheim.korap.query.SpanNextQuery 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)

Example 18 with SpanNextQuery

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

the class TestRepetitionIndex method testRepetitionInSequences.

@Test
public void testRepetitionInSequences() 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 SpanRepetitionQuery(new SpanTermQuery(new Term("base", "s:c")), 1, 2, true));
    kr = ki.search(sq, (short) 10);
    // 1-3, 1-4, 4-6
    assertEquals((long) 3, kr.getTotalResults());
    assertEquals(1, kr.getMatch(0).getStartPos());
    assertEquals(3, kr.getMatch(0).getEndPos());
    assertEquals(1, kr.getMatch(1).getStartPos());
    assertEquals(4, kr.getMatch(1).getEndPos());
    assertEquals(4, kr.getMatch(2).getStartPos());
    assertEquals(6, kr.getMatch(2).getEndPos());
    // ec{1,2}d
    sq2 = new SpanNextQuery(sq, new SpanTermQuery(new Term("base", "s:d")));
    kr = ki.search(sq2, (short) 10);
    assertEquals((long) 2, kr.getTotalResults());
    assertEquals(1, kr.getMatch(0).startPos);
    assertEquals(5, kr.getMatch(0).endPos);
    assertEquals(4, kr.getMatch(1).startPos);
    assertEquals(7, kr.getMatch(1).endPos);
    // Multiple documents
    ki.addDoc(createFieldDoc1());
    ki.commit();
    kr = ki.search(sq2, (short) 10);
    assertEquals((long) 5, kr.getTotalResults());
}
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 19 with SpanNextQuery

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

the class TestSegmentIndex method testCase4.

/**
 * Matching a SpanElementQuery and a SpanNextQuery
 * Multiple atomic indices
 */
@Test
public void testCase4() throws IOException {
    // log.trace("Testcase4");
    ki = new KrillIndex();
    ki.addDoc(createFieldDoc0());
    ki.commit();
    ki.addDoc(createFieldDoc1());
    ki.addDoc(createFieldDoc2());
    ki.commit();
    sq = new SpanSegmentQuery(new SpanElementQuery("base", "e"), new SpanNextQuery(new SpanTermQuery(new Term("base", "s:a")), new SpanTermQuery(new Term("base", "s:b"))));
    kr = ki.search(sq, (short) 10);
    ki.close();
    assertEquals("totalResults", kr.getTotalResults(), 2);
    // Match #0
    assertEquals("doc-number", 0, kr.getMatch(0).getLocalDocID());
    assertEquals("StartPos", 3, kr.getMatch(0).startPos);
    assertEquals("EndPos", 5, kr.getMatch(0).endPos);
    // Match #1
    assertEquals("doc-number", 0, kr.getMatch(1).getLocalDocID());
    assertEquals("StartPos", 1, kr.getMatch(1).startPos);
    assertEquals("EndPos", 3, kr.getMatch(1).endPos);
}
Also used : SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) SpanSegmentQuery(de.ids_mannheim.korap.query.SpanSegmentQuery) Term(org.apache.lucene.index.Term) KrillIndex(de.ids_mannheim.korap.KrillIndex) SpanElementQuery(de.ids_mannheim.korap.query.SpanElementQuery) SpanNextQuery(de.ids_mannheim.korap.query.SpanNextQuery) Test(org.junit.Test)

Example 20 with SpanNextQuery

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

the class TestUnorderedElementDistanceIndex method testCase4.

/**
 * Multiple documents
 * Skip to
 */
@Test
public void testCase4() throws IOException {
    // System.out.println("testCase4");
    ki = new KrillIndex();
    ki.addDoc(createFieldDoc1());
    ki.addDoc(createFieldDoc0());
    ki.addDoc(createFieldDoc3());
    ki.addDoc(createFieldDoc4());
    ki.commit();
    SpanQuery sq, edq;
    edq = createQuery("s", "s:b", "s:c", 1, 1, false);
    sq = new SpanNextQuery(edq, new SpanTermQuery(new Term("base", "s:e")));
    kr = ki.search(sq, (short) 10);
    assertEquals((long) 4, kr.getTotalResults());
    assertEquals(0, kr.getMatch(0).startPos);
    assertEquals(3, kr.getMatch(0).endPos);
    assertEquals(1, kr.getMatch(1).startPos);
    assertEquals(6, kr.getMatch(1).endPos);
    assertEquals(3, kr.getMatch(2).startPos);
    assertEquals(6, kr.getMatch(2).endPos);
    assertEquals(3, kr.getMatch(3).getLocalDocID());
    assertEquals(0, kr.getMatch(3).startPos);
    assertEquals(4, kr.getMatch(3).endPos);
}
Also used : 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

SpanNextQuery (de.ids_mannheim.korap.query.SpanNextQuery)36 Test (org.junit.Test)35 Term (org.apache.lucene.index.Term)34 SpanTermQuery (org.apache.lucene.search.spans.SpanTermQuery)34 KrillIndex (de.ids_mannheim.korap.KrillIndex)31 SpanQuery (org.apache.lucene.search.spans.SpanQuery)31 Result (de.ids_mannheim.korap.response.Result)15 SpanElementQuery (de.ids_mannheim.korap.query.SpanElementQuery)9 SpanClassQuery (de.ids_mannheim.korap.query.SpanClassQuery)6 SpanFocusQuery (de.ids_mannheim.korap.query.SpanFocusQuery)6 SpanRepetitionQuery (de.ids_mannheim.korap.query.SpanRepetitionQuery)6 DistanceConstraint (de.ids_mannheim.korap.query.DistanceConstraint)3 SpanWithinQuery (de.ids_mannheim.korap.query.SpanWithinQuery)3 SpanDistanceQuery (de.ids_mannheim.korap.query.SpanDistanceQuery)2 SpanRelationQuery (de.ids_mannheim.korap.query.SpanRelationQuery)2 SpanSegmentQuery (de.ids_mannheim.korap.query.SpanSegmentQuery)2 ArrayList (java.util.ArrayList)2 SpanOrQuery (org.apache.lucene.search.spans.SpanOrQuery)2 Krill (de.ids_mannheim.korap.Krill)1 KrillQuery (de.ids_mannheim.korap.KrillQuery)1