Search in sources :

Example 1 with SpanAlterQueryWrapper

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

the class TestSpanAlterQuery method spanAlterQuery5.

@Test
public void spanAlterQuery5() throws QueryException {
    SpanRegexQueryWrapper srequery = new SpanRegexQueryWrapper("field", "a[bc]d.?e");
    SpanAlterQueryWrapper ssaquery = new SpanAlterQueryWrapper("field");
    ssaquery.or("f").or(srequery).or("g");
    assertEquals("spanOr([field:f, SpanMultiTermQueryWrapper(field:/a[bc]d.?e/), field:g])", ssaquery.toQuery().toString());
}
Also used : SpanRegexQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanRegexQueryWrapper) SpanAlterQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanAlterQueryWrapper) Test(org.junit.Test)

Example 2 with SpanAlterQueryWrapper

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

the class TestSpanAlterQuery method spanAlterQuery3.

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

Example 3 with SpanAlterQueryWrapper

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

the class TestSpanSegmentQuery method spanSegmentAlterQuery.

@Test
public void spanSegmentAlterQuery() throws QueryException {
    SpanSegmentQueryWrapper ssquery = new SpanSegmentQueryWrapper("field");
    assertNull(ssquery.toQuery());
    ssquery.with("a");
    assertEquals("field:a", ssquery.toQuery().toString());
    ssquery.with(new SpanAlterQueryWrapper("field", "c", "d"));
    ssquery.with(new SpanRegexQueryWrapper("field", "a.*b"));
    assertEquals("spanSegment(spanSegment(field:a, spanOr([field:c, field:d])), SpanMultiTermQueryWrapper(field:/a.*b/))", ssquery.toQuery().toString());
}
Also used : SpanRegexQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanRegexQueryWrapper) SpanSegmentQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanSegmentQueryWrapper) SpanAlterQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanAlterQueryWrapper) Test(org.junit.Test)

Example 4 with SpanAlterQueryWrapper

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

the class TestSpanSegmentAlterQuery 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 5 with SpanAlterQueryWrapper

use of de.ids_mannheim.korap.query.wrap.SpanAlterQueryWrapper 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

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