Search in sources :

Example 31 with KrillIndex

use of de.ids_mannheim.korap.KrillIndex in project Krill by KorAP.

the class TestKrillCollectionIndex method testIndexWithNegation3.

@Test
public void testIndexWithNegation3() throws IOException {
    // This is identical to above but the operands are switched
    ki = new KrillIndex();
    ki.addDoc(createDoc1());
    ki.commit();
    ki.addDoc(createDoc2());
    ki.commit();
    ki.addDoc(createDoc3());
    ki.commit();
    CollectionBuilder cb = new CollectionBuilder();
    KrillCollection kcn = new KrillCollection(ki);
    // orGroup with simple Negation
    kcn.fromBuilder(cb.orGroup().with(cb.term("author", "Peter")).with(cb.term("textClass", "kultur").not()));
    assertEquals(2, kcn.docCount());
    kcn.fromBuilder(cb.orGroup().with(cb.term("author", "Sebastian")).with(cb.term("textClass", "kultur").not()));
    assertEquals(1, kcn.docCount());
    kcn.fromBuilder(cb.andGroup().with(cb.term("author", "Sebastian").not()).with(cb.term("author", "Frank").not()));
    assertEquals("AndGroup(-author:Sebastian -author:Frank)", kcn.toString());
    assertEquals(1, kcn.docCount());
    kcn.fromBuilder(cb.andGroup().with(cb.andGroup().with(cb.term("author", "Sebastian").not()).with(cb.term("author", "Frank").not())).with(cb.term("author", "Peter")));
    assertEquals("AndGroup(AndGroup(-author:Sebastian -author:Frank) author:Peter)", kcn.toString());
    assertEquals(1, kcn.docCount());
    kcn.fromBuilder(cb.andGroup().with(cb.andGroup().with(cb.term("author", "Sebastian").not()).with(cb.term("author", "Frank").not())).with(cb.re("textClass", "reis..")));
    assertEquals("AndGroup(AndGroup(-author:Sebastian -author:Frank) QueryWrapperFilter(textClass:/reis../))", kcn.toString());
    assertEquals(1, kcn.docCount());
}
Also used : KrillIndex(de.ids_mannheim.korap.KrillIndex) KrillCollection(de.ids_mannheim.korap.KrillCollection) Test(org.junit.Test)

Example 32 with KrillIndex

use of de.ids_mannheim.korap.KrillIndex 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) TestSimple.getJsonString(de.ids_mannheim.korap.TestSimple.getJsonString) 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 33 with KrillIndex

use of de.ids_mannheim.korap.KrillIndex in project Krill by KorAP.

the class TestKrillCollectionIndex method testKrillCollectionWithWrongJson.

@Test
public void testKrillCollectionWithWrongJson() throws IOException {
    ki = new KrillIndex();
    ki.addDoc(createDoc1());
    ki.addDoc(createDoc2());
    ki.addDoc(createDoc3());
    ki.commit();
    KrillCollection kc = new KrillCollection("{lalala}");
    assertEquals("Unable to parse JSON", kc.getError(0).getMessage());
    kc.setIndex(ki);
    long docs = 0, tokens = 0, sentences = 0, paragraphs = 0;
    try {
        docs = kc.numberOf("documents");
        tokens = kc.numberOf("tokens");
        sentences = kc.numberOf("sentences");
        paragraphs = kc.numberOf("paragraphs");
    } catch (IOException e) {
        e.printStackTrace();
    }
    assertEquals(0, docs);
    assertEquals(0, tokens);
    assertEquals(0, sentences);
    assertEquals(0, paragraphs);
    assertEquals(1, kc.getErrors().size());
    assertEquals(StatusCodes.UNABLE_TO_PARSE_JSON, kc.getErrors().get(0).getCode());
}
Also used : IOException(java.io.IOException) KrillIndex(de.ids_mannheim.korap.KrillIndex) KrillCollection(de.ids_mannheim.korap.KrillCollection) Test(org.junit.Test)

Example 34 with KrillIndex

use of de.ids_mannheim.korap.KrillIndex in project Krill by KorAP.

the class Resource method _initResponse.

private Response _initResponse() {
    Response kresp = new Response();
    kresp.setNode(Node.getName());
    kresp.setListener(Node.getListener());
    // Get index
    KrillIndex index = Node.getIndex();
    if (index == null) {
        kresp.addError(601, "Unable to find index");
        return kresp;
    }
    ;
    kresp.setVersion(index.getVersion());
    kresp.setName(index.getName());
    return kresp;
}
Also used : Response(de.ids_mannheim.korap.response.Response) KrillIndex(de.ids_mannheim.korap.KrillIndex)

Example 35 with KrillIndex

use of de.ids_mannheim.korap.KrillIndex in project Krill by KorAP.

the class Resource method match.

@GET
@Path("/match/{matchID}")
@Produces(MediaType.APPLICATION_JSON)
public String match(@PathParam("matchID") String id, @Context UriInfo uri) {
    Response kresp = _initResponse();
    if (kresp.hasErrors())
        return kresp.toJsonString();
    // Get index
    KrillIndex index = Node.getIndex();
    // Get query parameters
    MultivaluedMap<String, String> qp = uri.getQueryParameters();
    boolean includeSpans = false, includeHighlights = true, extendToSentence = false, info = false;
    // Optional query parameter "info" for more information on the match
    if (!_isNull(qp.getFirst("info")))
        info = true;
    // Optional query parameter "spans" for span information inclusion
    if (!_isNull(qp.getFirst("spans"))) {
        includeSpans = true;
        info = true;
    }
    ;
    // Optional query parameter "highlights" for highlight information inclusion
    String highlights = qp.getFirst("highlights");
    if (highlights != null && _isNull(highlights))
        includeHighlights = false;
    // Optional query parameter "extended" for sentence expansion
    if (!_isNull(qp.getFirst("extended")))
        extendToSentence = true;
    List<String> foundries = qp.get("foundry");
    List<String> layers = qp.get("layer");
    try {
        // Get match info
        return index.getMatchInfo(id, "tokens", info, foundries, layers, includeSpans, includeHighlights, extendToSentence).toJsonString();
    }// Nothing found
     catch (QueryException qe) {
        // Todo: Make Match rely on Response!
        kresp.addError(qe.getErrorCode(), qe.getMessage());
    }
    ;
    return kresp.toJsonString();
}
Also used : Response(de.ids_mannheim.korap.response.Response) QueryException(de.ids_mannheim.korap.util.QueryException) KrillIndex(de.ids_mannheim.korap.KrillIndex) Path(jakarta.ws.rs.Path) Produces(jakarta.ws.rs.Produces) GET(jakarta.ws.rs.GET)

Aggregations

KrillIndex (de.ids_mannheim.korap.KrillIndex)321 Test (org.junit.Test)310 Result (de.ids_mannheim.korap.response.Result)143 SpanQuery (org.apache.lucene.search.spans.SpanQuery)132 Term (org.apache.lucene.index.Term)93 SpanTermQuery (org.apache.lucene.search.spans.SpanTermQuery)84 Krill (de.ids_mannheim.korap.Krill)82 QueryBuilder (de.ids_mannheim.korap.query.QueryBuilder)56 SpanElementQuery (de.ids_mannheim.korap.query.SpanElementQuery)42 KrillCollection (de.ids_mannheim.korap.KrillCollection)39 TestSimple.getJsonString (de.ids_mannheim.korap.TestSimple.getJsonString)38 SpanNextQuery (de.ids_mannheim.korap.query.SpanNextQuery)37 Match (de.ids_mannheim.korap.response.Match)37 FieldDocument (de.ids_mannheim.korap.index.FieldDocument)33 JsonNode (com.fasterxml.jackson.databind.JsonNode)28 DistanceConstraint (de.ids_mannheim.korap.query.DistanceConstraint)27 SpanQueryWrapper (de.ids_mannheim.korap.query.wrap.SpanQueryWrapper)26 SpanClassQuery (de.ids_mannheim.korap.query.SpanClassQuery)25 SpanDistanceQuery (de.ids_mannheim.korap.query.SpanDistanceQuery)20 SpanWithinQuery (de.ids_mannheim.korap.query.SpanWithinQuery)18