Search in sources :

Example 21 with SpanElementQuery

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

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

the class TestSegmentIndex method testCase4.

/**
 * Matching a SpanElementQuery and a SpanNextQuery
 * Multiple atomic indices
 */
@Test
public void testCase4() throws IOException {
    // log.trace("Testcase4");
    ki = new KrillIndex();
    ki.addDoc(createFieldDoc0());
    ki.commit();
    ki.addDoc(createFieldDoc1());
    ki.addDoc(createFieldDoc2());
    ki.commit();
    sq = new SpanSegmentQuery(new SpanElementQuery("base", "e"), new SpanNextQuery(new SpanTermQuery(new Term("base", "s:a")), new SpanTermQuery(new Term("base", "s:b"))));
    kr = ki.search(sq, (short) 10);
    ki.close();
    assertEquals("totalResults", kr.getTotalResults(), 2);
    // Match #0
    assertEquals("doc-number", 0, kr.getMatch(0).getLocalDocID());
    assertEquals("StartPos", 3, kr.getMatch(0).startPos);
    assertEquals("EndPos", 5, kr.getMatch(0).endPos);
    // Match #1
    assertEquals("doc-number", 0, kr.getMatch(1).getLocalDocID());
    assertEquals("StartPos", 1, kr.getMatch(1).startPos);
    assertEquals("EndPos", 3, kr.getMatch(1).endPos);
}
Also used : SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) SpanSegmentQuery(de.ids_mannheim.korap.query.SpanSegmentQuery) Term(org.apache.lucene.index.Term) KrillIndex(de.ids_mannheim.korap.KrillIndex) SpanElementQuery(de.ids_mannheim.korap.query.SpanElementQuery) SpanNextQuery(de.ids_mannheim.korap.query.SpanNextQuery) Test(org.junit.Test)

Example 23 with SpanElementQuery

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

the class TestSegmentIndex method testCase5.

/**
 * Matching SpanElementQueries
 */
@Test
public void testCase5() throws IOException {
    // log.trace("Testcase5");
    sq = new SpanSegmentQuery(new SpanElementQuery("base", "e"), new SpanElementQuery("base", "e2"));
    kr = ki.search(sq, (short) 10);
    ki.close();
    assertEquals("totalResults", kr.getTotalResults(), 1);
    // Match #0
    assertEquals("doc-number", 0, kr.getMatch(0).getLocalDocID());
    assertEquals("StartPos", 3, kr.getMatch(0).startPos);
    assertEquals("EndPos", 5, kr.getMatch(0).endPos);
}
Also used : SpanSegmentQuery(de.ids_mannheim.korap.query.SpanSegmentQuery) SpanElementQuery(de.ids_mannheim.korap.query.SpanElementQuery) Test(org.junit.Test)

Example 24 with SpanElementQuery

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

the class TestSpanExpansionIndex method testCase2.

/**
 * Classnumber
 * Check the expansion offsets
 */
@Test
public void testCase2() {
    byte classNumber = 1;
    SpanExpansionQuery sq;
    // create new payload for the expansion offsets
    SpanTermQuery stq = new SpanTermQuery(new Term("tokens", "s:des"));
    sq = new SpanExpansionQuery(stq, 0, 2, -1, classNumber, true);
    kr = ki.search(sq, (short) 10);
    assertEquals(5, kr.getMatch(0).getStartPos());
    assertEquals(8, kr.getMatch(0).getEndPos());
    // expansion 5,7
    assertEquals(5, kr.getMatch(0).getStartPos(1));
    assertEquals(7, kr.getMatch(0).getEndPos(1));
    // expansion offsets
    assertEquals(6, kr.getMatch(1).getStartPos(1));
    assertEquals(7, kr.getMatch(1).getEndPos(1));
    assertEquals(7, kr.getMatch(2).getStartPos(1));
    assertEquals(7, kr.getMatch(2).getEndPos(1));
    assertEquals(154, kr.getMatch(3).getStartPos(1));
    assertEquals(156, kr.getMatch(3).getEndPos(1));
    /*
         * for (Match km : kr.getMatches()){
         * System.out.println(km.getStartPos() +","+km.getEndPos()+" "
         * +km.getSnippetBrackets()); }
         */
    // add expansion offsets to the existing payload
    SpanElementQuery seq = new SpanElementQuery("tokens", "base/s:s");
    sq = new SpanExpansionQuery(seq, 1, 2, 0, classNumber, true);
    kr = ki.search(sq, (short) 10);
    assertEquals(13, kr.getMatch(0).getStartPos());
    assertEquals(26, kr.getMatch(0).getEndPos());
    assertEquals(13, kr.getMatch(1).getStartPos());
    assertEquals(27, kr.getMatch(1).getEndPos());
    assertEquals(25, kr.getMatch(2).getStartPos());
    assertEquals(35, kr.getMatch(2).getEndPos());
    assertEquals(34, kr.getMatch(2).getStartPos(1));
    assertEquals(35, kr.getMatch(2).getEndPos(1));
    assertEquals(25, kr.getMatch(3).getStartPos());
    assertEquals(36, kr.getMatch(3).getEndPos());
    assertEquals(34, kr.getMatch(3).getStartPos(1));
    assertEquals(36, kr.getMatch(3).getEndPos(1));
/*
         * for (Match km : kr.getMatches()){
         * System.out.println(km.getStartPos() +","+km.getEndPos()+" "
         * +km.getSnippetBrackets()); }
         */
}
Also used : SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) SpanExpansionQuery(de.ids_mannheim.korap.query.SpanExpansionQuery) Term(org.apache.lucene.index.Term) SpanElementQuery(de.ids_mannheim.korap.query.SpanElementQuery) Test(org.junit.Test)

Example 25 with SpanElementQuery

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

the class TestRelationIndex method testCase9.

/**
 * Relation with specific sources and return any targets <br/>
 * Relation with specific sources and targets, return the targets
 * <br/>
 * Relation with specific sources and targets, return the sources
 *
 * @throws IOException
 */
@Test
public void testCase9() throws IOException {
    ki.addDoc(createFieldDoc2());
    ki.commit();
    // return all children of np
    SpanElementQuery seq1 = new SpanElementQuery("base", "np");
    SpanClassQuery scq1 = new SpanClassQuery(seq1, (byte) 1);
    SpanRelationQuery srq = new SpanRelationQuery(new SpanTermQuery(new Term("base", "<:child-of")), true, RelationDirection.LEFT);
    srq.setSourceClass((byte) 2);
    SpanRelationMatchQuery rm = new SpanRelationMatchQuery(srq, scq1, true);
    SpanFocusQuery rv = new SpanFocusQuery(rm, (byte) 2);
    rv.setSorted(false);
    assertEquals("focus(2: focus(#[1,2]spanSegment({2: source:spanRelation(base:<:child-of)}, {1: <base:np />})))", rv.toString());
    kr = ki.search(rv, (short) 10);
    assertEquals((long) 7, kr.getTotalResults());
    assertEquals(0, kr.getMatch(0).getStartPos());
    assertEquals(1, kr.getMatch(0).getEndPos());
    assertEquals(2, kr.getMatch(1).getStartPos());
    assertEquals(3, kr.getMatch(1).getEndPos());
    assertEquals(2, kr.getMatch(2).getStartPos());
    assertEquals(4, kr.getMatch(2).getEndPos());
    assertEquals(3, kr.getMatch(3).getStartPos());
    assertEquals(4, kr.getMatch(3).getEndPos());
    assertEquals(4, kr.getMatch(4).getStartPos());
    assertEquals(7, kr.getMatch(4).getEndPos());
    assertEquals(5, kr.getMatch(5).getStartPos());
    assertEquals(6, kr.getMatch(5).getEndPos());
    assertEquals(6, kr.getMatch(6).getStartPos());
    assertEquals(7, kr.getMatch(6).getEndPos());
}
Also used : SpanClassQuery(de.ids_mannheim.korap.query.SpanClassQuery) SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) SpanRelationQuery(de.ids_mannheim.korap.query.SpanRelationQuery) SpanRelationMatchQuery(de.ids_mannheim.korap.query.SpanRelationMatchQuery) Term(org.apache.lucene.index.Term) SpanElementQuery(de.ids_mannheim.korap.query.SpanElementQuery) SpanFocusQuery(de.ids_mannheim.korap.query.SpanFocusQuery) 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