use of de.ids_mannheim.korap.response.Match in project Krill by KorAP.
the class TestHighlight method highlightEmptySpan.
@Test
public void highlightEmptySpan() throws IOException, QueryException {
KrillIndex ki = new KrillIndex();
// <>:s$<b>65<i>38<b>0
// <a>x<a>y<a>zhij</a>hij</a>hij</a>hij</a>
FieldDocument fd = new FieldDocument();
fd.addTV("base", "x y z h i j h i j h i j ", "[(0-3)s:x|<>:a$<b>64<i>0<i>3<i>12<b>0]" + "[(3-6)s:y|<>:a$<b>64<i>3<i>6<i>9<b>0]" + "[(6-9)s:z|<>:a$<b>64<i>6<i>9<i>6|<>:a$<b>65<i>6]" + "[(9-12)s:h<b>0]" + "[(12-15)s:i]" + "[(15-18)s:j]" + "[(18-21)s:h]" + "[(21-24)s:i]" + "[(24-27)s:j]" + "[(27-30)s:h]" + "[(30-33)s:i]" + "[(33-36)s:j]");
ki.addDoc(fd);
// Commit!
ki.commit();
QueryBuilder kq = new QueryBuilder("base");
SpanQuery q = (SpanQuery) kq.tag("a").toQuery();
Krill qs = new Krill(q);
qs.getMeta().getContext().left.setToken(true).setLength((short) 5);
qs.getMeta().getContext().right.setToken(true).setLength((short) 5);
Result kr = ki.search(qs);
assertEquals((long) 4, kr.getTotalResults());
Match km = kr.getMatch(2);
assertEquals("<span class=\"context-left\">" + "</span>" + "<span class=\"match\">" + "<mark>x y z </mark>" + "</span><span class=\"context-right\">h i j h i j h i j </span>", km.getSnippetHTML());
km = kr.getMatch(3);
assertEquals("<span class=\"context-left\"><span class=\"match\"></span></span>", km.getSnippetHTML());
}
use of de.ids_mannheim.korap.response.Match in project Krill by KorAP.
the class TestHighlight method checkHighlightsManually.
@Test
public void checkHighlightsManually() 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.seg("s:a")).append(kq.seg("s:b")).append(kq.seg("s:c")).toQuery());
Match km = kr.getMatch(0);
km.addHighlight(0, 1, (short) 7);
assertEquals("<span class=\"context-left\"></span><span class=\"match\"><mark><mark class=\"class-7 level-0\">ab</mark>c</mark></span><span class=\"context-right\"></span>", km.getSnippetHTML());
km.addHighlight(1, 2, (short) 6);
assertEquals("<span class=\"context-left\"></span><span class=\"match\"><mark><mark class=\"class-7 level-0\">a<mark class=\"class-6 level-1\">b</mark></mark><mark class=\"class-6 level-1\">c</mark></mark></span><span class=\"context-right\"></span>", km.getSnippetHTML());
km.addHighlight(0, 1, (short) 5);
assertEquals("[[{5:{7:a{6:b}}}{6:c}]]", km.getSnippetBrackets());
assertEquals("<span class=\"context-left\"></span><span class=\"match\"><mark><mark class=\"class-5 level-0\"><mark class=\"class-7 level-1\">a<mark class=\"class-6 level-2\">b</mark></mark></mark><mark class=\"class-6 level-2\">c</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 TestFieldDocument method indexExample2.
@Test
public void indexExample2() throws Exception {
String json = new String("{" + " \"fields\" : [" + " { " + " \"primaryData\" : \"abc\"" + " }," + " {" + " \"name\" : \"tokens\"," + " \"data\" : [" + " [ \"s:a\", \"i:a\", \"_0$<i>0<i>1\", \"-:t$<i>3\"]," + " [ \"s:b\", \"i:b\", \"_1$<i>1<i>2\" ]," + " [ \"s:c\", \"i:c\", \"_2$<i>2<i>3\" ]" + " ]" + " }" + " ]," + " \"corpusID\" : \"WPD\"," + " \"ID\" : \"WPD-AAA-00001\"," + " \"textClass\" : \"music entertainment\"," + " \"author\" : \"Peter Frankenfeld\"," + " \"pubDate\" : 20130617," + " \"title\" : \"Wikipedia\"," + " \"subTitle\" : \"Die freie Enzyklopädie\"," + " \"pubPlace\" : \"Bochum\"" + "}");
KrillIndex ki = new KrillIndex();
FieldDocument fd = ki.addDoc(json);
ki.commit();
assertEquals(fd.getPrimaryData(), "abc");
assertEquals(fd.getCorpusID(), "WPD");
assertEquals(fd.getID(), "WPD-AAA-00001");
assertEquals(fd.getTextClass(), "music entertainment");
assertEquals(fd.getAuthor(), "Peter Frankenfeld");
assertEquals(fd.getTitle(), "Wikipedia");
assertEquals(fd.getSubTitle(), "Die freie Enzyklopädie");
assertEquals(fd.getPubPlace(), "Bochum");
assertEquals(fd.getPubDate().toDisplay(), "2013-06-17");
QueryBuilder kq = new QueryBuilder("tokens");
Result kr = ki.search((SpanQuery) kq.seq(kq.nr(3, kq.seg("s:b"))).toQuery());
Match km = kr.getMatch(0);
assertEquals(km.getPrimaryData(), "abc");
assertEquals(km.getCorpusID(), "WPD");
assertEquals(km.getDocID(), "WPD-AAA-00001");
assertEquals(km.getTextClass(), "music entertainment");
assertEquals(km.getAuthor(), "Peter Frankenfeld");
assertEquals(km.getTitle(), "Wikipedia");
assertEquals(km.getSubTitle(), "Die freie Enzyklopädie");
assertEquals(km.getPubPlace(), "Bochum");
assertEquals(km.getPubDate().toDisplay(), "2013-06-17");
assertEquals(km.getSnippetBrackets(), "a[[{3:b}]]c");
}
use of de.ids_mannheim.korap.response.Match in project Krill by KorAP.
the class Result method getOverview.
/**
* Stringifies the matches to give a brief overview on
* the result. Mainly used for testing.
*
* @return The stringified matches
*/
public String getOverview() {
StringBuilder sb = new StringBuilder();
sb.append("Search for: ").append(this.serialQuery).append("\n");
int i = 1;
// Add matches as bracket strings
for (Match km : this.getMatches()) sb.append(i++).append(": ").append(km.getSnippetBrackets()).append(" (Doc ").append(km.getLocalDocID()).append(")\n");
return sb.toString();
}
use of de.ids_mannheim.korap.response.Match in project Krill by KorAP.
the class Result method toTokenListJsonString.
// For Collocation Analysis API
@Deprecated
public String toTokenListJsonString() {
ObjectNode json = (ObjectNode) mapper.valueToTree(super.toJsonNode());
// Meta data for paging
ObjectNode meta = json.has("meta") ? (ObjectNode) json.get("meta") : (ObjectNode) json.putObject("meta");
if (this.context != null)
meta.put("context", this.getContext().toJsonNode());
meta.put("itemsPerPage", this.itemsPerPage);
meta.put("startIndex", this.startIndex);
if (this.itemsPerResource > 0)
meta.put("itemsPerResource", this.itemsPerResource);
if (this.serialQuery != null)
meta.put("serialQuery", this.serialQuery);
ArrayNode array = json.putArray("matches");
// Add matches as token lists
for (Match km : this.getMatches()) array.add(km.toTokenList());
try {
return mapper.writeValueAsString(json);
} catch (Exception e) {
log.warn(e.getLocalizedMessage());
}
;
return "{}";
}
Aggregations