Search in sources :

Example 31 with SpanNextQuery

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

the class TestNextIndex method sequenceSkipBug.

@Test
public void sequenceSkipBug() throws IOException {
    KrillIndex ki = new KrillIndex();
    ki.addDoc(createFieldDoc1());
    ki.addDoc(createFieldDoc3());
    ki.addDoc(createFieldDoc4());
    // match for 2
    ki.addDoc(createFieldDoc5());
    ki.addDoc(createFieldDoc1());
    ki.addDoc(createFieldDoc3());
    ki.addDoc(createFieldDoc4());
    ki.addDoc(createFieldDoc1());
    ki.addDoc(createFieldDoc1());
    ki.addDoc(createFieldDoc3());
    ki.addDoc(createFieldDoc1());
    ki.commit();
    // match for 2
    ki.addDoc(createFieldDoc5());
    ki.addDoc(createFieldDoc1());
    // match for 1 and 2
    ki.addDoc(createFieldDoc2());
    ki.addDoc(createFieldDoc1());
    ki.addDoc(createFieldDoc3());
    ki.addDoc(createFieldDoc4());
    ki.addDoc(createFieldDoc1());
    ki.addDoc(createFieldDoc3());
    ki.commit();
    // "cab" is in 2
    SpanQuery sq = new SpanNextQuery(new SpanNextQuery(new SpanTermQuery(new Term("base", "s:c")), new SpanTermQuery(new Term("base", "s:a"))), new SpanTermQuery(new Term("base", "s:b")));
    Result kr = ki.search(sq, (short) 10);
    assertEquals(0, kr.getMatch(0).getStartPos());
    assertEquals(3, kr.getMatch(0).getEndPos());
    assertEquals("totalResults", kr.getTotalResults(), 1);
    // "aba" is in 2 and 5
    sq = new SpanNextQuery(new SpanNextQuery(new SpanTermQuery(new Term("base", "s:a")), new SpanTermQuery(new Term("base", "s:b"))), new SpanTermQuery(new Term("base", "s:a")));
    kr = ki.search(sq, (short) 10);
    assertEquals("totalResults", kr.getTotalResults(), 3);
}
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) Result(de.ids_mannheim.korap.response.Result) Test(org.junit.Test)

Example 32 with SpanNextQuery

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

the class TestReferenceIndex method testCase1.

@Test
public void testCase1() throws IOException {
    ki = new KrillIndex();
    ki.addDoc(TestRelationIndex.createFieldDoc2());
    ki.commit();
    SpanTermQuery stq = new SpanTermQuery(new Term("base", "pos:V"));
    SpanElementQuery seq = new SpanElementQuery("base", "np");
    SpanClassQuery scq1 = new SpanClassQuery(stq, (byte) 1);
    SpanClassQuery scq2 = new SpanClassQuery(seq, (byte) 2);
    SpanNextQuery snq1 = new SpanNextQuery(scq1, scq2);
    SpanFocusQuery sfq1 = new SpanFocusQuery(snq1, (byte) 2);
    SpanRelationQuery srq = new SpanRelationQuery(new SpanTermQuery(new Term("base", "<:child-of")), true, RelationDirection.LEFT);
    SpanElementQuery seq2 = new SpanElementQuery("base", "pp");
    SpanClassQuery scq3 = new SpanClassQuery(seq2, (byte) 3);
    SpanRelationMatchQuery rq = new SpanRelationMatchQuery(srq, sfq1, scq3, true);
    // focus on np
    SpanFocusQuery sfq2 = new SpanFocusQuery(rq, (byte) 1);
    DistanceConstraint constraint = new DistanceConstraint(3, 3, true, false);
    SpanDistanceQuery sdq = new SpanDistanceQuery(sfq2, scq3, constraint, true);
    SpanReferenceQuery ref = new SpanReferenceQuery(sdq, (byte) 3, true);
    kr = ki.search(ref, (short) 10);
    /*
         * for (Match km : kr.getMatches()) {
         * 
         * System.out.println(km.getStartPos() + "," + km.getEndPos()
         * + " " + km.getSnippetBrackets()); }
         * System.out.println(kr.getTotalResults());
         */
    // cat=V & cat=np & cat=pp & #1 . #2 & #3 ->child-of #2 & #1 .{3,3} #3
    assertEquals("spanReference(spanDistance(focus(1: focus(#[1,2]spanSegment(" + "focus(#1: spanSegment(spanRelation(base:<:child-of), focus(2: spanNext(" + "{1: base:pos:V}, {2: <base:np />})))), {3: <base:pp />}))), " + "{3: <base:pp />}, [(w[3:3], ordered, notExcluded)]), 3)", ref.toString());
    assertEquals(1, kr.getMatch(0).getStartPos());
    assertEquals(7, kr.getMatch(0).getEndPos());
}
Also used : SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) SpanClassQuery(de.ids_mannheim.korap.query.SpanClassQuery) SpanRelationQuery(de.ids_mannheim.korap.query.SpanRelationQuery) SpanDistanceQuery(de.ids_mannheim.korap.query.SpanDistanceQuery) SpanRelationMatchQuery(de.ids_mannheim.korap.query.SpanRelationMatchQuery) DistanceConstraint(de.ids_mannheim.korap.query.DistanceConstraint) Term(org.apache.lucene.index.Term) SpanReferenceQuery(de.ids_mannheim.korap.query.SpanReferenceQuery) KrillIndex(de.ids_mannheim.korap.KrillIndex) SpanElementQuery(de.ids_mannheim.korap.query.SpanElementQuery) SpanFocusQuery(de.ids_mannheim.korap.query.SpanFocusQuery) SpanNextQuery(de.ids_mannheim.korap.query.SpanNextQuery) Test(org.junit.Test)

Example 33 with SpanNextQuery

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

the class TestRepetitionIndex method testMinZeroRepetition.

@Test
public void testMinZeroRepetition() throws IOException {
    ki = new KrillIndex();
    ki.addDoc(createFieldDoc0());
    ki.commit();
    SpanQuery sq, sq2;
    sq = new SpanTermQuery(new Term("base", "s:e"));
    kr = ki.search(sq, (short) 10);
    assertEquals((long) 4, kr.getTotalResults());
    assertEquals(1, kr.getMatch(0).getStartPos());
    assertEquals(2, kr.getMatch(0).getEndPos());
    assertEquals(4, kr.getMatch(1).getStartPos());
    assertEquals(5, kr.getMatch(1).getEndPos());
    assertEquals(7, kr.getMatch(2).getStartPos());
    assertEquals(8, kr.getMatch(2).getEndPos());
    assertEquals(8, kr.getMatch(3).getStartPos());
    assertEquals(9, kr.getMatch(3).getEndPos());
    try {
        sq2 = new SpanNextQuery(sq, new SpanRepetitionQuery(new SpanTermQuery(new Term("base", "s:c")), 0, 1, true));
    } catch (IllegalArgumentException e) {
        assertEquals("Minimum repetition must not lower than 1.", e.getMessage());
    }
}
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 34 with SpanNextQuery

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

the class TestSegmentIndex method testcase6.

/**
 * Skip to SegmentSpan
 */
@Test
public void testcase6() throws IOException {
    ki.addDoc(createFieldDoc4());
    ki.commit();
    sq = new SpanNextQuery(new SpanSegmentQuery(new SpanTermQuery(new Term("base", "s:b")), new SpanTermQuery(new Term("base", "s:c"))), new SpanTermQuery(new Term("base", "s:d")));
    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 (0)", 4, kr.getMatch(0).startPos);
    assertEquals("EndPos (0)", 6, kr.getMatch(0).endPos);
    // Match #1 in the other atomic index
    assertEquals("doc-number", 0, kr.getMatch(1).getLocalDocID());
    assertEquals("StartPos (0)", 0, kr.getMatch(1).startPos);
    assertEquals("EndPos (0)", 2, 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) SpanNextQuery(de.ids_mannheim.korap.query.SpanNextQuery) Test(org.junit.Test)

Example 35 with SpanNextQuery

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

the class TestUnorderedElementDistanceIndex method testCase5.

/**
 * Next
 */
@Test
public void testCase5() throws IOException {
    ki = new KrillIndex();
    ki.addDoc(createFieldDoc0());
    ki.commit();
    SpanQuery sq, edq;
    edq = createQuery("s", "s:b", "s:c", 0, 2, false);
    kr = ki.search(edq, (short) 10);
    assertEquals((long) 6, kr.getTotalResults());
    sq = new SpanNextQuery(new SpanTermQuery(new Term("base", "s:b")), edq);
    kr = ki.search(sq, (short) 10);
    assertEquals((long) 2, kr.getTotalResults());
    assertEquals(1, kr.getMatch(0).getStartPos());
    assertEquals(4, kr.getMatch(0).getEndPos());
    assertEquals(2, kr.getMatch(1).getStartPos());
    assertEquals(5, kr.getMatch(1).getEndPos());
// System.out.print(kr.getTotalResults()+"\n");
// for (int i=0; i< kr.getTotalResults(); i++){
// System.out.println(
// kr.match(i).getLocalDocID()+" "+
// kr.match(i).startPos + " " +
// kr.match(i).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