Search in sources :

Example 1 with SpanQueryWrapper

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

the class TestSimple method getJSONQuery.

// Get query wrapper based on json file
public static SpanQueryWrapper getJSONQuery(String jsonFile) throws QueryException {
    SpanQueryWrapper sqwi;
    // try {
    String json = getJsonString(jsonFile);
    sqwi = new KrillQuery("tokens").fromKoral(json);
    // };
    return sqwi;
}
Also used : KrillQuery(de.ids_mannheim.korap.KrillQuery) SpanQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanQueryWrapper)

Example 2 with SpanQueryWrapper

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

the class TestBenchmarkSpans method jsonQuery.

public static SpanQueryWrapper jsonQuery(String jsonFile) {
    SpanQueryWrapper sqwi;
    try {
        String json = getString(jsonFile);
        sqwi = new KrillQuery("tokens").fromKoral(json);
    } catch (QueryException e) {
        fail(e.getMessage());
        sqwi = new QueryBuilder("tokens").seg("???");
    }
    ;
    return sqwi;
}
Also used : QueryException(de.ids_mannheim.korap.util.QueryException) KrillQuery(de.ids_mannheim.korap.KrillQuery) SpanQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanQueryWrapper) QueryBuilder(de.ids_mannheim.korap.query.QueryBuilder)

Example 3 with SpanQueryWrapper

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

the class TestElementDistanceIndex method testCase6.

/**
 * Test query from json (2)
 */
@Test
public void testCase6() throws Exception {
    ki = new KrillIndex();
    ki.addDoc(createFieldDoc0());
    ki.addDoc(createFieldDoc1());
    ki.addDoc(createFieldDoc2());
    ki.commit();
    SpanQueryWrapper sqwi;
    sqwi = new QueryBuilder("tokens").tag("base/s:t");
    kr = ki.search(sqwi.toQuery(), (short) 10);
    assertEquals(kr.getTotalResults(), 1);
    assertEquals("[[ecebdc]]", kr.getMatch(0).getSnippetBrackets());
    String jsonPath = URLDecoder.decode(getClass().getResource("/queries/distances/in-same-t.jsonld").getFile(), "UTF-8");
    sqwi = jsonQuery(jsonPath);
    assertEquals("spanElementDistance(tokens:s:c, tokens:s:e, [(base/s:t[0:0], ordered, notExcluded)])", sqwi.toQuery().toString());
    kr = ki.search(sqwi.toQuery(), (short) 10);
    // Is 1 correct or should it not be ordered?
    assertEquals(1, kr.getTotalResults());
    assertEquals("[[ec]]ebdc", kr.getMatch(0).getSnippetBrackets());
}
Also used : SpanQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanQueryWrapper) QueryBuilder(de.ids_mannheim.korap.query.QueryBuilder) KrillIndex(de.ids_mannheim.korap.KrillIndex) Test(org.junit.Test)

Example 4 with SpanQueryWrapper

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

the class SpanSegmentQueryWrapper method _listToOrQuery.

private SpanQuery _listToOrQuery(ArrayList<SpanQueryWrapper> list) throws QueryException {
    if (list.size() == 1) {
        return (SpanQuery) list.get(0).toFragmentQuery();
    }
    ;
    Iterator<SpanQueryWrapper> clause = list.iterator();
    SpanOrQuery soquery = new SpanOrQuery(clause.next().toFragmentQuery());
    while (clause.hasNext()) {
        soquery.addClause(clause.next().toFragmentQuery());
    }
    ;
    return (SpanQuery) soquery;
}
Also used : SpanQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanQueryWrapper) SpanOrQuery(org.apache.lucene.search.spans.SpanOrQuery) SpanQuery(org.apache.lucene.search.spans.SpanQuery)

Example 5 with SpanQueryWrapper

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

the class KrillQuery method _groupFromJson.

// Deserialize koral:group
private SpanQueryWrapper _groupFromJson(JsonNode json) throws QueryException {
    // No operation
    if (!json.has("operation"))
        throw new QueryException(703, "Group expects operation");
    // Get operation
    String operation = json.get("operation").asText();
    if (DEBUG)
        log.trace("Found {} group", operation);
    if (!json.has("operands"))
        throw new QueryException(704, "Operation needs operand list");
    // Get all operands
    JsonNode operands = json.get("operands");
    if (operands == null || !operands.isArray())
        throw new QueryException(704, "Operation needs operand list");
    if (DEBUG)
        log.trace("Operands are {}", operands);
    SpanQueryWrapper spanReferenceQueryWrapper = _operationReferenceFromJSON(json, operands);
    if (spanReferenceQueryWrapper != null) {
        return spanReferenceQueryWrapper;
    }
    // Branch on operation
    switch(operation) {
        case "operation:junction":
            return this._operationJunctionFromJson(operands);
        case "operation:position":
            return this._operationPositionFromJson(json, operands);
        case "operation:sequence":
            return this._operationSequenceFromJson(json, operands);
        case "operation:class":
            return this._operationClassFromJson(json, operands);
        case "operation:repetition":
            return this._operationRepetitionFromJson(json, operands);
        case "operation:relation":
            // }
            if (json.has("relType"))
                return _operationRelationFromJson(operands, json.get("relType"));
            else // EM: legacy
            if (json.has("relation")) {
                return _operationRelationFromJson(operands, json.get("relation"));
            } else {
                throw new QueryException(717, "Missing relation node");
            }
        // Gracefully warn on merge support
        case "operation:merge":
            this.addWarning(774, "Merge operation is currently not supported");
            return _fromKoral(operands.get(0));
        // Deprecated in favor of operation:junction
        case "operation:or":
            return this._operationJunctionFromJson(operands);
        /*
              case "operation:submatch": // Deprecated in favor of koral:reference
              return this._operationSubmatchFromJson(json, operands);
            */
        case "operation:disjunction":
            return this._operationJunctionFromJson(operands);
    }
    ;
    // Unknown
    throw new QueryException(711, "Unknown group operation");
}
Also used : QueryException(de.ids_mannheim.korap.util.QueryException) JsonNode(com.fasterxml.jackson.databind.JsonNode) SpanQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanQueryWrapper)

Aggregations

SpanQueryWrapper (de.ids_mannheim.korap.query.wrap.SpanQueryWrapper)165 Test (org.junit.Test)150 SpanQuery (org.apache.lucene.search.spans.SpanQuery)65 KrillIndex (de.ids_mannheim.korap.KrillIndex)17 QueryException (de.ids_mannheim.korap.util.QueryException)14 KrillQuery (de.ids_mannheim.korap.KrillQuery)13 QueryBuilder (de.ids_mannheim.korap.query.QueryBuilder)11 Result (de.ids_mannheim.korap.response.Result)8 JsonNode (com.fasterxml.jackson.databind.JsonNode)7 Krill (de.ids_mannheim.korap.Krill)5 SpanRepetitionQueryWrapper (de.ids_mannheim.korap.query.wrap.SpanRepetitionQueryWrapper)3 TestSimple.getJsonString (de.ids_mannheim.korap.TestSimple.getJsonString)2 SpanClassQuery (de.ids_mannheim.korap.query.SpanClassQuery)2 SpanDistanceQuery (de.ids_mannheim.korap.query.SpanDistanceQuery)2 SpanWithinQuery (de.ids_mannheim.korap.query.SpanWithinQuery)2 SpanAlterQueryWrapper (de.ids_mannheim.korap.query.wrap.SpanAlterQueryWrapper)2 SpanRegexQueryWrapper (de.ids_mannheim.korap.query.wrap.SpanRegexQueryWrapper)2 SpanSegmentQueryWrapper (de.ids_mannheim.korap.query.wrap.SpanSegmentQueryWrapper)2 Term (org.apache.lucene.index.Term)2 SpanOrQuery (org.apache.lucene.search.spans.SpanOrQuery)2