Search in sources :

Example 6 with Match

use of de.ids_mannheim.korap.response.Match in project Krill by KorAP.

the class TestMatchIdentifier method indexExample7SentenceExpansion.

@Test
public void indexExample7SentenceExpansion() throws IOException, QueryException {
    KrillIndex ki = new KrillIndex();
    ki.addDoc(createSimpleFieldDoc());
    ki.addDoc(createSimpleFieldDoc2());
    ki.addDoc(createSimpleFieldDoc3());
    ki.addDoc(createSimpleFieldDoc4());
    ki.commit();
    Match km;
    km = ki.getMatchInfo("match-c1!d1-p3-4", "tokens", null, null, false, false);
    assertEquals("... [[{f/m:vier:{f/y:four:{it/is:4:{x/o:viertens:a}}}}]] ...", km.getSnippetBrackets());
    km = ki.getMatchInfo("match-c1!d1-p3-4", "tokens", null, null, false, false, // extendToSentence
    true);
    // This will
    // [{f/m:drei:{f/y:three:{it/is:3:{x/o:drittens:c}}}}{f/m:vier:{f/y:four:{it/is:4:{x/o:viertens:a}}}}{f/m:fuenf:{f/y:five:{it/is:5:{x/o:fünftens:b}}}}]
    assertEquals("[{f/m:drei:{f/y:three:{it/is:3:{x/o:drittens:c}}}}[{f/m:vier:{f/y:four:{it/is:4:{x/o:viertens:a}}}}]{f/m:fuenf:{f/y:five:{it/is:5:{x/o:fünftens:b}}}}]", km.getSnippetBrackets());
    assertEquals("<span class=\"context-left\"></span>" + "<span class=\"match\">" + "<span title=\"f/m:drei\">" + "<span title=\"f/y:three\">" + "<span title=\"it/is:3\">" + "<span title=\"x/o:drittens\">c</span>" + "</span>" + "</span>" + "</span>" + "<mark>" + "<span title=\"f/m:vier\">" + "<span title=\"f/y:four\">" + "<span title=\"it/is:4\">" + "<span title=\"x/o:viertens\">a</span>" + "</span>" + "</span>" + "</span>" + "</mark>" + "<span title=\"f/m:fuenf\">" + "<span title=\"f/y:five\">" + "<span title=\"it/is:5\">" + "<span title=\"x/o:fünftens\">b</span>" + "</span>" + "</span>" + "</span>" + "</span>" + "<span class=\"context-right\"></span>", km.getSnippetHTML());
/*
        km = ki.getMatchInfo("match-c1!d3-p3-4", "tokens", null, null, false,
                false, true); // extendToSentence
        
        assertEquals(
                "[{f/m:drei:{f/y:three:{it/is:3:{x/o:drittens:cc}}}} {f/m:vier:{f/y:four:{it/is:4:{x/o:viertens:aa}}}} {f/m:fuenf:{f/y:five:{it/is:5:{x/o:fünftens:bb}}}}]",
                km.getSnippetBrackets());
        
        
        km = ki.getMatchInfo("match-c1!d4-p4-6", "tokens", null, null, false,
                false, true); // extendToSentence
        assertEquals(
                "[{f/m:drei:{f/y:three:{it/is:3:{x/o:drittens:c}}}}{f/m:vier:{f/y:four:{it/is:4:{x/o:viertens:a}}}}{f/m:fuenf:{f/y:five:{it/is:5:{x/o:fünftens:b}}}}{f/m:sechs:{f/y:six:{it/is:6:{x/o:sechstens:c}}}}{f/m:sieben:{f/y:seven:{it/is:7:{x/o:siebtens:a}}}}]",
                km.getSnippetBrackets());
        */
}
Also used : KrillIndex(de.ids_mannheim.korap.KrillIndex) Match(de.ids_mannheim.korap.response.Match) Test(org.junit.Test)

Example 7 with Match

use of de.ids_mannheim.korap.response.Match in project Krill by KorAP.

the class TestMatchIdentifier method snippetBugTest.

// ND: Although this test is failing, I assume it is probably
// due to a data bug.
@Ignore
public void snippetBugTest() throws IOException, QueryException {
    KrillIndex ki = new KrillIndex();
    ki.addDoc(getClass().getResourceAsStream("/wiki/wpd15-u43-34816.json.gz"), true);
    ki.commit();
    Match km = ki.getMatchInfo("match-WPD15/U43/34816-p420-422", "tokens", "tt", "l", false, false);
    assertEquals("SnippetBrackets (with Spans)", "<span class=\"context-left\">" + "<span class=\"more\"></span></span>" + "<span class=\"match\">" + "<mark>" + "<span title=\"tt/l:online\">online</span> " + "<span title=\"tt/l:verfügbar\">verfügbar</span>" + "</mark>" + "</span>" + "<span class=\"context-right\">" + "<span class=\"more\"></span>" + "</span>", km.getSnippetHTML());
    km = ki.getMatchInfo("match-WPD15/U43/34816-p420-422", "tokens", "dereko", null, true, false);
    assertEquals("SnippetBrackets (with Spans)", "<span class=\"context-left\">" + "<span class=\"more\"></span>" + "</span>" + "<span class=\"match\">" + "<mark>" + "<span title=\"dereko/s:ref\">online</span> verfügbar" + "</mark>" + "</span>" + "<span class=\"context-right\">" + "<span class=\"more\"></span>" + "</span>", km.getSnippetHTML());
}
Also used : KrillIndex(de.ids_mannheim.korap.KrillIndex) Match(de.ids_mannheim.korap.response.Match) Ignore(org.junit.Ignore)

Example 8 with Match

use of de.ids_mannheim.korap.response.Match in project Krill by KorAP.

the class TestMatchIdentifier method indexExample1.

@Test
public void indexExample1() throws IOException {
    KrillIndex ki = new KrillIndex();
    ki.addDoc(createSimpleFieldDoc());
    ki.commit();
    QueryBuilder kq = new QueryBuilder("tokens");
    Krill ks = new Krill(kq.nr(2, kq.seq(kq.seg("s:b")).append(kq.nr(kq.seg("s:a")))));
    Result kr = ki.search(ks);
    assertEquals("totalResults", kr.getTotalResults(), 1);
    assertEquals("StartPos (0)", kr.getMatch(0).startPos, 7);
    assertEquals("EndPos (0)", kr.getMatch(0).endPos, 9);
    Match km = kr.getMatch(0);
    assertEquals("SnippetBrackets (0)", "... bcabca[[{2:b{1:a}}]]c", km.getSnippetBrackets());
    assertEquals("ID (0)", "match-c1!d1-p7-9(2)7-8(1)8-8", km.getID());
}
Also used : Krill(de.ids_mannheim.korap.Krill) 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)

Example 9 with Match

use of de.ids_mannheim.korap.response.Match in project Krill by KorAP.

the class TestMatchIdentifier method indexExample3.

@Test
public void indexExample3() throws IOException, QueryException {
    KrillIndex ki = new KrillIndex();
    ki.addDoc(createSimpleFieldDoc());
    ki.commit();
    Match km = ki.getMatchInfo("match-c1!d1-p7-9(4)8-8(2)7-8", "tokens", null, null, false, true);
    assertEquals("SnippetHTML (1)", "<span class=\"context-left\">" + "<span class=\"more\">" + "</span>" + "</span>" + "<span class=\"match\">" + "<mark>" + "<mark class=\"class-2 level-0\">" + "<span title=\"f/m:acht\">" + "<span title=\"f/y:eight\">" + "<span title=\"it/is:8\">" + "<span title=\"x/o:achtens\">" + "b" + "</span>" + "</span>" + "</span>" + "</span>" + "<mark class=\"class-4 level-1\">" + "<span title=\"f/m:neun\">" + "<span title=\"f/y:nine\">" + "<span title=\"it/is:9\">" + "<span title=\"x/o:neuntens\">" + "a" + "</span>" + "</span>" + "</span>" + "</span>" + "</mark>" + "</mark>" + "</mark>" + "</span>" + "<span class=\"context-right\">" + "<span class=\"more\">" + "</span>" + "</span>", km.getSnippetHTML());
}
Also used : KrillIndex(de.ids_mannheim.korap.KrillIndex) Match(de.ids_mannheim.korap.response.Match) Test(org.junit.Test)

Example 10 with Match

use of de.ids_mannheim.korap.response.Match in project Krill by KorAP.

the class TestMatchIdentifier method indexExample2.

@Test
public void indexExample2() throws IOException, QueryException {
    KrillIndex ki = new KrillIndex();
    ki.addDoc(createSimpleFieldDoc());
    ki.commit();
    Match km = ki.getMatch("match-c1!d1-p7-9(0)8-8(2)7-8");
    assertEquals("StartPos (0)", 7, km.getStartPos());
    assertEquals("EndPos (0)", 9, km.getEndPos());
    assertEquals("SnippetBrackets (0)", "... [[{2:b{a}}]] ...", km.getSnippetBrackets());
    assertEquals("ID (0)", "match-c1!d1-p7-9(0)8-8(2)7-8", km.getID());
    km = ki.getMatchInfo("match-c1!d1-p7-9(0)8-8(2)7-8", "tokens", "f", "m", false, false);
    assertEquals("SnippetBrackets (1)", "... [[{f/m:acht:b}{f/m:neun:a}]] ...", km.getSnippetBrackets());
    // Mirror identifier when passed
    km = ki.getMatchInfo("match-c1!d1-p7-9(0)8-8(2)7-8", "tokens", "f", null, false, false);
    assertEquals("SnippetBrackets (1b)", "... [[{f/m:acht:{f/y:eight:b}}{f/m:neun:{f/y:nine:a}}]] ...", km.getSnippetBrackets());
    JsonNode res = mapper.readTree(km.toJsonString());
    assertEquals("match-c1!d1-p7-9(0)8-8(2)7-8", res.at("/matchID").asText());
    km = ki.getMatchInfo("match-c1!d1-p7-9(0)8-8(2)7-8", "tokens", "f", "m", false, true);
    assertEquals("SnippetBrackets (2)", "... [[{2:{f/m:acht:b}{{f/m:neun:a}}}]] ...", km.getSnippetBrackets());
    km = ki.getMatchInfo("match-c1!d1-p7-9(4)8-8(2)7-8", "tokens", "f", "m", false, true);
    assertEquals("SnippetBrackets (3)", "... [[{2:{f/m:acht:b}{4:{f/m:neun:a}}}]] ...", km.getSnippetBrackets());
    km = ki.getMatchInfo("match-c1!d1-p7-9(4)8-8(2)7-8", "tokens", "f", null, false, true);
    assertEquals("SnippetBrackets (4)", "... [[{2:{f/m:acht:{f/y:eight:b}}{4:{f/m:neun:{f/y:nine:a}}}}]] ...", km.getSnippetBrackets());
    assertEquals("SnippetHTML (4)", "<span class=\"context-left\">" + "<span class=\"more\">" + "</span>" + "</span>" + "<span class=\"match\">" + "<mark>" + "<mark class=\"class-2 level-0\">" + "<span title=\"f/m:acht\">" + "<span title=\"f/y:eight\">" + "b" + "</span>" + "</span>" + "<mark class=\"class-4 level-1\">" + "<span title=\"f/m:neun\">" + "<span title=\"f/y:nine\">" + "a" + "</span>" + "</span>" + "</mark>" + "</mark>" + "</mark>" + "</span>" + "<span class=\"context-right\">" + "<span class=\"more\">" + "</span>" + "</span>", km.getSnippetHTML());
    res = mapper.readTree(km.toJsonString());
    assertEquals("tokens", res.at("/field").asText());
    assertTrue(res.at("/startMore").asBoolean());
    assertTrue(res.at("/endMore").asBoolean());
    assertEquals("c1", res.at("/corpusID").asText());
    assertEquals("d1", res.at("/docID").asText());
    assertEquals("match-c1!d1-p7-9(4)8-8(2)7-8", res.at("/matchID").asText());
    assertTrue(res.at("/pubDate").isMissingNode());
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) KrillIndex(de.ids_mannheim.korap.KrillIndex) Match(de.ids_mannheim.korap.response.Match) Test(org.junit.Test)

Aggregations

Match (de.ids_mannheim.korap.response.Match)37 Test (org.junit.Test)34 KrillIndex (de.ids_mannheim.korap.KrillIndex)30 Result (de.ids_mannheim.korap.response.Result)9 JsonNode (com.fasterxml.jackson.databind.JsonNode)8 QueryBuilder (de.ids_mannheim.korap.query.QueryBuilder)8 FieldDocument (de.ids_mannheim.korap.index.FieldDocument)7 Krill (de.ids_mannheim.korap.Krill)5 SpanQuery (org.apache.lucene.search.spans.SpanQuery)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 SpanClassQuery (de.ids_mannheim.korap.query.SpanClassQuery)1 SpanFocusQuery (de.ids_mannheim.korap.query.SpanFocusQuery)1 SpanNextQuery (de.ids_mannheim.korap.query.SpanNextQuery)1 SearchContext (de.ids_mannheim.korap.response.SearchContext)1 ArrayList (java.util.ArrayList)1 Term (org.apache.lucene.index.Term)1 SpanTermQuery (org.apache.lucene.search.spans.SpanTermQuery)1 Ignore (org.junit.Ignore)1