Search in sources :

Example 11 with KrillQuery

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

the class TestKrillQueryJSON method queryJSONcomplexSpanOrTerm.

@Test
public void queryJSONcomplexSpanOrTerm() throws QueryException {
    // startsWith(<base/s=s>, { lassen | laufen })
    try {
        String json = getString(getClass().getResource("/queries/bugs/span_or_bug.jsonld").getFile());
        KrillQuery kq = new KrillQuery("tokens");
        assertEquals(kq.fromKoral(json).toQuery().toString(), "spanStartsWith(<tokens:base/s:s />, spanOr([tokens:s:Er, tokens:s:Sie]))");
    } catch (QueryException e) {
        fail(e.getMessage());
    }
    ;
}
Also used : QueryException(de.ids_mannheim.korap.util.QueryException) KrillQuery(de.ids_mannheim.korap.KrillQuery) Test(org.junit.Test)

Example 12 with KrillQuery

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

the class TestKrillQueryJSON method queryJSONunderspecifiedTokenBug.

@Test
public void queryJSONunderspecifiedTokenBug() {
    // ((MORPH(APPR) ODER MORPH(APPRART)) /+w1 Urlaub
    try {
        String json = getString(getClass().getResource("/queries/bugs/underspecified_token.jsonld").getFile());
        new KrillQuery("tokens").fromKoral(json);
    } catch (QueryException e) {
        assertEquals(701, e.getErrorCode());
    }
    ;
}
Also used : QueryException(de.ids_mannheim.korap.util.QueryException) KrillQuery(de.ids_mannheim.korap.KrillQuery) Test(org.junit.Test)

Example 13 with KrillQuery

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

the class TestSampleIndex method testWildcardsWithJson.

@Test
public void testWildcardsWithJson() throws IOException, QueryException {
    SpanQueryWrapper sqwi = getJSONQuery(getClass().getResource("/queries/bugs/cosmas_wildcards_all.jsonld").getFile());
    SpanQuery sq = sqwi.toQuery();
    kr = sample.search(sq, (short) 10);
    assertEquals(4, kr.getMatches().size());
    // test krill apply
    Krill krill = new Krill();
    krill.setSpanQuery(sq);
    krill.setIndex(sample);
    kr = krill.apply();
    assertEquals(4, kr.getMatches().size());
    // test krill deserialization
    String jsonString = getJsonString(getClass().getResource("/queries/bugs/cosmas_wildcards_all.jsonld").getFile());
    krill = new Krill();
    ObjectMapper mapper = new ObjectMapper();
    JsonNode jsonNode = mapper.readTree(jsonString);
    final KrillQuery kq = new KrillQuery("tokens");
    krill.setQuery(kq);
    SpanQueryWrapper qw = kq.fromKoral(jsonNode.get("query"));
    assertEquals(sqwi.toQuery(), qw.toQuery());
    krill.setSpanQuery(qw.toQuery());
    kr = krill.apply(sample);
    assertEquals(4, kr.getMatches().size());
}
Also used : Krill(de.ids_mannheim.korap.Krill) KrillQuery(de.ids_mannheim.korap.KrillQuery) JsonNode(com.fasterxml.jackson.databind.JsonNode) SpanQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanQueryWrapper) TestSimple.getJsonString(de.ids_mannheim.korap.TestSimple.getJsonString) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SpanQuery(org.apache.lucene.search.spans.SpanQuery) Test(org.junit.Test)

Example 14 with KrillQuery

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

the class TestElementDistanceIndex method jsonQuery.

public static SpanQueryWrapper jsonQuery(String jsonFile) {
    SpanQueryWrapper sqwi;
    try {
        String json = getString(jsonFile);
        sqwi = new KrillQuery("tokens").fromKoral(json);
    } catch (QueryException e) {
        fail(e.getMessage());
        sqwi = new QueryBuilder("tokens").seg("???");
    }
    return sqwi;
}
Also used : QueryException(de.ids_mannheim.korap.util.QueryException) KrillQuery(de.ids_mannheim.korap.KrillQuery) SpanQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanQueryWrapper) QueryBuilder(de.ids_mannheim.korap.query.QueryBuilder)

Example 15 with KrillQuery

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

the class TestFieldDocument method jsonQuery.

public static SpanQueryWrapper jsonQuery(String jsonFile) {
    SpanQueryWrapper sqwi;
    try {
        String json = getString(jsonFile);
        sqwi = new KrillQuery("tokens").fromKoral(json);
    } catch (QueryException e) {
        fail(e.getMessage());
        sqwi = new QueryBuilder("tokens").seg("???");
    }
    ;
    return sqwi;
}
Also used : QueryException(de.ids_mannheim.korap.util.QueryException) KrillQuery(de.ids_mannheim.korap.KrillQuery) SpanQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanQueryWrapper) QueryBuilder(de.ids_mannheim.korap.query.QueryBuilder)

Aggregations

KrillQuery (de.ids_mannheim.korap.KrillQuery)22 Test (org.junit.Test)17 SpanQueryWrapper (de.ids_mannheim.korap.query.wrap.SpanQueryWrapper)13 QueryException (de.ids_mannheim.korap.util.QueryException)10 KrillIndex (de.ids_mannheim.korap.KrillIndex)7 QueryBuilder (de.ids_mannheim.korap.query.QueryBuilder)5 SpanQuery (org.apache.lucene.search.spans.SpanQuery)4 Result (de.ids_mannheim.korap.response.Result)3 SpanWithinQuery (de.ids_mannheim.korap.query.SpanWithinQuery)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Krill (de.ids_mannheim.korap.Krill)1 TestSimple.getJsonString (de.ids_mannheim.korap.TestSimple.getJsonString)1 SpanNextQuery (de.ids_mannheim.korap.query.SpanNextQuery)1