use of de.ids_mannheim.korap.query.SpanMultipleDistanceQuery in project Krill by KorAP.
the class TestWildcardIndex method testWildcardQuestionMark2.
@Test
public void testWildcardQuestionMark2() throws IOException {
ki = new KrillIndex();
ki.addDoc(createFieldDoc1());
ki.commit();
// Wildcard ? means regex . (expects exactly one character)
SpanMultiTermQueryWrapper<WildcardQuery> mtq = new SpanMultiTermQueryWrapper<WildcardQuery>(new WildcardQuery(new Term("tokens", "s:mein?")));
SpanMultipleDistanceQuery mdsq = new SpanMultipleDistanceQuery(new SpanClassQuery(mtq, (byte) 129), new SpanClassQuery(sq, (byte) 129), constraints, true, true);
kr = ki.search(mdsq, (short) 10);
assertEquals(1, kr.getMatches().size());
}
use of de.ids_mannheim.korap.query.SpanMultipleDistanceQuery in project Krill by KorAP.
the class TestRegexIndex method testWildcardQuestionMarkRewritten.
@Test
public void testWildcardQuestionMarkRewritten() throws IOException {
ki = new KrillIndex();
ki.addDoc(createFieldDoc1());
ki.commit();
// meine? /+w1:2,s0 &Erfahrung
// meine? rewritten into meine.
SpanMultiTermQueryWrapper<RegexpQuery> mtq = new SpanMultiTermQueryWrapper<RegexpQuery>(new RegexpQuery(new Term("tokens", "s:meine.")));
SpanMultipleDistanceQuery mdsq = new SpanMultipleDistanceQuery(new SpanClassQuery(mtq, (byte) 129), new SpanClassQuery(sq, (byte) 129), constraints, true, true);
kr = ki.search(mdsq, (short) 10);
assertEquals(3, kr.getMatches().size());
}
use of de.ids_mannheim.korap.query.SpanMultipleDistanceQuery in project Krill by KorAP.
the class TestRegexIndex method testWildcardPlusRewritten2.
@Test
public void testWildcardPlusRewritten2() throws IOException {
ki = new KrillIndex();
ki.addDoc(createFieldDoc1());
ki.commit();
// C2 mein+ /+w1:2,s0 &Erfahrung
// mein+ rewritten into mein.?
SpanMultiTermQueryWrapper<RegexpQuery> mtq = new SpanMultiTermQueryWrapper<RegexpQuery>(new RegexpQuery(new Term("tokens", "s:mein.?")));
SpanMultipleDistanceQuery mdsq = new SpanMultipleDistanceQuery(new SpanClassQuery(mtq, (byte) 129), new SpanClassQuery(sq, (byte) 129), constraints, true, true);
kr = ki.search(mdsq, (short) 10);
assertEquals(2, kr.getMatches().size());
}
use of de.ids_mannheim.korap.query.SpanMultipleDistanceQuery in project Krill by KorAP.
the class TestSampleIndex method testMultipleDistanceWithWildcards.
@Test
public void testMultipleDistanceWithWildcards() throws IOException, QueryException {
WildcardQuery wcquery = new WildcardQuery(new Term("tokens", "s:meine*"));
SpanMultiTermQueryWrapper<WildcardQuery> mtq = new SpanMultiTermQueryWrapper<WildcardQuery>(wcquery);
// meine* /+w1:2 &Erfahrung
SpanQuery tdq = new SpanDistanceQuery(mtq, sq, TestMultipleDistanceIndex.createConstraint("w", 1, 2, true, false), true);
kr = sample.search(tdq, (short) 10);
assertEquals(4, kr.getMatches().size());
assertEquals(107, kr.getMatch(0).getStartPos());
assertEquals(109, kr.getMatch(0).getEndPos());
assertEquals(132566, kr.getMatch(1).getStartPos());
assertEquals(132569, kr.getMatch(1).getEndPos());
assertEquals(161393, kr.getMatch(2).getStartPos());
assertEquals(161396, kr.getMatch(2).getEndPos());
assertEquals(10298, kr.getMatch(3).getStartPos());
assertEquals(10301, kr.getMatch(3).getEndPos());
// meine* /+s0 &Erfahrung
SpanQuery edq = new SpanDistanceQuery(mtq, sq, TestMultipleDistanceIndex.createConstraint("tokens", "base/s:s", 0, 0, true, false), true);
kr = sample.search(edq, (short) 20);
assertEquals(18, kr.getMatches().size());
// meine* /+w1:2,s0 &Erfahrung
SpanQuery mdsq = new SpanMultipleDistanceQuery(new SpanClassQuery(mtq, (byte) 129), new SpanClassQuery(sq, (byte) 129), constraints, true, true);
kr = sample.search(mdsq, (short) 10);
assertEquals(4, kr.getMatches().size());
// check SpanQueryWrapper generated query
SpanQueryWrapper sqwi = getJSONQuery(getClass().getResource("/queries/bugs/cosmas_wildcards.jsonld").getFile());
SpanQuery jsq = sqwi.toQuery();
assertEquals(mdsq.toString(), jsq.toString());
}
use of de.ids_mannheim.korap.query.SpanMultipleDistanceQuery in project Krill by KorAP.
the class TestMultipleDistanceIndex method testQueryWithWildCard.
@Test
public void testQueryWithWildCard() throws IOException {
// meine* /+w1:2,s0 &Erfahrung
ki = new KrillIndex();
ki.addDoc(createFieldDoc5());
ki.commit();
// Check simple rewriting
WildcardQuery wcquery = new WildcardQuery(new Term("tokens", "s:Meine*"));
SpanMultiTermQueryWrapper<WildcardQuery> mtq = new SpanMultiTermQueryWrapper<WildcardQuery>(wcquery);
assertEquals(wcquery.toString(), "tokens:s:Meine*");
kr = ki.search(mtq, (short) 10);
assertEquals(4, kr.getMatches().size());
assertEquals(0, kr.getMatch(0).getStartPos());
assertEquals(1, kr.getMatch(0).getEndPos());
// Check rewriting in multidistance query
SpanQuery sq = new SpanTermQuery(new Term("tokens", "l:Erfahrung"));
kr = ki.search(sq, (short) 10);
assertEquals(4, kr.getMatches().size());
List<DistanceConstraint> constraints = new ArrayList<DistanceConstraint>();
constraints.add(createConstraint("w", 1, 2, true, false));
constraints.add(createConstraint("tokens", "s", 0, 0, true, false));
SpanQuery mdsq = new SpanMultipleDistanceQuery(mtq, sq, constraints, true, true);
assertEquals(mdsq.toString(), "spanMultipleDistance(SpanMultiTermQueryWrapper(tokens:s:Meine*), " + "tokens:l:Erfahrung, [(w[1:2], ordered, notExcluded), (s[0:0], " + "ordered, notExcluded)])");
kr = ki.search(mdsq, (short) 10);
assertEquals(3, kr.getMatches().size());
assertEquals(0, kr.getMatch(0).getStartPos());
assertEquals(2, kr.getMatch(0).getEndPos());
// Check skipping with multiple documents
ki.addDoc(createFieldDoc6());
ki.addDoc(createFieldDoc7());
ki.addDoc(createFieldDoc8());
ki.commit();
kr = ki.search(mdsq, (short) 10);
assertEquals(6, kr.getMatches().size());
}
Aggregations