Search in sources :

Example 1 with SpanWithAttributeQueryWrapper

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

the class KrillQuery method _handleAttrGroup.

// Deserialize attribute groups
private SpanQueryWrapper _handleAttrGroup(SpanQueryWrapper elementWithIdWrapper, JsonNode attrNode) throws QueryException {
    if (!attrNode.has("relation")) {
        throw new QueryException(743, "Term group expects a relation");
    }
    if (!attrNode.has("operands")) {
        throw new QueryException(742, "Term group needs operand list");
    }
    String relation = attrNode.get("relation").asText();
    JsonNode operands = attrNode.get("operands");
    SpanQueryWrapper attrWrapper;
    if ("relation:and".equals(relation)) {
        List<SpanQueryWrapper> wrapperList = new ArrayList<SpanQueryWrapper>();
        for (JsonNode operand : operands) {
            attrWrapper = _termFromJson(operand);
            if (attrWrapper == null) {
                throw new QueryException(747, "Attribute is null");
            }
            wrapperList.add(attrWrapper);
        }
        if (elementWithIdWrapper != null) {
            return new SpanWithAttributeQueryWrapper(elementWithIdWrapper, wrapperList);
        } else {
            return new SpanWithAttributeQueryWrapper(wrapperList);
        }
    } else if ("relation:or".equals(relation)) {
        SpanAlterQueryWrapper saq = new SpanAlterQueryWrapper(field);
        SpanWithAttributeQueryWrapper saqw;
        for (JsonNode operand : operands) {
            attrWrapper = _termFromJson(operand);
            if (attrWrapper == null) {
                throw new QueryException(747, "Attribute is null");
            }
            if (elementWithIdWrapper != null) {
                saqw = new SpanWithAttributeQueryWrapper(elementWithIdWrapper, attrWrapper);
            } else {
                saqw = new SpanWithAttributeQueryWrapper(attrWrapper);
            }
            saq.or(saqw);
        }
        return saq;
    } else {
        throw new QueryException(716, "Unknown relation");
    }
}
Also used : QueryException(de.ids_mannheim.korap.util.QueryException) SpanAlterQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanAlterQueryWrapper) ArrayList(java.util.ArrayList) SpanWithAttributeQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanWithAttributeQueryWrapper) JsonNode(com.fasterxml.jackson.databind.JsonNode) SpanQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanQueryWrapper)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)1 SpanAlterQueryWrapper (de.ids_mannheim.korap.query.wrap.SpanAlterQueryWrapper)1 SpanQueryWrapper (de.ids_mannheim.korap.query.wrap.SpanQueryWrapper)1 SpanWithAttributeQueryWrapper (de.ids_mannheim.korap.query.wrap.SpanWithAttributeQueryWrapper)1 QueryException (de.ids_mannheim.korap.util.QueryException)1 ArrayList (java.util.ArrayList)1