Search in sources :

Example 1 with SpanFocusQueryWrapper

use of de.ids_mannheim.korap.query.wrap.SpanFocusQueryWrapper 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");
}
Also used : SpanRepetitionQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanRepetitionQueryWrapper) QueryException(de.ids_mannheim.korap.util.QueryException) JsonNode(com.fasterxml.jackson.databind.JsonNode) SpanQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanQueryWrapper) SpanSubspanQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanSubspanQueryWrapper) SpanFocusQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanFocusQueryWrapper)

Example 2 with SpanFocusQueryWrapper

use of de.ids_mannheim.korap.query.wrap.SpanFocusQueryWrapper in project Krill by KorAP.

the class KrillQuery method _operationSubmatchFromJson.

// Deserialize operation:submatch
@Deprecated
private SpanQueryWrapper _operationSubmatchFromJson(JsonNode json, JsonNode operands) throws QueryException {
    int number = 1;
    this.addMessage(0, "operation:submatch is deprecated");
    if (operands.size() != 1)
        throw new QueryException(705, "Number of operands is not acceptable");
    // Use class reference
    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();
    } else // Use span reference
    if (json.has("spanRef")) {
        throw new QueryException(762, "Span references are currently not supported");
    }
    ;
    return new SpanFocusQueryWrapper(this._fromKoral(operands.get(0)), number);
}
Also used : QueryException(de.ids_mannheim.korap.util.QueryException) SpanFocusQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanFocusQueryWrapper)

Aggregations

SpanFocusQueryWrapper (de.ids_mannheim.korap.query.wrap.SpanFocusQueryWrapper)2 QueryException (de.ids_mannheim.korap.util.QueryException)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 SpanQueryWrapper (de.ids_mannheim.korap.query.wrap.SpanQueryWrapper)1 SpanRepetitionQueryWrapper (de.ids_mannheim.korap.query.wrap.SpanRepetitionQueryWrapper)1 SpanSubspanQueryWrapper (de.ids_mannheim.korap.query.wrap.SpanSubspanQueryWrapper)1