use of de.ids_mannheim.korap.query.wrap.SpanSubspanQueryWrapper in project Krill by KorAP.
the class KrillQuery method _fromKoral.
private SpanQueryWrapper _fromKoral(JsonNode json, boolean isOperationRelation) throws QueryException {
int number = 0;
// TODO: Support @context for cosmas:...
if (!json.has("@type"))
throw new QueryException(701, "JSON-LD group has no @type attribute");
// Get @type for branching
String type = json.get("@type").asText();
switch(type) {
case "koral:group":
return this._groupFromJson(json);
case "koral:reference":
if (json.has("operation") && !json.get("operation").asText().equals("operation:focus"))
throw new QueryException(712, "Unknown reference operation");
if (!json.has("operands")) {
throw new QueryException(766, "Peripheral references are currently not supported");
}
JsonNode operands = json.get("operands");
if (!operands.isArray())
throw new QueryException(704, "Operation needs operand list");
if (operands.size() == 0)
throw new QueryException(704, "Operation needs operand list");
if (operands.size() != 1)
throw new QueryException(705, "Number of operands is not acceptable");
// Reference based on classes
if (json.has("classRef")) {
if (json.has("classRefOp")) {
throw new QueryException(761, "Class reference operators are currently not supported");
}
;
number = json.get("classRef").get(0).asInt();
if (number > MAX_CLASS_NUM)
throw new QueryException(709, "Valid class numbers exceeded");
} else // Reference based on spans
if (json.has("spanRef")) {
JsonNode spanRef = json.get("spanRef");
int length = 0;
int startOffset = 0;
if (!spanRef.isArray() || spanRef.size() == 0) {
throw new QueryException(714, "Span references expect a start position" + " and a length parameter");
}
;
if (spanRef.size() > 1)
length = spanRef.get(1).asInt(0);
startOffset = spanRef.get(0).asInt(0);
if (DEBUG)
log.trace("Wrap span reference {},{}", startOffset, length);
SpanQueryWrapper sqw = this._fromKoral(operands.get(0));
SpanSubspanQueryWrapper ssqw = new SpanSubspanQueryWrapper(sqw, startOffset, length);
return ssqw;
}
;
if (DEBUG)
log.trace("Wrap class reference {}", number);
return new SpanFocusQueryWrapper(this._fromKoral(operands.get(0)), number);
case "koral:token":
// The token is empty and should be treated like []
if (!json.has("wrap"))
return new SpanRepetitionQueryWrapper();
// Get wrapped token
return this._segFromJson(json.get("wrap"));
case "koral:span":
// it is allowed only in relation queries
if (isOperationRelation && !json.has("key") && !json.has("wrap") && !json.has("attr")) {
return new SpanRepetitionQueryWrapper();
}
if (!json.has("wrap"))
return this._termFromJson(json);
// This is an ugly hack
return this._termFromJson(json.get("wrap"), true);
}
;
// Unknown query type
throw new QueryException(713, "Query type is not supported");
}
Aggregations