| 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 org.apache.lucene.util.Version; |
| 7 | import org.apache.lucene.util.BytesRef; |
| 8 | import org.apache.lucene.util.Bits; |
| 9 | |
| 10 | import static org.junit.Assert.*; |
| 11 | import org.junit.Test; |
| 12 | import org.junit.Ignore; |
| 13 | import org.junit.runner.RunWith; |
| 14 | import org.junit.runners.JUnit4; |
| 15 | |
| 16 | import de.ids_mannheim.korap.KorapIndex; |
| 17 | import de.ids_mannheim.korap.KorapQuery; |
| 18 | import de.ids_mannheim.korap.index.FieldDocument; |
| 19 | import de.ids_mannheim.korap.analysis.MultiTermTokenStream; |
| 20 | |
| 21 | @RunWith(JUnit4.class) |
| 22 | public class TestKorapIndex { |
| 23 | |
| 24 | @Test |
| 25 | public void indexExample () throws IOException { |
| 26 | KorapIndex ki = new KorapIndex(); |
| 27 | |
| 28 | FieldDocument fd = new FieldDocument(); |
| 29 | |
| 30 | fd.addString("name", "Peter"); |
| 31 | fd.addInt("zahl1", 56); |
| 32 | fd.addInt("zahl2", "58"); |
| 33 | fd.addText("teaser", "Das ist der Name der Rose"); |
| 34 | fd.addTV("base", "ich bau", "[(0-3)s:ich|l:ich|p:PPER|-:sentences#-$<i>2][(4-7)s:bau|l:bauen|p:VVFIN]"); |
| 35 | ki.addDoc(fd); |
| 36 | |
| 37 | fd = new FieldDocument(); |
| 38 | |
| 39 | fd.addString("name", "Hans"); |
| 40 | fd.addInt("zahl1", 14); |
| 41 | fd.addText("teaser", "Das Sein"); |
| 42 | |
| 43 | MultiTermTokenStream mtts = fd.newMultiTermTokenStream(); |
| 44 | mtts.addMultiTermToken("s:wir#0-3", "l:wir", "p:PPER"); |
| 45 | mtts.addMultiTermToken("s:sind#4-8", "l:sein", "p:VVFIN"); |
| 46 | mtts.addMeta("sentences", (int) 5); |
| 47 | fd.addTV("base", "wir sind", mtts); |
| 48 | |
| 49 | ki.addDoc(fd); |
| 50 | |
| 51 | /* Save documents */ |
| 52 | ki.commit(); |
| 53 | |
| Nils Diewald | baf68c5 | 2013-11-20 13:22:19 +0000 | [diff] [blame] | 54 | assertEquals(2, ki.numberOf("base", "documents")); |
| 55 | assertEquals(7, ki.numberOf("base", "sentences")); |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 56 | |
| 57 | |
| 58 | fd = new FieldDocument(); |
| 59 | |
| 60 | fd.addString("name", "Frank"); |
| 61 | fd.addInt("zahl1", 59); |
| 62 | fd.addInt("zahl2", 65); |
| 63 | fd.addText("teaser", "Noch ein Versuch"); |
| 64 | fd.addTV("base", "ich bau", "[(0-3)s:der|l:der|p:DET|-:sentences#-$<i>3][(4-8)s:baum|l:baum|p:NN]"); |
| 65 | ki.addDoc(fd); |
| 66 | |
| 67 | /* Save documents */ |
| 68 | ki.commit(); |
| 69 | |
| Nils Diewald | baf68c5 | 2013-11-20 13:22:19 +0000 | [diff] [blame] | 70 | assertEquals(3, ki.numberOf("base", "documents")); |
| 71 | assertEquals(10, ki.numberOf("base", "sentences")); |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 72 | |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 73 | // KorapQuery kq = new KorapQuery("text"); |
| 74 | // ki.search(); |
| 75 | }; |
| 76 | }; |