Search in sources :

Example 11 with SpanWithinQuery

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

the class TestWithinIndex method indexExample1d.

@Test
public void indexExample1d() 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);
    fd = new FieldDocument();
    fd.addTV("base", "x   y   z   h   ", // 1
    "[(0-3)s:x]" + // 2
    "[(3-6)s:y]" + // 3
    "[(6-9)s:z]" + // 4
    "[(9-12)s:h]");
    ki.addDoc(fd);
    // <a>x<a>y<a>zabc</a>abc</a>abc</a>
    fd = new FieldDocument();
    fd.addTV("base", "x   y   z   a   b   c   a   b   c   a   b   c   ", // 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:a]" + // 5
    "[(12-15)s:b]" + // 6
    "[(15-18)s:c]" + // 7
    "[(18-21)s:a]" + // 8
    "[(21-24)s:b]" + // 9
    "[(24-27)s:c]" + // 10
    "[(27-30)s:a]" + // 11
    "[(30-33)s:b]" + // 12
    "[(33-36)s:c]");
    ki.addDoc(fd);
    // Save documents
    ki.commit();
    SpanQuery sq;
    Result kr;
    sq = new SpanElementQuery("base", "a");
    kr = ki.search(sq, (short) 15);
    sq = new SpanWithinQuery(new SpanElementQuery("base", "a"), new SpanTermQuery(new Term("base", "s:h")));
    kr = ki.search(sq, (short) 15);
    assertEquals("totalResults", kr.getTotalResults(), 6);
    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(3, 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 12 with SpanWithinQuery

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

the class TestWithinIndex method indexExample7.

@Test
public void indexExample7() throws IOException {
    KrillIndex ki = new KrillIndex();
    // 4,5,11,13
    // x<a>x h</a>i j h<a>i j</a>
    FieldDocument fd = new FieldDocument();
    fd.addTV("base", "xx hi j hi j", "[(0-1)s:x|i:x|_0$<i>0<i>1|-:a$<i>2|-:t$<i>8]" + "[(1-2)s:x|i:x|_1$<i>1<i>2|<>:a$<b>64<i>1<i>4<i>3<b>0]" + "[(3-4)s:h|i:h|_2$<i>3<i>4]" + "[(4-5)s:i|i:i|_3$<i>4<i>5]" + "[(6-7)s:j|i:j|_4$<i>6<i>7]" + "[(8-9)s:h|i:h|_5$<i>8<i>9]" + "[(9-10)s:i|i:i|_6$<i>9<i>10|<>:a$<b>64<i>9<i>12<i>8<b>0]" + "[(11-12)s:j|i:j|_7$<i>11<i>12]");
    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 SpanNextQuery(new SpanTermQuery(new Term("base", "s:i")), new SpanTermQuery(new Term("base", "s:j")))));
    Result kr = ki.search(sq, (short) 10);
    assertEquals("totalResults", kr.getTotalResults(), 0);
}
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 13 with SpanWithinQuery

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

the class TestWithinIndex method indexExample3Offsets.

@Test
public void indexExample3Offsets() throws IOException {
    KrillIndex ki = new KrillIndex();
    // Er schrie: <s>"Das war ich!"</s>
    FieldDocument fd = new FieldDocument();
    fd = new FieldDocument();
    fd.addTV("base", "Er schrie: \"Das war ich!\" und ging.", "[(0-2)s:Er|_0$<i>0<i>3]" + "[(3-9)s:schrie|_1$<i>3<i>9]" + "[(12-15)s:Das|_2$<i>12<i>15|<>:sentence$<b>64<i>11<i>25<i>5<b>0]" + "[(16-19)s:war|_3$<i>16<i>19]" + "[(20-23)s:ich|_4$<i>20<i>23]" + "[(26-29)s:und|_5$<i>26<i>29]" + "[(30-34)s:ging|_6$<i>30<i>34]");
    ki.addDoc(fd);
    // Save documents
    ki.commit();
    SpanQuery sq = new SpanClassQuery(new SpanElementQuery("base", "sentence"), (byte) 3);
    Result kr;
    kr = ki.search(sq, 0, (short) 15, true, (short) 1, true, (short) 1);
    assertEquals("totalResults", kr.getTotalResults(), 1);
    assertEquals("... schrie: [[\"{3:Das war ich}!\"]] und ...", kr.getMatch(0).getSnippetBrackets());
    assertEquals("<span class=\"context-left\"><span class=\"more\"></span>schrie: </span><span class=\"match\"><mark>&quot;<mark class=\"class-3 level-0\">Das war ich</mark>!&quot;</mark></span><span class=\"context-right\"> und<span class=\"more\"></span></span>", kr.getMatch(0).getSnippetHTML());
    kr = ki.search(sq, 0, (short) 15, true, (short) 0, true, (short) 0);
    assertEquals("... [[\"{3:Das war ich}!\"]] ...", kr.getMatch(0).getSnippetBrackets());
    assertEquals("totalResults", kr.getTotalResults(), 1);
    kr = ki.search(sq, 0, (short) 15, true, (short) 6, true, (short) 6);
    assertEquals("Er schrie: [[\"{3:Das war ich}!\"]] und ging.", kr.getMatch(0).getSnippetBrackets());
    assertEquals("totalResults", kr.getTotalResults(), 1);
    kr = ki.search(sq, 0, (short) 15, true, (short) 2, true, (short) 2);
    assertEquals("Er schrie: [[\"{3:Das war ich}!\"]] und ging ...", kr.getMatch(0).getSnippetBrackets());
    assertEquals("totalResults", kr.getTotalResults(), 1);
    sq = new SpanClassQuery(new SpanWithinQuery(new SpanElementQuery("base", "sentence"), new SpanClassQuery(new SpanTermQuery(new Term("base", "s:Das")), (byte) 2)), (byte) 1);
    kr = ki.search(sq, (short) 15);
    assertEquals("Er schrie: [[\"{1:{2:Das} war ich}!\"]] und ging.", kr.getMatch(0).getSnippetBrackets());
    assertEquals("totalResults", kr.getTotalResults(), 1);
    sq = new SpanClassQuery(new SpanWithinQuery(new SpanElementQuery("base", "sentence"), new SpanClassQuery(new SpanTermQuery(new Term("base", "s:war")), (byte) 2)), (byte) 1);
    kr = ki.search(sq, (short) 15);
    assertEquals("Er schrie: [[\"{1:Das {2:war} ich}!\"]] und ging.", kr.getMatch(0).getSnippetBrackets());
    assertEquals("totalResults", kr.getTotalResults(), 1);
    sq = new SpanClassQuery(new SpanWithinQuery(new SpanElementQuery("base", "sentence"), new SpanClassQuery(new SpanTermQuery(new Term("base", "s:ich")), (byte) 2)), (byte) 1);
    kr = ki.search(sq, (short) 15);
    assertEquals("Er schrie: [[\"{1:Das war {2:ich}}!\"]] und ging.", kr.getMatch(0).getSnippetBrackets());
    assertEquals("totalResults", kr.getTotalResults(), 1);
    sq = new SpanClassQuery(new SpanWithinQuery(new SpanElementQuery("base", "sentence"), new SpanClassQuery(new SpanTermQuery(new Term("base", "s:und")), (byte) 2)), (byte) 1);
    kr = ki.search(sq, (short) 15);
    assertEquals("totalResults", kr.getTotalResults(), 0);
    sq = new SpanClassQuery(new SpanWithinQuery(new SpanElementQuery("base", "sentence"), new SpanClassQuery(new SpanTermQuery(new Term("base", "s:schrie")), (byte) 2)), (byte) 1);
    kr = ki.search(sq, (short) 15);
    assertEquals("totalResults", kr.getTotalResults(), 0);
}
Also used : SpanClassQuery(de.ids_mannheim.korap.query.SpanClassQuery) 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 SpanWithinQuery

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

the class TestWithinIndex method indexExample2d.

@Test
public void indexExample2d() throws IOException {
    KrillIndex ki = new KrillIndex();
    // 2, 6, 9, 12, 7
    // <a><a><a>h  h  i  j  </a>h  i  </a>j  h  </a>i  j  <a>h  <a>h  </a></a>
    FieldDocument fd = new FieldDocument();
    fd.addTV("base", "h  h  i  j  h  i  j  h  i  j  h  h  ", "[(0-3)s:h|<>:a$<b>64<i>0<i>15<i>4<b>0|" + "<>:a$<b>64<i>0<i>18<i>6<b>0|" + // 1
    "<>:a$<b>64<i>0<i>27<i>8<b>0|_0$<i>0<i>3]" + // 2
    "[(3-6)s:h|_1$<i>3<i>6]" + // 3
    "[(6-9)s:i|_2$<i>6<i>9]" + // 4
    "[(9-12)s:j|_3$<i>9<i>12]" + // 5
    "[(12-15)s:h|_4$<i>12<i>15]" + // 6
    "[(15-18)s:i|_5$<i>15<i>18]" + // 7
    "[(18-21)s:j|_6$<i>18<i>21]" + // 8
    "[(21-24)s:h|_7$<i>21<i>24]" + // 9
    "[(24-27)s:i|_8$<i>24<i>27]" + // 10
    "[(27-30)s:j|_9$<i>27<i>30]" + "[(30-33)s:h|_10$<i>30<i>33|<>:a$<b>64<i>30<i>36<i>12<b>0]" + // 11
    "[(33-36)s:h|_11$<i>33<i>36|<>:a$<b>64<i>33<i>36<i>12<b>0]");
    // 12
    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(), 5);
    // <a><a><a>h  h  i  j  </a>h  i  </a>j  h  </a>i  j  <a>h  <a>h  </a></a>
    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)", 6, kr.getMatch(1).endPos);
    assertEquals("StartPos (2)", 0, kr.getMatch(2).startPos);
    assertEquals("EndPos (2)", 8, kr.getMatch(2).endPos);
    assertEquals("StartPos (3)", 10, kr.getMatch(3).startPos);
    assertEquals("EndPos (3)", 12, kr.getMatch(3).endPos);
    assertEquals("StartPos (4)", 11, kr.getMatch(4).startPos);
    assertEquals("EndPos (4)", 12, kr.getMatch(4).endPos);
    sq = new SpanWithinQuery(new SpanElementQuery("base", "a"), new SpanTermQuery(new Term("base", "s:h")));
    kr = ki.search(sq, (short) 15);
    // <a><a><a>h  h  i  j  </a>h  i  </a>j  h  </a>i  j  <a>h  <a>h  </a></a>
    assertEquals("totalResults", 12, 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)", 6, kr.getMatch(2).endPos);
    assertEquals("StartPos (3)", 0, kr.getMatch(3).startPos);
    assertEquals("EndPos (3)", 6, kr.getMatch(3).endPos);
    assertEquals("StartPos (4)", 0, kr.getMatch(4).startPos);
    assertEquals("EndPos (4)", 6, kr.getMatch(4).endPos);
    assertEquals("StartPos (5)", 0, kr.getMatch(5).startPos);
    assertEquals("EndPos (5)", 8, kr.getMatch(5).endPos);
    assertEquals("StartPos (6)", 0, kr.getMatch(6).startPos);
    assertEquals("EndPos (6)", 8, kr.getMatch(6).endPos);
    assertEquals("StartPos (7)", 0, kr.getMatch(7).startPos);
    assertEquals("EndPos (7)", 8, kr.getMatch(7).endPos);
    assertEquals("StartPos (8)", 0, kr.getMatch(8).startPos);
    assertEquals("EndPos (8)", 8, kr.getMatch(8).endPos);
    assertEquals("StartPos (9)", 10, kr.getMatch(9).startPos);
    assertEquals("EndPos (9)", 12, kr.getMatch(9).endPos);
    assertEquals("StartPos (10)", 10, kr.getMatch(10).startPos);
    assertEquals("EndPos (10)", 12, kr.getMatch(10).endPos);
    assertEquals("StartPos (11)", 11, kr.getMatch(11).startPos);
    assertEquals("EndPos (11)", 12, kr.getMatch(11).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 15 with SpanWithinQuery

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

the class TestWithinIndex method indexExample2b.

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

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