Search in sources :

Example 1 with SpanWithinQueryWrapper

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

the class KrillQuery method _operationPositionFromJson.

// Deserialize operation:position
private SpanQueryWrapper _operationPositionFromJson(JsonNode json, JsonNode operands) throws QueryException {
    if (operands.size() != 2)
        throw new QueryException(705, "Number of operands is not acceptable");
    String frame = "isAround";
    // Temporary workaround for wrongly set overlaps
    if (json.has("frames")) {
        JsonNode frameN = json.get("frames");
        if (frameN.isArray()) {
            frameN = json.get("frames").get(0);
            if (frameN != null && frameN.isValueNode())
                frame = frameN.asText().substring(7);
        }
        ;
    } else // <legacyCode>
    if (json.has("frame")) {
        this.addMessage(0, "Frame is deprecated");
        JsonNode frameN = json.get("frame");
        if (frameN != null && frameN.isValueNode())
            frame = frameN.asText().substring(6);
    }
    ;
    if (DEBUG)
        log.trace("Position frame is '{}'", frame);
    // Byte flag - should cover all 13 cases, i.e. two bytes long
    byte flag = WITHIN;
    switch(frame) {
        case "isAround":
            JsonNode operand = operands.get(0);
            if (operand.get("@type").asText().equals("koral:token")) {
                throw new QueryException(StatusCodes.INVALID_QUERY, "Token cannot contain another token or element.");
            }
            break;
        case "strictlyContains":
            flag = REAL_WITHIN;
            break;
        case "isWithin":
            break;
        case "startsWith":
            flag = STARTSWITH;
            break;
        case "endsWith":
            flag = ENDSWITH;
            break;
        case "matches":
            flag = MATCH;
            break;
        case "overlaps":
            flag = OVERLAP;
            this.addWarning(769, "Overlap variant currently interpreted as overlap");
            break;
        case "overlapsLeft":
            // Temporary workaround
            this.addWarning(769, "Overlap variant currently interpreted as overlap");
            flag = OVERLAP;
            break;
        case "overlapsRight":
            // Temporary workaround
            this.addWarning(769, "Overlap variant currently interpreted as overlap");
            flag = OVERLAP;
            break;
        case "strictlyOverlaps":
            flag = REAL_OVERLAP;
            break;
        default:
            throw new QueryException(706, "Frame type is unknown");
    }
    ;
    // <legacyCode>
    Boolean exclude;
    if (json.has("exclude") && json.get("exclude").asBoolean()) {
        throw new QueryException(760, "Exclusion is currently not supported in position operations");
    }
    ;
    // Create SpanWithin Query
    return new SpanWithinQueryWrapper(this._fromKoral(operands.get(0)), this._fromKoral(operands.get(1)), flag);
}
Also used : QueryException(de.ids_mannheim.korap.util.QueryException) JsonNode(com.fasterxml.jackson.databind.JsonNode) SpanWithinQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanWithinQueryWrapper)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)1 SpanWithinQueryWrapper (de.ids_mannheim.korap.query.wrap.SpanWithinQueryWrapper)1 QueryException (de.ids_mannheim.korap.util.QueryException)1