Search in sources :

Example 1 with SpanClassQueryWrapper

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

Aggregations

SpanClassQueryWrapper (de.ids_mannheim.korap.query.wrap.SpanClassQueryWrapper)1 SpanRepetitionQueryWrapper (de.ids_mannheim.korap.query.wrap.SpanRepetitionQueryWrapper)1 SpanSequenceQueryWrapper (de.ids_mannheim.korap.query.wrap.SpanSequenceQueryWrapper)1 QueryException (de.ids_mannheim.korap.util.QueryException)1 Test (org.junit.Test)1