Search in sources :

Example 1 with SpanSequenceQueryWrapper

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

the class TestNextIndex method indexExample7Distances.

@Test
public void indexExample7Distances() throws Exception {
    KrillIndex ki = new KrillIndex();
    ki.addDoc(createFieldDoc1());
    ki.addDoc(createFieldDoc2());
    ki.addDoc(createFieldDoc3());
    ki.addDoc(createFieldDoc4());
    ki.commit();
    SpanSequenceQueryWrapper sq = new SpanSequenceQueryWrapper("base");
    sq.append("i:b").append("i:d").withConstraint(1, 3);
    Result kr = ki.search(sq.toQuery(), (short) 10);
    assertEquals("totalResults", kr.getTotalResults(), 3);
    assertEquals("doc-number", "match-doc-0-p2-5", kr.getMatch(0).getID());
    assertEquals("doc-number", "match-doc-2-p2-4", kr.getMatch(1).getID());
    assertEquals("doc-number", "match-doc-3-p2-5", kr.getMatch(2).getID());
}
Also used : KrillIndex(de.ids_mannheim.korap.KrillIndex) SpanSequenceQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanSequenceQueryWrapper) Result(de.ids_mannheim.korap.response.Result) Test(org.junit.Test)

Example 2 with SpanSequenceQueryWrapper

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

the class TestSegmentNegationIndex method testcaseNegation.

@Test
public void testcaseNegation() throws Exception {
    ki = new KrillIndex();
    ki.addDoc(createFieldDoc0());
    ki.addDoc(createFieldDoc1());
    ki.addDoc(createFieldDoc2());
    ki.addDoc(createFieldDoc3());
    ki.commit();
    SpanSegmentQueryWrapper ssqw = new SpanSegmentQueryWrapper("tokens", "s:b");
    ssqw.with("s:c");
    SpanSequenceQueryWrapper sqw = new SpanSequenceQueryWrapper("tokens", ssqw).append("s:d");
    kr = ki.search(sqw.toQuery(), (short) 10);
    assertEquals("totalResults", kr.getTotalResults(), 2);
    // Match #0
    assertEquals("doc-number", 0, kr.getMatch(0).getLocalDocID());
    assertEquals("StartPos (0)", 4, kr.getMatch(0).startPos);
    assertEquals("EndPos (0)", 6, kr.getMatch(0).endPos);
    // Match #1 in the other atomic index
    assertEquals("doc-number", 3, kr.getMatch(1).getLocalDocID());
    assertEquals("StartPos (0)", 0, kr.getMatch(1).startPos);
    assertEquals("EndPos (0)", 2, kr.getMatch(1).endPos);
    ssqw = new SpanSegmentQueryWrapper("tokens", "s:b");
    ssqw.without("s:c");
    sqw = new SpanSequenceQueryWrapper("tokens", ssqw).append("s:a");
    kr = ki.search(sqw.toQuery(), (short) 10);
    assertEquals("doc-number", 0, kr.getMatch(0).getLocalDocID());
    assertEquals("StartPos (0)", 2, kr.getMatch(0).startPos);
    assertEquals("EndPos (0)", 4, kr.getMatch(0).endPos);
    assertEquals("doc-number", 1, kr.getMatch(1).getLocalDocID());
    assertEquals("StartPos (1)", 1, kr.getMatch(1).startPos);
    assertEquals("EndPos (1)", 3, kr.getMatch(1).endPos);
    assertEquals("doc-number", 1, kr.getMatch(2).getLocalDocID());
    assertEquals("StartPos (2)", 2, kr.getMatch(2).startPos);
    assertEquals("EndPos (2)", 4, kr.getMatch(2).endPos);
    assertEquals("doc-number", 2, kr.getMatch(3).getLocalDocID());
    assertEquals("StartPos (3)", 1, kr.getMatch(3).startPos);
    assertEquals("EndPos (3)", 3, kr.getMatch(3).endPos);
}
Also used : SpanSegmentQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanSegmentQueryWrapper) KrillIndex(de.ids_mannheim.korap.KrillIndex) SpanSequenceQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanSequenceQueryWrapper) Test(org.junit.Test)

Example 3 with SpanSequenceQueryWrapper

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

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

the class TestSpanSegmentSequenceQuery method spanSegmentSequenceQueryPrepend.

@Test
public void spanSegmentSequenceQueryPrepend() throws QueryException {
    SpanSequenceQueryWrapper sssq = new SpanSequenceQueryWrapper("field", "b", "c");
    sssq.prepend("a");
    assertEquals("spanNext(spanNext(field:a, field:b), field:c)", sssq.toQuery().toString());
}
Also used : SpanSequenceQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanSequenceQueryWrapper) Test(org.junit.Test)

Example 5 with SpanSequenceQueryWrapper

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

the class TestSpanSegmentSequenceQuery method spanSegmentSequenceQueryPrepend3.

@Test
public void spanSegmentSequenceQueryPrepend3() throws QueryException {
    SpanSequenceQueryWrapper sssq = new SpanSequenceQueryWrapper("field", "c", "d");
    SpanRegexQueryWrapper ssreq = new SpanRegexQueryWrapper("field", "a.?b");
    sssq.prepend(ssreq);
    assertEquals("spanNext(spanNext(SpanMultiTermQueryWrapper(field:/a.?b/), field:c), field: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

SpanSequenceQueryWrapper (de.ids_mannheim.korap.query.wrap.SpanSequenceQueryWrapper)14 Test (org.junit.Test)13 KrillIndex (de.ids_mannheim.korap.KrillIndex)3 SpanSegmentQueryWrapper (de.ids_mannheim.korap.query.wrap.SpanSegmentQueryWrapper)3 SpanWithinQuery (de.ids_mannheim.korap.query.SpanWithinQuery)2 SpanRegexQueryWrapper (de.ids_mannheim.korap.query.wrap.SpanRegexQueryWrapper)2 Result (de.ids_mannheim.korap.response.Result)2 QueryException (de.ids_mannheim.korap.util.QueryException)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 SpanElementQuery (de.ids_mannheim.korap.query.SpanElementQuery)1 SpanClassQueryWrapper (de.ids_mannheim.korap.query.wrap.SpanClassQueryWrapper)1 SpanRepetitionQueryWrapper (de.ids_mannheim.korap.query.wrap.SpanRepetitionQueryWrapper)1