use of de.ids_mannheim.korap.KrillCollection in project Krill by KorAP.
the class TestKrillCollectionIndex method filterExampleWithNullresult.
@Test
public void filterExampleWithNullresult() throws Exception {
// Construct index
KrillIndex ki = new KrillIndex();
// Indexing test files
for (String i : new String[] { "00001", "00002" }) {
ki.addDoc(getClass().getResourceAsStream("/wiki/" + i + ".json.gz"), true);
}
;
ki.commit();
// Create Virtual collections:
KrillCollection kc = new KrillCollection(ki);
assertEquals("Documents", 2, kc.numberOf("documents"));
kc.fromBuilder(kc.build().term("textClass", "nichts"));
assertEquals("Documents", 0, kc.numberOf("documents"));
assertEquals("Tokens", 0, kc.numberOf("tokens"));
assertEquals("Sentences", 0, kc.numberOf("sentences"));
assertEquals("Paragraphs", 0, kc.numberOf("paragraphs"));
}
use of de.ids_mannheim.korap.KrillCollection in project Krill by KorAP.
the class TestKrillCollectionIndex method testIndexWithRegexes.
@Test
public void testIndexWithRegexes() throws IOException {
ki = new KrillIndex();
FieldDocument fd = ki.addDoc(createDoc1());
ki.addDoc(createDoc2());
ki.addDoc(createDoc3());
ki.commit();
CollectionBuilder cb = new CollectionBuilder();
KrillCollection kcn = new KrillCollection(ki);
kcn.fromBuilder(cb.re("author", "Fran.*"));
assertEquals(1, kcn.docCount());
kcn.fromBuilder(cb.re("author", "Blin.*"));
assertEquals(0, kcn.docCount());
kcn.fromBuilder(cb.re("author", "Frank|Peter"));
assertEquals(2, kcn.docCount());
// "Frau" requires text request!
kcn.fromBuilder(cb.text("text", "Frau"));
assertEquals(1, kcn.docCount());
kcn.fromBuilder(cb.term("text", "frau"));
assertEquals(1, kcn.docCount());
kcn.fromBuilder(cb.re("text", "fra."));
assertEquals(1, kcn.docCount());
kcn.fromBuilder(cb.re("text", "fra.|ma.n"));
assertEquals(3, kcn.docCount());
String sv = fd.doc.getField("text").stringValue();
assertEquals("Der alte Mann ging über die Straße", sv);
kcn.fromBuilder(cb.term("text", sv));
assertEquals(1, kcn.docCount());
}
use of de.ids_mannheim.korap.KrillCollection in project Krill by KorAP.
the class TestKrillCollectionIndex method uidCollectionLegacy.
@Test
public void uidCollectionLegacy() throws IOException {
// Construct index
KrillIndex ki = new KrillIndex();
// Indexing test files
int uid = 1;
for (String i : new String[] { "00001", "00002", "00003", "00004", "00005", "00006", "02439" }) {
FieldDocument fd = ki.addDoc(uid++, getClass().getResourceAsStream("/wiki/" + i + ".json.gz"), true);
}
;
ki.commit();
assertEquals("Documents", 7, ki.numberOf("documents"));
assertEquals("Paragraphs", 174, ki.numberOf("paragraphs"));
assertEquals("Sentences", 281, ki.numberOf("sentences"));
assertEquals("Tokens", 2661, ki.numberOf("tokens"));
SpanQuery sq = new SpanTermQuery(new Term("tokens", "s:der"));
Result kr = ki.search(sq, (short) 10);
assertEquals(86, kr.getTotalResults());
// Create Virtual collections:
KrillCollection kc = new KrillCollection();
kc.filterUIDs(new String[] { "2", "3", "4" });
kc.setIndex(ki);
assertEquals("Documents", 3, kc.numberOf("documents"));
assertEquals("Paragraphs", 46, kc.numberOf("paragraphs"));
assertEquals("Sentences", 103, kc.numberOf("sentences"));
assertEquals("Tokens", 1229, kc.numberOf("tokens"));
Krill ks = new Krill(sq);
ks.setCollection(kc).getMeta().setStartIndex(0).setCount((short) 20).setContext(new SearchContext(true, (short) 5, true, (short) 5));
kr = ks.apply(ki);
// kr = ki.search(kc, sq, 0, (short) 20, true, (short) 5, true, (short) 5);
assertEquals((long) 39, kr.getTotalResults());
}
use of de.ids_mannheim.korap.KrillCollection in project Krill by KorAP.
the class TestKrill method searchJSONstartPage.
@Test
public void searchJSONstartPage() 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-paging.jsonld").getFile());
Krill ks = new Krill(json);
Result kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 10);
assertEquals(5, kr.getStartIndex());
assertEquals(5, kr.getItemsPerPage());
json = getJsonString(getClass().getResource("/queries/bsp-cutoff.jsonld").getFile());
ks = ks = new Krill(json);
kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), -1);
assertEquals(2, kr.getStartIndex());
assertEquals(2, kr.getItemsPerPage());
json = getJsonString(getClass().getResource("/queries/metaquery9.jsonld").getFile());
KrillCollection kc = new KrillCollection(json);
kc.setIndex(ki);
assertEquals(7, kc.numberOf("documents"));
}
use of de.ids_mannheim.korap.KrillCollection in project Krill by KorAP.
the class TestKrill method searchJSONitemsPerResourceServer.
@Test
public void searchJSONitemsPerResourceServer() throws IOException {
/*
* This test is a server-only implementation of
* TestResource#testCollection
*/
// Construct index
KrillIndex ki = new KrillIndex();
// Indexing test files
int uid = 1;
for (String i : new String[] { "00001", "00002", "00003", "00004", "00005", "00006", "02439" }) {
ki.addDoc(uid++, getClass().getResourceAsStream("/wiki/" + i + ".json.gz"), true);
}
;
ki.commit();
String json = getJsonString(getClass().getResource("/queries/bsp-uid-example.jsonld").getFile());
Krill ks = new Krill(json);
ks.getMeta().setItemsPerResource(1);
KrillCollection kc = new KrillCollection();
kc.filterUIDs(new String[] { "1", "4" });
kc.setIndex(ki);
ks.setCollection(kc);
Result kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 2);
assertEquals(0, kr.getStartIndex());
assertEquals(25, kr.getItemsPerPage());
}
Aggregations