use of de.ids_mannheim.korap.query.wrap.SpanQueryWrapper in project Krill by KorAP.
the class TestSimple method getJSONQuery.
// Get query wrapper based on json file
public static SpanQueryWrapper getJSONQuery(String jsonFile) throws QueryException {
SpanQueryWrapper sqwi;
// try {
String json = getJsonString(jsonFile);
sqwi = new KrillQuery("tokens").fromKoral(json);
// };
return sqwi;
}
use of de.ids_mannheim.korap.query.wrap.SpanQueryWrapper in project Krill by KorAP.
the class TestBenchmarkSpans 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;
}
use of de.ids_mannheim.korap.query.wrap.SpanQueryWrapper in project Krill by KorAP.
the class TestElementDistanceIndex method testCase6.
/**
* Test query from json (2)
*/
@Test
public void testCase6() throws Exception {
ki = new KrillIndex();
ki.addDoc(createFieldDoc0());
ki.addDoc(createFieldDoc1());
ki.addDoc(createFieldDoc2());
ki.commit();
SpanQueryWrapper sqwi;
sqwi = new QueryBuilder("tokens").tag("base/s:t");
kr = ki.search(sqwi.toQuery(), (short) 10);
assertEquals(kr.getTotalResults(), 1);
assertEquals("[[ecebdc]]", kr.getMatch(0).getSnippetBrackets());
String jsonPath = URLDecoder.decode(getClass().getResource("/queries/distances/in-same-t.jsonld").getFile(), "UTF-8");
sqwi = jsonQuery(jsonPath);
assertEquals("spanElementDistance(tokens:s:c, tokens:s:e, [(base/s:t[0:0], ordered, notExcluded)])", sqwi.toQuery().toString());
kr = ki.search(sqwi.toQuery(), (short) 10);
// Is 1 correct or should it not be ordered?
assertEquals(1, kr.getTotalResults());
assertEquals("[[ec]]ebdc", kr.getMatch(0).getSnippetBrackets());
}
use of de.ids_mannheim.korap.query.wrap.SpanQueryWrapper in project Krill by KorAP.
the class SpanSegmentQueryWrapper method _listToOrQuery.
private SpanQuery _listToOrQuery(ArrayList<SpanQueryWrapper> list) throws QueryException {
if (list.size() == 1) {
return (SpanQuery) list.get(0).toFragmentQuery();
}
;
Iterator<SpanQueryWrapper> clause = list.iterator();
SpanOrQuery soquery = new SpanOrQuery(clause.next().toFragmentQuery());
while (clause.hasNext()) {
soquery.addClause(clause.next().toFragmentQuery());
}
;
return (SpanQuery) soquery;
}
use of de.ids_mannheim.korap.query.wrap.SpanQueryWrapper in project Krill by KorAP.
the class KrillQuery method _groupFromJson.
// Deserialize koral:group
private SpanQueryWrapper _groupFromJson(JsonNode json) throws QueryException {
// No operation
if (!json.has("operation"))
throw new QueryException(703, "Group expects operation");
// Get operation
String operation = json.get("operation").asText();
if (DEBUG)
log.trace("Found {} group", operation);
if (!json.has("operands"))
throw new QueryException(704, "Operation needs operand list");
// Get all operands
JsonNode operands = json.get("operands");
if (operands == null || !operands.isArray())
throw new QueryException(704, "Operation needs operand list");
if (DEBUG)
log.trace("Operands are {}", operands);
SpanQueryWrapper spanReferenceQueryWrapper = _operationReferenceFromJSON(json, operands);
if (spanReferenceQueryWrapper != null) {
return spanReferenceQueryWrapper;
}
// Branch on operation
switch(operation) {
case "operation:junction":
return this._operationJunctionFromJson(operands);
case "operation:position":
return this._operationPositionFromJson(json, operands);
case "operation:sequence":
return this._operationSequenceFromJson(json, operands);
case "operation:class":
return this._operationClassFromJson(json, operands);
case "operation:repetition":
return this._operationRepetitionFromJson(json, operands);
case "operation:relation":
// }
if (json.has("relType"))
return _operationRelationFromJson(operands, json.get("relType"));
else // EM: legacy
if (json.has("relation")) {
return _operationRelationFromJson(operands, json.get("relation"));
} else {
throw new QueryException(717, "Missing relation node");
}
// Gracefully warn on merge support
case "operation:merge":
this.addWarning(774, "Merge operation is currently not supported");
return _fromKoral(operands.get(0));
// Deprecated in favor of operation:junction
case "operation:or":
return this._operationJunctionFromJson(operands);
/*
case "operation:submatch": // Deprecated in favor of koral:reference
return this._operationSubmatchFromJson(json, operands);
*/
case "operation:disjunction":
return this._operationJunctionFromJson(operands);
}
;
// Unknown
throw new QueryException(711, "Unknown group operation");
}
Aggregations