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>"<mark class=\"class-3 level-0\">Das war ich</mark>!"</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);
}
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);
}
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);
}
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()); }
*/
}
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());
}
Aggregations