use of de.ids_mannheim.korap.KrillIndex in project Krill by KorAP.
the class TestDistanceIndex method testSkipTo.
@Test
public void testSkipTo() throws IOException {
ki = new KrillIndex();
ki.addDoc(createFieldDoc2());
ki.addDoc(createFieldDoc1());
ki.commit();
SpanQuery firstClause = createQuery("s:d", "s:e", 3, 4, true);
kr = ki.search(firstClause, (short) 10);
assertEquals(kr.getTotalResults(), 3);
assertEquals(0, kr.getMatch(0).getLocalDocID());
assertEquals(2, kr.getMatch(0).startPos);
assertEquals(6, kr.getMatch(0).endPos);
assertEquals(1, kr.getMatch(1).getLocalDocID());
assertEquals(4, kr.getMatch(1).startPos);
assertEquals(8, kr.getMatch(1).endPos);
assertEquals(4, kr.getMatch(2).startPos);
assertEquals(9, kr.getMatch(2).endPos);
// The secondspans is skipped to doc# of the current firstspans
SpanQuery sq = new SpanSegmentQuery(createQuery("s:d", "s:e", 3, 4, true), createElementQuery("y", "x", 1, 2, true));
kr = ki.search(sq, (short) 10);
assertEquals(kr.getTotalResults(), 1);
assertEquals(4, kr.getMatch(0).startPos);
assertEquals(9, kr.getMatch(0).endPos);
}
use of de.ids_mannheim.korap.KrillIndex in project Krill by KorAP.
the class TestElementDistanceIndex method testNoMoreSecondSpans.
@Test
public void testNoMoreSecondSpans() throws IOException {
ki = new KrillIndex();
ki.addDoc(createFieldDoc3());
ki.addDoc(createFieldDoc5());
ki.commit();
// c or b
SpanOrQuery soq = new SpanOrQuery(new SpanTermQuery(new Term("tokens", "s:c")), new SpanTermQuery(new Term("tokens", "s:b")));
// d /s0(c or b)
SpanElementQuery e = new SpanElementQuery("tokens", "s");
SpanDistanceQuery sdq = new SpanDistanceQuery(new SpanTermQuery(new Term("tokens", "s:d")), soq, new DistanceConstraint(e, 0, 0, true, false), true);
kr = ki.search(sdq, (short) 10);
assertEquals(0, kr.getTotalResults());
}
use of de.ids_mannheim.korap.KrillIndex in project Krill by KorAP.
the class TestElementDistanceIndex method testNoElementSpans.
@Test
public void testNoElementSpans() throws IOException {
ki = new KrillIndex();
ki.addDoc(createFieldDoc3());
ki.addDoc(createFieldDoc5());
ki.commit();
// c or e
SpanOrQuery soq = new SpanOrQuery(new SpanTermQuery(new Term("tokens", "s:c")), new SpanTermQuery(new Term("tokens", "s:e")));
// (c or e) /s0 d
SpanElementQuery e = new SpanElementQuery("tokens", "s");
SpanDistanceQuery sdq = new SpanDistanceQuery(soq, new SpanTermQuery(new Term("tokens", "s:d")), new DistanceConstraint(e, 0, 0, true, false), true);
kr = ki.search(sdq, (short) 10);
}
use of de.ids_mannheim.korap.KrillIndex in project Krill by KorAP.
the class TestElementDistanceIndex method testCase1.
/**
* Multiple documents
* Ensure terms and elements are in the same doc
* Ensure terms are in elements
* Check filter candidate list
*/
@Test
public void testCase1() throws IOException {
ki = new KrillIndex();
ki.addDoc(createFieldDoc0());
ki.addDoc(createFieldDoc1());
ki.addDoc(createFieldDoc3());
ki.commit();
SpanQuery sq;
sq = createQuery("s", "s:b", "s:c", 1, 1, true);
kr = ki.search(sq, (short) 10);
assertEquals(4, kr.getTotalResults());
assertEquals(0, kr.getMatch(0).startPos);
assertEquals(3, kr.getMatch(0).endPos);
assertEquals(4, kr.getMatch(1).startPos);
assertEquals(7, kr.getMatch(1).endPos);
assertEquals(3, kr.getMatch(2).startPos);
assertEquals(5, kr.getMatch(2).endPos);
assertEquals(2, kr.getMatch(3).startPos);
assertEquals(4, kr.getMatch(3).endPos);
}
use of de.ids_mannheim.korap.KrillIndex in project Krill by KorAP.
the class TestElementDistanceIndex method testCase6.
/**
* Test query from json (2)
*/
@Test
public void testCase6() throws Exception {
ki = new KrillIndex();
ki.addDoc(createFieldDoc0());
ki.addDoc(createFieldDoc1());
ki.addDoc(createFieldDoc2());
ki.commit();
SpanQueryWrapper sqwi;
sqwi = new QueryBuilder("tokens").tag("base/s:t");
kr = ki.search(sqwi.toQuery(), (short) 10);
assertEquals(kr.getTotalResults(), 1);
assertEquals("[[ecebdc]]", kr.getMatch(0).getSnippetBrackets());
String jsonPath = getClass().getResource("/queries/distances/in-same-t.jsonld").getFile();
sqwi = getJsonQuery(jsonPath);
assertEquals("spanElementDistance(tokens:s:c, tokens:s:e, [(base/s:t[0:0], ordered, notExcluded)])", sqwi.toQuery().toString());
kr = ki.search(sqwi.toQuery(), (short) 10);
// Is 1 correct or
assertEquals(1, kr.getTotalResults());
// should it not be
// ordered?
assertEquals("[[ec]]ebdc", kr.getMatch(0).getSnippetBrackets());
}
Aggregations