use of de.ids_mannheim.korap.response.SearchContext in project Krill by KorAP.
the class TestMatchIdentifier method snippetBugTest3.
@Test
public void snippetBugTest3() throws IOException, QueryException {
KrillIndex ki = new KrillIndex();
ki.addDoc(getClass().getResourceAsStream("/wiki/WPD17-H81-63495.json.gz"), true);
ki.commit();
Match km;
String snippet;
km = ki.getMatchInfo("match-WPD17/H81/63495-p88-91", "tokens", "xyz", "s", false, false, false);
km.setContext(new SearchContext(true, (short) 2, true, (short) 2));
snippet = km.getSnippetHTML();
assertEquals("<span class=\"context-left\">" + "<span class=\"more\"></span>" + "angesehen wurde. " + "</span>" + "<span class=\"match\">" + "<mark>Der alte Baum</mark>" + "</span>" + "<span class=\"context-right\">" + " war eine" + "<span class=\"more\"></span>" + "</span>", snippet);
// Expansion - no context
km = ki.getMatchInfo("match-WPD17/H81/63495-p88-91", "tokens", "xyz", "s", true, true, true);
snippet = km.getSnippetHTML();
assertEquals("<span class=\"context-left\">" + "</span>" + "<span class=\"match\">" + "<mark>Der alte Baum</mark>" + " war eine Sommerlinde (Tilia platyphyllos) , " + "der neue ist eine Winterlinde (Tilia cordata)." + "</span>" + "<span class=\"context-right\">" + "</span>", snippet);
// Addition context
/*
TODO: Support context nonetheless
km = ki.getMatchInfo("match-WPD17/H81/63495-p88-91", "tokens",
"xyz", "s", true, true, true);
km.setContext(new SearchContext(true, (short) 2, true, (short) 2));
snippet = km.getSnippetHTML();
assertEquals(
"<span class=\"context-left\">"+
"xyz"+
"</span>"+
"<span class=\"match\">"+
"<mark>Der alte Baum</mark>"+
" war eine Sommerlinde (Tilia platyphyllos) , "+
"der neue ist eine Winterlinde (Tilia cordata)."+
"</span>"+
"<span class=\"context-right\">"+
"xyz"+
"</span>",
snippet
);
*/
km = ki.getMatchInfo("match-WPD17/H81/63495-p88-91", "tokens", null, null, false, true, true);
snippet = km.getSnippetHTML();
assertEquals("<span class=\"context-left\"></span>" + "<span class=\"match\">" + "<mark>" + "<span title=\"tt/l:die\">" + "<span title=\"tt/p:ART\">Der</span>" + "</span>" + " " + "<span title=\"tt/l:alt\">" + "<span title=\"tt/p:ADJA\">alte</span>" + "</span>" + " " + "<span title=\"tt/l:Baum\">" + "<span title=\"tt/p:NN\">Baum</span>" + "</span>" + "</mark>" + " " + "<span title=\"tt/l:sein\">" + "<span title=\"tt/p:VAFIN\">war</span>" + "</span>" + " " + "<span title=\"tt/l:eine\">" + "<span title=\"tt/p:ART\">eine</span>" + "</span>" + " " + "<span title=\"tt/l:Sommerlinde\">" + "<span title=\"tt/l:Sommerlinde\">" + "<span title=\"tt/p:NE\">" + "<span title=\"tt/p:NN\">Sommerlinde</span>" + "</span>" + "</span>" + "</span>" + " (" + "<span title=\"tt/p:NE\">Tilia</span>" + " " + "<span title=\"tt/p:ADJA\">" + "<span title=\"tt/p:ADJD\">" + "<span title=\"tt/p:NE\">" + "<span title=\"tt/p:NN\">" + "<span title=\"tt/p:VVFIN\">platyphyllos</span>" + "</span>" + "</span>" + "</span>" + "</span>" + ") , " + "<span title=\"tt/l:die\">" + "<span title=\"tt/p:ART\">der</span>" + "</span>" + " " + "<span title=\"tt/l:neu\">" + "<span title=\"tt/p:ADJA\">neue</span>" + "</span>" + " " + "<span title=\"tt/l:sein\">" + "<span title=\"tt/p:VAFIN\">ist</span>" + "</span>" + " " + "<span title=\"tt/l:eine\">" + "<span title=\"tt/p:ART\">eine</span>" + "</span>" + " " + "<span title=\"tt/l:Winterlinde\">" + "<span title=\"tt/l:Winterlinde\">" + "<span title=\"tt/p:NE\">" + "<span title=\"tt/p:NN\">Winterlinde</span>" + "</span>" + "</span>" + "</span>" + " (" + "<span title=\"tt/p:NE\">Tilia</span>" + " " + "<span title=\"tt/p:NE\">cordata</span>" + ")." + "</span>" + "<span class=\"context-right\">" + "</span>", snippet);
km = ki.getMatchInfo("match-WPD17/H81/63495-p88-91", "tokens", "dereko", "s", true, true, true);
snippet = km.getSnippetHTML();
assertEquals("<span class=\"context-left\"></span>" + "<span class=\"match\">" + "<span title=\"dereko/s:s\">" + "<mark>Der alte Baum</mark>" + " war eine " + "<span title=\"dereko/s:ref\">Sommerlinde</span>" + " (" + "<span title=\"dereko/s:hi\">Tilia platyphyllos</span>" + ") , der neue ist eine " + "<span title=\"dereko/s:ref\">Winterlinde</span> (" + "<span title=\"dereko/s:hi\">Tilia cordata</span>" + "</span>" + ")." + "</span>" + "<span class=\"context-right\"></span>", snippet);
}
use of de.ids_mannheim.korap.response.SearchContext in project Krill by KorAP.
the class TestKrill method searchJSONSentenceContext.
@Test
public void searchJSONSentenceContext() throws IOException {
// Construct index
KrillIndex ki = new KrillIndex();
// Indexing test files
for (String i : new String[] { "00001", "00002", "00003", "00004", "00005", "00006", "02439" }) {
ki.addDoc(getClass().getResourceAsStream("/wiki/" + i + ".json.gz"), true);
}
;
ki.commit();
String json = getJsonString(getClass().getResource("/queries/bsp-context-2.jsonld").getFile());
Krill ks = new Krill(json);
ks.getMeta().setCutOff(false);
SearchContext sc = ks.getMeta().getContext();
sc.left.setLength((short) 10);
sc.right.setLength((short) 10);
Result kr = ks.apply(ki);
assertEquals(kr.getMatch(1).getSnippetBrackets(), "... dezimalen [[Wert]] 65 sowohl ...");
assertEquals(kr.getTotalResults(), 3);
assertEquals(0, kr.getStartIndex());
assertEquals(25, kr.getItemsPerPage());
assertFalse(kr.getContext().toJsonNode().toString().equals("\"base/s:s\""));
json = getJsonString(getClass().getResource("/queries/bsp-context-sentence.jsonld").getFile());
kr = new Krill(json).apply(ki);
assertEquals(kr.getContext().toJsonNode().toString(), "\"base/s:s\"");
assertEquals(kr.getMatch(0).getSnippetBrackets(), "steht a für den dezimalen [[Wert]] 97 sowohl im ASCII-" + " als auch im Unicode-Zeichensatz");
assertEquals(kr.getMatch(1).getSnippetBrackets(), "steht A für den dezimalen [[Wert]] 65 sowohl im ASCII-" + " als auch im Unicode-Zeichensatz");
assertEquals(kr.getMatch(2).getSnippetBrackets(), "In einem Zahlensystem mit einer Basis größer " + "als 10 steht A oder a häufig für den dezimalen" + " [[Wert]] 10, siehe auch Hexadezimalsystem.");
}
Aggregations