use of de.ids_mannheim.korap.query.DistanceConstraint in project Krill by KorAP.
the class TestWPDIndex method createElementDistanceQuery.
private SpanDistanceQuery createElementDistanceQuery(String e, String x, String y, int min, int max, boolean isOrdered, boolean exclusion) {
SpanElementQuery eq = new SpanElementQuery("tokens", e);
SpanDistanceQuery sq = new SpanDistanceQuery(new SpanTermQuery(new Term("tokens", x)), new SpanTermQuery(new Term("tokens", y)), new DistanceConstraint(eq, min, max, isOrdered, exclusion), true);
return sq;
}
use of de.ids_mannheim.korap.query.DistanceConstraint in project Krill by KorAP.
the class TestClassFilterIndex method testDisjoint.
@Test
public void testDisjoint() throws IOException {
ki = new KrillIndex();
ki.addDoc(TestReferenceIndex.createFieldDoc0());
ki.commit();
SpanElementQuery seq1 = new SpanElementQuery("tokens", "np");
SpanElementQuery seq2 = new SpanElementQuery("tokens", "vp");
SpanClassQuery scq1 = new SpanClassQuery(seq1, (byte) 1);
SpanClassQuery scq2 = new SpanClassQuery(seq2, (byte) 2);
SpanDistanceQuery sdq = new SpanDistanceQuery(scq1, scq2, new DistanceConstraint(0, 1, false, false), true);
// kr = ki.search(sdq, (short) 10);
// for (Match km : kr.getMatches()) {
// System.out.println(km.getStartPos() + "," + km.getEndPos()
// + " "
// + km.getSnippetBrackets());
// }
SpanClassFilterQuery sq = new SpanClassFilterQuery(sdq, ClassOperation.DISJOINT, 2, 1, true);
kr = ki.search(sq, (short) 10);
// for (Match km : kr.getMatches()) {
// System.out.println(km.getStartPos() + "," + km.getEndPos()
// + " "
// + km.getSnippetBrackets());
// }
assertEquals(0, kr.getMatch(0).getStartPos());
assertEquals(5, kr.getMatch(0).getEndPos());
assertEquals("[[{1:Frankenstein}, {2:treat my daughter well}]]. She is the one that saved ...", kr.getMatch(0).getSnippetBrackets());
assertEquals(1, kr.getMatch(1).getStartPos());
assertEquals(6, kr.getMatch(1).getEndPos());
assertEquals("Frankenstein, [[{2:treat my daughter well}. {1:She}]] is the one that saved your ...", kr.getMatch(1).getSnippetBrackets());
assertEquals(5, kr.getMatch(2).getStartPos());
assertEquals(18, kr.getMatch(2).getEndPos());
assertEquals("Frankenstein, treat my daughter well. [[{1:She} {2:is the one that saved your master who you hold so dear}]].", kr.getMatch(2).getSnippetBrackets());
}
use of de.ids_mannheim.korap.query.DistanceConstraint in project Krill by KorAP.
the class TestClassFilterIndex method testMultipleSameClasses.
@Test
public void testMultipleSameClasses() throws IOException {
ki = new KrillIndex();
ki.addDoc(TestReferenceIndex.createFieldDoc0());
ki.commit();
SpanElementQuery seq1 = new SpanElementQuery("tokens", "nn");
SpanElementQuery seq = new SpanElementQuery("tokens", "prp");
SpanClassQuery scq1 = new SpanClassQuery(seq1, (byte) 1);
SpanClassQuery scq = new SpanClassQuery(seq, (byte) 1);
SpanDistanceQuery sdq = new SpanDistanceQuery(scq, scq1, new DistanceConstraint(3, 5, false, false), true);
SpanElementQuery seq2 = new SpanElementQuery("tokens", "vp");
SpanClassQuery scq2 = new SpanClassQuery(seq2, (byte) 2);
SpanDistanceQuery sdq2 = new SpanDistanceQuery(sdq, scq2, new DistanceConstraint(0, 1, false, false), true);
SpanClassFilterQuery sq = new SpanClassFilterQuery(sdq2, ClassOperation.INCLUDE, 2, 1, true);
kr = ki.search(sdq2, (short) 20);
assertEquals(6, kr.getTotalResults());
// for (Match km : kr.getMatches()) {
// System.out.println(km.getStartPos() + "," + km.getEndPos()
// + " "
// + km.getSnippetBrackets());
// }
kr = ki.search(sq, (short) 20);
// for (Match km : kr.getMatches()) {
// System.out.println(km.getStartPos() + "," + km.getEndPos()
// + " "
// + km.getSnippetBrackets());
// }
assertEquals(6, kr.getMatch(0).getStartPos());
assertEquals(18, kr.getMatch(0).getEndPos());
assertEquals("Frankenstein, treat my daughter well. She [[{2:is the {1:one} that saved {1:your} master who you hold so dear}]].", kr.getMatch(0).getSnippetBrackets());
}
use of de.ids_mannheim.korap.query.DistanceConstraint in project Krill by KorAP.
the class TestElementDistanceExclusionIndex method createQuery.
private SpanQuery createQuery(String e, String x, String y, int min, int max, boolean isOrdered, boolean exclusion) {
SpanElementQuery eq = new SpanElementQuery("base", e);
SpanDistanceQuery sq = new SpanDistanceQuery(new SpanTermQuery(new Term("base", x)), new SpanTermQuery(new Term("base", y)), new DistanceConstraint(eq, min, max, isOrdered, exclusion), true);
return sq;
}
use of de.ids_mannheim.korap.query.DistanceConstraint in project Krill by KorAP.
the class TestMultipleDistanceIndex method testCase1.
/**
* Unordered, same sentence
*/
@Test
public void testCase1() throws IOException {
ki = new KrillIndex();
ki.addDoc(createFieldDoc0());
ki.commit();
List<DistanceConstraint> constraints = new ArrayList<DistanceConstraint>();
constraints.add(createConstraint("w", 0, 2, false, false));
constraints.add(createConstraint("s", 0, 0, false, false));
SpanQuery mdq;
mdq = createQuery("s:b", "s:c", constraints, false);
kr = ki.search(mdq, (short) 10);
assertEquals((long) 3, kr.getTotalResults());
assertEquals(0, kr.getMatch(0).getStartPos());
assertEquals(2, kr.getMatch(0).getEndPos());
assertEquals(1, kr.getMatch(1).getStartPos());
assertEquals(2, kr.getMatch(1).getEndPos());
assertEquals(2, kr.getMatch(2).getStartPos());
assertEquals(4, kr.getMatch(2).getEndPos());
}
Aggregations