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()); }
*/
}
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);
}
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());
}
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);
}
Aggregations