use of de.ids_mannheim.korap.util.QueryException in project Krill by KorAP.
the class TestKrillQueryJSON method queryJSONcomplexSpanOrTerm.
@Test
public void queryJSONcomplexSpanOrTerm() throws QueryException {
// startsWith(<base/s=s>, { lassen | laufen })
try {
String json = getString(getClass().getResource("/queries/bugs/span_or_bug.jsonld").getFile());
KrillQuery kq = new KrillQuery("tokens");
assertEquals(kq.fromKoral(json).toQuery().toString(), "spanStartsWith(<tokens:base/s:s />, spanOr([tokens:s:Er, tokens:s:Sie]))");
} catch (QueryException e) {
fail(e.getMessage());
}
;
}
use of de.ids_mannheim.korap.util.QueryException in project Krill by KorAP.
the class TestKrillQueryJSON method queryJSONunderspecifiedTokenBug.
@Test
public void queryJSONunderspecifiedTokenBug() {
// ((MORPH(APPR) ODER MORPH(APPRART)) /+w1 Urlaub
try {
String json = getString(getClass().getResource("/queries/bugs/underspecified_token.jsonld").getFile());
new KrillQuery("tokens").fromKoral(json);
} catch (QueryException e) {
assertEquals(701, e.getErrorCode());
}
;
}
use of de.ids_mannheim.korap.util.QueryException in project Krill by KorAP.
the class TestSpanSequenceQuery method spanSequenceQueryWrapper.
@Test
public void spanSequenceQueryWrapper() throws QueryException {
SpanSequenceQueryWrapper ssqw, ssqw2;
SpanRepetitionQueryWrapper srqw;
SpanClassQueryWrapper scqw;
// Synopsis 1
ssqw = new SpanSequenceQueryWrapper("tokens", "der", "Baum");
assertEquals("spanNext(tokens:der, tokens:Baum)", ssqw.toQuery().toString());
// Synopsis 2
ssqw = new SpanSequenceQueryWrapper("tokens");
ssqw.append("der").append("Baum");
assertEquals("spanNext(tokens:der, tokens:Baum)", ssqw.toQuery().toString());
// Append a sequence
ssqw = new SpanSequenceQueryWrapper("tokens");
ssqw2 = new SpanSequenceQueryWrapper("tokens");
ssqw.append("der").append("Baum");
ssqw2.append("fiel").append("still");
ssqw.append(ssqw2);
// This may not be final
assertEquals("spanNext(spanNext(spanNext(tokens:der, tokens:Baum), tokens:fiel), tokens:still)", ssqw.toQuery().toString());
// Synopsis 3
ssqw = new SpanSequenceQueryWrapper("tokens", "Baum");
ssqw.prepend("der");
assertEquals("spanNext(tokens:der, tokens:Baum)", ssqw.toQuery().toString());
// Prepend a sequence
ssqw = new SpanSequenceQueryWrapper("tokens");
ssqw2 = new SpanSequenceQueryWrapper("tokens");
ssqw.append("fiel").append("still");
ssqw2.append("der").append("Baum");
ssqw.prepend(ssqw2);
// This may change
assertEquals("spanNext(spanNext(spanNext(tokens:der, tokens:Baum), tokens:fiel), tokens:still)", ssqw.toQuery().toString());
// Add constraint
ssqw.withConstraint(2, 4);
// This may change
assertEquals("spanDistance(spanDistance(spanDistance(tokens:der, " + "tokens:Baum, [(w[2:4], ordered, notExcluded)]), " + "tokens:fiel, [(w[2:4], ordered, notExcluded)]), " + "tokens:still, [(w[2:4], ordered, notExcluded)])", ssqw.toQuery().toString());
ssqw = new SpanSequenceQueryWrapper("tokens", "der", "Baum").withConstraint(1, 1);
assertEquals("spanNext(tokens:der, tokens:Baum)", ssqw.toQuery().toString());
ssqw = new SpanSequenceQueryWrapper("tokens", "der", "Baum").withConstraint(1, 2, "s");
assertEquals("spanElementDistance(tokens:der, tokens:Baum, [(s[1:2], ordered, notExcluded)])", ssqw.toQuery().toString());
ssqw = new SpanSequenceQueryWrapper("tokens", "der", "Baum").withConstraint(1, 2, "s").withConstraint(2, 3, "x");
assertEquals("spanMultipleDistance(tokens:der, tokens:Baum, " + "[(s[1:2], ordered, notExcluded), " + "(x[2:3], ordered, notExcluded)])", ssqw.toQuery().toString());
ssqw = new SpanSequenceQueryWrapper("tokens").append("Baum").prepend("der").withConstraint(1, 2, "s", true).withConstraint(2, 3, "x");
assertEquals("spanMultipleDistance(tokens:der, " + "tokens:Baum, [(s[1:2], ordered, excluded), " + "(x[2:3], ordered, notExcluded)])", ssqw.toQuery().toString());
// Support empty class ins sequence
ssqw = new SpanSequenceQueryWrapper("field", "Der");
srqw = new SpanRepetitionQueryWrapper();
scqw = new SpanClassQueryWrapper(srqw, (short) 3);
ssqw.append(scqw);
assertEquals("focus(254: spanContain(<field:base/s:t />, {254: spanExpansion(field:Der, []{1, 1}, right, class:3)}))", ssqw.toQuery().toString());
// Support empty class ins sequence
ssqw = new SpanSequenceQueryWrapper("field");
srqw = new SpanRepetitionQueryWrapper();
ssqw.append(srqw);
scqw = new SpanClassQueryWrapper(ssqw, (short) 2);
try {
scqw.toQuery();
} catch (Exception e) {
fail(e.getMessage() + " (Known issue)");
}
;
}
use of de.ids_mannheim.korap.util.QueryException in project Krill by KorAP.
the class TestSpanSequenceQueryJSON method queryJSONkoralOptionalityInDistanceBug.
@Test
public void queryJSONkoralOptionalityInDistanceBug() {
try {
// Sonne [] Mond?
SpanQueryWrapper sqwi = jsonQueryFile("distance-with-optionality.jsonld");
sqwi.toQuery().toString();
} catch (QueryException qe) {
assertEquals("Distance constraints not supported with empty, optional or negative operands", qe.getMessage());
}
// Could also be a distance at the end ... that's a query planner thing.
}
use of de.ids_mannheim.korap.util.QueryException in project Krill by KorAP.
the class TestElementDistanceIndex method jsonQuery.
public static SpanQueryWrapper jsonQuery(String jsonFile) {
SpanQueryWrapper sqwi;
try {
String json = getString(jsonFile);
sqwi = new KrillQuery("tokens").fromKoral(json);
} catch (QueryException e) {
fail(e.getMessage());
sqwi = new QueryBuilder("tokens").seg("???");
}
return sqwi;
}
Aggregations