use of de.ids_mannheim.korap.query.QueryBuilder in project Krill by KorAP.
the class TestRegexWildcardIndex method indexRegexCombined.
@Test
public void indexRegexCombined() throws Exception {
KrillIndex ki = new KrillIndex();
// abcabcabac
FieldDocument fd = new FieldDocument();
fd.addTV("base", "affe afffe baum baumgarten steingarten franz hans haus efeu effe", "[(0-4)s:affe|_0$<i>0<i>4|-:t$<i>10]" + "[(5-10)s:afffe|_1$<i>5<i>10]" + "[(11-15)s:baum|_2$<i>11<i>15]" + "[(16-26)s:baumgarten|_3$<i>16<i>26]" + "[(27-38)s:steingarten|_4$<i>27<i>38]" + "[(39-44)s:franz|_5$<i>39<i>44]" + "[(45-49)s:hans|_6$<i>45<i>49]" + "[(50-54)s:haus|_7$<i>50<i>54]" + "[(55-59)s:efeu|_8$<i>55<i>59]" + "[(60-64)s:effe|_9$<i>60<i>64]");
ki.addDoc(fd);
ki.commit();
QueryBuilder kq = new QueryBuilder("base");
SpanQuery sq = kq.seq(kq.seg("s:affe")).append(kq.re("s:af*e")).toQuery();
assertEquals("spanNext(base:s:affe, SpanMultiTermQueryWrapper(base:/s:af*e/))", sq.toString());
Krill ks = new Krill(sq);
ks.getMeta().getContext().left.setToken(true).setLength(1);
ks.getMeta().getContext().right.setToken(true).setLength(1);
Result kr = ki.search(ks);
assertEquals((long) 1, kr.getTotalResults());
assertEquals("[[affe afffe]] baum ...", kr.getMatch(0).getSnippetBrackets());
}
use of de.ids_mannheim.korap.query.QueryBuilder in project Krill by KorAP.
the class TestRegexWildcardIndex method indexWildcard.
@Test
public void indexWildcard() throws Exception {
KrillIndex ki = new KrillIndex();
// abcabcabac
FieldDocument fd = new FieldDocument();
fd.addTV("base", "affe afffe baum baumgarten steingarten franz hans haus efeu effe", "[(0-4)s:affe|_0$<i>0<i>4|-:t$<i>10]" + "[(5-10)s:afffe|_1$<i>5<i>10]" + "[(11-15)s:baum|_2$<i>11<i>15]" + "[(16-26)s:baumgarten|_3$<i>16<i>26]" + "[(27-38)s:steingarten|_4$<i>27<i>38]" + "[(39-44)s:franz|_5$<i>39<i>44]" + "[(45-49)s:hans|_6$<i>45<i>49]" + "[(50-54)s:haus|_7$<i>50<i>54]" + "[(55-59)s:efeu|_8$<i>55<i>59]" + "[(60-64)s:effe|_9$<i>60<i>64]");
ki.addDoc(fd);
ki.commit();
QueryBuilder kq = new QueryBuilder("base");
SpanQueryWrapper sq = kq.wc("s:af*e");
assertEquals("SpanMultiTermQueryWrapper(base:s:af*e)", sq.toQuery().toString());
Krill ks = _newKrill(sq);
Result kr = ki.search(ks);
assertEquals((long) 2, kr.getTotalResults());
assertEquals("[[affe]] afffe ...", kr.getMatch(0).getSnippetBrackets());
assertEquals("affe [[afffe]] baum ...", kr.getMatch(1).getSnippetBrackets());
ks = _newKrill(new QueryBuilder("base").wc("s:baum.*"));
kr = ki.search(ks);
assertEquals((long) 0, kr.getTotalResults());
ks = _newKrill(new QueryBuilder("base").wc("s:baum*"));
kr = ki.search(ks);
assertEquals((long) 2, kr.getTotalResults());
assertEquals("... afffe [[baum]] baumgarten ...", kr.getMatch(0).getSnippetBrackets());
assertEquals("... baum [[baumgarten]] steingarten ...", kr.getMatch(1).getSnippetBrackets());
ks = _newKrill(new QueryBuilder("base").wc("s:*garten"));
kr = ki.search(ks);
assertEquals((long) 2, kr.getTotalResults());
assertEquals("... baum [[baumgarten]] steingarten ...", kr.getMatch(0).getSnippetBrackets());
assertEquals("... baumgarten [[steingarten]] franz ...", kr.getMatch(1).getSnippetBrackets());
ks = _newKrill(new QueryBuilder("base").wc("s:ha?s"));
kr = ki.search(ks);
assertEquals((long) 2, kr.getTotalResults());
assertEquals("... franz [[hans]] haus ...", kr.getMatch(0).getSnippetBrackets());
assertEquals("... hans [[haus]] efeu ...", kr.getMatch(1).getSnippetBrackets());
ks = _newKrill(new QueryBuilder("base").wc("s:?ff?"));
kr = ki.search(ks);
assertEquals((long) 2, kr.getTotalResults());
assertEquals("[[affe]] afffe ...", kr.getMatch(0).getSnippetBrackets());
assertEquals("... efeu [[effe]]", kr.getMatch(1).getSnippetBrackets());
}
use of de.ids_mannheim.korap.query.QueryBuilder in project Krill by KorAP.
the class TestRegexWildcardIndex method indexRegexWithinRewrite.
@Test
public void indexRegexWithinRewrite() throws Exception {
KrillIndex ki = new KrillIndex();
// abcabcabac
FieldDocument fd = new FieldDocument();
fd.addTV("base", "affe afffe baum baumgarten steingarten franz hans haus efeu effe", "[(0-4)s:affe|_0$<i>0<i>4|-:t$<i>10]" + "[(5-10)s:afffe|_1$<i>5<i>10]" + "[(11-15)s:baum|_2$<i>11<i>15]" + "[(16-26)s:baumgarten|_3$<i>16<i>26]" + "[(27-38)s:steingarten|_4$<i>27<i>38]" + "[(39-44)s:franz|_5$<i>39<i>44]" + "[(45-49)s:hans|_6$<i>45<i>49]" + "[(50-54)s:haus|_7$<i>50<i>54]" + "[(55-59)s:efeu|_8$<i>55<i>59]" + "[(60-64)s:effe|_9$<i>60<i>64]");
ki.addDoc(fd);
ki.commit();
QueryBuilder kq = new QueryBuilder("base");
SpanQuery sq = kq.contains(kq.seq(kq.re("s:a.*e")).append(kq.re("s:af*e")), kq.seg("s:affe")).toQuery();
assertEquals("spanContain(spanNext(SpanMultiTermQueryWrapper(base:/s:a.*e/), SpanMultiTermQueryWrapper(base:/s:af*e/)), base:s:affe)", sq.toString());
Krill ks = new Krill(sq);
ks.getMeta().getContext().left.setToken(true).setLength(1);
ks.getMeta().getContext().right.setToken(true).setLength(1);
Result kr = ki.search(ks);
assertEquals((long) 1, kr.getTotalResults());
assertEquals("[[affe afffe]] baum ...", kr.getMatch(0).getSnippetBrackets());
// Test without matches in sequence
sq = kq.seq(kq.re("s:z.*e")).append(kq.seg("s:affe")).toQuery();
assertEquals("spanNext(SpanMultiTermQueryWrapper(base:/s:z.*e/), base:s:affe)", sq.toString());
kr = ki.search(new Krill(sq));
assertEquals((long) 0, kr.getTotalResults());
// Test without matches in segment
sq = kq.seg().with(kq.re("s:z.*e")).with("s:affe").toQuery();
assertEquals("spanSegment(SpanMultiTermQueryWrapper(base:/s:z.*e/), base:s:affe)", sq.toString());
kr = ki.search(new Krill(sq));
assertEquals((long) 0, kr.getTotalResults());
// Test without matches in or
sq = kq.or(kq.re("s:z.*e"), kq.seg("s:affe")).toQuery();
assertEquals("spanOr([SpanMultiTermQueryWrapper(base:/s:z.*e/), base:s:affe])", sq.toString());
kr = ki.search(new Krill(sq));
assertEquals((long) 1, kr.getTotalResults());
// Test without matches in within
sq = kq.within(kq.re("s:z.*e"), kq.seg("s:affe")).toQuery();
assertEquals("spanContain(SpanMultiTermQueryWrapper(base:/s:z.*e/), base:s:affe)", sq.toString());
kr = ki.search(new Krill(sq));
assertEquals((long) 0, kr.getTotalResults());
// Test without matches in within (reversed)
sq = kq.within(kq.seg("s:affe"), kq.re("s:z.*e")).toQuery();
assertEquals("spanContain(base:s:affe, SpanMultiTermQueryWrapper(base:/s:z.*e/))", sq.toString());
kr = ki.search(new Krill(sq));
assertEquals((long) 0, kr.getTotalResults());
// Test with classes
sq = kq.nr(kq.re("s:z.*e")).toQuery();
assertEquals("{1: SpanMultiTermQueryWrapper(base:/s:z.*e/)}", sq.toString());
kr = ki.search(new Krill(sq));
assertEquals((long) 0, kr.getTotalResults());
// Test with nested classes
sq = kq.within(kq.nr(kq.re("s:z.*e")), kq.seg("s:affe")).toQuery();
assertEquals("spanContain({1: SpanMultiTermQueryWrapper(base:/s:z.*e/)}, base:s:affe)", sq.toString());
kr = ki.search(new Krill(sq));
assertEquals((long) 0, kr.getTotalResults());
// Test with multiple distances
List<DistanceConstraint> constraints = new ArrayList<DistanceConstraint>();
constraints.add(TestMultipleDistanceIndex.createConstraint("w", 1, 2, true, false));
constraints.add(TestMultipleDistanceIndex.createConstraint("tokens", "base/s:s", 0, 0, true, false));
sq = new SpanMultipleDistanceQuery(kq.re("s:z.*e").toQuery(), kq.seg("s:affe").toQuery(), constraints, true, true);
assertEquals("spanMultipleDistance(SpanMultiTermQueryWrapper(base:/s:z.*e/), " + "base:s:affe, [(w[1:2], ordered, notExcluded), (" + "base/s:s[0:0], ordered, notExcluded)])", sq.toString());
kr = ki.search(new Krill(sq));
assertEquals((long) 0, kr.getTotalResults());
// Test with multiple distances and a class
sq = new SpanMultipleDistanceQuery(kq.nr(kq.re("s:z.*e")).toQuery(), kq.seg("s:affe").toQuery(), constraints, true, true);
assertEquals("spanMultipleDistance({1: SpanMultiTermQueryWrapper(base:/s:z.*e/)}, " + "base:s:affe, [(w[1:2], ordered, notExcluded), (base/s:s[0:0], ordered, notExcluded)])", sq.toString());
kr = ki.search(new Krill(sq));
assertEquals((long) 0, kr.getTotalResults());
}
use of de.ids_mannheim.korap.query.QueryBuilder in project Krill by KorAP.
the class TestWithinIndex method indexExample8.
/**
* SpanElementQueries
*/
@Test
public void indexExample8() throws QueryException, IOException {
KrillIndex ki = new KrillIndex();
FieldDocument fd = new FieldDocument();
// <a>xx <e>hi j <e>hi j</e></e></a>
fd.addTV("base", "xx hi j hi j", "[(0-1)s:x|i:x|_0$<i>0<i>1|<>:a$<b>64<i>0<i>12<i>8<b>0]" + "[(1-2)s:x|i:x|_1$<i>1<i>2]" + "[(3-4)s:h|i:h|_2$<i>3<i>4|<>:e$<b>64<i>3<i>12<i>8<b>0]" + "[(4-5)s:i|i:i|_3$<i>4<i>5]" + "[(6-7)s:j|i:j|_4$<i>6<i>7]" + "[(8-9)s:h|i:h|_5$<i>8<i>9|<>:e$<b>64<i>8<i>9<i>8<b>0]" + "[(9-10)s:i|i:i|_6$<i>9<i>10]" + "[(11-12)s:j|i:j|_7$<i>11<i>12]");
ki.addDoc(fd);
ki.commit();
assertEquals(1, ki.numberOf("documents"));
QueryBuilder qb = new KrillQuery("base").builder();
SpanQueryWrapper sqw;
Result kr;
/*
sqw = qb.seg("i:x");
kr = ki.search(sqw.toQuery(), (short) 10);
assertEquals(2, kr.getTotalResults());
sqw = qb.tag("a");
kr = ki.search(sqw.toQuery(), (short) 10);
assertEquals(1, kr.getTotalResults());
sqw = qb.startswith(qb.tag("a"), qb.seg("i:x"));
assertEquals("spanStartsWith(<base:a />, base:i:x)",
sqw.toQuery().toString());
kr = ki.search(sqw.toQuery(), (short) 10);
assertEquals(1, kr.getTotalResults());
*/
sqw = qb.startswith(qb.tag("e"), qb.seg("i:h"));
assertEquals("spanStartsWith(<base:e />, base:i:h)", sqw.toQuery().toString());
kr = ki.search(sqw.toQuery(), (short) 10);
assertEquals(2, kr.getTotalResults());
}
use of de.ids_mannheim.korap.query.QueryBuilder in project Krill by KorAP.
the class TestKrillQuery method KorapSequenceQuery5.
@Test
public void KorapSequenceQuery5() throws QueryException {
QueryBuilder kq = new QueryBuilder("field");
SpanQuery sq = kq.seq(kq.seg("try1")).append(kq.seg("try2")).withConstraint(2, 3, true).toQuery();
assertEquals("spanDistance(field:try1, field:try2, [(w[2:3], ordered, excluded)])", sq.toString());
}
Aggregations