use of de.ids_mannheim.korap.KrillMeta in project Krill by KorAP.
the class TestFieldDocument method indexExample3.
@Test
public void indexExample3() throws IOException {
// Construct index
KrillIndex ki = new KrillIndex();
// Indexing test files
for (String i : new String[] { "00001", "00002", "00003", "00004", "00005", "00006", "02439" }) {
FieldDocument fd = ki.addDoc(getClass().getResourceAsStream("/wiki/" + i + ".json.gz"), true);
}
;
ki.commit();
QueryBuilder kq = new QueryBuilder("tokens");
Krill ks;
Result kr;
// Start creating query
// within(<s>, {1: {2: [mate/p=ADJA & mate/m=number:sg]}[opennlp/p=NN & tt/p=NN]})
ks = new Krill(kq.within(kq.tag("base/s:s"), kq.nr(1, kq.seq(kq.seg("mate/p:ADJA")).append(kq.seg("opennlp/p:NN")))));
KrillMeta meta = ks.getMeta();
meta.setCount(1);
meta.setCutOff(true);
meta.getContext().left.setCharacter(true).setLength(6);
meta.getContext().right.setToken(true).setLength(6);
assertEquals("... okal. [[Der Buchstabe A hat in {1:deutschen Texten} eine durchschnittliche Häufigkeit von 6,51 %.]] Er ist damit der sechsthäufigste Buchstabe ...", ks.apply(ki).getMatch(0).getSnippetBrackets());
}
use of de.ids_mannheim.korap.KrillMeta in project Krill by KorAP.
the class TestKrill method searchIndex.
@Test
public void searchIndex() 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();
Krill ks = new Krill(new QueryBuilder("tokens").seg("s:Buchstaben"));
CollectionBuilder cb = new CollectionBuilder();
ks.getCollection().fromBuilder(cb.term("textClass", "reisen"));
KrillMeta meta = ks.getMeta();
meta.setCount(3);
meta.setStartIndex(5);
meta.getContext().left.setLength(1);
meta.getContext().right.setLength(1);
Result kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 6);
assertEquals(kr.getMatch(0).getSnippetBrackets(), "... dem [[Buchstaben]] A ...");
JsonNode res = ks.toJsonNode();
assertEquals(3, res.at("/meta/count").asInt());
assertEquals(5, res.at("/meta/startIndex").asInt());
assertEquals("token", res.at("/meta/context/left/0").asText());
assertEquals(1, res.at("/meta/context/left/1").asInt());
assertEquals("token", res.at("/meta/context/right/0").asText());
assertEquals(1, res.at("/meta/context/right/1").asInt());
}
use of de.ids_mannheim.korap.KrillMeta in project Krill by KorAP.
the class TestKrill method searchCount.
@Test
public void searchCount() {
Krill k = new Krill(new QueryBuilder("field1").seg("a").with("b"));
KrillMeta meta = k.getMeta();
// Count:
meta.setCount(30);
assertEquals(meta.getCount(), 30);
meta.setCount(20);
assertEquals(meta.getCount(), 20);
meta.setCount(-50);
assertEquals(meta.getCount(), 20);
meta.setCount(500);
assertEquals(meta.getCount(), meta.getCountMax());
}
use of de.ids_mannheim.korap.KrillMeta in project Krill by KorAP.
the class TestKrill method searchJSONitemsPerResource.
@Test
public void searchJSONitemsPerResource() 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-itemsPerResource.jsonld").getFile());
Krill ks = new Krill(json);
Result kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 10);
assertEquals(0, kr.getStartIndex());
assertEquals(20, kr.getItemsPerPage());
assertEquals("WPD_AAA.00001", kr.getMatch(0).getDocID());
assertEquals("WPD_AAA.00001", kr.getMatch(1).getDocID());
assertEquals("WPD_AAA.00001", kr.getMatch(6).getDocID());
assertEquals("WPD_AAA.00002", kr.getMatch(7).getDocID());
assertEquals("WPD_AAA.00002", kr.getMatch(8).getDocID());
assertEquals("WPD_AAA.00004", kr.getMatch(9).getDocID());
ks = new Krill(json);
ks.getMeta().setItemsPerResource(1);
kr = ks.apply(ki);
assertEquals("WPD_AAA.00001", kr.getMatch(0).getDocID());
assertEquals("WPD_AAA.00002", kr.getMatch(1).getDocID());
assertEquals("WPD_AAA.00004", kr.getMatch(2).getDocID());
assertEquals(kr.getTotalResults(), 3);
assertEquals(0, kr.getStartIndex());
assertEquals(20, kr.getItemsPerPage());
ks = new Krill(json);
ks.getMeta().setItemsPerResource(2);
kr = ks.apply(ki);
assertEquals("WPD_AAA.00001", kr.getMatch(0).getDocID());
assertEquals("WPD_AAA.00001", kr.getMatch(1).getDocID());
assertEquals("WPD_AAA.00002", kr.getMatch(2).getDocID());
assertEquals("WPD_AAA.00002", kr.getMatch(3).getDocID());
assertEquals("WPD_AAA.00004", kr.getMatch(4).getDocID());
assertEquals(kr.getTotalResults(), 5);
assertEquals(0, kr.getStartIndex());
assertEquals(20, kr.getItemsPerPage());
ks = new Krill(json);
KrillMeta meta = ks.getMeta();
meta.setItemsPerResource(1);
meta.setStartIndex(1);
meta.setCount(1);
kr = ks.apply(ki);
assertEquals("WPD_AAA.00002", kr.getMatch(0).getDocID());
assertEquals(kr.getTotalResults(), 3);
assertEquals(1, kr.getStartIndex());
assertEquals(1, kr.getItemsPerPage());
assertEquals((short) 1, kr.getItemsPerResource());
}
use of de.ids_mannheim.korap.KrillMeta in project Krill by KorAP.
the class TestKrill method searchStartIndex.
@Test
public void searchStartIndex() {
Krill k = new Krill(new QueryBuilder("field1").seg("a").with("b"));
KrillMeta meta = k.getMeta();
// startIndex
meta.setStartIndex(5);
assertEquals(meta.getStartIndex(), 5);
meta.setStartIndex(1);
assertEquals(meta.getStartIndex(), 1);
meta.setStartIndex(0);
assertEquals(meta.getStartIndex(), 0);
meta.setStartIndex(70);
assertEquals(meta.getStartIndex(), 70);
meta.setStartIndex(-5);
assertEquals(meta.getStartIndex(), 0);
}
Aggregations