Search in sources :

Example 21 with SpanDistanceQuery

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

the class TestSubSpanIndex method testCase1.

@Test
public void testCase1() throws IOException {
    SpanDistanceQuery sdq = new SpanDistanceQuery(new SpanTermQuery(new Term("tokens", "tt/p:NN")), new SpanTermQuery(new Term("tokens", "tt/p:VAFIN")), new DistanceConstraint(5, 5, true, false), true);
    SpanSubspanQuery ssq = new SpanSubspanQuery(sdq, 0, 2, true);
    kr = ki.search(ssq, (short) 10);
    assertEquals((long) 8, kr.getTotalResults());
    assertEquals(35, kr.getMatch(0).getStartPos());
    assertEquals(37, kr.getMatch(0).getEndPos());
    assertEquals(179, kr.getMatch(1).getStartPos());
    assertEquals(181, kr.getMatch(1).getEndPos());
    ssq = new SpanSubspanQuery(sdq, -2, 2, true);
    kr = ki.search(ssq, (short) 10);
    assertEquals(39, kr.getMatch(0).getStartPos());
    assertEquals(41, kr.getMatch(0).getEndPos());
    assertEquals(183, kr.getMatch(1).getStartPos());
    assertEquals(185, kr.getMatch(1).getEndPos());
/*
         * for (Match km : kr.getMatches()){
         * System.out.println(km.getStartPos() +","+km.getEndPos()
         * +km.getSnippetBrackets()); }
         */
}
Also used : SpanSubspanQuery(de.ids_mannheim.korap.query.SpanSubspanQuery) SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) SpanDistanceQuery(de.ids_mannheim.korap.query.SpanDistanceQuery) DistanceConstraint(de.ids_mannheim.korap.query.DistanceConstraint) Term(org.apache.lucene.index.Term) Test(org.junit.Test)

Example 22 with SpanDistanceQuery

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

the class TestWPDIndex method testCase2.

/**
 * Token exclusion distance spans
 */
@Test
public void testCase2() throws IOException {
    SpanQuery q = new SpanTermQuery(new Term("tokens", "s:Wir"));
    ks = new Krill(q);
    kr = ks.apply(ki);
    assertEquals(kr.getTotalResults(), 1907);
    SpanDistanceQuery sq;
    // ordered
    sq = createDistanceQuery("s:Wir", "s:kommen", 1, 1, true, true);
    ks = new Krill(sq);
    kr = ks.apply(ki);
    assertEquals(kr.getTotalResults(), 1899);
    // unordered
    sq = createDistanceQuery("s:Wir", "s:kommen", 1, 1, false, true);
    ks = new Krill(sq);
    kr = ks.apply(ki);
    assertEquals(kr.getTotalResults(), 1896);
}
Also used : Krill(de.ids_mannheim.korap.Krill) SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) SpanDistanceQuery(de.ids_mannheim.korap.query.SpanDistanceQuery) Term(org.apache.lucene.index.Term) SpanQuery(org.apache.lucene.search.spans.SpanQuery) Test(org.junit.Test)

Example 23 with SpanDistanceQuery

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

the class TestWPDIndex method testCase4.

/**
 * Element distance exclusion
 */
@Test
public void testCase4() throws IOException {
    SpanDistanceQuery sq = createElementDistanceQuery("s", "s:weg", "s:fahren", 1, 1, false, true);
    ks = new Krill(sq);
    kr = ks.apply(ki);
    assertEquals(kr.getTotalResults(), 979);
    // 0.8s
    // Check if it includes some results
    /*
        BooleanFilter bf = new BooleanFilter();
        bf.or("ID", "WPD_BBB.04463", "WPD_III.00758");
        */
    KrillCollection kc = new KrillCollection();
    CollectionBuilder cb = new CollectionBuilder();
    kc.fromBuilder(cb.orGroup().with(cb.term("ID", "WPD_BBB.04463")).with(cb.term("ID", "WPD_III.00758")));
    // kc.filter(bf);
    ks.setCollection(kc);
    kr = ks.apply(ki);
    assertEquals(1094, kr.getMatch(0).getStartPos());
    assertEquals(451, kr.getMatch(1).getEndPos());
}
Also used : Krill(de.ids_mannheim.korap.Krill) SpanDistanceQuery(de.ids_mannheim.korap.query.SpanDistanceQuery) CollectionBuilder(de.ids_mannheim.korap.collection.CollectionBuilder) KrillCollection(de.ids_mannheim.korap.KrillCollection) Test(org.junit.Test)

Example 24 with SpanDistanceQuery

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

the class TestWPDIndex method testCase3.

/**
 * Element distance spans
 */
@Test
public void testCase3() throws IOException {
    // ordered
    SpanDistanceQuery sq = createElementDistanceQuery("s", "s:weg", "s:fahren", 0, 1, true, false);
    ks = new Krill(sq);
    kr = ks.apply(ki);
    assertEquals(kr.getTotalResults(), 3);
    // unordered
    sq = createElementDistanceQuery("s", "s:weg", "s:fahren", 0, 1, false, false);
    ks = new Krill(sq);
    kr = ks.apply(ki);
    assertEquals(kr.getTotalResults(), 5);
    // only 0
    sq = createElementDistanceQuery("s", "s:weg", "s:fahren", 0, 0, false, false);
    kr = ki.search(sq, (short) 100);
    assertEquals(kr.getTotalResults(), 2);
    assertEquals("WPD_BBB.04463", kr.getMatch(0).getDocID());
    assertEquals(1094, kr.getMatch(0).getStartPos());
    assertEquals(1115, kr.getMatch(0).getEndPos());
    assertEquals("WPD_III.00758", kr.getMatch(1).getDocID());
    assertEquals(444, kr.getMatch(1).getStartPos());
    assertEquals(451, kr.getMatch(1).getEndPos());
    // only 1
    sq = createElementDistanceQuery("s", "s:weg", "s:fahren", 1, 1, false, false);
    ks = new Krill(sq);
    kr = ks.apply(ki);
    assertEquals(kr.getTotalResults(), 3);
}
Also used : Krill(de.ids_mannheim.korap.Krill) SpanDistanceQuery(de.ids_mannheim.korap.query.SpanDistanceQuery) Test(org.junit.Test)

Aggregations

SpanDistanceQuery (de.ids_mannheim.korap.query.SpanDistanceQuery)24 Test (org.junit.Test)21 DistanceConstraint (de.ids_mannheim.korap.query.DistanceConstraint)19 KrillIndex (de.ids_mannheim.korap.KrillIndex)13 Term (org.apache.lucene.index.Term)13 SpanTermQuery (org.apache.lucene.search.spans.SpanTermQuery)12 SpanElementQuery (de.ids_mannheim.korap.query.SpanElementQuery)11 SpanClassQuery (de.ids_mannheim.korap.query.SpanClassQuery)9 SpanQuery (org.apache.lucene.search.spans.SpanQuery)8 SpanClassFilterQuery (de.ids_mannheim.korap.query.SpanClassFilterQuery)6 Krill (de.ids_mannheim.korap.Krill)4 SpanSubspanQuery (de.ids_mannheim.korap.query.SpanSubspanQuery)3 ArrayList (java.util.ArrayList)3 SpanFocusQuery (de.ids_mannheim.korap.query.SpanFocusQuery)2 SpanMultipleDistanceQuery (de.ids_mannheim.korap.query.SpanMultipleDistanceQuery)2 SpanNextQuery (de.ids_mannheim.korap.query.SpanNextQuery)2 SpanReferenceQuery (de.ids_mannheim.korap.query.SpanReferenceQuery)2 SpanRelationMatchQuery (de.ids_mannheim.korap.query.SpanRelationMatchQuery)2 SpanRelationQuery (de.ids_mannheim.korap.query.SpanRelationQuery)2 SpanQueryWrapper (de.ids_mannheim.korap.query.wrap.SpanQueryWrapper)2