use of de.ids_mannheim.korap.query.SpanNextQuery in project Krill by KorAP.
the class TestNextIndex method indexExample5.
/**
* Multiple atomic indices
* Skip to a greater doc#
*/
@Test
public void indexExample5() throws IOException {
KrillIndex ki = new KrillIndex();
ki.addDoc(createFieldDoc1());
ki.addDoc(createFieldDoc2());
ki.commit();
ki.addDoc(createFieldDoc3());
ki.commit();
SpanQuery sq = new SpanNextQuery(new SpanTermQuery(new Term("base", "s:d")), new SpanTermQuery(new Term("base", "s:b")));
Result kr = ki.search(sq, (short) 10);
assertEquals("totalResults", kr.getTotalResults(), 2);
// Match #0
assertEquals("doc-number", 0, kr.getMatch(0).getLocalDocID());
assertEquals("StartPos", 4, kr.getMatch(0).startPos);
assertEquals("EndPos", 6, kr.getMatch(0).endPos);
// Match #1
assertEquals("doc-number", 0, kr.getMatch(1).getLocalDocID());
assertEquals("StartPos", 1, kr.getMatch(1).startPos);
assertEquals("EndPos", 3, kr.getMatch(1).endPos);
sq = new SpanNextQuery(new SpanTermQuery(new Term("base", "s:b")), new SpanTermQuery(new Term("base", "s:d")));
kr = ki.search(sq, (short) 10);
assertEquals("totalResults", kr.getTotalResults(), 1);
assertEquals("doc-number", 0, kr.getMatch(0).getLocalDocID());
assertEquals("StartPos", 2, kr.getMatch(0).startPos);
assertEquals("EndPos", 4, kr.getMatch(0).endPos);
}
use of de.ids_mannheim.korap.query.SpanNextQuery in project Krill by KorAP.
the class TestNextIndex method indexExample4.
@Test
public void indexExample4() throws IOException {
KrillIndex ki = new KrillIndex();
// abcabcabac
// abc<x>abc<x>a</x>b</x>ac
FieldDocument fd = new FieldDocument();
fd.addString("ID", "doc-1");
fd.addTV("base", "abcabcabac", "[(0-1)s:a|i:a|_0$<i>0<i>1|-:t$<i>10]" + "[(1-2)s:b|i:b|_1$<i>1<i>2]" + "[(2-3)s:c|i:c|_2$<i>2<i>3]" + "[(3-4)s:a|i:a|_3$<i>3<i>4|<>:x$<b>64<i>3<i>7<i>7<b>0]" + "[(4-5)s:b|i:b|_4$<i>4<i>5]" + "[(5-6)s:c|i:c|_5$<i>5<i>6]" + "[(6-7)s:a|i:a|_6$<i>6<i>7]<>:x$<b>64<i>6<i>8<i>8<b>0]" + "[(7-8)s:b|i:b|_7$<i>7<i>8]" + "[(8-9)s:a|i:a|_8$<i>8<i>9]" + "[(9-10)s:c|i:c|_9$<i>9<i>10]");
ki.addDoc(fd);
// xbz<x>xbzx</x>bxz
fd = new FieldDocument();
fd.addString("ID", "doc-2");
fd.addTV("base", "xbzxbzxbxz", "[(0-1)s:x|i:x|_0$<i>0<i>1|-:t$<i>10]" + "[(1-2)s:b|i:b|_1$<i>1<i>2]" + "[(2-3)s:z|i:z|_2$<i>2<i>3]" + "[(3-4)s:x|i:x|_3$<i>3<i>4|<>:x$<b>64<i>3<i>7<i>7<b>0]" + "[(4-5)s:b|i:b|_4$<i>4<i>5]" + "[(5-6)s:z|i:z|_5$<i>5<i>6]" + "[(6-7)s:x|i:x|_6$<i>6<i>7]" + "[(7-8)s:b|i:b|_7$<i>7<i>8]" + "[(8-9)s:x|i:x|_8$<i>8<i>9]" + "[(9-10)s:z|i:z|_9$<i>9<i>10]");
ki.addDoc(fd);
ki.commit();
SpanQuery sq;
Result kr;
sq = new SpanNextQuery(new SpanElementQuery("base", "x"), new SpanTermQuery(new Term("base", "s:b")));
kr = ki.search(sq, (short) 10);
assertEquals("TotalResults", kr.getTotalResults(), 2);
assertEquals("abc[[abcab]]ac", kr.getMatch(0).getSnippetBrackets());
assertEquals("xbz[[xbzxb]]xz", kr.getMatch(1).getSnippetBrackets());
sq = new SpanNextQuery(new SpanTermQuery(new Term("base", "s:c")), new SpanElementQuery("base", "x"));
kr = ki.search(sq, (short) 10);
assertEquals(kr.getTotalResults(), 1);
assertEquals("ab[[cabca]]bac", kr.getMatch(0).getSnippetBrackets());
sq = new SpanNextQuery(new SpanTermQuery(new Term("base", "s:z")), new SpanElementQuery("base", "x"));
kr = ki.search(sq, (short) 10);
assertEquals(1, kr.getTotalResults());
assertEquals("xb[[zxbzx]]bxz", kr.getMatch(0).getSnippetBrackets());
}
use of de.ids_mannheim.korap.query.SpanNextQuery in project Krill by KorAP.
the class TestNextIndex method indexExample9.
@Test
public void indexExample9() throws IOException {
KrillIndex ki = new KrillIndex();
ki.addDoc(createFieldDoc1());
ki.commit();
SpanQuery sq = new SpanNextQuery(new SpanOrQuery(new SpanTermQuery(new Term("base", "s:a")), new SpanTermQuery(new Term("base", "s:b"))), new SpanTermQuery(new Term("base", "s:c")));
Result kr = ki.search(sq, (short) 10);
assertEquals(0, kr.getMatch(0).getStartPos());
assertEquals(2, kr.getMatch(0).getEndPos());
assertEquals(3, kr.getMatch(1).getStartPos());
assertEquals(5, kr.getMatch(1).getEndPos());
}
use of de.ids_mannheim.korap.query.SpanNextQuery in project Krill by KorAP.
the class TestNextIndex method indexExample6.
/**
* Skip to NextSpan
*/
@Test
public void indexExample6() throws IOException {
KrillIndex ki = new KrillIndex();
ki.addDoc(createFieldDoc1());
ki.addDoc(createFieldDoc2());
ki.addDoc(createFieldDoc3());
ki.commit();
SpanQuery sq = new SpanNextQuery(new SpanTermQuery(new Term("base", "s:c")), new SpanNextQuery(new SpanTermQuery(new Term("base", "s:d")), new SpanTermQuery(new Term("base", "s:b"))));
Result kr = ki.search(sq, (short) 10);
assertEquals("totalResults", kr.getTotalResults(), 1);
assertEquals("doc-number", 2, kr.getMatch(0).getLocalDocID());
assertEquals("StartPos", 0, kr.getMatch(0).startPos);
assertEquals("EndPos", 3, kr.getMatch(0).endPos);
sq = new SpanNextQuery(new SpanTermQuery(new Term("base", "s:c")), new SpanNextQuery(new SpanFocusQuery(new SpanClassQuery(new SpanTermQuery(new Term("base", "s:d")), (byte) 1), (byte) 1), new SpanFocusQuery(new SpanClassQuery(new SpanTermQuery(new Term("base", "s:b")), (byte) 2), (byte) 2)));
kr = ki.search(sq, (short) 10);
assertEquals("doc-number", 2, kr.getMatch(0).getLocalDocID());
assertEquals("StartPos", 0, kr.getMatch(0).startPos);
assertEquals("EndPos", 3, kr.getMatch(0).endPos);
// for (Match km : kr.getMatches()) {
// System.out.println(km.getStartPos() + "," + km.getEndPos()
// + " "
// + km.getSnippetBrackets());
// }
}
use of de.ids_mannheim.korap.query.SpanNextQuery in project Krill by KorAP.
the class TestUnorderedDistanceIndex method testCase8.
/**
* Multiple NextSpans in the same first span position
*/
@Test
public void testCase8() throws IOException {
ki = new KrillIndex();
ki.addDoc(createFieldDoc1());
ki.commit();
SpanQuery sq = new SpanNextQuery(new SpanTermQuery(new Term("base", "s:d")), createQuery("s:c", "s:e", 1, 2, false));
kr = ki.search(sq, (short) 10);
assertEquals(kr.getTotalResults(), 3);
assertEquals(0, kr.getMatch(1).getStartPos());
assertEquals(4, kr.getMatch(1).getEndPos());
}
Aggregations