Search in sources :

Example 11 with KrillCollection

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"));
}
Also used : KrillIndex(de.ids_mannheim.korap.KrillIndex) KrillCollection(de.ids_mannheim.korap.KrillCollection) Test(org.junit.Test)

Example 12 with KrillCollection

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());
}
Also used : CollectionBuilder(de.ids_mannheim.korap.collection.CollectionBuilder) FieldDocument(de.ids_mannheim.korap.index.FieldDocument) KrillIndex(de.ids_mannheim.korap.KrillIndex) KrillCollection(de.ids_mannheim.korap.KrillCollection) Test(org.junit.Test)

Example 13 with KrillCollection

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());
}
Also used : Krill(de.ids_mannheim.korap.Krill) SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) SearchContext(de.ids_mannheim.korap.response.SearchContext) Term(org.apache.lucene.index.Term) FieldDocument(de.ids_mannheim.korap.index.FieldDocument) KrillIndex(de.ids_mannheim.korap.KrillIndex) KrillCollection(de.ids_mannheim.korap.KrillCollection) SpanQuery(org.apache.lucene.search.spans.SpanQuery) Result(de.ids_mannheim.korap.response.Result) Test(org.junit.Test)

Example 14 with KrillCollection

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"));
}
Also used : Krill(de.ids_mannheim.korap.Krill) TestSimple.getJsonString(de.ids_mannheim.korap.TestSimple.getJsonString) KrillIndex(de.ids_mannheim.korap.KrillIndex) KrillCollection(de.ids_mannheim.korap.KrillCollection) Result(de.ids_mannheim.korap.response.Result) Test(org.junit.Test)

Example 15 with KrillCollection

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());
}
Also used : Krill(de.ids_mannheim.korap.Krill) TestSimple.getJsonString(de.ids_mannheim.korap.TestSimple.getJsonString) KrillIndex(de.ids_mannheim.korap.KrillIndex) KrillCollection(de.ids_mannheim.korap.KrillCollection) Result(de.ids_mannheim.korap.response.Result) Test(org.junit.Test)

Aggregations

KrillCollection (de.ids_mannheim.korap.KrillCollection)37 Test (org.junit.Test)35 KrillIndex (de.ids_mannheim.korap.KrillIndex)24 Krill (de.ids_mannheim.korap.Krill)17 Result (de.ids_mannheim.korap.response.Result)15 CollectionBuilder (de.ids_mannheim.korap.collection.CollectionBuilder)11 SearchContext (de.ids_mannheim.korap.response.SearchContext)5 MMapDirectory (org.apache.lucene.store.MMapDirectory)5 TestSimple.getJsonString (de.ids_mannheim.korap.TestSimple.getJsonString)4 FieldDocument (de.ids_mannheim.korap.index.FieldDocument)4 QueryBuilder (de.ids_mannheim.korap.query.QueryBuilder)3 Term (org.apache.lucene.index.Term)2 SpanQuery (org.apache.lucene.search.spans.SpanQuery)2 SpanTermQuery (org.apache.lucene.search.spans.SpanTermQuery)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 SpanClassQuery (de.ids_mannheim.korap.query.SpanClassQuery)1 SpanDistanceQuery (de.ids_mannheim.korap.query.SpanDistanceQuery)1 SpanElementQuery (de.ids_mannheim.korap.query.SpanElementQuery)1 SpanFocusQuery (de.ids_mannheim.korap.query.SpanFocusQuery)1