Search in sources :

Example 6 with SpanAlterQueryWrapper

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

the class KrillQuery method _segFromJson.

// Deserialize koral:token
private SpanQueryWrapper _segFromJson(JsonNode json) throws QueryException {
    if (!json.has("@type"))
        throw new QueryException(701, "JSON-LD group has no @type attribute");
    String type = json.get("@type").asText();
    if (DEBUG)
        log.trace("Wrap new token definition by {}", type);
    // Branch on type
    switch(type) {
        case "koral:term":
            // case "match:eq":
            return this._termFromJson(json);
        case "koral:termGroup":
            if (!json.has("operands"))
                throw new QueryException(742, "Term group needs operand list");
            // Get operands
            JsonNode operands = json.get("operands");
            SpanSegmentQueryWrapper ssegqw = this.builder().seg();
            if (!json.has("relation"))
                throw new QueryException(743, "Term group expects a relation");
            switch(json.get("relation").asText()) {
                case "relation:and":
                    for (JsonNode operand : operands) {
                        SpanQueryWrapper part = this._segFromJson(operand);
                        if (part instanceof SpanAlterQueryWrapper) {
                            ssegqw.with((SpanAlterQueryWrapper) part);
                        } else if (part instanceof SpanRegexQueryWrapper) {
                            ssegqw.with((SpanRegexQueryWrapper) part);
                        } else if (part instanceof SpanSegmentQueryWrapper) {
                            ssegqw.with((SpanSegmentQueryWrapper) part);
                        } else {
                            throw new QueryException(744, "Operand not supported in term group");
                        }
                        ;
                    }
                    ;
                    return ssegqw;
                case "relation:or":
                    SpanAlterQueryWrapper ssaq = new SpanAlterQueryWrapper(this.field);
                    for (JsonNode operand : operands) {
                        ssaq.or(this._segFromJson(operand));
                    }
                    ;
                    return ssaq;
            }
            ;
    }
    ;
    throw new QueryException(745, "Token type is not supported");
}
Also used : QueryException(de.ids_mannheim.korap.util.QueryException) SpanRegexQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanRegexQueryWrapper) SpanSegmentQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanSegmentQueryWrapper) SpanAlterQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanAlterQueryWrapper) JsonNode(com.fasterxml.jackson.databind.JsonNode) SpanQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanQueryWrapper)

Example 7 with SpanAlterQueryWrapper

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

the class TestSpanAlterQuery method spanAlterQuery.

@Test
public void spanAlterQuery() throws QueryException {
    SpanAlterQueryWrapper ssaquery = new SpanAlterQueryWrapper("field");
    ssaquery.or("b");
    assertEquals("field:b", ssaquery.toQuery().toString());
}
Also used : SpanAlterQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanAlterQueryWrapper) Test(org.junit.Test)

Example 8 with SpanAlterQueryWrapper

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

the class TestSpanAlterQuery method spanAlterQuery2.

@Test
public void spanAlterQuery2() throws QueryException {
    SpanAlterQueryWrapper ssaquery = new SpanAlterQueryWrapper("field");
    ssaquery.or("b").or("c");
    assertEquals("spanOr([field:b, field:c])", ssaquery.toQuery().toString());
}
Also used : SpanAlterQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanAlterQueryWrapper) Test(org.junit.Test)

Example 9 with SpanAlterQueryWrapper

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

the class TestSpanAlterQuery method spanAlterQuery4.

@Test
public void spanAlterQuery4() throws QueryException {
    SpanSegmentQueryWrapper segquery = new SpanSegmentQueryWrapper("field", "a", "b", "c");
    SpanAlterQueryWrapper ssaquery = new SpanAlterQueryWrapper("field");
    ssaquery.or("d").or(segquery).or("e");
    assertEquals("spanOr([field:d, spanSegment(spanSegment(field:a, field:b), field:c), field:e])", ssaquery.toQuery().toString());
}
Also used : SpanSegmentQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanSegmentQueryWrapper) SpanAlterQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanAlterQueryWrapper) Test(org.junit.Test)

Example 10 with SpanAlterQueryWrapper

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

the class TestSpanSegmentAlterQuery method spanAlterQuery2.

@Test
public void spanAlterQuery2() throws QueryException {
    SpanAlterQueryWrapper ssaquery = new SpanAlterQueryWrapper("field");
    ssaquery.or("b").or("c");
    assertEquals("spanOr([field:b, field:c])", ssaquery.toQuery().toString());
}
Also used : SpanAlterQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanAlterQueryWrapper) Test(org.junit.Test)

Aggregations

SpanAlterQueryWrapper (de.ids_mannheim.korap.query.wrap.SpanAlterQueryWrapper)13 Test (org.junit.Test)11 SpanRegexQueryWrapper (de.ids_mannheim.korap.query.wrap.SpanRegexQueryWrapper)4 SpanSegmentQueryWrapper (de.ids_mannheim.korap.query.wrap.SpanSegmentQueryWrapper)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 SpanQueryWrapper (de.ids_mannheim.korap.query.wrap.SpanQueryWrapper)2 QueryException (de.ids_mannheim.korap.util.QueryException)2 SpanWithAttributeQueryWrapper (de.ids_mannheim.korap.query.wrap.SpanWithAttributeQueryWrapper)1 ArrayList (java.util.ArrayList)1