use of de.ids_mannheim.korap.KrillIndex in project Krill by KorAP.
the class TestSegmentNegationIndex method testcaseWarnings.
@Test
public void testcaseWarnings() throws Exception {
ki = new KrillIndex();
ki.addDoc(createFieldDoc0());
ki.addDoc(createFieldDoc1());
ki.addDoc(createFieldDoc2());
ki.addDoc(createFieldDoc3());
ki.commit();
kr = ki.search(new Krill("{\"query\" : { \"@type\" : \"koral:token\", \"wrap\" : { \"@type\" : \"koral:term\", \"key\" : \"a\", \"flags\" : [\"caseInsensitive\"], \"layer\" : \"orth\", \"match\" : \"match:eq\" }}}"));
assertEquals("totalResults", kr.getTotalResults(), 6);
assertEquals("Warning", kr.hasWarnings(), true);
assertEquals("Warning text", kr.getWarning(0).getMessage(), "Flag is unknown");
assertEquals("Warning text", kr.getWarning(0).toJsonString(), "[748,\"Flag is unknown\",\"caseInsensitive\"]");
// Negation of segment
kr = ki.search(new Krill("{\"query\" : { \"@type\" : \"koral:token\", \"wrap\" : { \"@type\" : \"koral:term\", \"key\" : \"a\", \"flags\" : [\"flags:caseInsensitive\"], \"layer\" : \"orth\", \"match\" : \"match:ne\" }}}"));
assertEquals("totalResults", kr.getTotalResults(), 4);
assertEquals("Warning", kr.hasWarnings(), true);
assertEquals("Warning text", kr.getWarning(0).getMessage(), "Exclusivity of query is ignored");
// Flag parameter injection
kr = ki.search(new Krill("{\"query\" : { \"@type\" : \"koral:token\", \"wrap\" : { \"@type\" : \"koral:term\", \"key\" : \"a\", \"flags\" : [{ \"injection\" : true }], \"layer\" : \"orth\", \"match\" : \"match:ne\" }}}"));
assertEquals("totalResults", kr.getTotalResults(), 6);
assertEquals("Warning", kr.hasWarnings(), true);
assertEquals("Warning text", kr.getWarning(0).getMessage(), "Flag is unknown");
assertEquals("Warning text", kr.getWarning(0).toJsonString(), "[748,\"Flag is unknown\"]");
}
use of de.ids_mannheim.korap.KrillIndex in project Krill by KorAP.
the class TestSegmentNegationIndex method testcaseNegation.
@Test
public void testcaseNegation() throws Exception {
ki = new KrillIndex();
ki.addDoc(createFieldDoc0());
ki.addDoc(createFieldDoc1());
ki.addDoc(createFieldDoc2());
ki.addDoc(createFieldDoc3());
ki.commit();
SpanSegmentQueryWrapper ssqw = new SpanSegmentQueryWrapper("tokens", "s:b");
ssqw.with("s:c");
SpanSequenceQueryWrapper sqw = new SpanSequenceQueryWrapper("tokens", ssqw).append("s:d");
kr = ki.search(sqw.toQuery(), (short) 10);
assertEquals("totalResults", kr.getTotalResults(), 2);
// Match #0
assertEquals("doc-number", 0, kr.getMatch(0).getLocalDocID());
assertEquals("StartPos (0)", 4, kr.getMatch(0).startPos);
assertEquals("EndPos (0)", 6, kr.getMatch(0).endPos);
// Match #1 in the other atomic index
assertEquals("doc-number", 3, kr.getMatch(1).getLocalDocID());
assertEquals("StartPos (0)", 0, kr.getMatch(1).startPos);
assertEquals("EndPos (0)", 2, kr.getMatch(1).endPos);
ssqw = new SpanSegmentQueryWrapper("tokens", "s:b");
ssqw.without("s:c");
sqw = new SpanSequenceQueryWrapper("tokens", ssqw).append("s:a");
kr = ki.search(sqw.toQuery(), (short) 10);
assertEquals("doc-number", 0, kr.getMatch(0).getLocalDocID());
assertEquals("StartPos (0)", 2, kr.getMatch(0).startPos);
assertEquals("EndPos (0)", 4, kr.getMatch(0).endPos);
assertEquals("doc-number", 1, kr.getMatch(1).getLocalDocID());
assertEquals("StartPos (1)", 1, kr.getMatch(1).startPos);
assertEquals("EndPos (1)", 3, kr.getMatch(1).endPos);
assertEquals("doc-number", 1, kr.getMatch(2).getLocalDocID());
assertEquals("StartPos (2)", 2, kr.getMatch(2).startPos);
assertEquals("EndPos (2)", 4, kr.getMatch(2).endPos);
assertEquals("doc-number", 2, kr.getMatch(3).getLocalDocID());
assertEquals("StartPos (3)", 1, kr.getMatch(3).startPos);
assertEquals("EndPos (3)", 3, kr.getMatch(3).endPos);
}
use of de.ids_mannheim.korap.KrillIndex in project Krill by KorAP.
the class TestSpanExpansionIndex method indexRegexSequence.
@Test
public void indexRegexSequence() throws Exception {
KrillIndex ki = new KrillIndex();
ki.addDoc(createFieldDoc5());
ki.commit();
QueryBuilder kq = new QueryBuilder("base");
SpanQueryWrapper sq = kq.seq(kq.or("s:baumgarten", "s:steingarten")).append(kq.seg().without(kq.or("s:franz", "s:hans")));
// Expected to find [baumgarten steingarten]
Krill ks = _newKrill(sq);
Result kr = ki.search(ks);
assertEquals((long) 1, kr.getTotalResults());
assertEquals("... baum [[baumgarten steingarten]] franz ...", kr.getMatch(0).getSnippetBrackets());
// The same result should be shown for:
sq = kq.seq(kq.re("s:.*garten")).append(kq.seg().without(kq.re("s:.*an.*")));
ks = _newKrill(sq);
kr = ki.search(ks);
assertEquals((long) 1, kr.getTotalResults());
assertEquals("... baum [[baumgarten steingarten]] franz ...", kr.getMatch(0).getSnippetBrackets());
}
use of de.ids_mannheim.korap.KrillIndex in project Krill by KorAP.
the class TestSpanExpansionIndex method testExpansionOverStart.
/**
* Expansion over start and end documents start => cut to 0
* TODO: end => to be handled in rendering process
*
* @throws IOException
*/
@Test
public void testExpansionOverStart() throws IOException {
KrillIndex ki = new KrillIndex();
ki.addDoc(createFieldDoc0());
ki.commit();
SpanTermQuery stq = new SpanTermQuery(new Term("base", "s:e"));
// left expansion precedes 0
SpanExpansionQuery seq = new SpanExpansionQuery(stq, 2, 2, -1, true);
kr = ki.search(seq, (short) 10);
assertEquals((long) 3, kr.getTotalResults());
assertEquals(2, kr.getMatch(0).getStartPos());
assertEquals(5, kr.getMatch(0).getEndPos());
// right expansion exceeds end position
seq = new SpanExpansionQuery(stq, 3, 3, 0, true);
kr = ki.search(seq, (short) 10);
assertEquals((long) 4, kr.getTotalResults());
assertEquals(7, kr.getMatch(2).getStartPos());
assertEquals(11, kr.getMatch(2).getEndPos());
assertEquals(8, kr.getMatch(3).getStartPos());
assertEquals(12, kr.getMatch(3).getEndPos());
/*
* for (Match km : kr.getMatches()){
* System.out.println(km.getStartPos() +","+km.getEndPos()+" "
* //+km.getSnippetBrackets() ); }
*/
}
use of de.ids_mannheim.korap.KrillIndex in project Krill by KorAP.
the class TestSpanExpansionIndex method testRightExpansionWithWrongSorting.
@Test
public void testRightExpansionWithWrongSorting() throws IOException {
KrillIndex ki = new KrillIndex();
ki.addDoc(simpleFieldDoc("abccef"));
ki.commit();
SpanTermQuery stq = new SpanTermQuery(new Term("base", "s:c"));
SpanExpansionQuery seqL = new SpanExpansionQuery(stq, 0, 2, -1, true);
kr = ki.search(seqL, (short) 20);
// for (Match km : kr.getMatches()) {
// System.out.println(km.getStartPos() + "," + km.getEndPos() + " " +
// km.getSnippetBrackets());
// };
SpanExpansionQuery seqR = new SpanExpansionQuery(seqL, 0, 2, 0, true);
assertEquals("spanExpansion(spanExpansion(base:s:c, []{0, 2}, left), []{0, 2}, right)", seqR.toString());
kr = ki.search(seqR, (short) 20);
// for (Match km : kr.getMatches()) {
// System.out.println(km.getStartPos() + "," + km.getEndPos() + " " +
// km.getSnippetBrackets());
// };
assertEquals("a[[bcc]]ef", kr.getMatch(5).getSnippetBrackets());
assertEquals("a[[bcce]]f", kr.getMatch(6).getSnippetBrackets());
assertEquals(18, kr.getTotalResults());
}
Aggregations