Search in sources :

Example 11 with SpanElementQuery

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

the class TestSubSpanIndex method testCaseNegativeSubSpan.

// Negative SubSpanQuery
@Test
public void testCaseNegativeSubSpan() throws IOException {
    KrillIndex ki = new KrillIndex();
    FieldDocument fd = new FieldDocument();
    fd.addTV("base", // <x>a <x>b </x>c </x>
    "a b c ", "[(0-1)s:a|i:a|_0$<i>0<i>2|<>:x$<b>64<i>0<i>6<i>3<b>0]" + "[(1-2)s:b|i:b|_1$<i>2<i>4|<>:x$<b>64<i>2<i>4<i>2<b>1]" + "[(3-4)s:c|i:c|_2$<i>4<i>6]");
    ki.addDoc(fd);
    ki.commit();
    SpanSubspanQuery ssq = new SpanSubspanQuery(new SpanElementQuery("base", "x"), -1, 1, true);
    kr = ki.search(ssq, (short) 10);
    /*        
        for (Match km : kr.getMatches()) {
            System.out.println(km.getStartPos() + "," + km.getEndPos()
                    + km.getSnippetBrackets());
        }
        */
    assertEquals(2, kr.getTotalResults());
    assertEquals(1, kr.getMatch(0).getStartPos());
    assertEquals(2, kr.getMatch(0).getEndPos());
    assertEquals("a [[b ]]c ", kr.getMatch(0).getSnippetBrackets());
    assertEquals(2, kr.getMatch(1).getStartPos());
    assertEquals(3, kr.getMatch(1).getEndPos());
    assertEquals("a b [[c ]]", kr.getMatch(1).getSnippetBrackets());
}
Also used : SpanSubspanQuery(de.ids_mannheim.korap.query.SpanSubspanQuery) KrillIndex(de.ids_mannheim.korap.KrillIndex) SpanElementQuery(de.ids_mannheim.korap.query.SpanElementQuery) Test(org.junit.Test)

Example 12 with SpanElementQuery

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

the class TestWPDIndex method createElementDistanceQuery.

private SpanDistanceQuery createElementDistanceQuery(String e, String x, String y, int min, int max, boolean isOrdered, boolean exclusion) {
    SpanElementQuery eq = new SpanElementQuery("tokens", e);
    SpanDistanceQuery sq = new SpanDistanceQuery(new SpanTermQuery(new Term("tokens", x)), new SpanTermQuery(new Term("tokens", y)), new DistanceConstraint(eq, min, max, isOrdered, exclusion), true);
    return sq;
}
Also used : SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) SpanDistanceQuery(de.ids_mannheim.korap.query.SpanDistanceQuery) DistanceConstraint(de.ids_mannheim.korap.query.DistanceConstraint) Term(org.apache.lucene.index.Term) SpanElementQuery(de.ids_mannheim.korap.query.SpanElementQuery)

Example 13 with SpanElementQuery

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

the class TestWithinIndex method indexExample2e.

@Test
public void indexExample2e() throws IOException {
    KrillIndex ki = new KrillIndex();
    // <a><a><a>h</a>hij</a>hij</a>
    FieldDocument fd = new FieldDocument();
    fd.addTV("base", // <a><a>hhij</a>hijh</a>ij</a>
    "h  h  i  j  h  i  j  h  i  j        ", "[s:h|_0$<i>0<i>3|<>:a$<b>64<i>0<i>12<i>4<b>0|" + "<>:a$<b>64<i>0<i>24<i>8<b>0|" + // 1
    "<>:a$<b>64<i>0<i>30<i>10<b>0]" + // 2
    "[s:h|_1$<i>3<i>6]" + // 3
    "[s:i|_2$<i>6<i>9]" + // 4
    "[s:j|_3$<i>9<i>12]" + // 5
    "[s:h|_4$<i>12<i>15]" + // 6
    "[s:i|_5$<i>15<i>18]" + // 7
    "[s:j|_6$<i>18<i>21]" + // 8
    "[s:h|_7$<i>21<i>24]" + // 9
    "[s:i|_8$<i>24<i>27]" + // 10
    "[s:j|_9$<i>27<i>30]");
    ki.addDoc(fd);
    // Save documents
    ki.commit();
    assertEquals(1, ki.numberOf("documents"));
    SpanQuery sq;
    Result kr;
    sq = new SpanWithinQuery(new SpanElementQuery("base", "a"), new SpanTermQuery(new Term("base", "s:h")));
    kr = ki.search(sq, (short) 10);
    // assertEquals("totalResults", 10, kr.getTotalResults());
    assertEquals("StartPos (0)", 0, kr.getMatch(0).startPos);
    assertEquals("EndPos (0)", 4, kr.getMatch(0).endPos);
    assertEquals("Snippet (0)", "[[h  h  i  j  ]]h  i  j  h  i  j   ...", kr.getMatch(0).getSnippetBrackets());
    assertEquals("StartPos (1)", 0, kr.getMatch(1).startPos);
    assertEquals("EndPos (1)", 4, kr.getMatch(1).endPos);
    assertEquals("Snippet (1)", "[[h  h  i  j  ]]h  i  j  h  i  j   ...", kr.getMatch(1).getSnippetBrackets());
    assertEquals("StartPos (2)", 0, kr.getMatch(2).startPos);
    assertEquals("EndPos (2)", 8, kr.getMatch(2).endPos);
    assertEquals("Snippet (2)", "[[h  h  i  j  h  i  j  h  ]]i  j        ", kr.getMatch(2).getSnippetBrackets());
    assertEquals("StartPos (3)", 0, kr.getMatch(3).startPos);
    assertEquals("EndPos (3)", 8, kr.getMatch(3).endPos);
    assertEquals("Snippet (3)", "[[h  h  i  j  h  i  j  h  ]]i  j        ", kr.getMatch(3).getSnippetBrackets());
    assertEquals("StartPos (4)", 0, kr.getMatch(4).startPos);
    assertEquals("EndPos (4)", 8, kr.getMatch(4).endPos);
    assertEquals("Snippet (4)", "[[h  h  i  j  h  i  j  h  ]]i  j        ", kr.getMatch(4).getSnippetBrackets());
    assertEquals("StartPos (5)", 0, kr.getMatch(5).startPos);
    assertEquals("EndPos (5)", 8, kr.getMatch(5).endPos);
    assertEquals("Snippet (5)", "[[h  h  i  j  h  i  j  h  ]]i  j        ", kr.getMatch(5).getSnippetBrackets());
    assertEquals("StartPos (6)", 0, kr.getMatch(6).startPos);
    assertEquals("EndPos (6)", 10, kr.getMatch(6).endPos);
    assertEquals("StartPos (7)", 0, kr.getMatch(7).startPos);
    assertEquals("EndPos (7)", 10, kr.getMatch(7).endPos);
    assertEquals("StartPos (8)", 0, kr.getMatch(8).startPos);
    assertEquals("EndPos (8)", 10, kr.getMatch(8).endPos);
    assertEquals("StartPos (9)", 0, kr.getMatch(9).startPos);
    assertEquals("EndPos (9)", 10, kr.getMatch(9).endPos);
}
Also used : SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) SpanWithinQuery(de.ids_mannheim.korap.query.SpanWithinQuery) Term(org.apache.lucene.index.Term) KrillIndex(de.ids_mannheim.korap.KrillIndex) SpanElementQuery(de.ids_mannheim.korap.query.SpanElementQuery) SpanQuery(org.apache.lucene.search.spans.SpanQuery) Result(de.ids_mannheim.korap.response.Result) Test(org.junit.Test)

Example 14 with SpanElementQuery

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

the class TestWithinIndex method indexExample1a.

// Todo: primary data as a non-indexed field separated.
@Test
public void indexExample1a() throws IOException {
    KrillIndex ki = new KrillIndex();
    // <a>x<a>y<a>zhij</a>hij</a>hij</a>
    FieldDocument fd = new FieldDocument();
    fd.addTV("base", "x   y   z   h   i   j   h   i   j   h   i   j   ", // 1
    "[(0-3)s:x|<>:a$<b>64<i>0<i>36<i>12<b>0]" + // 2
    "[(3-6)s:y|<>:a$<b>64<i>3<i>27<i>9<b>0]" + // 3
    "[(6-9)s:z|<>:a$<b>64<i>6<i>18<i>6<b>0]" + // 4
    "[(9-12)s:h]" + // 5
    "[(12-15)s:i]" + // 6
    "[(15-18)s:j]" + // 7
    "[(18-21)s:h]" + // 8
    "[(21-24)s:i]" + // 9
    "[(24-27)s:j]" + // 10
    "[(27-30)s:h]" + // 11
    "[(30-33)s:i]" + // 12
    "[(33-36)s:j]");
    ki.addDoc(fd);
    ki.commit();
    SpanQuery sq;
    Result kr;
    sq = new SpanWithinQuery(new SpanElementQuery("base", "a"), new SpanTermQuery(new Term("base", "s:h")));
    kr = ki.search(sq, (short) 10);
    assertEquals("totalResults", kr.getTotalResults(), 6);
    assertEquals("StartPos (0)", 0, kr.getMatch(0).startPos);
    assertEquals("EndPos (0)", 12, kr.getMatch(0).endPos);
    assertEquals("StartPos (1)", 0, kr.getMatch(1).startPos);
    assertEquals("EndPos (1)", 12, kr.getMatch(1).endPos);
    assertEquals("StartPos (2)", 0, kr.getMatch(2).startPos);
    assertEquals("EndPos (2)", 12, kr.getMatch(2).endPos);
    assertEquals("StartPos (3)", 1, kr.getMatch(3).startPos);
    assertEquals("EndPos (3)", 9, kr.getMatch(3).endPos);
    assertEquals("StartPos (4)", 1, kr.getMatch(4).startPos);
    assertEquals("EndPos (4)", 9, kr.getMatch(4).endPos);
    assertEquals("StartPos (5)", 2, kr.getMatch(5).startPos);
    assertEquals("EndPos (5)", 6, kr.getMatch(5).endPos);
    assertEquals(1, ki.numberOf("documents"));
}
Also used : SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) SpanWithinQuery(de.ids_mannheim.korap.query.SpanWithinQuery) Term(org.apache.lucene.index.Term) KrillIndex(de.ids_mannheim.korap.KrillIndex) SpanElementQuery(de.ids_mannheim.korap.query.SpanElementQuery) SpanQuery(org.apache.lucene.search.spans.SpanQuery) Result(de.ids_mannheim.korap.response.Result) Test(org.junit.Test)

Example 15 with SpanElementQuery

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

the class TestWithinIndex method indexExample3.

@Test
public void indexExample3() throws IOException {
    KrillIndex ki = new KrillIndex();
    // <a><a><a>u</a></a></a>
    FieldDocument fd = new FieldDocument();
    fd.addTV("base", "xyz", "[(0-3)s:xyz|<>:a$<b>64<i>0<i>3<i>0<b>0|" + "<>:a$<b>64<i>0<i>3<i>0<b>0|" + "<>:a$<b>64<i>0<i>3<i>0<b>0|" + "<>:b$<b>64<i>0<i>3<i>0<b>0]");
    ki.addDoc(fd);
    // <a><b>x<a>y<a>zcde</a>cde</a>cde</b></a>
    fd = new FieldDocument();
    fd.addTV("base", "x   y   z   c   d   e   c   d   e   c   d   e   ", "[(0-3)s:x|<>:a$<b>64<i>0<i>36<i>12<b>0|" + "<>:b$<b>64<i>0<i>36<i>12<b>0]" + "[(3-6)s:y|<>:a$<b>64<i>3<i>27<i>9<b>0]" + "[(6-9)s:z|<>:a$<b>64<i>6<i>18<i>6<b>0]" + "[(9-12)s:c]" + "[(12-15)s:d]" + "[(15-18)s:e]" + "[(18-21)s:c]" + "[(21-24)s:d]" + "[(24-27)s:e]" + "[(27-30)s:c]" + "[(30-33)s:d]" + "[(33-36)s:e]");
    ki.addDoc(fd);
    // xyz
    fd = new FieldDocument();
    fd.addTV("base", "x   y   z   ", "[(0-3)s:x]" + "[(3-6)s:y]" + "[(6-9)s:z]");
    ki.addDoc(fd);
    // <a>x<a><b>y<a>zcde</a>cde</b></a>cde</a>
    fd = new FieldDocument();
    fd.addTV("base", "x   y   z   k   l   m   k   l   m   k   l   m   ", "[(0-3)s:x|<>:a$<b>64<i>0<i>3<i>12<b>0]" + "[(3-6)s:y|<>:a$<b>64<i>3<i>6<i>9<b>0|" + "<>:b$<b>64<i>3<i>6<i>9<b>0]" + "[(6-9)s:z|<>:a$<b>64<i>6<i>9<i>6<b>0]" + "[(9-12)s:k]" + "[(12-15)s:l]" + "[(15-18)s:m]" + "[(18-21)s:k]" + "[(21-24)s:l]" + "[(24-27)s:m]" + "[(27-30)s:k]" + "[(30-33)s:l]" + "[(33-36)s:m]");
    ki.addDoc(fd);
    // <a><a><a>h</a>hhij</a>hij</a>hij</a>
    fd = new FieldDocument();
    fd.addTV("base", "h   i   j   h   i   j   h   i   j   ", "[(0-3)s:h|" + "<>:a$<b>64<i>0<i>18<i>3<b>0|" + "<>:a$<b>64<i>0<i>27<i>6<b>0|" + "<>:a$<b>64<i>0<i>36<i>9<b>0]" + "[(3-6)s:h]" + "[(12-15)s:i]" + "[(15-18)s:j]" + "[(18-21)s:h]" + "[(21-24)s:i]" + "[(24-27)s:j]" + "[(27-30)s:h]" + "[(30-33)s:i]" + "[(33-36)s:j]");
    ki.addDoc(fd);
    // xyz
    fd = new FieldDocument();
    fd.addTV("base", "a  b  c  ", "[(0-3)s:a]" + "[(3-6)s:b]" + "[(6-9)s:c]");
    ki.addDoc(fd);
    // Save documents
    ki.commit();
    assertEquals(6, ki.numberOf("documents"));
    SpanQuery sq = new SpanElementQuery("base", "a");
    Result kr = ki.search(sq, (short) 15);
    assertEquals("totalResults", kr.getTotalResults(), 12);
    assertEquals("StartPos (0)", 0, kr.getMatch(0).startPos);
    assertEquals("EndPos (0)", 0, kr.getMatch(0).endPos);
    assertEquals("StartPos (1)", 0, kr.getMatch(1).startPos);
    assertEquals("EndPos (1)", 0, kr.getMatch(1).endPos);
    assertEquals("StartPos (2)", 0, kr.getMatch(2).startPos);
    assertEquals("EndPos (2)", 0, kr.getMatch(2).endPos);
    assertEquals("StartPos (3)", 0, kr.getMatch(3).startPos);
    assertEquals("EndPos (3)", 12, kr.getMatch(3).endPos);
    assertEquals("StartPos (4)", 1, kr.getMatch(4).startPos);
    assertEquals("EndPos (4)", 9, kr.getMatch(4).endPos);
    assertEquals("StartPos (5)", 2, kr.getMatch(5).startPos);
    assertEquals("EndPos (5)", 6, kr.getMatch(5).endPos);
    assertEquals("StartPos (6)", 0, kr.getMatch(6).startPos);
    assertEquals("EndPos (6)", 12, kr.getMatch(6).endPos);
    assertEquals("StartPos (7)", 1, kr.getMatch(7).startPos);
    assertEquals("EndPos (7)", 9, kr.getMatch(7).endPos);
    assertEquals("StartPos (8)", 2, kr.getMatch(8).startPos);
    assertEquals("EndPos (8)", 6, kr.getMatch(8).endPos);
    assertEquals("StartPos (9)", 0, kr.getMatch(9).startPos);
    assertEquals("EndPos (9)", 3, kr.getMatch(9).endPos);
    assertEquals("StartPos (10)", 0, kr.getMatch(10).startPos);
    assertEquals("EndPos (10)", 6, kr.getMatch(10).endPos);
    assertEquals("StartPos (11)", 0, kr.getMatch(11).startPos);
    assertEquals("EndPos (11)", 9, kr.getMatch(11).endPos);
}
Also used : KrillIndex(de.ids_mannheim.korap.KrillIndex) SpanElementQuery(de.ids_mannheim.korap.query.SpanElementQuery) SpanQuery(org.apache.lucene.search.spans.SpanQuery) Result(de.ids_mannheim.korap.response.Result) Test(org.junit.Test)

Aggregations

SpanElementQuery (de.ids_mannheim.korap.query.SpanElementQuery)57 Test (org.junit.Test)53 KrillIndex (de.ids_mannheim.korap.KrillIndex)37 Term (org.apache.lucene.index.Term)36 SpanTermQuery (org.apache.lucene.search.spans.SpanTermQuery)35 SpanQuery (org.apache.lucene.search.spans.SpanQuery)32 Result (de.ids_mannheim.korap.response.Result)26 SpanClassQuery (de.ids_mannheim.korap.query.SpanClassQuery)16 SpanWithinQuery (de.ids_mannheim.korap.query.SpanWithinQuery)16 DistanceConstraint (de.ids_mannheim.korap.query.DistanceConstraint)11 SpanDistanceQuery (de.ids_mannheim.korap.query.SpanDistanceQuery)11 SpanFocusQuery (de.ids_mannheim.korap.query.SpanFocusQuery)10 SpanNextQuery (de.ids_mannheim.korap.query.SpanNextQuery)9 SpanRelationQuery (de.ids_mannheim.korap.query.SpanRelationQuery)8 SpanAttributeQuery (de.ids_mannheim.korap.query.SpanAttributeQuery)6 SpanClassFilterQuery (de.ids_mannheim.korap.query.SpanClassFilterQuery)6 SpanRelationMatchQuery (de.ids_mannheim.korap.query.SpanRelationMatchQuery)6 SpanWithAttributeQuery (de.ids_mannheim.korap.query.SpanWithAttributeQuery)6 SpanSegmentQuery (de.ids_mannheim.korap.query.SpanSegmentQuery)4 ArrayList (java.util.ArrayList)4