use of de.ids_mannheim.korap.query.SpanElementQuery in project Krill by KorAP.
the class TestAttributeIndex method testCase3.
/**
* same attribute types referring to different element types
*/
@Test
public void testCase3() throws IOException {
ki.addDoc(createFieldDoc2());
ki.commit();
List<SpanQuery> sql = new ArrayList<>();
sql.add(new SpanAttributeQuery(new SpanTermQuery(new Term("base", "@:class=header")), true));
sql.add(new SpanAttributeQuery(new SpanTermQuery(new Term("base", "@:class=book")), true, true));
SpanQuery sq = new SpanWithAttributeQuery(new SpanElementQuery("base", "div"), sql, true);
kr = ki.search(sq, (short) 10);
assertEquals((long) 3, kr.getTotalResults());
assertEquals(1, kr.getMatch(0).getStartPos());
assertEquals(2, kr.getMatch(0).getEndPos());
assertEquals(5, kr.getMatch(1).getStartPos());
assertEquals(6, kr.getMatch(1).getEndPos());
assertEquals(6, kr.getMatch(2).getStartPos());
assertEquals(7, kr.getMatch(2).getEndPos());
}
use of de.ids_mannheim.korap.query.SpanElementQuery 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.SpanElementQuery 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.SpanElementQuery 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.SpanElementQuery in project Krill by KorAP.
the class TestElementIndex method indexExample5.
@Test
public void indexExample5() throws IOException {
KrillIndex ki = new KrillIndex();
FieldDocument fd = new FieldDocument();
fd.addTV("base", "111111ccc222222fff333333iiijjj", "[(0-3)s:a|_0$<i>0<i>3|<>:a$<b>64<i>0<i>6<i>1<b>0]" + "[(3-6)s:b|_1$<i>3<i>6]" + "[(6-9)s:c|_2$<i>6<i>9]" + "[(9-12)s:d|_3$<i>9<i>12|<>:a$<b>64<i>9<i>15<i>4<b>0]" + "[(12-15)s:e|_4$<i>12<i>15]" + "[(15-18)s:f|_5$<i>15<i>18]" + "[(18-21)s:g|_6$<i>18<i>21|<>:a$<b>64<i>18<i>24<i>8<b>0]" + "[(21-24)s:h|_7$<i>21<i>24]" + "[(24-27)s:i|_8$<i>24<i>27]" + "[(27-30)s:j|_9$<i>27<i>30]");
ki.addDoc(fd);
// Save documents
ki.commit();
assertEquals(1, ki.numberOf("documents"));
SpanQuery sq = new SpanElementQuery("base", "a");
Result kr = ki.search(sq, 0, (short) 15, false, (short) 3, false, (short) 3);
assertEquals("[[111111]]ccc ...", kr.getMatch(0).getSnippetBrackets());
assertEquals("... ccc[[222222]]fff ...", kr.getMatch(1).getSnippetBrackets());
assertEquals("... fff[[333333]]iii ...", kr.getMatch(2).getSnippetBrackets());
}
Aggregations