use of de.ids_mannheim.korap.KrillIndex 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());
}
use of de.ids_mannheim.korap.KrillIndex in project Krill by KorAP.
the class TestUnorderedDistanceIndex method testCase4.
/**
* Skip to
*/
@Test
public void testCase4() throws IOException {
// System.out.println("testcase 4");
ki = new KrillIndex();
ki.addDoc(createFieldDoc0());
ki.addDoc(createFieldDoc1());
ki.addDoc(createFieldDoc2());
ki.commit();
SpanQuery sq = new SpanNextQuery(createQuery("s:d", "s:e", 1, 2, false), new SpanTermQuery(new Term("base", "s:f")));
kr = ki.search(sq, (short) 10);
assertEquals(kr.getTotalResults(), 2);
assertEquals(2, kr.getMatch(0).getLocalDocID());
assertEquals(2, kr.getMatch(0).getStartPos());
assertEquals(6, kr.getMatch(0).getEndPos());
assertEquals(3, kr.getMatch(1).getStartPos());
assertEquals(6, kr.getMatch(1).getEndPos());
}
use of de.ids_mannheim.korap.KrillIndex in project Krill by KorAP.
the class TestUnorderedDistanceIndex method testCase2.
/**
* Multiple documents
* Ensure same doc
* Both candidate lists are empty, but there is a span left in the
* doc
* Both candidate lists are empty, but there are more matches in
* the doc
*
* @throws IOException
*/
@Test
public void testCase2() throws IOException {
// System.out.println("testcase 2");
ki = new KrillIndex();
ki.addDoc(createFieldDoc0());
ki.addDoc(createFieldDoc1());
ki.commit();
SpanQuery sq = createQuery("s:c", "s:d", 1, 2, false);
kr = ki.search(sq, (short) 10);
assertEquals(kr.getTotalResults(), 6);
}
use of de.ids_mannheim.korap.KrillIndex in project Krill by KorAP.
the class TestWithinIndex method indexExample1c.
@Test
public void indexExample1c() throws IOException {
// Cases 9, 12, 13
KrillIndex ki = new KrillIndex();
// <a>x<a>y<a>zhij</a>hij</a>hij</a>
FieldDocument fd = new FieldDocument();
fd.addTV("base", "x y z h i j h i j h i j ", // 1
"[(0-3)s:x|<>:a$<b>64<i>0<i>36<i>12<b>0]" + // 2
"[(3-6)s:y|<>:a$<b>64<i>3<i>27<i>9<b>0]" + // 3
"[(6-9)s:z|<>:a$<b>64<i>6<i>18<i>6<b>0]" + // 4
"[(9-12)s:h]" + // 5
"[(12-15)s:i]" + // 6
"[(15-18)s:j]" + // 7
"[(18-21)s:h]" + // 8
"[(21-24)s:i]" + // 9
"[(24-27)s:j]" + // 10
"[(27-30)s:h]" + // 11
"[(30-33)s:i]" + // 12
"[(33-36)s:j]");
ki.addDoc(fd);
// <a>x<a>y<a>zabc</a>abc</a>abc</a>
fd = new FieldDocument();
fd.addTV("base", "x y z a b c a b c a b c ", // 1
"[(0-3)s:x|<>:a$<b>64<i>0<i>36<i>12<b>0]" + // 2
"[(3-6)s:y|<>:a$<b>64<i>3<i>27<i>9<b>0]" + // 3
"[(6-9)s:z|<>:a$<b>64<i>6<i>18<i>6<b>0]" + // 4
"[(9-12)s:a]" + // 5
"[(12-15)s:b]" + // 6
"[(15-18)s:c]" + // 7
"[(18-21)s:a]" + // 8
"[(21-24)s:b]" + // 9
"[(24-27)s:c]" + // 10
"[(27-30)s:a]" + // 11
"[(30-33)s:b]" + // 12
"[(33-36)s:c]");
ki.addDoc(fd);
// Save documents
ki.commit();
SpanQuery sq;
Result kr;
sq = new SpanWithinQuery(new SpanElementQuery("base", "a"), new SpanTermQuery(new Term("base", "s:h")));
kr = ki.search(sq, (short) 15);
assertEquals("totalResults", kr.getTotalResults(), 6);
assertEquals("StartPos (0)", 0, kr.getMatch(0).startPos);
assertEquals("EndPos (0)", 12, kr.getMatch(0).endPos);
assertEquals("Doc (0)", 0, kr.getMatch(0).internalDocID);
assertEquals("StartPos (1)", 0, kr.getMatch(1).startPos);
assertEquals("EndPos (1)", 12, kr.getMatch(1).endPos);
assertEquals("Doc (1)", 0, kr.getMatch(1).internalDocID);
assertEquals("StartPos (2)", 0, kr.getMatch(2).startPos);
assertEquals("EndPos (2)", 12, kr.getMatch(2).endPos);
assertEquals("Doc (2)", 0, kr.getMatch(2).internalDocID);
assertEquals("StartPos (3)", 1, kr.getMatch(3).startPos);
assertEquals("EndPos (3)", 9, kr.getMatch(3).endPos);
assertEquals("Doc (3)", 0, kr.getMatch(3).internalDocID);
assertEquals("StartPos (4)", 1, kr.getMatch(4).startPos);
assertEquals("EndPos (4)", 9, kr.getMatch(4).endPos);
assertEquals("Doc (4)", 0, kr.getMatch(4).internalDocID);
assertEquals("StartPos (5)", 2, kr.getMatch(5).startPos);
assertEquals("EndPos (5)", 6, kr.getMatch(5).endPos);
assertEquals("Doc (5)", 0, kr.getMatch(5).internalDocID);
assertEquals(2, ki.numberOf("documents"));
}
use of de.ids_mannheim.korap.KrillIndex in project Krill by KorAP.
the class TestWithinIndex method indexExample3Offsets.
@Test
public void indexExample3Offsets() throws IOException {
KrillIndex ki = new KrillIndex();
// Er schrie: <s>"Das war ich!"</s>
FieldDocument fd = new FieldDocument();
fd = new FieldDocument();
fd.addTV("base", "Er schrie: \"Das war ich!\" und ging.", "[(0-2)s:Er|_0$<i>0<i>3]" + "[(3-9)s:schrie|_1$<i>3<i>9]" + "[(12-15)s:Das|_2$<i>12<i>15|<>:sentence$<b>64<i>11<i>25<i>5<b>0]" + "[(16-19)s:war|_3$<i>16<i>19]" + "[(20-23)s:ich|_4$<i>20<i>23]" + "[(26-29)s:und|_5$<i>26<i>29]" + "[(30-34)s:ging|_6$<i>30<i>34]");
ki.addDoc(fd);
// Save documents
ki.commit();
SpanQuery sq = new SpanClassQuery(new SpanElementQuery("base", "sentence"), (byte) 3);
Result kr;
kr = ki.search(sq, 0, (short) 15, true, (short) 1, true, (short) 1);
assertEquals("totalResults", kr.getTotalResults(), 1);
assertEquals("... schrie: [[\"{3:Das war ich}!\"]] und ...", kr.getMatch(0).getSnippetBrackets());
assertEquals("<span class=\"context-left\"><span class=\"more\"></span>schrie: </span><span class=\"match\"><mark>"<mark class=\"class-3 level-0\">Das war ich</mark>!"</mark></span><span class=\"context-right\"> und<span class=\"more\"></span></span>", kr.getMatch(0).getSnippetHTML());
kr = ki.search(sq, 0, (short) 15, true, (short) 0, true, (short) 0);
assertEquals("... [[\"{3:Das war ich}!\"]] ...", kr.getMatch(0).getSnippetBrackets());
assertEquals("totalResults", kr.getTotalResults(), 1);
kr = ki.search(sq, 0, (short) 15, true, (short) 6, true, (short) 6);
assertEquals("Er schrie: [[\"{3:Das war ich}!\"]] und ging.", kr.getMatch(0).getSnippetBrackets());
assertEquals("totalResults", kr.getTotalResults(), 1);
kr = ki.search(sq, 0, (short) 15, true, (short) 2, true, (short) 2);
assertEquals("Er schrie: [[\"{3:Das war ich}!\"]] und ging ...", kr.getMatch(0).getSnippetBrackets());
assertEquals("totalResults", kr.getTotalResults(), 1);
sq = new SpanClassQuery(new SpanWithinQuery(new SpanElementQuery("base", "sentence"), new SpanClassQuery(new SpanTermQuery(new Term("base", "s:Das")), (byte) 2)), (byte) 1);
kr = ki.search(sq, (short) 15);
assertEquals("Er schrie: [[\"{1:{2:Das} war ich}!\"]] und ging.", kr.getMatch(0).getSnippetBrackets());
assertEquals("totalResults", kr.getTotalResults(), 1);
sq = new SpanClassQuery(new SpanWithinQuery(new SpanElementQuery("base", "sentence"), new SpanClassQuery(new SpanTermQuery(new Term("base", "s:war")), (byte) 2)), (byte) 1);
kr = ki.search(sq, (short) 15);
assertEquals("Er schrie: [[\"{1:Das {2:war} ich}!\"]] und ging.", kr.getMatch(0).getSnippetBrackets());
assertEquals("totalResults", kr.getTotalResults(), 1);
sq = new SpanClassQuery(new SpanWithinQuery(new SpanElementQuery("base", "sentence"), new SpanClassQuery(new SpanTermQuery(new Term("base", "s:ich")), (byte) 2)), (byte) 1);
kr = ki.search(sq, (short) 15);
assertEquals("Er schrie: [[\"{1:Das war {2:ich}}!\"]] und ging.", kr.getMatch(0).getSnippetBrackets());
assertEquals("totalResults", kr.getTotalResults(), 1);
sq = new SpanClassQuery(new SpanWithinQuery(new SpanElementQuery("base", "sentence"), new SpanClassQuery(new SpanTermQuery(new Term("base", "s:und")), (byte) 2)), (byte) 1);
kr = ki.search(sq, (short) 15);
assertEquals("totalResults", kr.getTotalResults(), 0);
sq = new SpanClassQuery(new SpanWithinQuery(new SpanElementQuery("base", "sentence"), new SpanClassQuery(new SpanTermQuery(new Term("base", "s:schrie")), (byte) 2)), (byte) 1);
kr = ki.search(sq, (short) 15);
assertEquals("totalResults", kr.getTotalResults(), 0);
}
Aggregations