Search in sources :

Example 6 with SpanWithinQuery

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

the class TestWithinIndex method queryJSONcomplexSpanOrTerm.

@Test
public void queryJSONcomplexSpanOrTerm() throws QueryException, IOException {
    /*
          at org.apache.lucene.search.spans.SpanOrQuery$1.doc(SpanOrQuery.java:234)
          at de.ids_mannheim.korap.query.spans.WithinSpans.toSameDoc(WithinSpans.java:423)
          at de.ids_mannheim.korap.query.spans.WithinSpans.next(WithinSpans.java:375)
          at de.ids_mannheim.korap.KrillIndex.search(KrillIndex.java:1293)
          at de.ids_mannheim.korap.Krill.apply(Krill.java:304)
        */
    String jsonPath = URLDecoder.decode(getClass().getResource("/queries/bugs/span_or_bug.jsonld").getFile(), "UTF-8");
    String jsonPQuery = readFile(jsonPath);
    SpanQueryWrapper sqwi = new KrillQuery("tokens").fromKoral(jsonPQuery);
    SpanWithinQuery sq = (SpanWithinQuery) sqwi.toQuery();
    assertEquals("spanStartsWith(<tokens:base/s:s />, " + "spanOr([tokens:s:Er, tokens:s:Sie]))", sq.toString());
    KrillIndex ki = new KrillIndex();
    ki.addDoc(getClass().getResourceAsStream("/wiki/DDD-08370.json.gz"), true);
    ki.addDoc(getClass().getResourceAsStream("/wiki/SSS-09803.json.gz"), true);
    ki.commit();
    Result kr = ki.search(sq, (short) 1);
    assertEquals(1, kr.getTotalResults());
}
Also used : KrillQuery(de.ids_mannheim.korap.KrillQuery) SpanWithinQuery(de.ids_mannheim.korap.query.SpanWithinQuery) SpanQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanQueryWrapper) KrillIndex(de.ids_mannheim.korap.KrillIndex) Result(de.ids_mannheim.korap.response.Result) Test(org.junit.Test)

Example 7 with SpanWithinQuery

use of de.ids_mannheim.korap.query.SpanWithinQuery 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 8 with SpanWithinQuery

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

the class TestWithinIndex method indexExample4.

@Test
public void indexExample4() throws IOException {
    KrillIndex ki = new KrillIndex();
    // Case 1, 6, 7, 13
    // xy<a><a>x</a>b<a>c</a></a>x
    FieldDocument fd = new FieldDocument();
    fd.addTV("base", "x  y  x  b  c  x  ", "[(0-3)s:x|_0$<i>0<i>3]" + "[(3-6)s:y|_1$<i>3<i>6]" + "[(6-9)s:x|_2$<i>6<i>9|<>:a$<b>64<i>6<i>9<i>3<b>0|" + "<>:a$<b>64<i>6<i>15<i>5<b>0]" + "[(9-12)s:b|_3$<i>9<i>12]" + "[(12-15)s:c|_4$<i>12<i>15|<>:a$<b>64<i>12<i>15<i>5<b>0]" + "[(15-18)s:x|_5$<i>15<i>18]");
    ki.addDoc(fd);
    // Save documents
    ki.commit();
    assertEquals(1, ki.numberOf("documents"));
    SpanQuery sq = new SpanWithinQuery(new SpanElementQuery("base", "a"), new SpanTermQuery(new Term("base", "s:x")));
    assertEquals("spanContain(<base:a />, base:s:x)", sq.toString());
    Result kr = ki.search(sq, (short) 10);
    assertEquals("totalResults", kr.getTotalResults(), 2);
    assertEquals("x  y  [[x  ]]b  c  x  ", kr.getMatch(0).getSnippetBrackets());
    assertEquals("x  y  [[x  b  c  ]]x  ", kr.getMatch(1).getSnippetBrackets());
    assertEquals("StartPos (0)", 2, kr.getMatch(0).startPos);
    assertEquals("EndPos (0)", 3, kr.getMatch(0).endPos);
    assertEquals("StartPos (1)", 2, kr.getMatch(1).startPos);
    assertEquals("EndPos (1)", 5, kr.getMatch(1).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 9 with SpanWithinQuery

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

the class TestWithinIndex method indexExample1c.

@Test
public void indexExample1c() 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>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 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(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 10 with SpanWithinQuery

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

the class TestWithinIndex method indexExample6.

@Test
public void indexExample6() throws IOException {
    KrillIndex ki = new KrillIndex();
    // 2,5,8,12,13
    // h<a><a>i</a>j</a><a>h</a>i j<a>h i</a>j
    FieldDocument fd = new FieldDocument();
    fd.addTV("base", "hijhi jh ij", "[(0-1)s:h|i:h|_0$<i>0<i>1|-:a$<i>4|-:t$<i>9]" + "[(1-2)s:i|i:i|_1$<i>1<i>2|<>:a$<b>64<i>1<i>2<i>2<b>0|" + "<>:a$<b>64<i>1<i>3<i>3<b>0]" + "[(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>4<i>4<b>0]" + "[(4-5)s:i|i:i|_4$<i>4<i>5]" + "[(6-7)s:j|i:j|_5$<i>6<i>7]" + "[(7-8)s:h|i:h|_6$<i>7<i>8|<>:a$<b>64<i>7<i>10<i>8<b>0]" + "[(9-10)s:i|i:i|_7$<i>9<i>10]" + "[(10-11)s:j|i:j|_8$<i>10<i>11]");
    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)

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