use of de.ids_mannheim.korap.query.wrap.SpanRegexQueryWrapper in project Krill by KorAP.
the class KrillQuery method _segFromJson.
// Deserialize koral:token
private SpanQueryWrapper _segFromJson(JsonNode json) throws QueryException {
if (!json.has("@type"))
throw new QueryException(701, "JSON-LD group has no @type attribute");
String type = json.get("@type").asText();
if (DEBUG)
log.trace("Wrap new token definition by {}", type);
// Branch on type
switch(type) {
case "koral:term":
// case "match:eq":
return this._termFromJson(json);
case "koral:termGroup":
if (!json.has("operands"))
throw new QueryException(742, "Term group needs operand list");
// Get operands
JsonNode operands = json.get("operands");
SpanSegmentQueryWrapper ssegqw = this.builder().seg();
if (!json.has("relation"))
throw new QueryException(743, "Term group expects a relation");
switch(json.get("relation").asText()) {
case "relation:and":
for (JsonNode operand : operands) {
SpanQueryWrapper part = this._segFromJson(operand);
if (part instanceof SpanAlterQueryWrapper) {
ssegqw.with((SpanAlterQueryWrapper) part);
} else if (part instanceof SpanRegexQueryWrapper) {
ssegqw.with((SpanRegexQueryWrapper) part);
} else if (part instanceof SpanSegmentQueryWrapper) {
ssegqw.with((SpanSegmentQueryWrapper) part);
} else {
throw new QueryException(744, "Operand not supported in term group");
}
;
}
;
return ssegqw;
case "relation:or":
SpanAlterQueryWrapper ssaq = new SpanAlterQueryWrapper(this.field);
for (JsonNode operand : operands) {
ssaq.or(this._segFromJson(operand));
}
;
return ssaq;
}
;
}
;
throw new QueryException(745, "Token type is not supported");
}
use of de.ids_mannheim.korap.query.wrap.SpanRegexQueryWrapper in project Krill by KorAP.
the class TestSpanSegmentQuery method spanSegmentRegexQuery.
@Test
public void spanSegmentRegexQuery() throws QueryException {
SpanSegmentQueryWrapper ssquery = new SpanSegmentQueryWrapper("field");
assertNull(ssquery.toQuery());
ssquery.with("a");
assertEquals("field:a", ssquery.toQuery().toString());
ssquery.with(new SpanRegexQueryWrapper("field", "a.*b"));
assertEquals("spanSegment(field:a, SpanMultiTermQueryWrapper(field:/a.*b/))", ssquery.toQuery().toString());
ssquery.with("c");
assertEquals("spanSegment(spanSegment(field:a, SpanMultiTermQueryWrapper(field:/a.*b/)), field:c)", ssquery.toQuery().toString());
ssquery.with("d").with("e");
assertEquals("spanSegment(spanSegment(spanSegment(spanSegment(field:a, SpanMultiTermQueryWrapper(field:/a.*b/)), field:c), field:d), field:e)", ssquery.toQuery().toString());
ssquery.without(new SpanRegexQueryWrapper("field", "x.?y"));
assertEquals("spanNot(spanSegment(spanSegment(spanSegment(spanSegment(field:a, SpanMultiTermQueryWrapper(field:/a.*b/)), field:c), field:d), field:e), SpanMultiTermQueryWrapper(field:/x.?y/), 0, 0)", ssquery.toQuery().toString());
ssquery.without(new SpanRegexQueryWrapper("field", "z{5,9}"));
assertEquals("spanNot(spanSegment(spanSegment(spanSegment(spanSegment(field:a, SpanMultiTermQueryWrapper(field:/a.*b/)), field:c), field:d), field:e), spanOr([SpanMultiTermQueryWrapper(field:/x.?y/), SpanMultiTermQueryWrapper(field:/z{5,9}/)]), 0, 0)", ssquery.toQuery().toString());
}
use of de.ids_mannheim.korap.query.wrap.SpanRegexQueryWrapper in project Krill by KorAP.
the class TestSpanSegmentAlterQuery method spanAlterQuery5.
@Test
public void spanAlterQuery5() throws QueryException {
SpanRegexQueryWrapper srequery = new SpanRegexQueryWrapper("field", "a[bc]d.?e");
SpanAlterQueryWrapper ssaquery = new SpanAlterQueryWrapper("field");
ssaquery.or("f").or(srequery).or("g");
assertEquals("spanOr([field:f, SpanMultiTermQueryWrapper(field:/a[bc]d.?e/), field:g])", ssaquery.toQuery().toString());
}
use of de.ids_mannheim.korap.query.wrap.SpanRegexQueryWrapper in project Krill by KorAP.
the class TestSpanSegmentSequenceQuery method spanSegmentSequenceQuery3.
@Test
public void spanSegmentSequenceQuery3() throws QueryException {
SpanSequenceQueryWrapper sssq = new SpanSequenceQueryWrapper("field", "a", "b");
SpanRegexQueryWrapper ssreq = new SpanRegexQueryWrapper("field", "c.?d");
sssq.append(ssreq);
assertEquals("spanNext(spanNext(field:a, field:b), SpanMultiTermQueryWrapper(field:/c.?d/))", sssq.toQuery().toString());
}
Aggregations