use of de.ids_mannheim.korap.query.SpanDistanceQuery 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.SpanDistanceQuery 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.SpanDistanceQuery 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.SpanDistanceQuery 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.SpanDistanceQuery 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());
}
Aggregations