use of de.ids_mannheim.korap.query.DistanceConstraint in project Krill by KorAP.
the class TestMultipleDistanceIndex method testCase3.
/**
* Multiple documents
* Ensure same doc (inner term span)
*/
@Test
public void testCase3() throws IOException {
ki = new KrillIndex();
ki.addDoc(createFieldDoc0());
ki.addDoc(createFieldDoc1());
ki.addDoc(createFieldDoc2());
ki.commit();
List<DistanceConstraint> constraints = new ArrayList<DistanceConstraint>();
constraints.add(createConstraint("w", 1, 2, false, false));
constraints.add(createConstraint("s", 1, 2, false, false));
SpanQuery mdq;
mdq = createQuery("s:b", "s:e", constraints, false);
kr = ki.search(mdq, (short) 10);
assertEquals((long) 5, kr.getTotalResults());
assertEquals(3, kr.getMatch(0).getStartPos());
assertEquals(6, kr.getMatch(0).getEndPos());
assertEquals(2, kr.getMatch(1).getLocalDocID());
assertEquals(1, kr.getMatch(2).getStartPos());
assertEquals(4, kr.getMatch(2).getEndPos());
assertEquals(3, kr.getMatch(3).getStartPos());
assertEquals(5, kr.getMatch(3).getEndPos());
assertEquals(4, kr.getMatch(4).getStartPos());
assertEquals(7, kr.getMatch(4).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
// );
// }
}
use of de.ids_mannheim.korap.query.DistanceConstraint in project Krill by KorAP.
the class TestMultipleDistanceIndex method testCase7.
/**
* Exclusion, multiple documents
*/
@Test
public void testCase7() throws IOException {
ki = new KrillIndex();
ki.addDoc(createFieldDoc2());
ki.commit();
SpanQuery sx = new SpanTermQuery(new Term("base", "s:b"));
SpanQuery sy = new SpanTermQuery(new Term("base", "s:c"));
// Second constraint
SpanDistanceQuery sq = new SpanDistanceQuery(sx, sy, createConstraint("s", 0, 0, false, true), true);
kr = ki.search(sq, (short) 10);
assertEquals((long) 3, kr.getTotalResults());
// 0-1, 1-2, 6-7
// Exclusion within the same sentence
List<DistanceConstraint> constraints = new ArrayList<DistanceConstraint>();
constraints.add(createConstraint("w", 0, 2, false, true));
constraints.add(createConstraint("s", 0, 0, false, true));
SpanQuery mdq;
mdq = createQuery("s:b", "s:c", constraints, false);
kr = ki.search(mdq, (short) 10);
assertEquals((long) 2, kr.getTotalResults());
assertEquals(0, kr.getMatch(0).getStartPos());
assertEquals(1, kr.getMatch(0).getEndPos());
assertEquals(6, kr.getMatch(1).getStartPos());
assertEquals(7, kr.getMatch(1).getEndPos());
// Third constraint
sq = new SpanDistanceQuery(sx, sy, createConstraint("p", 0, 0, false, true), true);
kr = ki.search(sq, (short) 10);
assertEquals((long) 1, kr.getTotalResults());
// 6-7
constraints.add(createConstraint("p", 0, 0, false, true));
mdq = createQuery("s:b", "s:c", constraints, false);
kr = ki.search(mdq, (short) 10);
assertEquals((long) 1, kr.getTotalResults());
assertEquals(6, kr.getMatch(0).getStartPos());
assertEquals(7, kr.getMatch(0).getEndPos());
}
use of de.ids_mannheim.korap.query.DistanceConstraint in project Krill by KorAP.
the class TestMultipleDistanceIndex method testUnorderedTokenDistance.
@Test
public void testUnorderedTokenDistance() throws IOException {
ki = new KrillIndex();
ki.addDoc(createFieldDoc4());
ki.commit();
List<DistanceConstraint> constraints = new ArrayList<DistanceConstraint>();
constraints.add(createConstraint("w", 0, 5, true, false));
constraints.add(createConstraint("s", 0, 0, true, false));
SpanQuery mdq;
mdq = createQuery("s:Begin", "s:Moderator", constraints, false);
kr = ki.search(mdq, (short) 10);
assertEquals(1, kr.getMatch(0).getStartPos());
assertEquals(7, kr.getMatch(0).getEndPos());
SpanQuery sq = new SpanDistanceQuery(mdq, new SpanTermQuery(new Term("base", "s:ruft")), new DistanceConstraint(0, 0, false, false), true);
kr = ki.search(sq, (short) 10);
assertEquals(1, kr.getMatch(0).getStartPos());
assertEquals(7, kr.getMatch(0).getEndPos());
}
use of de.ids_mannheim.korap.query.DistanceConstraint in project Krill by KorAP.
the class TestMultipleDistanceIndex method testQueryWithWildCard.
@Test
public void testQueryWithWildCard() throws IOException {
// meine* /+w1:2,s0 &Erfahrung
ki = new KrillIndex();
ki.addDoc(createFieldDoc5());
ki.commit();
// Check simple rewriting
WildcardQuery wcquery = new WildcardQuery(new Term("tokens", "s:Meine*"));
SpanMultiTermQueryWrapper<WildcardQuery> mtq = new SpanMultiTermQueryWrapper<WildcardQuery>(wcquery);
assertEquals(wcquery.toString(), "tokens:s:Meine*");
kr = ki.search(mtq, (short) 10);
assertEquals(4, kr.getMatches().size());
assertEquals(0, kr.getMatch(0).getStartPos());
assertEquals(1, kr.getMatch(0).getEndPos());
// Check rewriting in multidistance query
SpanQuery sq = new SpanTermQuery(new Term("tokens", "l:Erfahrung"));
kr = ki.search(sq, (short) 10);
assertEquals(4, kr.getMatches().size());
List<DistanceConstraint> constraints = new ArrayList<DistanceConstraint>();
constraints.add(createConstraint("w", 1, 2, true, false));
constraints.add(createConstraint("tokens", "s", 0, 0, true, false));
SpanQuery mdsq = new SpanMultipleDistanceQuery(mtq, sq, constraints, true, true);
assertEquals(mdsq.toString(), "spanMultipleDistance(SpanMultiTermQueryWrapper(tokens:s:Meine*), " + "tokens:l:Erfahrung, [(w[1:2], ordered, notExcluded), (s[0:0], " + "ordered, notExcluded)])");
kr = ki.search(mdsq, (short) 10);
assertEquals(3, kr.getMatches().size());
assertEquals(0, kr.getMatch(0).getStartPos());
assertEquals(2, kr.getMatch(0).getEndPos());
// Check skipping with multiple documents
ki.addDoc(createFieldDoc6());
ki.addDoc(createFieldDoc7());
ki.addDoc(createFieldDoc8());
ki.commit();
kr = ki.search(mdsq, (short) 10);
assertEquals(6, kr.getMatches().size());
}
use of de.ids_mannheim.korap.query.DistanceConstraint in project Krill by KorAP.
the class TestMultipleDistanceIndex method testCase6.
/**
* Exclusion
* Gaps
*/
@Test
public void testCase6() throws IOException {
ki = new KrillIndex();
ki.addDoc(createFieldDoc3());
ki.commit();
// First constraint - token exclusion
SpanQuery sx = new SpanTermQuery(new Term("base", "s:b"));
SpanQuery sy = new SpanTermQuery(new Term("base", "s:c"));
DistanceConstraint dc1 = createConstraint("w", 0, 1, false, true);
SpanDistanceQuery sq = new SpanDistanceQuery(sx, sy, dc1, true);
kr = ki.search(sq, (short) 10);
assertEquals((long) 1, kr.getTotalResults());
// 4-5
// Second constraint - element distance
DistanceConstraint dc2 = createConstraint("s", 1, 1, false, false);
sq = new SpanDistanceQuery(sx, sy, dc2, true);
kr = ki.search(sq, (short) 10);
// 0-3, 1-3, 1-4, 1-5, 3-7, 4-7
assertEquals((long) 6, kr.getTotalResults());
List<DistanceConstraint> constraints = new ArrayList<DistanceConstraint>();
constraints.add(dc1);
constraints.add(dc2);
SpanQuery mdq;
mdq = createQuery("s:b", "s:c", constraints, false);
kr = ki.search(mdq, (short) 10);
assertEquals((long) 2, kr.getTotalResults());
assertEquals(1, kr.getMatch(0).getStartPos());
assertEquals(5, kr.getMatch(0).getEndPos());
assertEquals(4, kr.getMatch(1).getStartPos());
assertEquals(7, kr.getMatch(1).getEndPos());
}
Aggregations