Search in sources :

Example 6 with CollectionBuilder

use of de.ids_mannheim.korap.collection.CollectionBuilder in project Krill by KorAP.

the class TestKrillCollectionIndex method testIndexWithDateRanges.

@Test
public void testIndexWithDateRanges() throws IOException {
    ki = new KrillIndex();
    ki.addDoc(createDoc1());
    ki.addDoc(createDoc2());
    ki.addDoc(createDoc3());
    ki.commit();
    CollectionBuilder cb = new CollectionBuilder();
    KrillCollection kcn = new KrillCollection(ki);
    kcn.fromBuilder(cb.date("pubDate", "2005"));
    assertEquals(3, kcn.docCount());
    kcn.fromBuilder(cb.date("pubDate", "2005-12"));
    assertEquals(3, kcn.docCount());
    kcn.fromBuilder(cb.date("pubDate", "2005-12-10"));
    assertEquals(1, kcn.docCount());
    kcn.fromBuilder(cb.date("pubDate", "2005-12-16"));
    assertEquals(1, kcn.docCount());
    kcn.fromBuilder(cb.date("pubDate", "2005-12-07"));
    assertEquals(1, kcn.docCount());
    kcn.fromBuilder(cb.since("pubDate", "2005-12-07"));
    assertEquals(3, kcn.docCount());
    kcn.fromBuilder(cb.since("pubDate", "2005-12-10"));
    assertEquals(2, kcn.docCount());
    kcn.fromBuilder(cb.since("pubDate", "2005-12-16"));
    assertEquals(1, kcn.docCount());
    kcn.fromBuilder(cb.till("pubDate", "2005-12-16"));
    assertEquals(3, kcn.docCount());
    kcn.fromBuilder(cb.till("pubDate", "2005-12-10"));
    assertEquals(2, kcn.docCount());
    kcn.fromBuilder(cb.till("pubDate", "2005-12-07"));
    assertEquals(1, kcn.docCount());
    kcn.fromBuilder(cb.date("pubDate", "2005-12-10").not());
    assertEquals(2, kcn.docCount());
    kcn.fromBuilder(cb.date("pubDate", "2005-12-16").not());
    assertEquals(2, kcn.docCount());
    kcn.fromBuilder(cb.date("pubDate", "2005-12-07").not());
    assertEquals(2, kcn.docCount());
    kcn.fromBuilder(cb.date("pubDate", "2005-12-09").not());
    assertEquals(3, kcn.docCount());
    kcn.fromBuilder(cb.till("pubDate", "2005-12-16").not());
    assertEquals(0, kcn.docCount());
    kcn.fromBuilder(cb.till("pubDate", "2005-12-15").not());
    assertEquals(1, kcn.docCount());
    kcn.fromBuilder(cb.till("pubDate", "2005-12-10").not());
    assertEquals(1, kcn.docCount());
    kcn.fromBuilder(cb.till("pubDate", "2005-12-09").not());
    assertEquals(2, kcn.docCount());
    kcn.fromBuilder(cb.till("pubDate", "2005-12-07").not());
    assertEquals(2, kcn.docCount());
    kcn.fromBuilder(cb.till("pubDate", "2005-12-06").not());
    assertEquals(3, kcn.docCount());
}
Also used : CollectionBuilder(de.ids_mannheim.korap.collection.CollectionBuilder) KrillIndex(de.ids_mannheim.korap.KrillIndex) KrillCollection(de.ids_mannheim.korap.KrillCollection) Test(org.junit.Test)

Example 7 with CollectionBuilder

use of de.ids_mannheim.korap.collection.CollectionBuilder in project Krill by KorAP.

the class TestKrillCollectionIndex method testIndexWithCollectionBuilder.

@Test
public void testIndexWithCollectionBuilder() throws IOException {
    ki = new KrillIndex();
    ki.addDoc(createDoc1());
    ki.addDoc(createDoc2());
    ki.addDoc(createDoc3());
    ki.commit();
    CollectionBuilder cb = new CollectionBuilder();
    KrillCollection kcn = new KrillCollection(ki);
    // Simple string tests
    kcn.fromBuilder(cb.term("author", "Frank"));
    assertEquals(1, kcn.docCount());
    kcn.fromBuilder(cb.term("author", "Peter"));
    assertEquals(1, kcn.docCount());
    kcn.fromBuilder(cb.term("author", "Sebastian"));
    assertEquals(1, kcn.docCount());
    kcn.fromBuilder(cb.term("author", "Michael"));
    assertEquals(0, kcn.docCount());
    kcn.fromBuilder(cb.term("nothing", "nothing"));
    assertEquals(0, kcn.docCount());
    kcn.fromBuilder(cb.term("textClass", "reisen"));
    assertEquals(3, kcn.docCount());
    kcn.fromBuilder(cb.term("textClass", "kultur"));
    assertEquals(2, kcn.docCount());
    kcn.fromBuilder(cb.term("textClass", "finanzen"));
    assertEquals(1, kcn.docCount());
    // Simple orGroup tests
    kcn.fromBuilder(cb.orGroup().with(cb.term("author", "Frank")).with(cb.term("author", "Michael")));
    assertEquals(1, kcn.docCount());
    kcn.fromBuilder(cb.orGroup().with(cb.term("author", "Frank")).with(cb.term("author", "Sebastian")));
    assertEquals(2, kcn.docCount());
    kcn.fromBuilder(cb.orGroup().with(cb.term("author", "Frank")).with(cb.term("author", "Sebastian")).with(cb.term("author", "Peter")));
    assertEquals(3, kcn.docCount());
    kcn.fromBuilder(cb.orGroup().with(cb.term("author", "Huhu")).with(cb.term("author", "Haha")).with(cb.term("author", "Hehe")));
    assertEquals(0, kcn.docCount());
    // Multi field orGroup tests
    kcn.fromBuilder(cb.orGroup().with(cb.term("ID", "doc-1")).with(cb.term("author", "Peter")));
    assertEquals(2, kcn.docCount());
    kcn.fromBuilder(cb.orGroup().with(cb.term("ID", "doc-1")).with(cb.term("author", "Frank")));
    assertEquals(1, kcn.docCount());
    kcn.fromBuilder(cb.orGroup().with(cb.term("ID", "doc-1")).with(cb.term("author", "Michael")));
    assertEquals(1, kcn.docCount());
    // Simple andGroup tests
    kcn.fromBuilder(cb.andGroup().with(cb.term("author", "Frank")).with(cb.term("author", "Michael")));
    assertEquals(0, kcn.docCount());
    kcn.fromBuilder(cb.andGroup().with(cb.term("ID", "doc-1")).with(cb.term("author", "Frank")));
    assertEquals(1, kcn.docCount());
    // andGroup in keyword field test
    kcn.fromBuilder(cb.andGroup().with(cb.term("textClass", "reisen")).with(cb.term("textClass", "finanzen")));
    assertEquals(1, kcn.docCount());
    kcn.fromBuilder(cb.andGroup().with(cb.term("textClass", "reisen")).with(cb.term("textClass", "kultur")));
    assertEquals(2, kcn.docCount());
    kcn.fromBuilder(cb.andGroup().with(cb.term("textClass", "finanzen")).with(cb.term("textClass", "kultur")));
    assertEquals(0, kcn.docCount());
    kcn.fromBuilder(cb.term("text", "mann"));
    assertEquals(3, kcn.docCount());
    kcn.fromBuilder(cb.term("text", "frau"));
    assertEquals(1, kcn.docCount());
}
Also used : CollectionBuilder(de.ids_mannheim.korap.collection.CollectionBuilder) KrillIndex(de.ids_mannheim.korap.KrillIndex) KrillCollection(de.ids_mannheim.korap.KrillCollection) Test(org.junit.Test)

Example 8 with CollectionBuilder

use of de.ids_mannheim.korap.collection.CollectionBuilder in project Krill by KorAP.

the class TestKrillCollectionIndex method testIndexWithNegation.

@Test
public void testIndexWithNegation() throws IOException {
    ki = new KrillIndex();
    ki.addDoc(createDoc1());
    ki.addDoc(createDoc2());
    ki.addDoc(createDoc3());
    ki.commit();
    CollectionBuilder cb = new CollectionBuilder();
    KrillCollection kcn = new KrillCollection(ki);
    // Simple negation tests
    kcn.fromBuilder(cb.term("author", "Frank").not());
    assertEquals(2, kcn.docCount());
    kcn.fromBuilder(cb.term("textClass", "reisen").not());
    assertEquals(0, kcn.docCount());
    kcn.fromBuilder(cb.term("textClass", "kultur").not());
    assertEquals(1, kcn.docCount());
    // orGroup with simple Negation
    kcn.fromBuilder(cb.orGroup().with(cb.term("textClass", "kultur").not()).with(cb.term("author", "Peter")));
    assertEquals(2, kcn.docCount());
    kcn.fromBuilder(cb.orGroup().with(cb.term("textClass", "kultur").not()).with(cb.term("author", "Sebastian")));
    assertEquals(1, kcn.docCount());
}
Also used : CollectionBuilder(de.ids_mannheim.korap.collection.CollectionBuilder) KrillIndex(de.ids_mannheim.korap.KrillIndex) KrillCollection(de.ids_mannheim.korap.KrillCollection) Test(org.junit.Test)

Example 9 with CollectionBuilder

use of de.ids_mannheim.korap.collection.CollectionBuilder 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 10 with CollectionBuilder

use of de.ids_mannheim.korap.collection.CollectionBuilder 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());
}
Also used : Krill(de.ids_mannheim.korap.Krill) KrillMeta(de.ids_mannheim.korap.KrillMeta) CollectionBuilder(de.ids_mannheim.korap.collection.CollectionBuilder) JsonNode(com.fasterxml.jackson.databind.JsonNode) TestSimple.getJsonString(de.ids_mannheim.korap.TestSimple.getJsonString) QueryBuilder(de.ids_mannheim.korap.query.QueryBuilder) KrillIndex(de.ids_mannheim.korap.KrillIndex) Result(de.ids_mannheim.korap.response.Result) Test(org.junit.Test)

Aggregations

CollectionBuilder (de.ids_mannheim.korap.collection.CollectionBuilder)33 Test (org.junit.Test)33 KrillCollection (de.ids_mannheim.korap.KrillCollection)11 KrillIndex (de.ids_mannheim.korap.KrillIndex)11 Krill (de.ids_mannheim.korap.Krill)5 Result (de.ids_mannheim.korap.response.Result)4 QueryBuilder (de.ids_mannheim.korap.query.QueryBuilder)3 TestSimple.getJsonString (de.ids_mannheim.korap.TestSimple.getJsonString)2 FieldDocument (de.ids_mannheim.korap.index.FieldDocument)2 SearchContext (de.ids_mannheim.korap.response.SearchContext)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 KrillMeta (de.ids_mannheim.korap.KrillMeta)1 SpanDistanceQuery (de.ids_mannheim.korap.query.SpanDistanceQuery)1