Search in sources :

Example 16 with QueryException

use of de.ids_mannheim.korap.util.QueryException in project Krill by KorAP.

the class TestKrillQueryJSON method queryJSONcomplexSpanOrTerm.

@Test
public void queryJSONcomplexSpanOrTerm() throws QueryException {
    // startsWith(<base/s=s>, { lassen | laufen })
    try {
        String json = getString(getClass().getResource("/queries/bugs/span_or_bug.jsonld").getFile());
        KrillQuery kq = new KrillQuery("tokens");
        assertEquals(kq.fromKoral(json).toQuery().toString(), "spanStartsWith(<tokens:base/s:s />, spanOr([tokens:s:Er, tokens:s:Sie]))");
    } catch (QueryException e) {
        fail(e.getMessage());
    }
    ;
}
Also used : QueryException(de.ids_mannheim.korap.util.QueryException) KrillQuery(de.ids_mannheim.korap.KrillQuery) Test(org.junit.Test)

Example 17 with QueryException

use of de.ids_mannheim.korap.util.QueryException in project Krill by KorAP.

the class TestKrillQueryJSON method queryJSONunderspecifiedTokenBug.

@Test
public void queryJSONunderspecifiedTokenBug() {
    // ((MORPH(APPR) ODER MORPH(APPRART)) /+w1 Urlaub
    try {
        String json = getString(getClass().getResource("/queries/bugs/underspecified_token.jsonld").getFile());
        new KrillQuery("tokens").fromKoral(json);
    } catch (QueryException e) {
        assertEquals(701, e.getErrorCode());
    }
    ;
}
Also used : QueryException(de.ids_mannheim.korap.util.QueryException) KrillQuery(de.ids_mannheim.korap.KrillQuery) Test(org.junit.Test)

Example 18 with QueryException

use of de.ids_mannheim.korap.util.QueryException in project Krill by KorAP.

the class TestSpanSequenceQuery method spanSequenceQueryWrapper.

@Test
public void spanSequenceQueryWrapper() throws QueryException {
    SpanSequenceQueryWrapper ssqw, ssqw2;
    SpanRepetitionQueryWrapper srqw;
    SpanClassQueryWrapper scqw;
    // Synopsis 1
    ssqw = new SpanSequenceQueryWrapper("tokens", "der", "Baum");
    assertEquals("spanNext(tokens:der, tokens:Baum)", ssqw.toQuery().toString());
    // Synopsis 2
    ssqw = new SpanSequenceQueryWrapper("tokens");
    ssqw.append("der").append("Baum");
    assertEquals("spanNext(tokens:der, tokens:Baum)", ssqw.toQuery().toString());
    // Append a sequence
    ssqw = new SpanSequenceQueryWrapper("tokens");
    ssqw2 = new SpanSequenceQueryWrapper("tokens");
    ssqw.append("der").append("Baum");
    ssqw2.append("fiel").append("still");
    ssqw.append(ssqw2);
    // This may not be final
    assertEquals("spanNext(spanNext(spanNext(tokens:der, tokens:Baum), tokens:fiel), tokens:still)", ssqw.toQuery().toString());
    // Synopsis 3
    ssqw = new SpanSequenceQueryWrapper("tokens", "Baum");
    ssqw.prepend("der");
    assertEquals("spanNext(tokens:der, tokens:Baum)", ssqw.toQuery().toString());
    // Prepend a sequence
    ssqw = new SpanSequenceQueryWrapper("tokens");
    ssqw2 = new SpanSequenceQueryWrapper("tokens");
    ssqw.append("fiel").append("still");
    ssqw2.append("der").append("Baum");
    ssqw.prepend(ssqw2);
    // This may change
    assertEquals("spanNext(spanNext(spanNext(tokens:der, tokens:Baum), tokens:fiel), tokens:still)", ssqw.toQuery().toString());
    // Add constraint
    ssqw.withConstraint(2, 4);
    // This may change
    assertEquals("spanDistance(spanDistance(spanDistance(tokens:der, " + "tokens:Baum, [(w[2:4], ordered, notExcluded)]), " + "tokens:fiel, [(w[2:4], ordered, notExcluded)]), " + "tokens:still, [(w[2:4], ordered, notExcluded)])", ssqw.toQuery().toString());
    ssqw = new SpanSequenceQueryWrapper("tokens", "der", "Baum").withConstraint(1, 1);
    assertEquals("spanNext(tokens:der, tokens:Baum)", ssqw.toQuery().toString());
    ssqw = new SpanSequenceQueryWrapper("tokens", "der", "Baum").withConstraint(1, 2, "s");
    assertEquals("spanElementDistance(tokens:der, tokens:Baum, [(s[1:2], ordered, notExcluded)])", ssqw.toQuery().toString());
    ssqw = new SpanSequenceQueryWrapper("tokens", "der", "Baum").withConstraint(1, 2, "s").withConstraint(2, 3, "x");
    assertEquals("spanMultipleDistance(tokens:der, tokens:Baum, " + "[(s[1:2], ordered, notExcluded), " + "(x[2:3], ordered, notExcluded)])", ssqw.toQuery().toString());
    ssqw = new SpanSequenceQueryWrapper("tokens").append("Baum").prepend("der").withConstraint(1, 2, "s", true).withConstraint(2, 3, "x");
    assertEquals("spanMultipleDistance(tokens:der, " + "tokens:Baum, [(s[1:2], ordered, excluded), " + "(x[2:3], ordered, notExcluded)])", ssqw.toQuery().toString());
    // Support empty class ins sequence
    ssqw = new SpanSequenceQueryWrapper("field", "Der");
    srqw = new SpanRepetitionQueryWrapper();
    scqw = new SpanClassQueryWrapper(srqw, (short) 3);
    ssqw.append(scqw);
    assertEquals("focus(254: spanContain(<field:base/s:t />, {254: spanExpansion(field:Der, []{1, 1}, right, class:3)}))", ssqw.toQuery().toString());
    // Support empty class ins sequence
    ssqw = new SpanSequenceQueryWrapper("field");
    srqw = new SpanRepetitionQueryWrapper();
    ssqw.append(srqw);
    scqw = new SpanClassQueryWrapper(ssqw, (short) 2);
    try {
        scqw.toQuery();
    } catch (Exception e) {
        fail(e.getMessage() + " (Known issue)");
    }
    ;
}
Also used : SpanRepetitionQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanRepetitionQueryWrapper) SpanClassQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanClassQueryWrapper) SpanSequenceQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanSequenceQueryWrapper) QueryException(de.ids_mannheim.korap.util.QueryException) Test(org.junit.Test)

Example 19 with QueryException

use of de.ids_mannheim.korap.util.QueryException in project Krill by KorAP.

the class TestSpanSequenceQueryJSON method queryJSONkoralOptionalityInDistanceBug.

@Test
public void queryJSONkoralOptionalityInDistanceBug() {
    try {
        // Sonne [] Mond?
        SpanQueryWrapper sqwi = jsonQueryFile("distance-with-optionality.jsonld");
        sqwi.toQuery().toString();
    } catch (QueryException qe) {
        assertEquals("Distance constraints not supported with empty, optional or negative operands", qe.getMessage());
    }
// Could also be a distance at the end ... that's a query planner thing.
}
Also used : QueryException(de.ids_mannheim.korap.util.QueryException) SpanQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanQueryWrapper) Test(org.junit.Test)

Example 20 with QueryException

use of de.ids_mannheim.korap.util.QueryException in project Krill by KorAP.

the class TestElementDistanceIndex 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)

Aggregations

QueryException (de.ids_mannheim.korap.util.QueryException)32 SpanQueryWrapper (de.ids_mannheim.korap.query.wrap.SpanQueryWrapper)14 JsonNode (com.fasterxml.jackson.databind.JsonNode)10 KrillQuery (de.ids_mannheim.korap.KrillQuery)10 Test (org.junit.Test)9 QueryBuilder (de.ids_mannheim.korap.query.QueryBuilder)5 SpanRepetitionQueryWrapper (de.ids_mannheim.korap.query.wrap.SpanRepetitionQueryWrapper)4 DistanceConstraint (de.ids_mannheim.korap.query.DistanceConstraint)2 SpanAlterQueryWrapper (de.ids_mannheim.korap.query.wrap.SpanAlterQueryWrapper)2 SpanFocusQueryWrapper (de.ids_mannheim.korap.query.wrap.SpanFocusQueryWrapper)2 SpanRegexQueryWrapper (de.ids_mannheim.korap.query.wrap.SpanRegexQueryWrapper)2 SpanSegmentQueryWrapper (de.ids_mannheim.korap.query.wrap.SpanSegmentQueryWrapper)2 SpanSequenceQueryWrapper (de.ids_mannheim.korap.query.wrap.SpanSequenceQueryWrapper)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 KrillIndex (de.ids_mannheim.korap.KrillIndex)1 RelationDirection (de.ids_mannheim.korap.constants.RelationDirection)1 SpanDistanceQuery (de.ids_mannheim.korap.query.SpanDistanceQuery)1 SpanMultipleDistanceQuery (de.ids_mannheim.korap.query.SpanMultipleDistanceQuery)1