Search in sources :

Example 16 with SpanWithinQuery

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

the class TestWithinIndex method indexExample5.

@Test
public void indexExample5() throws IOException {
    // 1,2,3,6,9,10,12
    KrillIndex ki = new KrillIndex();
    // hij<a>hi<a>h<a>ij</a></a>hi</a>
    FieldDocument fd = new FieldDocument();
    fd.addTV("base", "hijhihijhi", "[(0-1)s:h|i:h|_0$<i>0<i>1|-:a$<i>3|-:t$<i>10]" + "[(1-2)s:i|i:i|_1$<i>1<i>2]" + "[(2-3)s:j|i:j|_2$<i>2<i>3]" + "[(3-4)s:h|i:h|_3$<i>3<i>4|<>:a$<b>64<i>3<i>10<i>10<b>0]" + "[(4-5)s:i|i:i|_4$<i>4<i>5]" + "[(5-6)s:h|i:h|_5$<i>5<i>6|<>:a$<b>64<i>5<i>8<i>8<b>0]" + "[(6-7)s:i|i:i|_6$<i>6<i>7|<>:a$<b>64<i>6<i>8<i>8<b>0]" + "[(7-8)s:j|i:j|_7$<i>7<i>8]" + "[(8-9)s:h|i:h|_8$<i>8<i>9]" + "[(9-10)s:i|i:i|_9$<i>9<i>10]");
    ki.addDoc(fd);
    // Save documents
    ki.commit();
    assertEquals(1, ki.numberOf("documents"));
    SpanQuery sq = new SpanWithinQuery(new SpanElementQuery("base", "a"), new SpanNextQuery(new SpanTermQuery(new Term("base", "s:h")), new SpanTermQuery(new Term("base", "s:i"))));
    Result kr = ki.search(sq, (short) 10);
    assertEquals("totalResults", kr.getTotalResults(), 4);
    assertEquals("StartPos (0)", 3, kr.getMatch(0).startPos);
    assertEquals("EndPos (0)", 10, kr.getMatch(0).endPos);
    assertEquals("StartPos (1)", 3, kr.getMatch(1).startPos);
    assertEquals("EndPos (1)", 10, kr.getMatch(1).endPos);
    assertEquals("StartPos (2)", 3, kr.getMatch(2).startPos);
    assertEquals("EndPos (2)", 10, kr.getMatch(2).endPos);
    assertEquals("StartPos (3)", 5, kr.getMatch(3).startPos);
    assertEquals("EndPos (3)", 8, kr.getMatch(3).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) SpanNextQuery(de.ids_mannheim.korap.query.SpanNextQuery) Result(de.ids_mannheim.korap.response.Result) Test(org.junit.Test)

Example 17 with SpanWithinQuery

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

the class TestWithinIndex method indexExample2c.

@Test
public void indexExample2c() throws IOException {
    KrillIndex ki = new KrillIndex();
    // <a><a><a>h  h  i  j  </a>h  i  j  </a>h  i  j  </a>h  <a>i  </a>
    FieldDocument fd = new FieldDocument();
    fd.addTV("base", "h  h  i  j  h  i  j  h  i  j  h  i  ", "[(0-3)s:h|<>:a$<b>64<i>0<i>15<i>4<b>0|" + "<>:a$<b>64<i>0<i>21<i>7<b>0|" + // 1
    "<>:a$<b>64<i>0<i>30<i>10<b>0]" + // 2
    "[(3-6)s:h]" + // 3
    "[(6-9)s:i]" + // 4
    "[(9-12)s:j]" + // 5
    "[(12-15)s:h]" + // 6
    "[(15-18)s:i]" + // 7
    "[(18-21)s:j]" + // 8
    "[(21-24)s:h]" + // 9
    "[(24-27)s:i]" + // 10
    "[(27-30)s:j]" + // 11
    "[(30-33)s:h]" + // 12
    "[(33-36)s:i|<>:a$<b>64<i>33<i>36<i>12<b>0]");
    ki.addDoc(fd);
    // Save documents
    ki.commit();
    assertEquals(1, ki.numberOf("documents"));
    SpanQuery sq = new SpanElementQuery("base", "a");
    Result kr = ki.search(sq, (short) 10);
    assertEquals("totalResults", kr.getTotalResults(), 4);
    assertEquals("StartPos (0)", 0, kr.getMatch(0).startPos);
    assertEquals("EndPos (0)", 4, kr.getMatch(0).endPos);
    assertEquals("StartPos (1)", 0, kr.getMatch(1).startPos);
    assertEquals("EndPos (1)", 7, kr.getMatch(1).endPos);
    assertEquals("StartPos (2)", 0, kr.getMatch(2).startPos);
    assertEquals("EndPos (2)", 10, kr.getMatch(2).endPos);
    assertEquals("StartPos (3)", 11, kr.getMatch(3).startPos);
    assertEquals("EndPos (3)", 12, kr.getMatch(3).endPos);
    sq = new SpanWithinQuery(new SpanElementQuery("base", "a"), new SpanTermQuery(new Term("base", "s:h")));
    kr = ki.search(sq, (short) 10);
    // <a><a><a>h  h  i  j  </a>h  i  j  </a>h  i  j  </a>h  <a>i  </a>
    assertEquals("totalResults", 9, kr.getTotalResults());
    assertEquals("StartPos (0)", 0, kr.getMatch(0).startPos);
    assertEquals("EndPos (0)", 4, kr.getMatch(0).endPos);
    assertEquals("StartPos (1)", 0, kr.getMatch(1).startPos);
    assertEquals("EndPos (1)", 4, kr.getMatch(1).endPos);
    assertEquals("StartPos (2)", 0, kr.getMatch(2).startPos);
    assertEquals("EndPos (2)", 7, kr.getMatch(2).endPos);
    assertEquals("StartPos (3)", 0, kr.getMatch(3).startPos);
    assertEquals("EndPos (3)", 7, kr.getMatch(3).endPos);
    assertEquals("StartPos (4)", 0, kr.getMatch(4).startPos);
    assertEquals("EndPos (4)", 7, kr.getMatch(4).endPos);
    assertEquals("StartPos (5)", 0, kr.getMatch(5).startPos);
    assertEquals("EndPos (5)", 10, kr.getMatch(5).endPos);
    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);
}
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 18 with SpanWithinQuery

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

the class TestWithinIndex method indexExample1b.

@Test
public void indexExample1b() throws IOException {
    // Cases 9, 12, 13
    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);
    // <a>x<a>y<a>zhij</a>hij</a>hij</a>
    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);
    // Save documents
    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) 15);
    assertEquals("totalResults", kr.getTotalResults(), 12);
    assertEquals("StartPos (0)", 0, kr.getMatch(0).startPos);
    assertEquals("EndPos (0)", 12, kr.getMatch(0).endPos);
    assertEquals("Doc (0)", 0, kr.getMatch(0).internalDocID);
    assertEquals("StartPos (1)", 0, kr.getMatch(1).startPos);
    assertEquals("EndPos (1)", 12, kr.getMatch(1).endPos);
    assertEquals("Doc (1)", 0, kr.getMatch(1).internalDocID);
    assertEquals("StartPos (2)", 0, kr.getMatch(2).startPos);
    assertEquals("EndPos (2)", 12, kr.getMatch(2).endPos);
    assertEquals("Doc (2)", 0, kr.getMatch(2).internalDocID);
    assertEquals("StartPos (3)", 1, kr.getMatch(3).startPos);
    assertEquals("EndPos (3)", 9, kr.getMatch(3).endPos);
    assertEquals("Doc (3)", 0, kr.getMatch(3).internalDocID);
    assertEquals("StartPos (4)", 1, kr.getMatch(4).startPos);
    assertEquals("EndPos (4)", 9, kr.getMatch(4).endPos);
    assertEquals("Doc (4)", 0, kr.getMatch(4).internalDocID);
    assertEquals("StartPos (5)", 2, kr.getMatch(5).startPos);
    assertEquals("EndPos (5)", 6, kr.getMatch(5).endPos);
    assertEquals("Doc (5)", 0, kr.getMatch(5).internalDocID);
    assertEquals("StartPos (6)", 0, kr.getMatch(6).startPos);
    assertEquals("EndPos (6)", 12, kr.getMatch(6).endPos);
    assertEquals("Doc (6)", 1, kr.getMatch(6).internalDocID);
    assertEquals("StartPos (7)", 0, kr.getMatch(7).startPos);
    assertEquals("EndPos (7)", 12, kr.getMatch(7).endPos);
    assertEquals("Doc (7)", 1, kr.getMatch(7).internalDocID);
    assertEquals("StartPos (8)", 0, kr.getMatch(8).startPos);
    assertEquals("EndPos (8)", 12, kr.getMatch(8).endPos);
    assertEquals("Doc (8)", 1, kr.getMatch(8).internalDocID);
    assertEquals("StartPos (9)", 1, kr.getMatch(9).startPos);
    assertEquals("EndPos (9)", 9, kr.getMatch(9).endPos);
    assertEquals("Doc (9)", 1, kr.getMatch(9).internalDocID);
    assertEquals("StartPos (10)", 1, kr.getMatch(10).startPos);
    assertEquals("EndPos (10)", 9, kr.getMatch(10).endPos);
    assertEquals("Doc (10)", 1, kr.getMatch(10).internalDocID);
    assertEquals("StartPos (11)", 2, kr.getMatch(11).startPos);
    assertEquals("EndPos (11)", 6, kr.getMatch(11).endPos);
    assertEquals("Doc (11)", 1, kr.getMatch(11).internalDocID);
    /*
        for (Match km : kr.getMatches()){		
        	System.out.println(km.getStartPos() +","+km.getEndPos()+" "
                               +km.getSnippetBrackets());
        };	
        */
    assertEquals(2, 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 19 with SpanWithinQuery

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

the class TestSpanWithinQuery method spanSegmentWithinQuery.

@Test
public void spanSegmentWithinQuery() throws QueryException {
    SpanSequenceQueryWrapper ssquery = new SpanSequenceQueryWrapper("field", "a", "b", "c");
    SpanWithinQuery ssequery = new SpanWithinQuery("s", ssquery.toQuery());
    assertEquals("spanContain(<field:s />, spanNext(spanNext(field:a, field:b), field:c))", ssequery.toString());
    ssquery = new SpanSequenceQueryWrapper("field", "a", "b");
    ssequery = new SpanWithinQuery("p", ssquery.toQuery());
    assertEquals("spanContain(<field:p />, spanNext(field:a, field:b))", ssequery.toString());
}
Also used : SpanWithinQuery(de.ids_mannheim.korap.query.SpanWithinQuery) SpanSequenceQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanSequenceQueryWrapper) Test(org.junit.Test)

Example 20 with SpanWithinQuery

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

the class TestSpanWithinQuery method spanSegmentStartsWithQuery.

@Test
public void spanSegmentStartsWithQuery() throws QueryException {
    SpanSequenceQueryWrapper ssquery = new SpanSequenceQueryWrapper("field", "a", "b", "c");
    SpanWithinQuery ssequery = new SpanWithinQuery(new SpanElementQuery("field", "s"), ssquery.toQuery(), SpanWithinQuery.STARTSWITH, true);
    assertEquals("spanStartsWith(<field:s />, spanNext(spanNext(field:a, field:b), field:c))", ssequery.toString());
}
Also used : SpanWithinQuery(de.ids_mannheim.korap.query.SpanWithinQuery) SpanSequenceQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanSequenceQueryWrapper) SpanElementQuery(de.ids_mannheim.korap.query.SpanElementQuery) Test(org.junit.Test)

Aggregations

SpanWithinQuery (de.ids_mannheim.korap.query.SpanWithinQuery)20 Test (org.junit.Test)18 KrillIndex (de.ids_mannheim.korap.KrillIndex)17 Result (de.ids_mannheim.korap.response.Result)17 SpanElementQuery (de.ids_mannheim.korap.query.SpanElementQuery)16 SpanQuery (org.apache.lucene.search.spans.SpanQuery)16 Term (org.apache.lucene.index.Term)15 SpanTermQuery (org.apache.lucene.search.spans.SpanTermQuery)15 SpanClassQuery (de.ids_mannheim.korap.query.SpanClassQuery)4 SpanFocusQuery (de.ids_mannheim.korap.query.SpanFocusQuery)3 SpanNextQuery (de.ids_mannheim.korap.query.SpanNextQuery)3 KrillQuery (de.ids_mannheim.korap.KrillQuery)2 SpanQueryWrapper (de.ids_mannheim.korap.query.wrap.SpanQueryWrapper)2 SpanSequenceQueryWrapper (de.ids_mannheim.korap.query.wrap.SpanSequenceQueryWrapper)2 Krill (de.ids_mannheim.korap.Krill)1 KrillCollection (de.ids_mannheim.korap.KrillCollection)1 SearchContext (de.ids_mannheim.korap.response.SearchContext)1 Ignore (org.junit.Ignore)1