use of de.ids_mannheim.korap.query.QueryBuilder in project Krill by KorAP.
the class TestResult method checkJSONTokenResult.
@Test
public void checkJSONTokenResult() throws Exception {
KrillIndex ki = new KrillIndex();
FieldDocument fd = new FieldDocument();
fd.addString("ID", "doc-1");
fd.addString("UID", "1");
fd.addTV("base", "abab", "[(0-1)s:a|i:a|_0#0-1|-:t$<i>4]" + "[(1-2)s:b|i:b|_1#1-2]" + "[(2-3)s:a|i:c|_2#2-3]" + "[(3-4)s:b|i:a|_3#3-4]");
ki.addDoc(fd);
fd = new FieldDocument();
fd.addString("ID", "doc-2");
fd.addString("UID", "2");
fd.addTV("base", "aba", "[(0-1)s:a|i:a|_0#0-1|-:t$<i>3]" + "[(1-2)s:b|i:b|_1#1-2]" + "[(2-3)s:a|i:c|_2#2-3]");
ki.addDoc(fd);
// Commit!
ki.commit();
QueryBuilder kq = new QueryBuilder("base");
SpanQuery q = (SpanQuery) kq.seq(kq.seg("s:a")).append(kq.seg("s:b")).toQuery();
Result kr = ki.search(q);
assertEquals((long) 3, kr.getTotalResults());
ObjectMapper mapper = new ObjectMapper();
JsonNode res = mapper.readTree(kr.toTokenListJsonString());
assertEquals(3, res.at("/meta/totalResults").asInt());
assertEquals("spanNext(base:s:a, base:s:b)", res.at("/meta/serialQuery").asText());
assertEquals(0, res.at("/meta/startIndex").asInt());
assertEquals(25, res.at("/meta/itemsPerPage").asInt());
assertEquals("doc-1", res.at("/matches/0/textSigle").asText());
assertEquals(0, res.at("/matches/0/tokens/0/0").asInt());
assertEquals(1, res.at("/matches/0/tokens/0/1").asInt());
assertEquals(1, res.at("/matches/0/tokens/1/0").asInt());
assertEquals(2, res.at("/matches/0/tokens/1/1").asInt());
assertEquals("doc-1", res.at("/matches/1/textSigle").asText());
assertEquals(2, res.at("/matches/1/tokens/0/0").asInt());
assertEquals(3, res.at("/matches/1/tokens/0/1").asInt());
assertEquals(3, res.at("/matches/1/tokens/1/0").asInt());
assertEquals(4, res.at("/matches/1/tokens/1/1").asInt());
assertEquals("doc-2", res.at("/matches/2/textSigle").asText());
assertEquals(0, res.at("/matches/2/tokens/0/0").asInt());
assertEquals(1, res.at("/matches/2/tokens/0/1").asInt());
assertEquals(1, res.at("/matches/2/tokens/1/0").asInt());
assertEquals(2, res.at("/matches/2/tokens/1/1").asInt());
}
use of de.ids_mannheim.korap.query.QueryBuilder in project Krill by KorAP.
the class TestElementDistanceIndex method jsonQuery.
public static SpanQueryWrapper jsonQuery(String jsonFile) {
SpanQueryWrapper sqwi;
try {
String json = getString(jsonFile);
sqwi = new KrillQuery("tokens").fromKoral(json);
} catch (QueryException e) {
fail(e.getMessage());
sqwi = new QueryBuilder("tokens").seg("???");
}
return sqwi;
}
use of de.ids_mannheim.korap.query.QueryBuilder in project Krill by KorAP.
the class TestFieldDocument method jsonQuery.
public static SpanQueryWrapper jsonQuery(String jsonFile) {
SpanQueryWrapper sqwi;
try {
String json = getString(jsonFile);
sqwi = new KrillQuery("tokens").fromKoral(json);
} catch (QueryException e) {
fail(e.getMessage());
sqwi = new QueryBuilder("tokens").seg("???");
}
;
return sqwi;
}
use of de.ids_mannheim.korap.query.QueryBuilder in project Krill by KorAP.
the class TestMatchIndex method indexExample3.
@Test
public void indexExample3() throws Exception {
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();
Result kr;
QueryBuilder kq = new QueryBuilder("base");
SpanQuery sq = kq.nr(1, kq.seq(kq.seg("s:b")).append(kq.seg("s:a")).append(kq.nr(2, kq.seg("s:c")))).toQuery();
kr = ki.search(sq, 0, (short) 20, true, (short) 2, true, (short) 5);
assertEquals("totalResults", kr.getTotalResults(), 1);
assertEquals("SnippetBrackets (0)", "... ca[[{1:ba{2:c}}]]", kr.getMatch(0).getSnippetBrackets());
}
use of de.ids_mannheim.korap.query.QueryBuilder 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());
}
Aggregations