| Nils Diewald | e364570 | 2014-11-07 21:15:20 +0000 | [diff] [blame] | 1 | package de.ids_mannheim.korap.search; |
| 2 | |
| 3 | import java.util.*; |
| 4 | import java.io.*; |
| 5 | |
| 6 | import static de.ids_mannheim.korap.TestSimple.*; |
| 7 | |
| Nils Diewald | bbd39a5 | 2015-02-23 19:56:57 +0000 | [diff] [blame] | 8 | import de.ids_mannheim.korap.Krill; |
| Nils Diewald | 2d5f810 | 2015-02-26 21:07:54 +0000 | [diff] [blame] | 9 | import de.ids_mannheim.korap.KrillCollection; |
| Nils Diewald | 0339d46 | 2015-02-26 14:53:56 +0000 | [diff] [blame] | 10 | import de.ids_mannheim.korap.KrillQuery; |
| Nils Diewald | a14ecd6 | 2015-02-26 21:00:20 +0000 | [diff] [blame] | 11 | import de.ids_mannheim.korap.KrillIndex; |
| Nils Diewald | e364570 | 2014-11-07 21:15:20 +0000 | [diff] [blame] | 12 | import de.ids_mannheim.korap.index.FieldDocument; |
| Nils Diewald | 884dbcf | 2015-02-27 17:02:28 +0000 | [diff] [blame] | 13 | import de.ids_mannheim.korap.response.Result; |
| Nils Diewald | e364570 | 2014-11-07 21:15:20 +0000 | [diff] [blame] | 14 | import java.nio.file.Files; |
| 15 | import java.nio.file.FileSystem; |
| 16 | import java.nio.file.Path; |
| 17 | import java.nio.charset.StandardCharsets; |
| 18 | import java.nio.ByteBuffer; |
| 19 | |
| Akron | 484c3c1 | 2015-07-07 20:25:44 +0200 | [diff] [blame] | 20 | import org.apache.commons.lang.StringUtils; |
| 21 | import org.apache.lucene.analysis.Analyzer; |
| 22 | import org.apache.lucene.analysis.TokenStream; |
| 23 | import org.apache.lucene.analysis.tokenattributes.CharTermAttribute; |
| 24 | |
| Nils Diewald | e364570 | 2014-11-07 21:15:20 +0000 | [diff] [blame] | 25 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 26 | import com.fasterxml.jackson.databind.JsonNode; |
| 27 | |
| 28 | import static org.junit.Assert.*; |
| 29 | import org.junit.Test; |
| 30 | import org.junit.Ignore; |
| 31 | import org.junit.runner.RunWith; |
| 32 | import org.junit.runners.JUnit4; |
| 33 | |
| 34 | @RunWith(JUnit4.class) |
| 35 | public class TestMetaFields { |
| Akron | 640458c | 2015-06-25 12:36:15 +0200 | [diff] [blame] | 36 | |
| Nils Diewald | e364570 | 2014-11-07 21:15:20 +0000 | [diff] [blame] | 37 | @Test |
| 38 | public void searchMetaFields () throws IOException { |
| 39 | |
| Nils Diewald | 3aa9e69 | 2015-02-20 22:20:11 +0000 | [diff] [blame] | 40 | // Construct index |
| Nils Diewald | a14ecd6 | 2015-02-26 21:00:20 +0000 | [diff] [blame] | 41 | KrillIndex ki = new KrillIndex(); |
| Nils Diewald | 3aa9e69 | 2015-02-20 22:20:11 +0000 | [diff] [blame] | 42 | // Indexing test files |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 43 | for (String i : new String[] { "00001", "00002" }) { |
| Eliza Margaretha | 6f98920 | 2016-10-14 21:48:29 +0200 | [diff] [blame] | 44 | ki.addDoc(getClass().getResourceAsStream("/wiki/" + i + ".json.gz"), |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 45 | true); |
| Nils Diewald | 3aa9e69 | 2015-02-20 22:20:11 +0000 | [diff] [blame] | 46 | }; |
| 47 | ki.commit(); |
| Nils Diewald | e364570 | 2014-11-07 21:15:20 +0000 | [diff] [blame] | 48 | |
| Eliza Margaretha | 6f98920 | 2016-10-14 21:48:29 +0200 | [diff] [blame] | 49 | String jsonString = getJsonString(getClass() |
| 50 | .getResource("/queries/metas/fields.jsonld").getFile()); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 51 | |
| Nils Diewald | bbd39a5 | 2015-02-23 19:56:57 +0000 | [diff] [blame] | 52 | Krill ks = new Krill(jsonString); |
| Nils Diewald | e364570 | 2014-11-07 21:15:20 +0000 | [diff] [blame] | 53 | |
| Nils Diewald | 884dbcf | 2015-02-27 17:02:28 +0000 | [diff] [blame] | 54 | Result kr = ks.apply(ki); |
| Nils Diewald | 3aa9e69 | 2015-02-20 22:20:11 +0000 | [diff] [blame] | 55 | assertEquals((long) 17, kr.getTotalResults()); |
| 56 | assertEquals(0, kr.getStartIndex()); |
| 57 | assertEquals(9, kr.getItemsPerPage()); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 58 | |
| Nils Diewald | 3aa9e69 | 2015-02-20 22:20:11 +0000 | [diff] [blame] | 59 | ObjectMapper mapper = new ObjectMapper(); |
| 60 | JsonNode res = mapper.readTree(kr.toJsonString()); |
| Akron | b116644 | 2015-06-27 00:34:19 +0200 | [diff] [blame] | 61 | |
| Akron | b116644 | 2015-06-27 00:34:19 +0200 | [diff] [blame] | 62 | // mirror fields |
| 63 | assertEquals(9, res.at("/meta/count").asInt()); |
| 64 | |
| 65 | if (res.at("/meta/fields/0").asText().equals("UID")) { |
| 66 | assertEquals("corpusID", res.at("/meta/fields/1").asText()); |
| 67 | } |
| 68 | else { |
| 69 | assertEquals("corpusID", res.at("/meta/fields/0").asText()); |
| 70 | assertEquals("UID", res.at("/meta/fields/1").asText()); |
| 71 | }; |
| 72 | |
| Nils Diewald | 3aa9e69 | 2015-02-20 22:20:11 +0000 | [diff] [blame] | 73 | assertEquals(0, res.at("/matches/0/UID").asInt()); |
| 74 | assertEquals("WPD", res.at("/matches/0/corpusID").asText()); |
| Akron | 12f1f5b | 2015-06-24 15:56:52 +0200 | [diff] [blame] | 75 | assertTrue(res.at("/matches/0/docID").isMissingNode()); |
| 76 | assertTrue(res.at("/matches/0/textSigle").isMissingNode()); |
| 77 | assertTrue(res.at("/matches/0/ID").isMissingNode()); |
| 78 | assertTrue(res.at("/matches/0/author").isMissingNode()); |
| 79 | assertTrue(res.at("/matches/0/title").isMissingNode()); |
| 80 | assertTrue(res.at("/matches/0/subTitle").isMissingNode()); |
| 81 | assertTrue(res.at("/matches/0/textClass").isMissingNode()); |
| 82 | assertTrue(res.at("/matches/0/pubPlace").isMissingNode()); |
| 83 | assertTrue(res.at("/matches/0/pubDate").isMissingNode()); |
| 84 | assertTrue(res.at("/matches/0/foundries").isMissingNode()); |
| 85 | assertTrue(res.at("/matches/0/layerInfos").isMissingNode()); |
| 86 | assertTrue(res.at("/matches/0/tokenization").isMissingNode()); |
| Nils Diewald | e364570 | 2014-11-07 21:15:20 +0000 | [diff] [blame] | 87 | |
| Eliza Margaretha | 6f98920 | 2016-10-14 21:48:29 +0200 | [diff] [blame] | 88 | jsonString = getJsonString(getClass() |
| 89 | .getResource("/queries/metas/fields_2.jsonld").getFile()); |
| Nils Diewald | bbd39a5 | 2015-02-23 19:56:57 +0000 | [diff] [blame] | 90 | ks = new Krill(jsonString); |
| Nils Diewald | 3aa9e69 | 2015-02-20 22:20:11 +0000 | [diff] [blame] | 91 | kr = ks.apply(ki); |
| 92 | assertEquals((long) 17, kr.getTotalResults()); |
| 93 | assertEquals(0, kr.getStartIndex()); |
| 94 | assertEquals(2, kr.getItemsPerPage()); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 95 | |
| Nils Diewald | 3aa9e69 | 2015-02-20 22:20:11 +0000 | [diff] [blame] | 96 | mapper = new ObjectMapper(); |
| 97 | res = mapper.readTree(kr.toJsonString()); |
| 98 | assertEquals(0, res.at("/matches/0/UID").asInt()); |
| Akron | 12f1f5b | 2015-06-24 15:56:52 +0200 | [diff] [blame] | 99 | assertTrue(res.at("/matches/0/corpusID").isMissingNode()); |
| Eliza Margaretha | 6f98920 | 2016-10-14 21:48:29 +0200 | [diff] [blame] | 100 | assertEquals("Ruru,Jens.Ol,Aglarech", |
| 101 | res.at("/matches/0/author").asText()); |
| Nils Diewald | 3aa9e69 | 2015-02-20 22:20:11 +0000 | [diff] [blame] | 102 | assertEquals("A", res.at("/matches/0/title").asText()); |
| 103 | assertEquals("WPD_AAA.00001", res.at("/matches/0/docID").asText()); |
| Akron | 3e0403f | 2015-06-24 20:59:13 +0200 | [diff] [blame] | 104 | assertTrue(res.at("/matches/0/textSigle").isMissingNode()); |
| Eliza Margaretha | 6f98920 | 2016-10-14 21:48:29 +0200 | [diff] [blame] | 105 | assertEquals("match-WPD_AAA.00001-p6-7", |
| 106 | res.at("/matches/0/matchID").asText()); |
| Akron | 48937e9 | 2015-06-26 01:49:02 +0200 | [diff] [blame] | 107 | // assertEquals("p6-7", res.at("/matches/0/matchID").asText()); |
| Akron | 32b9519 | 2019-01-11 13:58:55 +0100 | [diff] [blame] | 108 | assertTrue(res.at("/matches/0/subTitle").isMissingNode()); |
| Nils Diewald | 3aa9e69 | 2015-02-20 22:20:11 +0000 | [diff] [blame] | 109 | assertEquals("", res.at("/matches/0/subTitle").asText()); |
| 110 | assertEquals("", res.at("/matches/0/textClass").asText()); |
| 111 | assertEquals("", res.at("/matches/0/pubPlace").asText()); |
| 112 | assertEquals("", res.at("/matches/0/pubDate").asText()); |
| 113 | assertEquals("", res.at("/matches/0/foundries").asText()); |
| 114 | assertEquals("", res.at("/matches/0/layerInfo").asText()); |
| 115 | assertEquals("", res.at("/matches/0/tokenization").asText()); |
| Nils Diewald | e364570 | 2014-11-07 21:15:20 +0000 | [diff] [blame] | 116 | }; |
| Akron | 3e0403f | 2015-06-24 20:59:13 +0200 | [diff] [blame] | 117 | |
| Akron | 640458c | 2015-06-25 12:36:15 +0200 | [diff] [blame] | 118 | |
| Akron | 3e0403f | 2015-06-24 20:59:13 +0200 | [diff] [blame] | 119 | @Test |
| 120 | public void searchMetaFieldsNew () throws IOException { |
| 121 | |
| 122 | // Construct index |
| 123 | KrillIndex ki = new KrillIndex(); |
| Akron | 640458c | 2015-06-25 12:36:15 +0200 | [diff] [blame] | 124 | ki.addDoc(getClass().getResourceAsStream("/goe/AGX-00002.json"), false); |
| Akron | 3e0403f | 2015-06-24 20:59:13 +0200 | [diff] [blame] | 125 | ki.commit(); |
| 126 | |
| Eliza Margaretha | 6f98920 | 2016-10-14 21:48:29 +0200 | [diff] [blame] | 127 | String jsonString = getJsonString(getClass() |
| 128 | .getResource("/queries/metas/fields_no.jsonld").getFile()); |
| Akron | 3e0403f | 2015-06-24 20:59:13 +0200 | [diff] [blame] | 129 | |
| 130 | Krill ks = new Krill(jsonString); |
| 131 | Result kr = ks.apply(ki); |
| 132 | ObjectMapper mapper = new ObjectMapper(); |
| 133 | JsonNode res = mapper.readTree(kr.toJsonString()); |
| 134 | assertEquals(0, res.at("/matches/0/UID").asInt()); |
| 135 | assertEquals("GOE_AGX.00002", res.at("/matches/0/textSigle").asText()); |
| Eliza Margaretha | 6f98920 | 2016-10-14 21:48:29 +0200 | [diff] [blame] | 136 | assertEquals("Maximen und Reflexionen", |
| 137 | res.at("/matches/0/title").asText()); |
| Akron | 3e0403f | 2015-06-24 20:59:13 +0200 | [diff] [blame] | 138 | assertEquals("1982", res.at("/matches/0/pubDate").asText()); |
| Eliza Margaretha | 6f98920 | 2016-10-14 21:48:29 +0200 | [diff] [blame] | 139 | assertEquals("Goethe, Johann Wolfgang von", |
| 140 | res.at("/matches/0/author").asText()); |
| Akron | 3e0403f | 2015-06-24 20:59:13 +0200 | [diff] [blame] | 141 | assertEquals("GOE_AGX", res.at("/matches/0/docSigle").asText()); |
| 142 | assertEquals("GOE", res.at("/matches/0/corpusSigle").asText()); |
| Eliza Margaretha | 6f98920 | 2016-10-14 21:48:29 +0200 | [diff] [blame] | 143 | assertEquals("Religion und Christentum", |
| 144 | res.at("/matches/0/subTitle").asText()); |
| Akron | 3e0403f | 2015-06-24 20:59:13 +0200 | [diff] [blame] | 145 | assertEquals("München", res.at("/matches/0/pubPlace").asText()); |
| Akron | 640458c | 2015-06-25 12:36:15 +0200 | [diff] [blame] | 146 | assertEquals( |
| 147 | "base/s=spans cnx/c=spans cnx/l=tokens cnx/m=tokens cnx/p=tokens cnx/s=spans cnx/syn=tokens corenlp/c=spans corenlp/ne=tokens corenlp/p=tokens corenlp/s=spans glemm/l=tokens mate/l=tokens mate/m=tokens mate/p=tokens opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans xip/c=spans xip/l=tokens xip/p=tokens xip/s=spans", |
| 148 | res.at("/matches/0/layerInfos").asText()); |
| Akron | 3e0403f | 2015-06-24 20:59:13 +0200 | [diff] [blame] | 149 | assertTrue(res.at("/matches/0/textType").isMissingNode()); |
| Eliza Margaretha | 6f98920 | 2016-10-14 21:48:29 +0200 | [diff] [blame] | 150 | assertEquals("match-GOE_AGX.00002-p7-8", |
| 151 | res.at("/matches/0/matchID").asText()); |
| Akron | 48937e9 | 2015-06-26 01:49:02 +0200 | [diff] [blame] | 152 | |
| Akron | 3e0403f | 2015-06-24 20:59:13 +0200 | [diff] [blame] | 153 | |
| 154 | // All fields |
| Eliza Margaretha | 6f98920 | 2016-10-14 21:48:29 +0200 | [diff] [blame] | 155 | jsonString = getJsonString(getClass() |
| 156 | .getResource("/queries/metas/fields_all.jsonld").getFile()); |
| Akron | 3e0403f | 2015-06-24 20:59:13 +0200 | [diff] [blame] | 157 | |
| 158 | ks = new Krill(jsonString); |
| 159 | kr = ks.apply(ki); |
| 160 | mapper = new ObjectMapper(); |
| 161 | res = mapper.readTree(kr.toJsonString()); |
| Eliza Margaretha | 6f98920 | 2016-10-14 21:48:29 +0200 | [diff] [blame] | 162 | assertEquals("Verlag C. H. Beck", |
| 163 | res.at("/matches/0/publisher").asText()); |
| Akron | 3e0403f | 2015-06-24 20:59:13 +0200 | [diff] [blame] | 164 | assertEquals("Aphorismus", res.at("/matches/0/textType").asText()); |
| 165 | assertEquals("Aphorismen", res.at("/matches/0/textTypeRef").asText()); |
| Akron | 640458c | 2015-06-25 12:36:15 +0200 | [diff] [blame] | 166 | assertEquals( |
| 167 | "Goethe, Johann Wolfgang von: Maximen und Reflexionen. Religion und Christentum, [Aphorismen], (Erstveröffentlichung: Stuttgart ; Tübingen, 1827-1842), In: Goethe, Johann Wolfgang von: Goethes Werke, Bd. 12, Schriften zur Kunst. Schriften zur Literatur. Maximen und Reflexionen, Hrsg.: Trunz, Erich. München: Verlag C. H. Beck, 1982, S. 372-377", |
| 168 | res.at("/matches/0/reference").asText()); |
| Akron | 3e0403f | 2015-06-24 20:59:13 +0200 | [diff] [blame] | 169 | assertEquals("de", res.at("/matches/0/language").asText()); |
| Eliza Margaretha | 6f98920 | 2016-10-14 21:48:29 +0200 | [diff] [blame] | 170 | assertEquals("opennlp#tokens", |
| 171 | res.at("/matches/0/tokenSource").asText()); |
| Akron | 640458c | 2015-06-25 12:36:15 +0200 | [diff] [blame] | 172 | assertEquals( |
| 173 | "base base/paragraphs base/sentences connexor connexor/morpho connexor/phrase connexor/sentences connexor/syntax corenlp corenlp/constituency corenlp/morpho corenlp/namedentities corenlp/sentences glemm glemm/morpho mate mate/morpho opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences xip xip/constituency xip/morpho xip/sentences", |
| 174 | res.at("/matches/0/foundries").asText()); |
| Akron | 2b921a6 | 2019-01-14 18:52:45 +0100 | [diff] [blame] | 175 | |
| Eliza Margaretha | 6f98920 | 2016-10-14 21:48:29 +0200 | [diff] [blame] | 176 | assertEquals("Goethe-Korpus", |
| 177 | res.at("/matches/0/corpusTitle").asText()); |
| Akron | 7e3a10f | 2017-05-05 15:36:20 +0200 | [diff] [blame] | 178 | assertEquals("QAO-NC", res.at("/matches/0/availability").asText()); |
| Akron | 640458c | 2015-06-25 12:36:15 +0200 | [diff] [blame] | 179 | assertEquals("Goethe: Maximen und Reflexionen, (1827-1842)", |
| 180 | res.at("/matches/0/docTitle").asText()); |
| Akron | 3e0403f | 2015-06-24 20:59:13 +0200 | [diff] [blame] | 181 | assertEquals("1827", res.at("/matches/0/creationDate").asText()); |
| Akron | 69b958c | 2017-02-15 22:49:45 +0100 | [diff] [blame] | 182 | // assertEquals("372-377", res.at("/matches/0/pages").asText()); |
| Eliza Margaretha | 6f98920 | 2016-10-14 21:48:29 +0200 | [diff] [blame] | 183 | assertEquals("match-GOE_AGX.00002-p7-8", |
| 184 | res.at("/matches/0/matchID").asText()); |
| Akron | 6590c32 | 2015-07-02 16:08:13 +0200 | [diff] [blame] | 185 | |
| 186 | |
| 187 | // @All fields |
| Eliza Margaretha | 6f98920 | 2016-10-14 21:48:29 +0200 | [diff] [blame] | 188 | jsonString = getJsonString(getClass() |
| 189 | .getResource("/queries/metas/fields_at_all.jsonld").getFile()); |
| Akron | 6590c32 | 2015-07-02 16:08:13 +0200 | [diff] [blame] | 190 | |
| 191 | ks = new Krill(jsonString); |
| 192 | kr = ks.apply(ki); |
| 193 | mapper = new ObjectMapper(); |
| 194 | res = mapper.readTree(kr.toJsonString()); |
| 195 | |
| Eliza Margaretha | 6f98920 | 2016-10-14 21:48:29 +0200 | [diff] [blame] | 196 | assertEquals("Verlag C. H. Beck", |
| 197 | res.at("/matches/0/publisher").asText()); |
| Akron | 6590c32 | 2015-07-02 16:08:13 +0200 | [diff] [blame] | 198 | assertEquals("Aphorismus", res.at("/matches/0/textType").asText()); |
| 199 | assertEquals("Aphorismen", res.at("/matches/0/textTypeRef").asText()); |
| 200 | assertEquals( |
| 201 | "Goethe, Johann Wolfgang von: Maximen und Reflexionen. Religion und Christentum, [Aphorismen], (Erstveröffentlichung: Stuttgart ; Tübingen, 1827-1842), In: Goethe, Johann Wolfgang von: Goethes Werke, Bd. 12, Schriften zur Kunst. Schriften zur Literatur. Maximen und Reflexionen, Hrsg.: Trunz, Erich. München: Verlag C. H. Beck, 1982, S. 372-377", |
| 202 | res.at("/matches/0/reference").asText()); |
| 203 | assertEquals("de", res.at("/matches/0/language").asText()); |
| Eliza Margaretha | 6f98920 | 2016-10-14 21:48:29 +0200 | [diff] [blame] | 204 | assertEquals("opennlp#tokens", |
| 205 | res.at("/matches/0/tokenSource").asText()); |
| Akron | 6590c32 | 2015-07-02 16:08:13 +0200 | [diff] [blame] | 206 | assertEquals( |
| 207 | "base base/paragraphs base/sentences connexor connexor/morpho connexor/phrase connexor/sentences connexor/syntax corenlp corenlp/constituency corenlp/morpho corenlp/namedentities corenlp/sentences glemm glemm/morpho mate mate/morpho opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences xip xip/constituency xip/morpho xip/sentences", |
| 208 | res.at("/matches/0/foundries").asText()); |
| Eliza Margaretha | 6f98920 | 2016-10-14 21:48:29 +0200 | [diff] [blame] | 209 | assertEquals("Goethe-Korpus", |
| 210 | res.at("/matches/0/corpusTitle").asText()); |
| Akron | e64cc16 | 2019-01-08 18:40:37 +0100 | [diff] [blame] | 211 | assertEquals("QAO-NC", res.at("/matches/0/availability").asText()); |
| Akron | 6590c32 | 2015-07-02 16:08:13 +0200 | [diff] [blame] | 212 | assertEquals("Goethe: Maximen und Reflexionen, (1827-1842)", |
| 213 | res.at("/matches/0/docTitle").asText()); |
| 214 | assertEquals("1827", res.at("/matches/0/creationDate").asText()); |
| Akron | 69b958c | 2017-02-15 22:49:45 +0100 | [diff] [blame] | 215 | // assertEquals("372-377", res.at("/matches/0/pages").asText()); |
| Eliza Margaretha | 6f98920 | 2016-10-14 21:48:29 +0200 | [diff] [blame] | 216 | assertEquals("match-GOE_AGX.00002-p7-8", |
| 217 | res.at("/matches/0/matchID").asText()); |
| Akron | 3e0403f | 2015-06-24 20:59:13 +0200 | [diff] [blame] | 218 | }; |
| Akron | 48937e9 | 2015-06-26 01:49:02 +0200 | [diff] [blame] | 219 | |
| Akron | 4055017 | 2015-08-04 03:06:12 +0200 | [diff] [blame] | 220 | |
| Akron | 484c3c1 | 2015-07-07 20:25:44 +0200 | [diff] [blame] | 221 | @Test |
| 222 | public void searchCollectionFields () throws IOException { |
| 223 | KrillIndex ki = new KrillIndex(); |
| 224 | FieldDocument fd = new FieldDocument(); |
| 225 | fd.addString("corpusSigle", "ABC"); |
| 226 | fd.addString("docSigle", "ABC-123"); |
| 227 | fd.addString("textSigle", "ABC-123-0001"); |
| 228 | fd.addText("title", "Die Wahlverwandschaften"); |
| 229 | fd.addText("author", "Johann Wolfgang von Goethe"); |
| Akron | a6dabb7 | 2019-01-09 13:09:41 +0100 | [diff] [blame] | 230 | fd.addKeywords("textClass", "reisen wissenschaft"); |
| Akron | 484c3c1 | 2015-07-07 20:25:44 +0200 | [diff] [blame] | 231 | fd.addInt("pubDate", 20130617); |
| 232 | fd.addTV("tokens", "abc", "[(0-1)s:a|i:a|_0#0-1|-:t$<i>10]" |
| 233 | + "[(1-2)s:b|i:b|_1#1-2]" + "[(2-3)s:c|i:c|_2#2-3]"); |
| 234 | ki.addDoc(fd); |
| 235 | |
| 236 | FieldDocument fd2 = new FieldDocument(); |
| 237 | fd2.addString("corpusSigle", "ABC"); |
| 238 | fd2.addString("docSigle", "ABC-125"); |
| 239 | fd2.addString("textSigle", "ABC-125-0001"); |
| 240 | fd2.addText("title", "Die Glocke"); |
| 241 | fd2.addText("author", "Schiller, Friedrich"); |
| Akron | a6dabb7 | 2019-01-09 13:09:41 +0100 | [diff] [blame] | 242 | fd2.addKeywords("textClass", "Reisen geschichte"); |
| Akron | 484c3c1 | 2015-07-07 20:25:44 +0200 | [diff] [blame] | 243 | fd2.addInt("pubDate", 20130203); |
| 244 | fd2.addTV("tokens", "abc", "[(0-1)s:a|i:a|_0#0-1|-:t$<i>10]" |
| 245 | + "[(1-2)s:b|i:b|_1#1-2]" + "[(2-3)s:c|i:c|_2#2-3]"); |
| 246 | ki.addDoc(fd2); |
| 247 | ki.commit(); |
| 248 | |
| 249 | // textClass = reisen & wissenschaft |
| Eliza Margaretha | 6f98920 | 2016-10-14 21:48:29 +0200 | [diff] [blame] | 250 | String jsonString = getJsonString(getClass() |
| 251 | .getResource("/queries/collections/collection_textClass.jsonld") |
| 252 | .getFile()); |
| Akron | 484c3c1 | 2015-07-07 20:25:44 +0200 | [diff] [blame] | 253 | Krill ks = new Krill(jsonString); |
| 254 | KrillCollection kc = ks.getCollection(); |
| 255 | kc.setIndex(ki); |
| Akron | 484c3c1 | 2015-07-07 20:25:44 +0200 | [diff] [blame] | 256 | assertEquals(1, kc.numberOf("documents")); |
| 257 | |
| 258 | // textClass = reisen |
| Eliza Margaretha | 6f98920 | 2016-10-14 21:48:29 +0200 | [diff] [blame] | 259 | jsonString = getJsonString(getClass() |
| 260 | .getResource( |
| 261 | "/queries/collections/collection_textClass_2.jsonld") |
| 262 | .getFile()); |
| Akron | 484c3c1 | 2015-07-07 20:25:44 +0200 | [diff] [blame] | 263 | ks = new Krill(jsonString); |
| 264 | kc = ks.getCollection(); |
| 265 | kc.setIndex(ki); |
| Akron | 484c3c1 | 2015-07-07 20:25:44 +0200 | [diff] [blame] | 266 | assertEquals(2, kc.numberOf("documents")); |
| 267 | |
| 268 | /* |
| Akron | 484c3c1 | 2015-07-07 20:25:44 +0200 | [diff] [blame] | 269 | TokenStream ts = fd2.doc.getField("author").tokenStream( |
| 270 | (Analyzer) ki.writer().getAnalyzer(), |
| 271 | (TokenStream) null |
| 272 | ); |
| 273 | // OffsetAttribute offsetAttribute = ts.addAttribute(OffsetAttribute.class); |
| 274 | CharTermAttribute charTermAttribute = ts.addAttribute(CharTermAttribute.class); |
| Eliza Margaretha | 6f98920 | 2016-10-14 21:48:29 +0200 | [diff] [blame] | 275 | |
| Akron | 484c3c1 | 2015-07-07 20:25:44 +0200 | [diff] [blame] | 276 | ts.reset(); |
| 277 | while (ts.incrementToken()) { |
| 278 | String term = charTermAttribute.toString(); |
| 279 | System.err.println(">>" + term + "<<"); |
| 280 | }; |
| 281 | */ |
| 282 | |
| 283 | // author = wolfgang |
| Eliza Margaretha | 6f98920 | 2016-10-14 21:48:29 +0200 | [diff] [blame] | 284 | jsonString = getJsonString(getClass() |
| 285 | .getResource("/queries/collections/collection_goethe.jsonld") |
| 286 | .getFile()); |
| Akron | 484c3c1 | 2015-07-07 20:25:44 +0200 | [diff] [blame] | 287 | ks = new Krill(jsonString); |
| 288 | kc = ks.getCollection(); |
| 289 | kc.setIndex(ki); |
| Akron | 484c3c1 | 2015-07-07 20:25:44 +0200 | [diff] [blame] | 290 | assertEquals(1, kc.numberOf("documents")); |
| 291 | |
| 292 | // author = Wolfgang |
| Eliza Margaretha | 6f98920 | 2016-10-14 21:48:29 +0200 | [diff] [blame] | 293 | jsonString = getJsonString(getClass() |
| 294 | .getResource("/queries/collections/collection_goethe_2.jsonld") |
| 295 | .getFile()); |
| Akron | 484c3c1 | 2015-07-07 20:25:44 +0200 | [diff] [blame] | 296 | ks = new Krill(jsonString); |
| 297 | kc = ks.getCollection(); |
| 298 | kc.setIndex(ki); |
| Akron | 484c3c1 | 2015-07-07 20:25:44 +0200 | [diff] [blame] | 299 | assertEquals(1, kc.numberOf("documents")); |
| 300 | |
| 301 | Result kr = ks.apply(ki); |
| Akron | 4055017 | 2015-08-04 03:06:12 +0200 | [diff] [blame] | 302 | |
| Akron | 484c3c1 | 2015-07-07 20:25:44 +0200 | [diff] [blame] | 303 | ObjectMapper mapper = new ObjectMapper(); |
| 304 | JsonNode res = mapper.readTree(kr.toJsonString()); |
| 305 | assertEquals(1, res.at("/meta/totalResults").asInt()); |
| 306 | }; |
| 307 | |
| Akron | 48937e9 | 2015-06-26 01:49:02 +0200 | [diff] [blame] | 308 | |
| 309 | @Test |
| 310 | public void searchMetaContext () throws IOException { |
| 311 | |
| 312 | // All fields |
| Eliza Margaretha | 6f98920 | 2016-10-14 21:48:29 +0200 | [diff] [blame] | 313 | String jsonString = getJsonString(getClass() |
| 314 | .getResource("/queries/metas/context_paragraph.jsonld") |
| 315 | .getFile()); |
| Akron | 48937e9 | 2015-06-26 01:49:02 +0200 | [diff] [blame] | 316 | |
| 317 | Krill ks = new Krill(jsonString); |
| 318 | assertTrue(ks.getMeta().getContext().isSpanDefined()); |
| 319 | assertEquals("base/p", ks.getMeta().getContext().getSpanContext()); |
| 320 | }; |
| Akron | 8bb3bc3 | 2018-12-12 19:34:56 +0100 | [diff] [blame] | 321 | |
| 322 | |
| 323 | @Test |
| 324 | public void searchMetaAssets () throws IOException { |
| 325 | KrillIndex ki = new KrillIndex(); |
| 326 | FieldDocument fd = new FieldDocument(); |
| 327 | fd.addString("textSigle", "ABC-123-0002"); |
| 328 | fd.addText("title", "Die Wahlverwandtschaften"); |
| 329 | fd.addText("author", "Johann Wolfgang von Goethe"); |
| Akron | a6dabb7 | 2019-01-09 13:09:41 +0100 | [diff] [blame] | 330 | fd.addKeywords("textClass", "reisen wissenschaft"); |
| Akron | 8bb3bc3 | 2018-12-12 19:34:56 +0100 | [diff] [blame] | 331 | fd.addInt("pubDate", 20130617); |
| 332 | fd.addTV("tokens", "abc", "[(0-1)s:a|i:a|_0#0-1|-:t$<i>10]" |
| 333 | + "[(1-2)s:b|i:b|_1#1-2]" + "[(2-3)s:c|i:c|_2#2-3]"); |
| 334 | fd.addAttachement("WikiLink", "data:application/x.korap-link,https://de.wikipedia.org/wiki/Beispiel"); |
| 335 | ki.addDoc(fd); |
| 336 | ki.commit(); |
| 337 | |
| 338 | assertEquals(fd.doc.getField("textSigle").stringValue(), "ABC-123-0002"); |
| 339 | assertEquals(fd.doc.getField("title").stringValue(), "Die Wahlverwandtschaften"); |
| 340 | assertEquals(fd.doc.getField("author").stringValue(), "Johann Wolfgang von Goethe"); |
| 341 | assertEquals(fd.doc.getField("textClass").stringValue(), "reisen wissenschaft"); |
| 342 | assertEquals(fd.doc.getField("pubDate").stringValue(), "20130617"); |
| 343 | assertEquals(fd.doc.getField("WikiLink").stringValue(), "data:application/x.korap-link,https://de.wikipedia.org/wiki/Beispiel"); |
| 344 | } |
| 345 | |
| Nils Diewald | e364570 | 2014-11-07 21:15:20 +0000 | [diff] [blame] | 346 | }; |