Search in sources :

Example 6 with KrillQuery

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

the class TestSpanExpansionIndex method testExpansionQueryBug3.

/**
 * Query rewrite bug
 *
 * @throws IOException
 */
@Test
public void testExpansionQueryBug3() throws IOException, QueryException {
    KrillIndex ki = new KrillIndex();
    ki.addDoc(createFieldDoc3());
    ki.addDoc(createFieldDoc4());
    ki.commit();
    String jsonPath = URLDecoder.decode(getClass().getResource("/queries/bugs/expansion_bug_3.jsonld").getFile(), "UTF-8");
    String json = readFile(jsonPath);
    KrillQuery kq = new KrillQuery("base");
    SpanQuery sq = kq.fromKoral(json).toQuery();
    assertEquals(sq.toString(), "focus(254: spanContain(<base:base/s:t />, {254: spanExpansion(base:s:c, []{0, 4}, right)}))");
    kr = ki.search(sq, (short) 10);
    assertEquals("[[c]]ab", kr.getMatch(0).getSnippetBrackets());
    assertEquals("[[ca]]b", kr.getMatch(1).getSnippetBrackets());
    assertEquals("[[cab]]", kr.getMatch(2).getSnippetBrackets());
    assertEquals("[[c]]e", kr.getMatch(3).getSnippetBrackets());
    assertEquals("[[ce]]", kr.getMatch(4).getSnippetBrackets());
    assertEquals(5, kr.getTotalResults());
    sq = kq.builder().tag("base/s:t").toQuery();
    assertEquals(sq.toString(), "<base:base/s:t />");
    kr = ki.search(sq, (short) 5);
    assertEquals("[[cab]]", kr.getMatch(0).getSnippetBrackets());
    assertEquals("[[ce]]", kr.getMatch(1).getSnippetBrackets());
    assertEquals(2, kr.getTotalResults());
}
Also used : KrillQuery(de.ids_mannheim.korap.KrillQuery) KrillIndex(de.ids_mannheim.korap.KrillIndex) SpanQuery(org.apache.lucene.search.spans.SpanQuery) Test(org.junit.Test)

Example 7 with KrillQuery

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

the class TestKrillQueryJSON method queryJSONelement.

@Test
public void queryJSONelement() throws QueryException {
    // <base/s=s>
    try {
        String json = getString(getClass().getResource("/queries/element/simple-element.jsonld").getFile());
        KrillQuery kq = new KrillQuery("tokens");
        assertEquals(kq.fromKoral(json).toQuery().toString(), "<tokens:base/s:s />");
    } 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 8 with KrillQuery

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

the class TestKrillQueryJSON method queryJSONflags2.

@Test
public void queryJSONflags2() throws QueryException {
    // buchstabe/i
    try {
        String json = getString(getClass().getResource("/queries/flags/unknown1.jsonld").getFile());
        KrillQuery kq = new KrillQuery("tokens");
        assertEquals(kq.fromKoral(json).toQuery().toString(), "tokens:s:buchstabe");
        assertEquals(kq.getWarning(0).getCode(), 748);
        json = getString(getClass().getResource("/queries/flags/unknown2.jsonld").getFile());
        kq = new KrillQuery("tokens");
        assertEquals(kq.fromKoral(json).toQuery().toString(), "tokens:i:buchstabe");
        assertEquals(kq.getWarning(0).getCode(), 748);
        json = getString(getClass().getResource("/queries/flags/unknown3.jsonld").getFile());
        kq = new KrillQuery("tokens");
        assertEquals(kq.fromKoral(json).toQuery().toString(), "tokens:i:buchstabe");
        assertEquals(kq.getWarning(0).getCode(), 748);
    } 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 9 with KrillQuery

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

the class TestKrillQueryJSON method queryJSONDemo.

@Test
public void queryJSONDemo() throws QueryException {
    SpanQueryWrapper sqwi = new KrillQuery("tokens").fromKoral("{ \"query\" : { \"@type\" : \"koral:token\", \"wrap\" : { \"@type\" : \"koral:term\", \"foundry\" : \"base\", \"layer\" : \"p\", \"key\" : \"foo\", \"match\" : \"match:eq\" }}}");
    assertEquals(sqwi.toQuery().toString(), "tokens:base/p:foo");
}
Also used : KrillQuery(de.ids_mannheim.korap.KrillQuery) SpanQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanQueryWrapper) Test(org.junit.Test)

Example 10 with KrillQuery

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

the class TestKrillQueryJSON method queryJSONregexRewrite1.

@Test
public void queryJSONregexRewrite1() throws QueryException {
    // "der" [.+?]
    String json = getString(getClass().getResource("/queries/sequence/regex-rewrite-1.jsonld").getFile());
    KrillQuery kq = new KrillQuery("tokens");
    assertEquals(kq.fromKoral(json).toQuery().toString(), "focus(254: spanContain(<tokens:base/s:t />, {254: spanExpansion(tokens:s:der, []{1, 1}, right)}))");
}
Also used : KrillQuery(de.ids_mannheim.korap.KrillQuery) Test(org.junit.Test)

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