| Eliza Margaretha | 0192918 | 2014-02-19 11:48:59 +0000 | [diff] [blame] | 1 | package de.ids_mannheim.korap.index; |
| 2 | |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 3 | import java.util.*; |
| 4 | import java.io.*; |
| 5 | |
| 6 | import static org.junit.Assert.*; |
| 7 | import org.junit.Test; |
| 8 | import org.junit.Ignore; |
| 9 | import org.junit.runner.RunWith; |
| 10 | import org.junit.runners.JUnit4; |
| 11 | |
| Nils Diewald | a14ecd6 | 2015-02-26 21:00:20 +0000 | [diff] [blame] | 12 | import de.ids_mannheim.korap.KrillIndex; |
| Nils Diewald | 0339d46 | 2015-02-26 14:53:56 +0000 | [diff] [blame] | 13 | import de.ids_mannheim.korap.KrillQuery; |
| Nils Diewald | 884dbcf | 2015-02-27 17:02:28 +0000 | [diff] [blame] | 14 | import de.ids_mannheim.korap.response.Result; |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 15 | import de.ids_mannheim.korap.query.SpanElementQuery; |
| 16 | import de.ids_mannheim.korap.query.SpanWithinQuery; |
| 17 | import de.ids_mannheim.korap.query.SpanNextQuery; |
| 18 | import de.ids_mannheim.korap.query.SpanClassQuery; |
| 19 | import de.ids_mannheim.korap.index.FieldDocument; |
| Nils Diewald | e4986d7 | 2015-02-27 17:35:00 +0000 | [diff] [blame] | 20 | import de.ids_mannheim.korap.index.MultiTermTokenStream; |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 21 | import de.ids_mannheim.korap.index.PositionsToOffset; |
| 22 | |
| 23 | import org.apache.lucene.index.AtomicReaderContext; |
| 24 | import org.apache.lucene.search.spans.SpanQuery; |
| 25 | import org.apache.lucene.search.spans.SpanTermQuery; |
| 26 | import org.apache.lucene.index.TermContext; |
| 27 | import org.apache.lucene.util.OpenBitSet; |
| 28 | import org.apache.lucene.search.DocIdSet; |
| 29 | import org.apache.lucene.util.DocIdBitSet; |
| 30 | import org.apache.lucene.util.Bits; |
| 31 | |
| 32 | import java.nio.ByteBuffer; |
| 33 | |
| 34 | |
| 35 | @RunWith(JUnit4.class) |
| 36 | public class TestPosToOffset { |
| 37 | |
| 38 | @Test |
| 39 | public void indexExample1 () throws IOException { |
| Nils Diewald | d37f7e4 | 2015-02-27 21:08:22 +0000 | [diff] [blame] | 40 | KrillIndex ki = new KrillIndex(); |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 41 | |
| Nils Diewald | d37f7e4 | 2015-02-27 21:08:22 +0000 | [diff] [blame] | 42 | FieldDocument fd = new FieldDocument(); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 43 | fd.addTV("base", "a b c", "[(0-1)s:a|i:a|_0#0-1|-:t$<i>3]" |
| 44 | + "[(2-3)s:b|i:b|_1#2-3]" + "[(4-5)s:c|i:c|_2#4-5]"); |
| Nils Diewald | d37f7e4 | 2015-02-27 21:08:22 +0000 | [diff] [blame] | 45 | ki.addDoc(fd); |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 46 | |
| Nils Diewald | d37f7e4 | 2015-02-27 21:08:22 +0000 | [diff] [blame] | 47 | fd = new FieldDocument(); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 48 | fd.addTV("base", "x y z", "[(0-1)s:x|i:x|_0#0-2|-:t$<i>3]" |
| 49 | + "[(3-4)s:y|i:y|_1#3-4]" + "[(6-7)s:z|i:z|_2#6-7]"); // 3 |
| Nils Diewald | d37f7e4 | 2015-02-27 21:08:22 +0000 | [diff] [blame] | 50 | ki.addDoc(fd); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 51 | ki.commit(); |
| 52 | |
| Nils Diewald | d37f7e4 | 2015-02-27 21:08:22 +0000 | [diff] [blame] | 53 | String field = "base"; |
| 54 | for (AtomicReaderContext atomic : ki.reader().leaves()) { |
| 55 | PositionsToOffset pto = new PositionsToOffset(atomic, field); |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 56 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 57 | pto.add(0, 1); |
| 58 | pto.add(0, 2); |
| 59 | pto.add(1, 2); |
| 60 | pto.add(1, 1); |
| 61 | pto.add(1, 20); |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 62 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 63 | assertEquals("Start 0,1", pto.start(0, 1), 2); |
| 64 | assertEquals("End 0,1", pto.end(0, 1), 3); |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 65 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 66 | assertEquals("Start 0,2", pto.start(0, 2), 4); |
| 67 | assertEquals("End 0,2", pto.end(0, 2), 5); |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 68 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 69 | assertEquals("Start 1,2", pto.start(1, 2), 6); |
| 70 | assertEquals("End 1,2", pto.end(1, 2), 7); |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 71 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 72 | assertEquals("Start 1,1", pto.start(1, 1), 3); |
| 73 | assertEquals("End 1,1", pto.end(1, 1), 4); |
| 74 | |
| 75 | assertEquals("Start 1,20", pto.start(1, 20), 0); |
| 76 | assertEquals("End 1,20", pto.end(1, 20), -1); |
| Nils Diewald | d37f7e4 | 2015-02-27 21:08:22 +0000 | [diff] [blame] | 77 | }; |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 78 | }; |
| 79 | }; |