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());
}
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());
}
;
}
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());
}
;
}
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");
}
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)}))");
}
Aggregations