Search in sources :

Example 6 with SpanRegexQueryWrapper

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

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

the class TestSpanSegmentQuery method spanSegmentRegexQuery.

@Test
public void spanSegmentRegexQuery() throws QueryException {
    SpanSegmentQueryWrapper ssquery = new SpanSegmentQueryWrapper("field");
    assertNull(ssquery.toQuery());
    ssquery.with("a");
    assertEquals("field:a", ssquery.toQuery().toString());
    ssquery.with(new SpanRegexQueryWrapper("field", "a.*b"));
    assertEquals("spanSegment(field:a, SpanMultiTermQueryWrapper(field:/a.*b/))", ssquery.toQuery().toString());
    ssquery.with("c");
    assertEquals("spanSegment(spanSegment(field:a, SpanMultiTermQueryWrapper(field:/a.*b/)), field:c)", ssquery.toQuery().toString());
    ssquery.with("d").with("e");
    assertEquals("spanSegment(spanSegment(spanSegment(spanSegment(field:a, SpanMultiTermQueryWrapper(field:/a.*b/)), field:c), field:d), field:e)", ssquery.toQuery().toString());
    ssquery.without(new SpanRegexQueryWrapper("field", "x.?y"));
    assertEquals("spanNot(spanSegment(spanSegment(spanSegment(spanSegment(field:a, SpanMultiTermQueryWrapper(field:/a.*b/)), field:c), field:d), field:e), SpanMultiTermQueryWrapper(field:/x.?y/), 0, 0)", ssquery.toQuery().toString());
    ssquery.without(new SpanRegexQueryWrapper("field", "z{5,9}"));
    assertEquals("spanNot(spanSegment(spanSegment(spanSegment(spanSegment(field:a, SpanMultiTermQueryWrapper(field:/a.*b/)), field:c), field:d), field:e), spanOr([SpanMultiTermQueryWrapper(field:/x.?y/), SpanMultiTermQueryWrapper(field:/z{5,9}/)]), 0, 0)", ssquery.toQuery().toString());
}
Also used : SpanRegexQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanRegexQueryWrapper) SpanSegmentQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanSegmentQueryWrapper) Test(org.junit.Test)

Example 8 with SpanRegexQueryWrapper

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

the class TestSpanSegmentAlterQuery 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 9 with SpanRegexQueryWrapper

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

the class TestSpanSegmentSequenceQuery method spanSegmentSequenceQuery3.

@Test
public void spanSegmentSequenceQuery3() throws QueryException {
    SpanSequenceQueryWrapper sssq = new SpanSequenceQueryWrapper("field", "a", "b");
    SpanRegexQueryWrapper ssreq = new SpanRegexQueryWrapper("field", "c.?d");
    sssq.append(ssreq);
    assertEquals("spanNext(spanNext(field:a, field:b), SpanMultiTermQueryWrapper(field:/c.?d/))", sssq.toQuery().toString());
}
Also used : SpanRegexQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanRegexQueryWrapper) SpanSequenceQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanSequenceQueryWrapper) Test(org.junit.Test)

Aggregations

SpanRegexQueryWrapper (de.ids_mannheim.korap.query.wrap.SpanRegexQueryWrapper)9 Test (org.junit.Test)7 SpanSegmentQueryWrapper (de.ids_mannheim.korap.query.wrap.SpanSegmentQueryWrapper)5 SpanAlterQueryWrapper (de.ids_mannheim.korap.query.wrap.SpanAlterQueryWrapper)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 SpanQueryWrapper (de.ids_mannheim.korap.query.wrap.SpanQueryWrapper)2 SpanSequenceQueryWrapper (de.ids_mannheim.korap.query.wrap.SpanSequenceQueryWrapper)2 QueryException (de.ids_mannheim.korap.util.QueryException)2 Test (de.ids_mannheim.korap.Test)1 MultiTerm (de.ids_mannheim.korap.index.MultiTerm)1 QueryBuilder (de.ids_mannheim.korap.query.QueryBuilder)1 SpanRepetitionQueryWrapper (de.ids_mannheim.korap.query.wrap.SpanRepetitionQueryWrapper)1 SpanWildcardQueryWrapper (de.ids_mannheim.korap.query.wrap.SpanWildcardQueryWrapper)1 Iterator (java.util.Iterator)1 StandardAnalyzer (org.apache.lucene.analysis.standard.StandardAnalyzer)1 DirectoryReader (org.apache.lucene.index.DirectoryReader)1 IndexWriter (org.apache.lucene.index.IndexWriter)1 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)1 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)1 Term (org.apache.lucene.index.Term)1