Search in sources :

Example 1 with QueryBuilder

use of de.ids_mannheim.korap.query.QueryBuilder in project Krill by KorAP.

the class TestBenchmarkSpans 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 2 with QueryBuilder

use of de.ids_mannheim.korap.query.QueryBuilder in project Krill by KorAP.

the class TestHighlight method highlightEmptySpan.

@Test
public void highlightEmptySpan() throws IOException, QueryException {
    KrillIndex ki = new KrillIndex();
    // <>:s$<b>65<i>38<b>0
    // <a>x<a>y<a>zhij</a>hij</a>hij</a>hij</a>
    FieldDocument fd = new FieldDocument();
    fd.addTV("base", "x  y  z  h  i  j  h  i  j  h  i  j  ", "[(0-3)s:x|<>:a$<b>64<i>0<i>3<i>12<b>0]" + "[(3-6)s:y|<>:a$<b>64<i>3<i>6<i>9<b>0]" + "[(6-9)s:z|<>:a$<b>64<i>6<i>9<i>6|<>:a$<b>65<i>6]" + "[(9-12)s:h<b>0]" + "[(12-15)s:i]" + "[(15-18)s:j]" + "[(18-21)s:h]" + "[(21-24)s:i]" + "[(24-27)s:j]" + "[(27-30)s:h]" + "[(30-33)s:i]" + "[(33-36)s:j]");
    ki.addDoc(fd);
    // Commit!
    ki.commit();
    QueryBuilder kq = new QueryBuilder("base");
    SpanQuery q = (SpanQuery) kq.tag("a").toQuery();
    Krill qs = new Krill(q);
    qs.getMeta().getContext().left.setToken(true).setLength((short) 5);
    qs.getMeta().getContext().right.setToken(true).setLength((short) 5);
    Result kr = ki.search(qs);
    assertEquals((long) 4, kr.getTotalResults());
    Match km = kr.getMatch(2);
    assertEquals("<span class=\"context-left\">" + "</span>" + "<span class=\"match\">" + "<mark>x  y  z  </mark>" + "</span><span class=\"context-right\">h  i  j  h  i  j  h  i  j  </span>", km.getSnippetHTML());
    km = kr.getMatch(3);
    assertEquals("<span class=\"context-left\"><span class=\"match\"></span></span>", km.getSnippetHTML());
}
Also used : Krill(de.ids_mannheim.korap.Krill) QueryBuilder(de.ids_mannheim.korap.query.QueryBuilder) FieldDocument(de.ids_mannheim.korap.index.FieldDocument) KrillIndex(de.ids_mannheim.korap.KrillIndex) SpanQuery(org.apache.lucene.search.spans.SpanQuery) Result(de.ids_mannheim.korap.response.Result) Match(de.ids_mannheim.korap.response.Match) Test(org.junit.Test)

Example 3 with QueryBuilder

use of de.ids_mannheim.korap.query.QueryBuilder in project Krill by KorAP.

the class TestHighlight method checkHighlightsManually.

@Test
public void checkHighlightsManually() throws IOException, QueryException {
    KrillIndex ki = new KrillIndex();
    String json = new String("{" + "  \"fields\" : [" + "    { " + "      \"primaryData\" : \"abc\"" + "    }," + "    {" + "      \"name\" : \"tokens\"," + "      \"data\" : [" + "         [ \"s:a\", \"i:a\", \"_0#0-1\", \"-:t$<i>3\"]," + "         [ \"s:b\", \"i:b\", \"_1#1-2\" ]," + "         [ \"s:c\", \"i:c\", \"_2#2-3\" ]" + "      ]" + "    }" + "  ]" + "}");
    FieldDocument fd = ki.addDoc(json);
    ki.commit();
    QueryBuilder kq = new QueryBuilder("tokens");
    Result kr = ki.search((SpanQuery) kq.seq(kq.seg("s:a")).append(kq.seg("s:b")).append(kq.seg("s:c")).toQuery());
    Match km = kr.getMatch(0);
    km.addHighlight(0, 1, (short) 7);
    assertEquals("<span class=\"context-left\"></span><span class=\"match\"><mark><mark class=\"class-7 level-0\">ab</mark>c</mark></span><span class=\"context-right\"></span>", km.getSnippetHTML());
    km.addHighlight(1, 2, (short) 6);
    assertEquals("<span class=\"context-left\"></span><span class=\"match\"><mark><mark class=\"class-7 level-0\">a<mark class=\"class-6 level-1\">b</mark></mark><mark class=\"class-6 level-1\">c</mark></mark></span><span class=\"context-right\"></span>", km.getSnippetHTML());
    km.addHighlight(0, 1, (short) 5);
    assertEquals("[[{5:{7:a{6:b}}}{6:c}]]", km.getSnippetBrackets());
    assertEquals("<span class=\"context-left\"></span><span class=\"match\"><mark><mark class=\"class-5 level-0\"><mark class=\"class-7 level-1\">a<mark class=\"class-6 level-2\">b</mark></mark></mark><mark class=\"class-6 level-2\">c</mark></mark></span><span class=\"context-right\"></span>", km.getSnippetHTML());
}
Also used : QueryBuilder(de.ids_mannheim.korap.query.QueryBuilder) FieldDocument(de.ids_mannheim.korap.index.FieldDocument) KrillIndex(de.ids_mannheim.korap.KrillIndex) Result(de.ids_mannheim.korap.response.Result) Match(de.ids_mannheim.korap.response.Match) Test(org.junit.Test)

Example 4 with QueryBuilder

use of de.ids_mannheim.korap.query.QueryBuilder in project Krill by KorAP.

the class TestElementDistanceIndex method testCase6.

/**
 * Test query from json (2)
 */
@Test
public void testCase6() throws Exception {
    ki = new KrillIndex();
    ki.addDoc(createFieldDoc0());
    ki.addDoc(createFieldDoc1());
    ki.addDoc(createFieldDoc2());
    ki.commit();
    SpanQueryWrapper sqwi;
    sqwi = new QueryBuilder("tokens").tag("base/s:t");
    kr = ki.search(sqwi.toQuery(), (short) 10);
    assertEquals(kr.getTotalResults(), 1);
    assertEquals("[[ecebdc]]", kr.getMatch(0).getSnippetBrackets());
    String jsonPath = URLDecoder.decode(getClass().getResource("/queries/distances/in-same-t.jsonld").getFile(), "UTF-8");
    sqwi = jsonQuery(jsonPath);
    assertEquals("spanElementDistance(tokens:s:c, tokens:s:e, [(base/s:t[0:0], ordered, notExcluded)])", sqwi.toQuery().toString());
    kr = ki.search(sqwi.toQuery(), (short) 10);
    // Is 1 correct or should it not be ordered?
    assertEquals(1, kr.getTotalResults());
    assertEquals("[[ec]]ebdc", kr.getMatch(0).getSnippetBrackets());
}
Also used : SpanQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanQueryWrapper) QueryBuilder(de.ids_mannheim.korap.query.QueryBuilder) KrillIndex(de.ids_mannheim.korap.KrillIndex) Test(org.junit.Test)

Example 5 with QueryBuilder

use of de.ids_mannheim.korap.query.QueryBuilder in project Krill by KorAP.

the class TestFieldDocument method indexExample2.

@Test
public void indexExample2() throws Exception {
    String json = new String("{" + "  \"fields\" : [" + "    { " + "      \"primaryData\" : \"abc\"" + "    }," + "    {" + "      \"name\" : \"tokens\"," + "      \"data\" : [" + "         [ \"s:a\", \"i:a\", \"_0$<i>0<i>1\", \"-:t$<i>3\"]," + "         [ \"s:b\", \"i:b\", \"_1$<i>1<i>2\" ]," + "         [ \"s:c\", \"i:c\", \"_2$<i>2<i>3\" ]" + "      ]" + "    }" + "  ]," + "  \"corpusID\"  : \"WPD\"," + "  \"ID\"        : \"WPD-AAA-00001\"," + "  \"textClass\" : \"music entertainment\"," + "  \"author\"    : \"Peter Frankenfeld\"," + "  \"pubDate\"   : 20130617," + "  \"title\"     : \"Wikipedia\"," + "  \"subTitle\"  : \"Die freie Enzyklopädie\"," + "  \"pubPlace\"  : \"Bochum\"" + "}");
    KrillIndex ki = new KrillIndex();
    FieldDocument fd = ki.addDoc(json);
    ki.commit();
    assertEquals(fd.getPrimaryData(), "abc");
    assertEquals(fd.getCorpusID(), "WPD");
    assertEquals(fd.getID(), "WPD-AAA-00001");
    assertEquals(fd.getTextClass(), "music entertainment");
    assertEquals(fd.getAuthor(), "Peter Frankenfeld");
    assertEquals(fd.getTitle(), "Wikipedia");
    assertEquals(fd.getSubTitle(), "Die freie Enzyklopädie");
    assertEquals(fd.getPubPlace(), "Bochum");
    assertEquals(fd.getPubDate().toDisplay(), "2013-06-17");
    QueryBuilder kq = new QueryBuilder("tokens");
    Result kr = ki.search((SpanQuery) kq.seq(kq.nr(3, kq.seg("s:b"))).toQuery());
    Match km = kr.getMatch(0);
    assertEquals(km.getPrimaryData(), "abc");
    assertEquals(km.getCorpusID(), "WPD");
    assertEquals(km.getDocID(), "WPD-AAA-00001");
    assertEquals(km.getTextClass(), "music entertainment");
    assertEquals(km.getAuthor(), "Peter Frankenfeld");
    assertEquals(km.getTitle(), "Wikipedia");
    assertEquals(km.getSubTitle(), "Die freie Enzyklopädie");
    assertEquals(km.getPubPlace(), "Bochum");
    assertEquals(km.getPubDate().toDisplay(), "2013-06-17");
    assertEquals(km.getSnippetBrackets(), "a[[{3:b}]]c");
}
Also used : QueryBuilder(de.ids_mannheim.korap.query.QueryBuilder) KrillIndex(de.ids_mannheim.korap.KrillIndex) Result(de.ids_mannheim.korap.response.Result) Match(de.ids_mannheim.korap.response.Match) Test(org.junit.Test)

Aggregations

QueryBuilder (de.ids_mannheim.korap.query.QueryBuilder)72 Test (org.junit.Test)67 SpanQuery (org.apache.lucene.search.spans.SpanQuery)39 KrillIndex (de.ids_mannheim.korap.KrillIndex)33 Result (de.ids_mannheim.korap.response.Result)32 Krill (de.ids_mannheim.korap.Krill)27 FieldDocument (de.ids_mannheim.korap.index.FieldDocument)14 SpanQueryWrapper (de.ids_mannheim.korap.query.wrap.SpanQueryWrapper)11 Match (de.ids_mannheim.korap.response.Match)8 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 KrillQuery (de.ids_mannheim.korap.KrillQuery)5 QueryException (de.ids_mannheim.korap.util.QueryException)5 KrillMeta (de.ids_mannheim.korap.KrillMeta)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 KrillCollection (de.ids_mannheim.korap.KrillCollection)3 TestSimple.getJsonString (de.ids_mannheim.korap.TestSimple.getJsonString)3 CollectionBuilder (de.ids_mannheim.korap.collection.CollectionBuilder)3 SearchContext (de.ids_mannheim.korap.response.SearchContext)3 Test (de.ids_mannheim.korap.Test)2 DistanceConstraint (de.ids_mannheim.korap.query.DistanceConstraint)1