use of de.ids_mannheim.korap.response.Match in project Krill by KorAP.
the class TestMatchIndex method indexExampleExtend.
@Test
public void indexExampleExtend() throws IOException {
KrillIndex ki = new KrillIndex();
// abcabcabac
FieldDocument fd = new FieldDocument();
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]" + "[(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]" + "[(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);
ki.commit();
SpanQuery sq;
Result kr;
sq = new SpanFocusQuery(new SpanNextQuery(new SpanClassQuery(new SpanTermQuery(new Term("base", "s:a")), (byte) 2), new SpanClassQuery(new SpanTermQuery(new Term("base", "s:b")), (byte) 3)), (byte) 3);
kr = ki.search(sq, (short) 10);
assertEquals("totalResults", kr.getTotalResults(), 3);
Match km = kr.getMatch(0);
assertEquals("StartPos (0)", 1, km.startPos);
assertEquals("EndPos (0)", 2, km.endPos);
assertEquals("SnippetBrackets (0)", "a[[{3:b}]]cabcab ...", km.getSnippetBrackets());
sq = new SpanFocusQuery(new SpanFocusQuery(new SpanNextQuery(new SpanClassQuery(new SpanTermQuery(new Term("base", "s:a")), (byte) 2), new SpanClassQuery(new SpanTermQuery(new Term("base", "s:b")), (byte) 3)), (byte) 3), (byte) 2);
kr = ki.search(sq, (short) 10);
km = kr.getMatch(0);
assertEquals("StartPos (0)", 0, km.startPos);
assertEquals("EndPos (0)", 1, km.endPos);
assertEquals("SnippetBrackets (0)", "[[{2:a}]]bcabca ...", km.getSnippetBrackets());
// TODO: Check ID
}
use of de.ids_mannheim.korap.response.Match in project Krill by KorAP.
the class TestHighlight method checkHighlights.
@Test
public void checkHighlights() throws IOException, QueryException {
KrillIndex ki = new KrillIndex();
String json = new String("{" + " \"fields\" : [" + " { " + " \"primaryData\" : \"abc\"" + " }," + " {" + " \"name\" : \"tokens\"," + " \"data\" : [" + " [ \"s:a\", \"i:a\", \"_0#0-1\", \"-:t$<i>3\"]," + " [ \"s:b\", \"i:b\", \"_1#1-2\" ]," + " [ \"s:c\", \"i:c\", \"_2#2-3\" ]" + " ]" + " }" + " ]" + "}");
FieldDocument fd = ki.addDoc(json);
ki.commit();
QueryBuilder kq = new QueryBuilder("tokens");
Result kr = ki.search((SpanQuery) kq.seq(kq.nr(1, kq.seg("s:b"))).toQuery());
Match km = kr.getMatch(0);
assertEquals(km.getStartPos(), 1);
assertEquals(km.getEndPos(), 2);
assertEquals(km.getStartPos(1), 1);
assertEquals(km.getEndPos(1), 2);
assertEquals("<span class=\"context-left\">a</span><span class=\"match\"><mark><mark class=\"class-1 level-0\">b</mark></mark></span><span class=\"context-right\">c</span>", km.getSnippetHTML());
kr = ki.search((SpanQuery) kq.seq(kq.nr(1, kq.seg("s:b"))).append(kq.nr(2, kq.seg("s:c"))).toQuery());
km = kr.getMatch(0);
assertEquals(km.getStartPos(), 1);
assertEquals(km.getEndPos(), 3);
assertEquals(km.getStartPos(1), 1);
assertEquals(km.getEndPos(1), 2);
assertEquals(km.getStartPos(2), 2);
assertEquals(km.getEndPos(2), 3);
assertEquals("<span class=\"context-left\">a</span><span class=\"match\"><mark><mark class=\"class-1 level-0\">b</mark><mark class=\"class-2 level-0\">c</mark></mark></span><span class=\"context-right\"></span>", km.getSnippetHTML());
kr = ki.search((SpanQuery) kq.seq(kq.nr(1, kq.seq(kq.seg("s:a")).append(kq.seg("s:b")))).append(kq.nr(2, kq.seg("s:c"))).toQuery());
km = kr.getMatch(0);
assertEquals(km.getStartPos(), 0);
assertEquals(km.getEndPos(), 3);
assertEquals(km.getStartPos(1), 0);
assertEquals(km.getEndPos(1), 2);
assertEquals(km.getStartPos(2), 2);
assertEquals(km.getEndPos(2), 3);
assertEquals("<span class=\"context-left\"></span><span class=\"match\"><mark><mark class=\"class-1 level-0\">ab</mark><mark class=\"class-2 level-0\">c</mark></mark></span><span class=\"context-right\"></span>", km.getSnippetHTML());
kr = ki.search((SpanQuery) kq.nr(3, kq.seq(kq.nr(1, kq.seq(kq.seg("s:a")).append(kq.seg("s:b")))).append(kq.nr(2, kq.seg("s:c")))).toQuery());
km = kr.getMatch(0);
assertEquals(km.getStartPos(), 0);
assertEquals(km.getEndPos(), 3);
assertEquals(km.getStartPos(1), 0);
assertEquals(km.getEndPos(1), 2);
assertEquals(km.getStartPos(2), 2);
assertEquals(km.getEndPos(2), 3);
assertEquals(km.getStartPos(3), 0);
assertEquals(km.getEndPos(3), 3);
assertEquals("<span class=\"context-left\"></span><span class=\"match\"><mark><mark class=\"class-3 level-0\"><mark class=\"class-1 level-1\">ab</mark><mark class=\"class-2 level-1\">c</mark></mark></mark></span><span class=\"context-right\"></span>", km.getSnippetHTML());
}
use of de.ids_mannheim.korap.response.Match in project Krill by KorAP.
the class TestHighlight method highlightEscapes.
@Test
public void highlightEscapes() throws IOException, QueryException {
KrillIndex ki = new KrillIndex();
FieldDocument fd = new FieldDocument();
fd.addString("ID", "doc-1");
fd.addString("UID", "1");
fd.addString("textSigle", "c1/d1/1");
// Make this clean for HTML and Brackets!
fd.addTV("base", "Mit \"Mann\" & {Ma\\us}", "[(0-3)s:Mit|i:mit|_0#0-3|-:t$<i>4|<>:base/t:t$<b>64<i>0<i>20<i>4<b>0]" + "[(4-10)s:\"Mann\"|i:\"mann\"|base/l:\"Mann\"|_1#4-10]" + "[(11-12)s:&|i:&|base/l:&|_2#11-12]" + "[(13-20)s:{Ma\\us}|i:{ma\\us}|_3#13-20]");
ki.addDoc(fd);
// Commit!
ki.commit();
QueryBuilder kq = new QueryBuilder("base");
SpanQuery q = (SpanQuery) kq.tag("base/t:t").toQuery();
Krill qs = new Krill(q);
qs.getMeta().getContext().left.setToken(true).setLength((short) 0);
qs.getMeta().getContext().right.setToken(true).setLength((short) 0);
Result kr = ki.search(qs);
assertEquals((long) 1, kr.getTotalResults());
assertEquals("[[Mit \"Mann\" & \\{Ma\\\\us\\}]]", kr.getMatch(0).getSnippetBrackets());
assertEquals("<span class=\"context-left\"></span><span class=\"match\"><mark>Mit "Mann" & {Ma\\us}</mark></span><span class=\"context-right\"></span>", kr.getMatch(0).getSnippetHTML());
assertEquals("match-c1/d1/1-p0-4", kr.getMatch(0).getID());
Match km = ki.getMatchInfo("match-c1/d1/1-p0-4", "base", true, (ArrayList) null, (ArrayList) null, true, true, false);
assertEquals(0, km.getStartPos());
assertEquals("<span class=\"context-left\"></span>" + "<span class=\"match\"><mark><span title=\"base/t:t\">" + "Mit " + "<span title=\"base/l:"Mann"\">" + ""Mann"" + "</span>" + " " + "<span title=\"base/l:&\">&</span>" + " " + "{Ma\\us}" + "</span>" + "</mark></span>" + "<span class=\"context-right\"></span>", km.getSnippetHTML());
}
use of de.ids_mannheim.korap.response.Match in project Krill by KorAP.
the class TestMatchIdentifier method indexExample4.
@Test
public void indexExample4() throws IOException, QueryException {
KrillIndex ki = new KrillIndex();
ki.addDoc(createSimpleFieldDoc());
ki.commit();
Match km = ki.getMatchInfo("match-c1!d1-p7-9(4)8-8(2)7-8", "tokens", null, null, false, false);
assertEquals("SnippetHTML (1)", "<span class=\"context-left\">" + "<span class=\"more\">" + "</span>" + "</span>" + "<span class=\"match\">" + "<mark>" + "<span title=\"f/m:acht\">" + "<span title=\"f/y:eight\">" + "<span title=\"it/is:8\">" + "<span title=\"x/o:achtens\">" + "b" + "</span>" + "</span>" + "</span>" + "</span>" + "<span title=\"f/m:neun\">" + "<span title=\"f/y:nine\">" + "<span title=\"it/is:9\">" + "<span title=\"x/o:neuntens\">" + "a" + "</span>" + "</span>" + "</span>" + "</span>" + "</mark>" + "</span>" + "<span class=\"context-right\">" + "<span class=\"more\">" + "</span>" + "</span>", km.getSnippetHTML());
}
use of de.ids_mannheim.korap.response.Match in project Krill by KorAP.
the class TestMatchIdentifier method indexExampleMultipleFoundries.
@Test
public void indexExampleMultipleFoundries() throws IOException, QueryException {
KrillIndex ki = new KrillIndex();
ki.addDoc(createSimpleFieldDoc4());
ki.commit();
Match km = ki.getMatchInfo("match-c1!d4-p3-9", "tokens", "f", "m", false, false);
assertEquals("f:m info", km.getSnippetBrackets(), "... [[{f/m:vier:a}{f/m:fuenf:b}{f/m:sechs:c}{f/m:sieben:a}{f/m:acht:b}{f/m:neun:a}]] ...");
km = ki.getMatchInfo("match-c1!d4-p3-9", "tokens", "f", null, false, false);
assertEquals("f info", km.getSnippetBrackets(), "... [[{f/m:vier:{f/y:four:a}}{f/m:fuenf:{f/y:five:b}}{f/m:sechs:{f/y:six:c}}{f/m:sieben:{f/y:seven:a}}{f/m:acht:{f/y:eight:b}}{f/m:neun:{f/y:nine:a}}]] ...");
km = ki.getMatchInfo("match-c1!d4-p3-4", "tokens", null, null, false, false);
assertEquals("all info", km.getSnippetBrackets(), "... [[{f/m:vier:{f/y:four:{it/is:4:{x/o:viertens:a}}}}]] ...");
ArrayList<String> foundryList = new ArrayList<>(2);
foundryList.add("f");
foundryList.add("x");
km = ki.getMatchInfo("match-c1!d4-p3-4", "tokens", true, foundryList, (ArrayList<String>) null, false, false, false);
assertEquals("f|x info", km.getSnippetBrackets(), "... [[{f/m:vier:{f/y:four:{x/o:viertens:a}}}]] ...");
foundryList.clear();
foundryList.add("y");
foundryList.add("x");
km = ki.getMatchInfo("match-c1!d4-p3-4", "tokens", true, foundryList, (ArrayList<String>) null, false, false, false);
assertEquals("y|x info", km.getSnippetBrackets(), "... [[{x/o:viertens:a}]] ...");
foundryList.clear();
foundryList.add("f");
foundryList.add("it");
ArrayList<String> layerList = new ArrayList<>(2);
layerList.add("is");
km = ki.getMatchInfo("match-c1!d4-p3-4", "tokens", true, foundryList, layerList, false, false, false);
assertEquals("f|it/is", km.getSnippetBrackets(), "... [[{it/is:4:a}]] ...");
}
Aggregations