use of de.ids_mannheim.korap.query.SpanNextQuery in project Krill by KorAP.
the class TestNextIndex method sequenceSkipBug.
@Test
public void sequenceSkipBug() throws IOException {
KrillIndex ki = new KrillIndex();
ki.addDoc(createFieldDoc1());
ki.addDoc(createFieldDoc3());
ki.addDoc(createFieldDoc4());
// match for 2
ki.addDoc(createFieldDoc5());
ki.addDoc(createFieldDoc1());
ki.addDoc(createFieldDoc3());
ki.addDoc(createFieldDoc4());
ki.addDoc(createFieldDoc1());
ki.addDoc(createFieldDoc1());
ki.addDoc(createFieldDoc3());
ki.addDoc(createFieldDoc1());
ki.commit();
// match for 2
ki.addDoc(createFieldDoc5());
ki.addDoc(createFieldDoc1());
// match for 1 and 2
ki.addDoc(createFieldDoc2());
ki.addDoc(createFieldDoc1());
ki.addDoc(createFieldDoc3());
ki.addDoc(createFieldDoc4());
ki.addDoc(createFieldDoc1());
ki.addDoc(createFieldDoc3());
ki.commit();
// "cab" is in 2
SpanQuery sq = new SpanNextQuery(new SpanNextQuery(new SpanTermQuery(new Term("base", "s:c")), new SpanTermQuery(new Term("base", "s:a"))), new SpanTermQuery(new Term("base", "s:b")));
Result kr = ki.search(sq, (short) 10);
assertEquals(0, kr.getMatch(0).getStartPos());
assertEquals(3, kr.getMatch(0).getEndPos());
assertEquals("totalResults", kr.getTotalResults(), 1);
// "aba" is in 2 and 5
sq = new SpanNextQuery(new SpanNextQuery(new SpanTermQuery(new Term("base", "s:a")), new SpanTermQuery(new Term("base", "s:b"))), new SpanTermQuery(new Term("base", "s:a")));
kr = ki.search(sq, (short) 10);
assertEquals("totalResults", kr.getTotalResults(), 3);
}
use of de.ids_mannheim.korap.query.SpanNextQuery in project Krill by KorAP.
the class TestReferenceIndex method testCase1.
@Test
public void testCase1() throws IOException {
ki = new KrillIndex();
ki.addDoc(TestRelationIndex.createFieldDoc2());
ki.commit();
SpanTermQuery stq = new SpanTermQuery(new Term("base", "pos:V"));
SpanElementQuery seq = new SpanElementQuery("base", "np");
SpanClassQuery scq1 = new SpanClassQuery(stq, (byte) 1);
SpanClassQuery scq2 = new SpanClassQuery(seq, (byte) 2);
SpanNextQuery snq1 = new SpanNextQuery(scq1, scq2);
SpanFocusQuery sfq1 = new SpanFocusQuery(snq1, (byte) 2);
SpanRelationQuery srq = new SpanRelationQuery(new SpanTermQuery(new Term("base", "<:child-of")), true, RelationDirection.LEFT);
SpanElementQuery seq2 = new SpanElementQuery("base", "pp");
SpanClassQuery scq3 = new SpanClassQuery(seq2, (byte) 3);
SpanRelationMatchQuery rq = new SpanRelationMatchQuery(srq, sfq1, scq3, true);
// focus on np
SpanFocusQuery sfq2 = new SpanFocusQuery(rq, (byte) 1);
DistanceConstraint constraint = new DistanceConstraint(3, 3, true, false);
SpanDistanceQuery sdq = new SpanDistanceQuery(sfq2, scq3, constraint, true);
SpanReferenceQuery ref = new SpanReferenceQuery(sdq, (byte) 3, true);
kr = ki.search(ref, (short) 10);
/*
* for (Match km : kr.getMatches()) {
*
* System.out.println(km.getStartPos() + "," + km.getEndPos()
* + " " + km.getSnippetBrackets()); }
* System.out.println(kr.getTotalResults());
*/
// cat=V & cat=np & cat=pp & #1 . #2 & #3 ->child-of #2 & #1 .{3,3} #3
assertEquals("spanReference(spanDistance(focus(1: focus(#[1,2]spanSegment(" + "focus(#1: spanSegment(spanRelation(base:<:child-of), focus(2: spanNext(" + "{1: base:pos:V}, {2: <base:np />})))), {3: <base:pp />}))), " + "{3: <base:pp />}, [(w[3:3], ordered, notExcluded)]), 3)", ref.toString());
assertEquals(1, kr.getMatch(0).getStartPos());
assertEquals(7, kr.getMatch(0).getEndPos());
}
use of de.ids_mannheim.korap.query.SpanNextQuery in project Krill by KorAP.
the class TestRepetitionIndex method testMinZeroRepetition.
@Test
public void testMinZeroRepetition() throws IOException {
ki = new KrillIndex();
ki.addDoc(createFieldDoc0());
ki.commit();
SpanQuery sq, sq2;
sq = new SpanTermQuery(new Term("base", "s:e"));
kr = ki.search(sq, (short) 10);
assertEquals((long) 4, kr.getTotalResults());
assertEquals(1, kr.getMatch(0).getStartPos());
assertEquals(2, kr.getMatch(0).getEndPos());
assertEquals(4, kr.getMatch(1).getStartPos());
assertEquals(5, kr.getMatch(1).getEndPos());
assertEquals(7, kr.getMatch(2).getStartPos());
assertEquals(8, kr.getMatch(2).getEndPos());
assertEquals(8, kr.getMatch(3).getStartPos());
assertEquals(9, kr.getMatch(3).getEndPos());
try {
sq2 = new SpanNextQuery(sq, new SpanRepetitionQuery(new SpanTermQuery(new Term("base", "s:c")), 0, 1, true));
} catch (IllegalArgumentException e) {
assertEquals("Minimum repetition must not lower than 1.", e.getMessage());
}
}
use of de.ids_mannheim.korap.query.SpanNextQuery in project Krill by KorAP.
the class TestSegmentIndex method testcase6.
/**
* Skip to SegmentSpan
*/
@Test
public void testcase6() throws IOException {
ki.addDoc(createFieldDoc4());
ki.commit();
sq = new SpanNextQuery(new SpanSegmentQuery(new SpanTermQuery(new Term("base", "s:b")), new SpanTermQuery(new Term("base", "s:c"))), new SpanTermQuery(new Term("base", "s:d")));
kr = ki.search(sq, (short) 10);
ki.close();
assertEquals("totalResults", kr.getTotalResults(), 2);
// Match #0
assertEquals("doc-number", 0, kr.getMatch(0).getLocalDocID());
assertEquals("StartPos (0)", 4, kr.getMatch(0).startPos);
assertEquals("EndPos (0)", 6, kr.getMatch(0).endPos);
// Match #1 in the other atomic index
assertEquals("doc-number", 0, kr.getMatch(1).getLocalDocID());
assertEquals("StartPos (0)", 0, kr.getMatch(1).startPos);
assertEquals("EndPos (0)", 2, kr.getMatch(1).endPos);
}
use of de.ids_mannheim.korap.query.SpanNextQuery in project Krill by KorAP.
the class TestUnorderedElementDistanceIndex method testCase5.
/**
* Next
*/
@Test
public void testCase5() throws IOException {
ki = new KrillIndex();
ki.addDoc(createFieldDoc0());
ki.commit();
SpanQuery sq, edq;
edq = createQuery("s", "s:b", "s:c", 0, 2, false);
kr = ki.search(edq, (short) 10);
assertEquals((long) 6, kr.getTotalResults());
sq = new SpanNextQuery(new SpanTermQuery(new Term("base", "s:b")), edq);
kr = ki.search(sq, (short) 10);
assertEquals((long) 2, kr.getTotalResults());
assertEquals(1, kr.getMatch(0).getStartPos());
assertEquals(4, kr.getMatch(0).getEndPos());
assertEquals(2, kr.getMatch(1).getStartPos());
assertEquals(5, kr.getMatch(1).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
// );
// }
}
Aggregations