Search in sources :

Example 16 with KrillQuery

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

the class TestClass method queryJSONpoly1.

@Test
public void queryJSONpoly1() throws QueryException, IOException {
    String jsonPath = URLDecoder.decode(getClass().getResource("/queries/poly1.json").getFile(), "UTF-8");
    String jsonQuery = readFile(jsonPath);
    SpanQueryWrapper sqwi = new KrillQuery("tokens").fromKoral(jsonQuery);
    SpanNextQuery sq = (SpanNextQuery) sqwi.toQuery();
    // System.out.println(sq.toString());
    ki = new KrillIndex();
    ki.addDoc(getClass().getResourceAsStream("/wiki/JJJ-00785.json.gz"), true);
    ki.addDoc(getClass().getResourceAsStream("/wiki/DDD-01402.json.gz"), true);
    ki.commit();
    kr = ki.search(sq, (short) 10);
    assertEquals(61, kr.getMatch(0).getStartPos());
    assertEquals(64, kr.getMatch(0).getEndPos());
    assertEquals("... Bruckner (Wien) und Mathis Lussy (Paris). [[{1:Inspiriert} " + "{2:durch die}]] additiven Modelle arabischer Rhythmik (er half ...", kr.getMatch(0).getSnippetBrackets());
    assertEquals(31, kr.getMatch(1).getStartPos());
    assertEquals(34, kr.getMatch(1).getEndPos());
    assertEquals("... des Sendens wird ein unhörbarer Unterton [[{1:mitgesendet}, " + "{2:auf den}]] das angesprochene Funkgerät reagiert. Die Abkürzung ...", kr.getMatch(1).getSnippetBrackets());
}
Also used : KrillQuery(de.ids_mannheim.korap.KrillQuery) SpanQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanQueryWrapper) KrillIndex(de.ids_mannheim.korap.KrillIndex) SpanNextQuery(de.ids_mannheim.korap.query.SpanNextQuery) Test(org.junit.Test)

Example 17 with KrillQuery

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

the class TestClass method queryJSONpoly4.

@Test
public void queryJSONpoly4() throws QueryException, IOException {
    String jsonPath = URLDecoder.decode(getClass().getResource("/queries/poly4.json").getFile(), "UTF-8");
    String jsonQuery = readFile(jsonPath);
    SpanQueryWrapper sqwi = new KrillQuery("tokens").fromKoral(jsonQuery);
    SpanQuery sq = sqwi.toQuery();
    // System.out.println(sq.toString());
    ki = new KrillIndex();
    ki.addDoc(getClass().getResourceAsStream("/wiki/SSS-09803.json.gz"), true);
    ki.commit();
    kr = ki.search(sq, (short) 10);
    /*
        for (Match km : kr.getMatches()){
        	System.out.println(km.getStartPos() +","+km.getEndPos()+" "
        			+km.getSnippetBrackets()
        	);
        }
        */
    assertEquals((long) 5315, kr.getTotalResults());
    assertEquals(3, kr.getMatch(0).getStartPos());
    assertEquals(5, kr.getMatch(0).getEndPos());
// fail("Tests have to be updated");
}
Also used : KrillQuery(de.ids_mannheim.korap.KrillQuery) SpanQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanQueryWrapper) KrillIndex(de.ids_mannheim.korap.KrillIndex) SpanQuery(org.apache.lucene.search.spans.SpanQuery) Test(org.junit.Test)

Example 18 with KrillQuery

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

the class TestSpanExpansionIndex method testCase7.

/**
 * Skip to
 */
@Test
public void testCase7() throws IOException, QueryException {
    KrillIndex ki = new KrillIndex();
    ki.addDoc(getClass().getResourceAsStream("/wiki/00001.json.gz"), true);
    ki.addDoc(getClass().getResourceAsStream("/wiki/00002.json.gz"), true);
    ki.commit();
    String jsonPath = URLDecoder.decode(getClass().getResource("/queries/poly3.json").getFile(), "UTF-8");
    String jsonQuery = readFile(jsonPath);
    SpanQueryWrapper sqwi = new KrillQuery("tokens").fromKoral(jsonQuery);
    SpanQuery sq = sqwi.toQuery();
    // System.out.println(sq.toString());
    kr = ki.search(sq, (short) 20);
    assertEquals(205, kr.getMatch(0).getStartPos());
    assertEquals(208, kr.getMatch(0).getEndPos());
/*
         * for (Match km : kr.getMatches()){
         * System.out.println(km.getStartPos() +","+km.getEndPos()+" "
         * +km.getSnippetBrackets() ); }
         */
}
Also used : KrillQuery(de.ids_mannheim.korap.KrillQuery) SpanQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanQueryWrapper) KrillIndex(de.ids_mannheim.korap.KrillIndex) SpanQuery(org.apache.lucene.search.spans.SpanQuery) Test(org.junit.Test)

Example 19 with KrillQuery

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

the class TestKrillQueryJSON method queryJSONinfiniteExpansion.

@Test
public void queryJSONinfiniteExpansion() throws QueryException {
    // der []*
    try {
        String json = getString(getClass().getResource("/queries/bugs/expansion_bug_3.jsonld").getFile());
        KrillQuery kq = new KrillQuery("tokens");
        assertEquals(kq.fromKoral(json).toQuery().toString(), "focus(254: spanContain(<tokens:base/s:t />, {254: spanExpansion(tokens:s:c, []{0, 4}, right)}))");
    } 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 20 with KrillQuery

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

the class TestKrillQueryJSON method queryJSONdistancesWithRegexes.

@Test
public void queryJSONdistancesWithRegexes() throws QueryException {
    // "der" []{2,3} [opennlp/p="NN"]
    try {
        String json = getString(getClass().getResource("/queries/bugs/distances_with_regex_bug.jsonld").getFile());
        KrillQuery kq = new KrillQuery("tokens");
        assertEquals(kq.fromKoral(json).toQuery().toString(), "spanDistance(SpanMultiTermQueryWrapper(tokens:/s:der/), SpanMultiTermQueryWrapper(tokens:/opennlp/p:NN/), [(w[3:4], ordered, notExcluded)])");
    } 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)

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