| Eliza Margaretha | 6a78069 | 2014-01-15 09:45:42 +0000 | [diff] [blame] | 1 | package de.ids_mannheim.korap.search; |
| 2 | |
| margaretha | f70addb | 2015-04-27 13:17:18 +0200 | [diff] [blame] | 3 | import static de.ids_mannheim.korap.TestSimple.getString; |
| 4 | import static org.junit.Assert.assertEquals; |
| Akron | 001dab3 | 2015-07-02 12:30:15 +0200 | [diff] [blame] | 5 | import static org.junit.Assert.assertTrue; |
| margaretha | f70addb | 2015-04-27 13:17:18 +0200 | [diff] [blame] | 6 | import static org.junit.Assert.assertFalse; |
| 7 | import static org.junit.Assert.assertNull; |
| Nils Diewald | c925b49 | 2013-12-03 23:56:10 +0000 | [diff] [blame] | 8 | |
| margaretha | f70addb | 2015-04-27 13:17:18 +0200 | [diff] [blame] | 9 | import java.io.IOException; |
| 10 | import java.util.HashMap; |
| Nils Diewald | 56dc258 | 2014-11-04 21:33:46 +0000 | [diff] [blame] | 11 | |
| Nils Diewald | c925b49 | 2013-12-03 23:56:10 +0000 | [diff] [blame] | 12 | import org.junit.Test; |
| Akron | 176c9b1 | 2015-07-29 19:53:40 +0200 | [diff] [blame] | 13 | import org.junit.Ignore; |
| Nils Diewald | c925b49 | 2013-12-03 23:56:10 +0000 | [diff] [blame] | 14 | import org.junit.runner.RunWith; |
| 15 | import org.junit.runners.JUnit4; |
| 16 | |
| margaretha | f70addb | 2015-04-27 13:17:18 +0200 | [diff] [blame] | 17 | import com.fasterxml.jackson.databind.JsonNode; |
| 18 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 19 | |
| 20 | import de.ids_mannheim.korap.Krill; |
| 21 | import de.ids_mannheim.korap.KrillCollection; |
| 22 | import de.ids_mannheim.korap.KrillIndex; |
| 23 | import de.ids_mannheim.korap.KrillMeta; |
| 24 | import de.ids_mannheim.korap.collection.CollectionBuilder; |
| 25 | import de.ids_mannheim.korap.index.FieldDocument; |
| 26 | import de.ids_mannheim.korap.query.QueryBuilder; |
| margaretha | f70addb | 2015-04-27 13:17:18 +0200 | [diff] [blame] | 27 | import de.ids_mannheim.korap.response.Result; |
| 28 | import de.ids_mannheim.korap.response.SearchContext; |
| 29 | |
| Nils Diewald | c925b49 | 2013-12-03 23:56:10 +0000 | [diff] [blame] | 30 | @RunWith(JUnit4.class) |
| Nils Diewald | bbd39a5 | 2015-02-23 19:56:57 +0000 | [diff] [blame] | 31 | public class TestKrill { |
| Nils Diewald | c925b49 | 2013-12-03 23:56:10 +0000 | [diff] [blame] | 32 | @Test |
| 33 | public void searchCount () { |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 34 | Krill k = new Krill(new QueryBuilder("field1").seg("a").with("b")); |
| Nils Diewald | f5ab4b2 | 2015-02-25 20:55:16 +0000 | [diff] [blame] | 35 | |
| 36 | KrillMeta meta = k.getMeta(); |
| 37 | |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 38 | // Count: |
| Nils Diewald | f5ab4b2 | 2015-02-25 20:55:16 +0000 | [diff] [blame] | 39 | meta.setCount(30); |
| 40 | assertEquals(meta.getCount(), 30); |
| 41 | meta.setCount(20); |
| 42 | assertEquals(meta.getCount(), 20); |
| 43 | meta.setCount(-50); |
| 44 | assertEquals(meta.getCount(), 20); |
| 45 | meta.setCount(500); |
| 46 | assertEquals(meta.getCount(), meta.getCountMax()); |
| Nils Diewald | c925b49 | 2013-12-03 23:56:10 +0000 | [diff] [blame] | 47 | }; |
| 48 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 49 | |
| Nils Diewald | c925b49 | 2013-12-03 23:56:10 +0000 | [diff] [blame] | 50 | @Test |
| 51 | public void searchStartIndex () { |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 52 | Krill k = new Krill(new QueryBuilder("field1").seg("a").with("b")); |
| Nils Diewald | f5ab4b2 | 2015-02-25 20:55:16 +0000 | [diff] [blame] | 53 | |
| 54 | KrillMeta meta = k.getMeta(); |
| 55 | |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 56 | // startIndex |
| Nils Diewald | f5ab4b2 | 2015-02-25 20:55:16 +0000 | [diff] [blame] | 57 | meta.setStartIndex(5); |
| 58 | assertEquals(meta.getStartIndex(), 5); |
| 59 | meta.setStartIndex(1); |
| 60 | assertEquals(meta.getStartIndex(), 1); |
| 61 | meta.setStartIndex(0); |
| 62 | assertEquals(meta.getStartIndex(), 0); |
| 63 | meta.setStartIndex(70); |
| 64 | assertEquals(meta.getStartIndex(), 70); |
| 65 | meta.setStartIndex(-5); |
| 66 | assertEquals(meta.getStartIndex(), 0); |
| Nils Diewald | c925b49 | 2013-12-03 23:56:10 +0000 | [diff] [blame] | 67 | }; |
| 68 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 69 | |
| Nils Diewald | c925b49 | 2013-12-03 23:56:10 +0000 | [diff] [blame] | 70 | @Test |
| 71 | public void searchQuery () { |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 72 | Krill ks = new Krill(new QueryBuilder("field1").seg("a").with("b")); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 73 | // query |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 74 | assertEquals(ks.getSpanQuery().toString(), |
| 75 | "spanSegment(field1:a, field1:b)"); |
| Nils Diewald | c925b49 | 2013-12-03 23:56:10 +0000 | [diff] [blame] | 76 | }; |
| 77 | |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 78 | |
| Nils Diewald | c925b49 | 2013-12-03 23:56:10 +0000 | [diff] [blame] | 79 | @Test |
| 80 | public void searchIndex () throws IOException { |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 81 | // Construct index |
| Nils Diewald | a14ecd6 | 2015-02-26 21:00:20 +0000 | [diff] [blame] | 82 | KrillIndex ki = new KrillIndex(); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 83 | // Indexing test files |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 84 | for (String i : new String[] { "00001", "00002", "00003", "00004", |
| 85 | "00005", "00006", "02439" }) { |
| Nils Diewald | 5033355 | 2015-03-02 15:54:46 +0000 | [diff] [blame] | 86 | ki.addDoc( |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 87 | getClass().getResourceAsStream("/wiki/" + i + ".json.gz"), |
| 88 | true); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 89 | }; |
| 90 | ki.commit(); |
| Nils Diewald | c925b49 | 2013-12-03 23:56:10 +0000 | [diff] [blame] | 91 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 92 | Krill ks = new Krill(new QueryBuilder("tokens").seg("s:Buchstaben")); |
| Nils Diewald | f5ab4b2 | 2015-02-25 20:55:16 +0000 | [diff] [blame] | 93 | |
| Akron | 176c9b1 | 2015-07-29 19:53:40 +0200 | [diff] [blame] | 94 | CollectionBuilder cb = new CollectionBuilder(); |
| 95 | |
| 96 | ks.getCollection().fromBuilder(cb.term("textClass", "reisen")); |
| Nils Diewald | f5ab4b2 | 2015-02-25 20:55:16 +0000 | [diff] [blame] | 97 | |
| 98 | KrillMeta meta = ks.getMeta(); |
| 99 | meta.setCount(3); |
| 100 | meta.setStartIndex(5); |
| 101 | meta.getContext().left.setLength(1); |
| 102 | meta.getContext().right.setLength(1); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 103 | |
| Nils Diewald | 884dbcf | 2015-02-27 17:02:28 +0000 | [diff] [blame] | 104 | Result kr = ks.apply(ki); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 105 | assertEquals(kr.getTotalResults(), 6); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 106 | assertEquals(kr.getMatch(0).getSnippetBrackets(), |
| 107 | "... dem [Buchstaben] A ..."); |
| Nils Diewald | f5ab4b2 | 2015-02-25 20:55:16 +0000 | [diff] [blame] | 108 | |
| 109 | JsonNode res = ks.toJsonNode(); |
| 110 | assertEquals(3, res.at("/meta/count").asInt()); |
| 111 | assertEquals(5, res.at("/meta/startIndex").asInt()); |
| 112 | assertEquals("token", res.at("/meta/context/left/0").asText()); |
| 113 | assertEquals(1, res.at("/meta/context/left/1").asInt()); |
| 114 | assertEquals("token", res.at("/meta/context/right/0").asText()); |
| 115 | assertEquals(1, res.at("/meta/context/right/1").asInt()); |
| Nils Diewald | c925b49 | 2013-12-03 23:56:10 +0000 | [diff] [blame] | 116 | }; |
| Nils Diewald | c6b7875 | 2013-12-05 19:05:12 +0000 | [diff] [blame] | 117 | |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 118 | |
| Nils Diewald | c6b7875 | 2013-12-05 19:05:12 +0000 | [diff] [blame] | 119 | @Test |
| 120 | public void searchJSON () throws IOException { |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 121 | // Construct index |
| Nils Diewald | a14ecd6 | 2015-02-26 21:00:20 +0000 | [diff] [blame] | 122 | KrillIndex ki = new KrillIndex(); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 123 | // Indexing test files |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 124 | for (String i : new String[] { "00001", "00002", "00003", "00004", |
| 125 | "00005", "00006", "02439" }) { |
| Nils Diewald | 5033355 | 2015-03-02 15:54:46 +0000 | [diff] [blame] | 126 | ki.addDoc( |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 127 | getClass().getResourceAsStream("/wiki/" + i + ".json.gz"), |
| 128 | true); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 129 | }; |
| 130 | ki.commit(); |
| Nils Diewald | c6b7875 | 2013-12-05 19:05:12 +0000 | [diff] [blame] | 131 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 132 | String json = getString(getClass().getResource( |
| 133 | "/queries/metaquery3.jsonld").getFile()); |
| Nils Diewald | c6b7875 | 2013-12-05 19:05:12 +0000 | [diff] [blame] | 134 | |
| Nils Diewald | bbd39a5 | 2015-02-23 19:56:57 +0000 | [diff] [blame] | 135 | Krill ks = new Krill(json); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 136 | Result kr = ks.apply(ki); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 137 | assertEquals(kr.getTotalResults(), 66); |
| 138 | assertEquals(5, kr.getItemsPerPage()); |
| 139 | assertEquals(5, kr.getStartIndex()); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 140 | assertEquals("... a: A ist [der klangreichste] der V ...", |
| 141 | kr.getMatch(0).getSnippetBrackets()); |
| Nils Diewald | b1c3b65 | 2013-12-28 22:47:00 +0000 | [diff] [blame] | 142 | }; |
| Nils Diewald | 01b4ce3 | 2013-12-05 22:39:25 +0000 | [diff] [blame] | 143 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 144 | |
| Nils Diewald | b1c3b65 | 2013-12-28 22:47:00 +0000 | [diff] [blame] | 145 | @Test |
| 146 | public void searchJSON2 () throws IOException { |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 147 | // Construct index |
| Nils Diewald | a14ecd6 | 2015-02-26 21:00:20 +0000 | [diff] [blame] | 148 | KrillIndex ki = new KrillIndex(); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 149 | // Indexing test files |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 150 | for (String i : new String[] { "00001", "00002", "00003", "00004", |
| 151 | "00005", "00006", "02439", "00012-fakemeta", "00030-fakemeta", |
| 152 | /* |
| 153 | "02035-substring", |
| 154 | "05663-unbalanced", |
| 155 | "07452-deep" |
| 156 | */ |
| 157 | }) { |
| Nils Diewald | 5033355 | 2015-03-02 15:54:46 +0000 | [diff] [blame] | 158 | ki.addDoc( |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 159 | getClass().getResourceAsStream("/wiki/" + i + ".json.gz"), |
| 160 | true); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 161 | }; |
| 162 | ki.commit(); |
| Nils Diewald | b1c3b65 | 2013-12-28 22:47:00 +0000 | [diff] [blame] | 163 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 164 | String json = getString(getClass().getResource( |
| 165 | "/queries/metaquery4.jsonld").getFile()); |
| Nils Diewald | b1c3b65 | 2013-12-28 22:47:00 +0000 | [diff] [blame] | 166 | |
| Nils Diewald | bbd39a5 | 2015-02-23 19:56:57 +0000 | [diff] [blame] | 167 | Krill ks = new Krill(json); |
| Nils Diewald | 884dbcf | 2015-02-27 17:02:28 +0000 | [diff] [blame] | 168 | Result kr = ks.apply(ki); |
| Nils Diewald | c86aa48 | 2014-02-12 16:58:05 +0000 | [diff] [blame] | 169 | |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 170 | assertEquals(kr.getTotalResults(), 1); |
| Nils Diewald | 979b2fe | 2014-09-29 16:21:41 +0000 | [diff] [blame] | 171 | |
| Nils Diewald | bbd39a5 | 2015-02-23 19:56:57 +0000 | [diff] [blame] | 172 | ks = new Krill(json); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 173 | // Ignore the collection part of the query! |
| Nils Diewald | 2d5f810 | 2015-02-26 21:07:54 +0000 | [diff] [blame] | 174 | ks.setCollection(new KrillCollection()); |
| Nils Diewald | 3aa9e69 | 2015-02-20 22:20:11 +0000 | [diff] [blame] | 175 | kr = ks.apply(ki); |
| Nils Diewald | 979b2fe | 2014-09-29 16:21:41 +0000 | [diff] [blame] | 176 | |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 177 | assertEquals(kr.getTotalResults(), 5); |
| Nils Diewald | b1c3b65 | 2013-12-28 22:47:00 +0000 | [diff] [blame] | 178 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 179 | json = getString(getClass().getResource("/queries/metaquery5.jsonld") |
| 180 | .getFile()); |
| Nils Diewald | b1c3b65 | 2013-12-28 22:47:00 +0000 | [diff] [blame] | 181 | |
| Nils Diewald | bbd39a5 | 2015-02-23 19:56:57 +0000 | [diff] [blame] | 182 | ks = new Krill(json); |
| Nils Diewald | 3aa9e69 | 2015-02-20 22:20:11 +0000 | [diff] [blame] | 183 | kr = ks.apply(ki); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 184 | assertEquals(kr.getTotalResults(), 1); |
| 185 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 186 | json = getString(getClass().getResource("/queries/metaquery6.jsonld") |
| 187 | .getFile()); |
| Nils Diewald | bbd39a5 | 2015-02-23 19:56:57 +0000 | [diff] [blame] | 188 | ks = new Krill(json); |
| Nils Diewald | 3aa9e69 | 2015-02-20 22:20:11 +0000 | [diff] [blame] | 189 | kr = ks.apply(ki); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 190 | assertEquals(kr.getTotalResults(), 1); |
| Nils Diewald | c6b7875 | 2013-12-05 19:05:12 +0000 | [diff] [blame] | 191 | }; |
| 192 | |
| Akron | bb5d173 | 2015-06-22 01:22:40 +0200 | [diff] [blame] | 193 | |
| Akron | c63697c | 2015-06-17 22:32:02 +0200 | [diff] [blame] | 194 | // Todo: There SHOULD be a failure here, but Koral currently creates empty collections |
| 195 | @Test |
| 196 | public void queryJSONapiTest1 () { |
| Akron | bb5d173 | 2015-06-22 01:22:40 +0200 | [diff] [blame] | 197 | Krill test = new Krill( |
| 198 | "{\"@context\":\"http://korap.ids-mannheim.de/ns/koral/0.3/context.jsonld\",\"errors\":[],\"warnings\":[],\"messages\":[],\"collection\":{},\"query\":{\"@type\":\"koral:token\",\"wrap\":{\"@type\":\"koral:term\",\"layer\":\"orth\",\"key\":\"Baum\",\"match\":\"match:eq\"}},\"meta\":{}}"); |
| Akron | c63697c | 2015-06-17 22:32:02 +0200 | [diff] [blame] | 199 | assertFalse(test.hasErrors()); |
| 200 | }; |
| 201 | |
| Nils Diewald | c6b7875 | 2013-12-05 19:05:12 +0000 | [diff] [blame] | 202 | |
| 203 | @Test |
| 204 | public void searchJSONFailure () throws IOException { |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 205 | // Construct index |
| Nils Diewald | a14ecd6 | 2015-02-26 21:00:20 +0000 | [diff] [blame] | 206 | KrillIndex ki = new KrillIndex(); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 207 | // Indexing test files |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 208 | for (String i : new String[] { "00001", "00002", "00003", "00004", |
| 209 | "00005", "00006", "02439" }) { |
| Nils Diewald | 5033355 | 2015-03-02 15:54:46 +0000 | [diff] [blame] | 210 | ki.addDoc( |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 211 | getClass().getResourceAsStream("/wiki/" + i + ".json.gz"), |
| 212 | true); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 213 | }; |
| 214 | ki.commit(); |
| Nils Diewald | 884dbcf | 2015-02-27 17:02:28 +0000 | [diff] [blame] | 215 | Result kr = new Krill("{ query").apply(ki); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 216 | assertEquals(kr.getTotalResults(), 0); |
| 217 | assertEquals(kr.getError(0).getMessage(), "Unable to parse JSON"); |
| Nils Diewald | c6b7875 | 2013-12-05 19:05:12 +0000 | [diff] [blame] | 218 | }; |
| 219 | |
| 220 | |
| Nils Diewald | 9f31083 | 2013-12-06 22:38:55 +0000 | [diff] [blame] | 221 | @Test |
| 222 | public void searchJSONindexboundary () throws IOException { |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 223 | // Construct index |
| Nils Diewald | a14ecd6 | 2015-02-26 21:00:20 +0000 | [diff] [blame] | 224 | KrillIndex ki = new KrillIndex(); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 225 | // Indexing test files |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 226 | for (String i : new String[] { "00001", "00002", "00003", "00004", |
| 227 | "00005", "00006", "02439" }) { |
| Nils Diewald | 5033355 | 2015-03-02 15:54:46 +0000 | [diff] [blame] | 228 | ki.addDoc( |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 229 | getClass().getResourceAsStream("/wiki/" + i + ".json.gz"), |
| 230 | true); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 231 | }; |
| 232 | ki.commit(); |
| Nils Diewald | 9f31083 | 2013-12-06 22:38:55 +0000 | [diff] [blame] | 233 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 234 | String json = getString(getClass().getResource( |
| 235 | "/queries/bsp-fail1.jsonld").getFile()); |
| Nils Diewald | 9f31083 | 2013-12-06 22:38:55 +0000 | [diff] [blame] | 236 | |
| Nils Diewald | 884dbcf | 2015-02-27 17:02:28 +0000 | [diff] [blame] | 237 | Result kr = new Krill(json).apply(ki); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 238 | assertEquals(0, kr.getStartIndex()); |
| 239 | assertEquals(kr.getTotalResults(), 0); |
| 240 | assertEquals(25, kr.getItemsPerPage()); |
| Nils Diewald | 9f31083 | 2013-12-06 22:38:55 +0000 | [diff] [blame] | 241 | }; |
| 242 | |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 243 | |
| Nils Diewald | 9f31083 | 2013-12-06 22:38:55 +0000 | [diff] [blame] | 244 | @Test |
| 245 | public void searchJSONindexboundary2 () throws IOException { |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 246 | // Construct index |
| Nils Diewald | a14ecd6 | 2015-02-26 21:00:20 +0000 | [diff] [blame] | 247 | KrillIndex ki = new KrillIndex(); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 248 | // Indexing test files |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 249 | for (String i : new String[] { "00001", "00002", "00003", "00004", |
| 250 | "00005", "00006", "02439" }) { |
| Nils Diewald | 5033355 | 2015-03-02 15:54:46 +0000 | [diff] [blame] | 251 | ki.addDoc( |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 252 | getClass().getResourceAsStream("/wiki/" + i + ".json.gz"), |
| 253 | true); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 254 | }; |
| 255 | ki.commit(); |
| Nils Diewald | 9f31083 | 2013-12-06 22:38:55 +0000 | [diff] [blame] | 256 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 257 | String json = getString(getClass().getResource( |
| 258 | "/queries/bsp-fail2.jsonld").getFile()); |
| Nils Diewald | 9f31083 | 2013-12-06 22:38:55 +0000 | [diff] [blame] | 259 | |
| Nils Diewald | 884dbcf | 2015-02-27 17:02:28 +0000 | [diff] [blame] | 260 | Result kr = new Krill(json).apply(ki); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 261 | assertEquals(50, kr.getItemsPerPage()); |
| 262 | assertEquals(49950, kr.getStartIndex()); |
| 263 | assertEquals(kr.getTotalResults(), 0); |
| Nils Diewald | 9f31083 | 2013-12-06 22:38:55 +0000 | [diff] [blame] | 264 | }; |
| 265 | |
| Akron | 4055017 | 2015-08-04 03:06:12 +0200 | [diff] [blame] | 266 | |
| Akron | 001dab3 | 2015-07-02 12:30:15 +0200 | [diff] [blame] | 267 | /* |
| 268 | * Queries should be mirrored correctly for debugging reasons. |
| 269 | */ |
| 270 | @Test |
| 271 | public void queryJSONmirrorTestBug () throws IOException { |
| 272 | // Construct index |
| 273 | KrillIndex ki = new KrillIndex(); |
| 274 | String json = getString(getClass().getResource( |
| Akron | 4055017 | 2015-08-04 03:06:12 +0200 | [diff] [blame] | 275 | "/queries/bugs/failing_mirror.jsonld").getFile()); |
| Akron | 001dab3 | 2015-07-02 12:30:15 +0200 | [diff] [blame] | 276 | Krill ks = new Krill(json); |
| 277 | Result kr = ks.apply(ki); |
| 278 | |
| 279 | ObjectMapper mapper = new ObjectMapper(); |
| 280 | JsonNode res = mapper.readTree(kr.toJsonString()); |
| 281 | |
| 282 | assertEquals("Unable to parse JSON", res.at("/errors/0/1").asText()); |
| 283 | |
| 284 | json = getString(getClass().getResource( |
| Akron | 4055017 | 2015-08-04 03:06:12 +0200 | [diff] [blame] | 285 | "/queries/bugs/failing_mirror_2.jsonld").getFile()); |
| Akron | 001dab3 | 2015-07-02 12:30:15 +0200 | [diff] [blame] | 286 | ks = new Krill(json); |
| 287 | kr = ks.apply(ki); |
| 288 | |
| 289 | res = mapper.readTree(kr.toJsonString()); |
| 290 | |
| Akron | 4055017 | 2015-08-04 03:06:12 +0200 | [diff] [blame] | 291 | assertEquals(23, res.at("/meta/count").asInt()); |
| 292 | assertEquals(25, res.at("/meta/itemsPerPage").asInt()); |
| Akron | 001dab3 | 2015-07-02 12:30:15 +0200 | [diff] [blame] | 293 | assertEquals("base/s:p", res.at("/meta/context").asText()); |
| 294 | assertFalse(res.at("/query").isMissingNode()); |
| 295 | assertTrue(res.at("/query/@type").isMissingNode()); |
| 296 | assertTrue(res.at("/collection/@type").isMissingNode()); |
| 297 | }; |
| 298 | |
| 299 | |
| Nils Diewald | c6b7875 | 2013-12-05 19:05:12 +0000 | [diff] [blame] | 300 | |
| Nils Diewald | eabed8b | 2013-12-17 16:46:43 +0000 | [diff] [blame] | 301 | @Test |
| 302 | public void searchJSONcontext () throws IOException { |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 303 | // Construct index |
| Nils Diewald | a14ecd6 | 2015-02-26 21:00:20 +0000 | [diff] [blame] | 304 | KrillIndex ki = new KrillIndex(); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 305 | // Indexing test files |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 306 | for (String i : new String[] { "00001", "00002", "00003", "00004", |
| 307 | "00005", "00006", "02439" }) { |
| Nils Diewald | 5033355 | 2015-03-02 15:54:46 +0000 | [diff] [blame] | 308 | ki.addDoc( |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 309 | getClass().getResourceAsStream("/wiki/" + i + ".json.gz"), |
| 310 | true); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 311 | }; |
| 312 | ki.commit(); |
| Nils Diewald | eabed8b | 2013-12-17 16:46:43 +0000 | [diff] [blame] | 313 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 314 | String json = getString(getClass().getResource( |
| 315 | "/queries/bsp-context.jsonld").getFile()); |
| Nils Diewald | eabed8b | 2013-12-17 16:46:43 +0000 | [diff] [blame] | 316 | |
| Nils Diewald | bbd39a5 | 2015-02-23 19:56:57 +0000 | [diff] [blame] | 317 | Krill ks = new Krill(json); |
| Nils Diewald | 884dbcf | 2015-02-27 17:02:28 +0000 | [diff] [blame] | 318 | Result kr = ks.apply(ki); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 319 | assertEquals(kr.getTotalResults(), 10); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 320 | assertEquals("A bzw. a ist der erste Buchstabe des" |
| 321 | + " lateinischen [Alphabets] und ein Vokal." |
| 322 | + " Der Buchstabe A hat in deutschen Texten" |
| 323 | + " eine durchschnittliche Häufigkeit ...", kr.getMatch(0) |
| 324 | .getSnippetBrackets()); |
| Nils Diewald | b3a09db | 2013-12-21 00:22:02 +0000 | [diff] [blame] | 325 | |
| Nils Diewald | f5ab4b2 | 2015-02-25 20:55:16 +0000 | [diff] [blame] | 326 | ks.getMeta().setCount(5); |
| 327 | ks.getMeta().setStartPage(2); |
| Nils Diewald | 3aa9e69 | 2015-02-20 22:20:11 +0000 | [diff] [blame] | 328 | kr = ks.apply(ki); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 329 | assertEquals(kr.getTotalResults(), 10); |
| 330 | assertEquals(5, kr.getStartIndex()); |
| 331 | assertEquals(5, kr.getItemsPerPage()); |
| Nils Diewald | 891c53c | 2013-12-23 16:37:46 +0000 | [diff] [blame] | 332 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 333 | json = getString(getClass() |
| 334 | .getResource("/queries/bsp-context-2.jsonld").getFile()); |
| Nils Diewald | 891c53c | 2013-12-23 16:37:46 +0000 | [diff] [blame] | 335 | |
| Nils Diewald | bbd39a5 | 2015-02-23 19:56:57 +0000 | [diff] [blame] | 336 | kr = new Krill(json).apply(ki); |
| 337 | |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 338 | assertEquals(kr.getTotalResults(), -1); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 339 | assertEquals("... lls seit den Griechen beibehalten worden." |
| 340 | + " 3. Bedeutungen in der Biologie steht A für" |
| 341 | + " das Nukleosid Adenosin steht A die Base" |
| 342 | + " Adenin steht A für die Aminosäure Alanin" |
| 343 | + " in der Informatik steht a für den dezimalen" |
| 344 | + " [Wert] 97 sowohl im ASCII- als auch im" |
| 345 | + " Unicode-Zeichensatz steht A für den dezimalen" |
| 346 | + " Wert 65 sowohl im ASCII- als auch im" |
| 347 | + " Unicode-Zeichensatz als Kfz-Kennzeichen" |
| 348 | + " steht A in Deutschland für Augsburg." |
| 349 | + " in Österreich auf ...", kr.getMatch(0).getSnippetBrackets()); |
| Nils Diewald | eabed8b | 2013-12-17 16:46:43 +0000 | [diff] [blame] | 350 | }; |
| 351 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 352 | |
| Nils Diewald | 364eb64 | 2013-12-22 15:03:01 +0000 | [diff] [blame] | 353 | @Test |
| 354 | public void searchJSONstartPage () throws IOException { |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 355 | // Construct index |
| Nils Diewald | a14ecd6 | 2015-02-26 21:00:20 +0000 | [diff] [blame] | 356 | KrillIndex ki = new KrillIndex(); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 357 | // Indexing test files |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 358 | for (String i : new String[] { "00001", "00002", "00003", "00004", |
| 359 | "00005", "00006", "02439" }) { |
| Nils Diewald | 5033355 | 2015-03-02 15:54:46 +0000 | [diff] [blame] | 360 | ki.addDoc( |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 361 | getClass().getResourceAsStream("/wiki/" + i + ".json.gz"), |
| 362 | true); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 363 | }; |
| 364 | ki.commit(); |
| Nils Diewald | 364eb64 | 2013-12-22 15:03:01 +0000 | [diff] [blame] | 365 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 366 | String json = getString(getClass().getResource( |
| 367 | "/queries/bsp-paging.jsonld").getFile()); |
| Nils Diewald | 364eb64 | 2013-12-22 15:03:01 +0000 | [diff] [blame] | 368 | |
| Nils Diewald | bbd39a5 | 2015-02-23 19:56:57 +0000 | [diff] [blame] | 369 | Krill ks = new Krill(json); |
| Nils Diewald | 884dbcf | 2015-02-27 17:02:28 +0000 | [diff] [blame] | 370 | Result kr = ks.apply(ki); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 371 | assertEquals(kr.getTotalResults(), 10); |
| 372 | assertEquals(5, kr.getStartIndex()); |
| 373 | assertEquals(5, kr.getItemsPerPage()); |
| Nils Diewald | 364eb64 | 2013-12-22 15:03:01 +0000 | [diff] [blame] | 374 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 375 | json = getString(getClass().getResource("/queries/bsp-cutoff.jsonld") |
| 376 | .getFile()); |
| Nils Diewald | bbd39a5 | 2015-02-23 19:56:57 +0000 | [diff] [blame] | 377 | ks = ks = new Krill(json); |
| Nils Diewald | 3aa9e69 | 2015-02-20 22:20:11 +0000 | [diff] [blame] | 378 | kr = ks.apply(ki); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 379 | assertEquals(kr.getTotalResults(), -1); |
| 380 | assertEquals(2, kr.getStartIndex()); |
| 381 | assertEquals(2, kr.getItemsPerPage()); |
| Nils Diewald | 364eb64 | 2013-12-22 15:03:01 +0000 | [diff] [blame] | 382 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 383 | json = getString(getClass().getResource("/queries/metaquery9.jsonld") |
| 384 | .getFile()); |
| Nils Diewald | 2d5f810 | 2015-02-26 21:07:54 +0000 | [diff] [blame] | 385 | KrillCollection kc = new KrillCollection(json); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 386 | kc.setIndex(ki); |
| 387 | assertEquals(7, kc.numberOf("documents")); |
| Nils Diewald | 364eb64 | 2013-12-22 15:03:01 +0000 | [diff] [blame] | 388 | }; |
| Nils Diewald | eabed8b | 2013-12-17 16:46:43 +0000 | [diff] [blame] | 389 | |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 390 | |
| Nils Diewald | fb4d7b0 | 2014-04-09 17:56:17 +0000 | [diff] [blame] | 391 | @Test |
| Nils Diewald | 7cf8c6d | 2014-05-28 18:37:38 +0000 | [diff] [blame] | 392 | public void searchJSONitemsPerResource () throws IOException { |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 393 | // Construct index |
| Nils Diewald | a14ecd6 | 2015-02-26 21:00:20 +0000 | [diff] [blame] | 394 | KrillIndex ki = new KrillIndex(); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 395 | // Indexing test files |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 396 | for (String i : new String[] { "00001", "00002", "00003", "00004", |
| 397 | "00005", "00006", "02439" }) { |
| Nils Diewald | 5033355 | 2015-03-02 15:54:46 +0000 | [diff] [blame] | 398 | ki.addDoc( |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 399 | getClass().getResourceAsStream("/wiki/" + i + ".json.gz"), |
| 400 | true); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 401 | }; |
| 402 | ki.commit(); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 403 | String json = getString(getClass().getResource( |
| 404 | "/queries/bsp-itemsPerResource.jsonld").getFile()); |
| Nils Diewald | 7cf8c6d | 2014-05-28 18:37:38 +0000 | [diff] [blame] | 405 | |
| Nils Diewald | bbd39a5 | 2015-02-23 19:56:57 +0000 | [diff] [blame] | 406 | Krill ks = new Krill(json); |
| Nils Diewald | 884dbcf | 2015-02-27 17:02:28 +0000 | [diff] [blame] | 407 | Result kr = ks.apply(ki); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 408 | assertEquals(kr.getTotalResults(), 10); |
| 409 | assertEquals(0, kr.getStartIndex()); |
| 410 | assertEquals(20, kr.getItemsPerPage()); |
| Nils Diewald | 7cf8c6d | 2014-05-28 18:37:38 +0000 | [diff] [blame] | 411 | |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 412 | assertEquals("WPD_AAA.00001", kr.getMatch(0).getDocID()); |
| 413 | assertEquals("WPD_AAA.00001", kr.getMatch(1).getDocID()); |
| 414 | assertEquals("WPD_AAA.00001", kr.getMatch(6).getDocID()); |
| 415 | assertEquals("WPD_AAA.00002", kr.getMatch(7).getDocID()); |
| 416 | assertEquals("WPD_AAA.00002", kr.getMatch(8).getDocID()); |
| 417 | assertEquals("WPD_AAA.00004", kr.getMatch(9).getDocID()); |
| Nils Diewald | 7cf8c6d | 2014-05-28 18:37:38 +0000 | [diff] [blame] | 418 | |
| Nils Diewald | bbd39a5 | 2015-02-23 19:56:57 +0000 | [diff] [blame] | 419 | ks = new Krill(json); |
| Nils Diewald | f5ab4b2 | 2015-02-25 20:55:16 +0000 | [diff] [blame] | 420 | ks.getMeta().setItemsPerResource(1); |
| Nils Diewald | 7cf8c6d | 2014-05-28 18:37:38 +0000 | [diff] [blame] | 421 | |
| Nils Diewald | 3aa9e69 | 2015-02-20 22:20:11 +0000 | [diff] [blame] | 422 | kr = ks.apply(ki); |
| Nils Diewald | 7cf8c6d | 2014-05-28 18:37:38 +0000 | [diff] [blame] | 423 | |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 424 | assertEquals("WPD_AAA.00001", kr.getMatch(0).getDocID()); |
| 425 | assertEquals("WPD_AAA.00002", kr.getMatch(1).getDocID()); |
| 426 | assertEquals("WPD_AAA.00004", kr.getMatch(2).getDocID()); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 427 | |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 428 | assertEquals(kr.getTotalResults(), 3); |
| 429 | assertEquals(0, kr.getStartIndex()); |
| 430 | assertEquals(20, kr.getItemsPerPage()); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 431 | |
| Nils Diewald | bbd39a5 | 2015-02-23 19:56:57 +0000 | [diff] [blame] | 432 | ks = new Krill(json); |
| Nils Diewald | f5ab4b2 | 2015-02-25 20:55:16 +0000 | [diff] [blame] | 433 | ks.getMeta().setItemsPerResource(2); |
| Nils Diewald | 7cf8c6d | 2014-05-28 18:37:38 +0000 | [diff] [blame] | 434 | |
| Nils Diewald | 3aa9e69 | 2015-02-20 22:20:11 +0000 | [diff] [blame] | 435 | kr = ks.apply(ki); |
| Nils Diewald | 7cf8c6d | 2014-05-28 18:37:38 +0000 | [diff] [blame] | 436 | |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 437 | assertEquals("WPD_AAA.00001", kr.getMatch(0).getDocID()); |
| 438 | assertEquals("WPD_AAA.00001", kr.getMatch(1).getDocID()); |
| 439 | assertEquals("WPD_AAA.00002", kr.getMatch(2).getDocID()); |
| 440 | assertEquals("WPD_AAA.00002", kr.getMatch(3).getDocID()); |
| 441 | assertEquals("WPD_AAA.00004", kr.getMatch(4).getDocID()); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 442 | |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 443 | assertEquals(kr.getTotalResults(), 5); |
| 444 | assertEquals(0, kr.getStartIndex()); |
| 445 | assertEquals(20, kr.getItemsPerPage()); |
| Nils Diewald | 7cf8c6d | 2014-05-28 18:37:38 +0000 | [diff] [blame] | 446 | |
| Nils Diewald | bbd39a5 | 2015-02-23 19:56:57 +0000 | [diff] [blame] | 447 | ks = new Krill(json); |
| Nils Diewald | f5ab4b2 | 2015-02-25 20:55:16 +0000 | [diff] [blame] | 448 | KrillMeta meta = ks.getMeta(); |
| 449 | meta.setItemsPerResource(1); |
| 450 | meta.setStartIndex(1); |
| 451 | meta.setCount(1); |
| Nils Diewald | 7cf8c6d | 2014-05-28 18:37:38 +0000 | [diff] [blame] | 452 | |
| Nils Diewald | 3aa9e69 | 2015-02-20 22:20:11 +0000 | [diff] [blame] | 453 | kr = ks.apply(ki); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 454 | |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 455 | assertEquals("WPD_AAA.00002", kr.getMatch(0).getDocID()); |
| Nils Diewald | 7cf8c6d | 2014-05-28 18:37:38 +0000 | [diff] [blame] | 456 | |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 457 | assertEquals(kr.getTotalResults(), 3); |
| 458 | assertEquals(1, kr.getStartIndex()); |
| 459 | assertEquals(1, kr.getItemsPerPage()); |
| Nils Diewald | 7cf8c6d | 2014-05-28 18:37:38 +0000 | [diff] [blame] | 460 | |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 461 | assertEquals((short) 1, kr.getItemsPerResource()); |
| Nils Diewald | 7cf8c6d | 2014-05-28 18:37:38 +0000 | [diff] [blame] | 462 | }; |
| 463 | |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 464 | |
| Nils Diewald | d723d81 | 2014-09-23 18:50:52 +0000 | [diff] [blame] | 465 | @Test |
| 466 | public void searchJSONitemsPerResourceServer () throws IOException { |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 467 | /* |
| 468 | * This test is a server-only implementation of |
| 469 | * TestResource#testCollection |
| 470 | */ |
| 471 | // Construct index |
| Nils Diewald | a14ecd6 | 2015-02-26 21:00:20 +0000 | [diff] [blame] | 472 | KrillIndex ki = new KrillIndex(); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 473 | // Indexing test files |
| 474 | int uid = 1; |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 475 | for (String i : new String[] { "00001", "00002", "00003", "00004", |
| 476 | "00005", "00006", "02439" }) { |
| 477 | ki.addDoc(uid++, |
| 478 | getClass().getResourceAsStream("/wiki/" + i + ".json.gz"), |
| 479 | true); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 480 | }; |
| 481 | ki.commit(); |
| Nils Diewald | d723d81 | 2014-09-23 18:50:52 +0000 | [diff] [blame] | 482 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 483 | String json = getString(getClass().getResource( |
| 484 | "/queries/bsp-uid-example.jsonld").getFile()); |
| Nils Diewald | d723d81 | 2014-09-23 18:50:52 +0000 | [diff] [blame] | 485 | |
| Nils Diewald | bbd39a5 | 2015-02-23 19:56:57 +0000 | [diff] [blame] | 486 | Krill ks = new Krill(json); |
| Nils Diewald | f5ab4b2 | 2015-02-25 20:55:16 +0000 | [diff] [blame] | 487 | ks.getMeta().setItemsPerResource(1); |
| 488 | |
| Nils Diewald | 2d5f810 | 2015-02-26 21:07:54 +0000 | [diff] [blame] | 489 | KrillCollection kc = new KrillCollection(); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 490 | kc.filterUIDs(new String[] { "1", "4" }); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 491 | kc.setIndex(ki); |
| 492 | ks.setCollection(kc); |
| Nils Diewald | d723d81 | 2014-09-23 18:50:52 +0000 | [diff] [blame] | 493 | |
| Nils Diewald | 884dbcf | 2015-02-27 17:02:28 +0000 | [diff] [blame] | 494 | Result kr = ks.apply(ki); |
| Nils Diewald | d723d81 | 2014-09-23 18:50:52 +0000 | [diff] [blame] | 495 | |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 496 | assertEquals(kr.getTotalResults(), 2); |
| 497 | assertEquals(0, kr.getStartIndex()); |
| 498 | assertEquals(25, kr.getItemsPerPage()); |
| Nils Diewald | d723d81 | 2014-09-23 18:50:52 +0000 | [diff] [blame] | 499 | }; |
| Nils Diewald | ba197f2 | 2014-11-01 17:21:46 +0000 | [diff] [blame] | 500 | |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 501 | |
| Nils Diewald | ba197f2 | 2014-11-01 17:21:46 +0000 | [diff] [blame] | 502 | @Test |
| 503 | public void searchJSONnewJSON () throws IOException { |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 504 | // Construct index |
| Nils Diewald | a14ecd6 | 2015-02-26 21:00:20 +0000 | [diff] [blame] | 505 | KrillIndex ki = new KrillIndex(); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 506 | // Indexing test files |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 507 | FieldDocument fd = ki.addDoc(1, |
| 508 | getClass().getResourceAsStream("/goe/AGA-03828.json.gz"), true); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 509 | ki.commit(); |
| Nils Diewald | ba197f2 | 2014-11-01 17:21:46 +0000 | [diff] [blame] | 510 | |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 511 | assertEquals(fd.getUID(), 1); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 512 | assertEquals(fd.getTextSigle(), "GOE_AGA.03828"); |
| 513 | assertEquals(fd.getDocSigle(), "GOE_AGA"); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 514 | assertEquals(fd.getCorpusSigle(), "GOE"); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 515 | assertEquals(fd.getTitle(), "Autobiographische Einzelheiten"); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 516 | assertNull(fd.getSubTitle()); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 517 | assertEquals(fd.getTextType(), "Autobiographie"); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 518 | assertNull(fd.getTextTypeArt()); |
| 519 | assertNull(fd.getTextTypeRef()); |
| 520 | assertNull(fd.getTextColumn()); |
| 521 | assertNull(fd.getTextDomain()); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 522 | assertEquals(fd.getPages(), "529-547"); |
| 523 | assertEquals(fd.getLicense(), "QAO-NC"); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 524 | assertEquals(fd.getCreationDate().toString(), "18200000"); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 525 | assertEquals(fd.getPubDate().toString(), "19820000"); |
| 526 | assertEquals(fd.getAuthor(), "Goethe, Johann Wolfgang von"); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 527 | assertNull(fd.getTextClass()); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 528 | assertEquals(fd.getLanguage(), "de"); |
| 529 | assertEquals(fd.getPubPlace(), "München"); |
| 530 | assertEquals(fd.getReference(), "Goethe, Johann Wolfgang von:" |
| 531 | + " Autobiographische Einzelheiten," |
| 532 | + " (Geschrieben bis 1832), In: Goethe," |
| 533 | + " Johann Wolfgang von: Goethes Werke," |
| 534 | + " Bd. 10, Autobiographische Schriften" |
| 535 | + " II, Hrsg.: Trunz, Erich. München: " |
| 536 | + "Verlag C. H. Beck, 1982, S. 529-547"); |
| 537 | assertEquals(fd.getPublisher(), "Verlag C. H. Beck"); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 538 | assertNull(fd.getEditor()); |
| 539 | assertNull(fd.getFileEditionStatement()); |
| 540 | assertNull(fd.getBiblEditionStatement()); |
| 541 | assertNull(fd.getKeywords()); |
| 542 | |
| 543 | assertEquals(fd.getTokenSource(), "opennlp#tokens"); |
| 544 | assertEquals(fd.getFoundries(), |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 545 | "base base/paragraphs base/sentences corenlp " |
| 546 | + "corenlp/constituency corenlp/morpho " |
| 547 | + "corenlp/namedentities corenlp/sentences " |
| 548 | + "glemm glemm/morpho mate mate/morpho" |
| 549 | + " opennlp opennlp/morpho opennlp/sentences" |
| 550 | + " treetagger treetagger/morpho " |
| 551 | + "treetagger/sentences"); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 552 | assertEquals(fd.getLayerInfos(), |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 553 | "base/s=spans corenlp/c=spans corenlp/ne=tokens" |
| 554 | + " corenlp/p=tokens corenlp/s=spans glemm/l=tokens" |
| 555 | + " mate/l=tokens mate/m=tokens mate/p=tokens" |
| 556 | + " opennlp/p=tokens opennlp/s=spans tt/l=tokens" |
| 557 | + " tt/p=tokens tt/s=spans"); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 558 | |
| 559 | assertEquals(fd.getCorpusTitle(), "Goethes Werke"); |
| 560 | assertNull(fd.getCorpusSubTitle()); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 561 | assertEquals(fd.getCorpusAuthor(), "Goethe, Johann Wolfgang von"); |
| 562 | assertEquals(fd.getCorpusEditor(), "Trunz, Erich"); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 563 | assertEquals(fd.getDocTitle(), |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 564 | "Goethe: Autobiographische Schriften II, (1817-1825, 1832)"); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 565 | assertNull(fd.getDocSubTitle()); |
| 566 | assertNull(fd.getDocEditor()); |
| 567 | assertNull(fd.getDocAuthor()); |
| 568 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 569 | Krill ks = new Krill(new QueryBuilder("tokens").seg("mate/m:case:nom") |
| 570 | .with("mate/m:number:pl")); |
| Nils Diewald | 884dbcf | 2015-02-27 17:02:28 +0000 | [diff] [blame] | 571 | Result kr = ks.apply(ki); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 572 | |
| 573 | assertEquals(kr.getTotalResults(), 148); |
| 574 | assertEquals(0, kr.getStartIndex()); |
| 575 | assertEquals(25, kr.getItemsPerPage()); |
| Nils Diewald | ba197f2 | 2014-11-01 17:21:46 +0000 | [diff] [blame] | 576 | }; |
| Nils Diewald | 06368ba | 2014-11-03 20:53:27 +0000 | [diff] [blame] | 577 | |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 578 | |
| Nils Diewald | 06368ba | 2014-11-03 20:53:27 +0000 | [diff] [blame] | 579 | @Test |
| 580 | public void searchJSONnewJSON2 () throws IOException { |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 581 | // Construct index |
| Nils Diewald | a14ecd6 | 2015-02-26 21:00:20 +0000 | [diff] [blame] | 582 | KrillIndex ki = new KrillIndex(); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 583 | // Indexing test files |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 584 | FieldDocument fd = ki.addDoc(1, |
| 585 | getClass().getResourceAsStream("/bzk/D59-00089.json.gz"), true); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 586 | ki.commit(); |
| Nils Diewald | 06368ba | 2014-11-03 20:53:27 +0000 | [diff] [blame] | 587 | |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 588 | assertEquals(fd.getUID(), 1); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 589 | assertEquals(fd.getTextSigle(), "BZK_D59.00089"); |
| 590 | assertEquals(fd.getDocSigle(), "BZK_D59"); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 591 | assertEquals(fd.getCorpusSigle(), "BZK"); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 592 | assertEquals(fd.getTitle(), "Saragat-Partei zerfällt"); |
| 593 | assertEquals(fd.getPubDate().toString(), "19590219"); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 594 | |
| 595 | assertNull(fd.getSubTitle()); |
| 596 | assertNull(fd.getAuthor()); |
| 597 | assertNull(fd.getEditor()); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 598 | assertEquals(fd.getPubPlace(), "Berlin"); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 599 | assertNull(fd.getPublisher()); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 600 | assertEquals(fd.getTextType(), "Zeitung: Tageszeitung"); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 601 | assertNull(fd.getTextTypeArt()); |
| 602 | assertEquals(fd.getTextTypeRef(), "Tageszeitung"); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 603 | assertEquals(fd.getTextDomain(), "Politik"); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 604 | assertEquals(fd.getCreationDate().toString(), "19590219"); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 605 | assertEquals(fd.getLicense(), "ACA-NC-LC"); |
| 606 | assertEquals(fd.getTextColumn(), "POLITIK"); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 607 | assertNull(fd.getPages()); |
| 608 | assertEquals(fd.getTextClass(), "politik ausland"); |
| 609 | assertNull(fd.getFileEditionStatement()); |
| 610 | assertNull(fd.getBiblEditionStatement()); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 611 | |
| 612 | assertEquals(fd.getLanguage(), "de"); |
| 613 | assertEquals(fd.getReference(), |
| 614 | "Neues Deutschland, [Tageszeitung], 19.02.1959, Jg. 14," |
| 615 | + " Berliner Ausgabe, S. 7. - Sachgebiet: Politik, " |
| 616 | + "Originalressort: POLITIK; Saragat-Partei zerfällt"); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 617 | assertNull(fd.getPublisher()); |
| 618 | assertNull(fd.getKeywords()); |
| 619 | |
| 620 | assertEquals(fd.getTokenSource(), "opennlp#tokens"); |
| 621 | |
| 622 | assertEquals( |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 623 | fd.getFoundries(), |
| 624 | "base base/paragraphs base/sentences corenlp " |
| 625 | + "corenlp/constituency corenlp/morpho corenlp/namedentities" |
| 626 | + " corenlp/sentences glemm glemm/morpho mate mate/morpho" |
| 627 | + " opennlp opennlp/morpho opennlp/sentences treetagger" |
| 628 | + " treetagger/morpho treetagger/sentences"); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 629 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 630 | assertEquals(fd.getLayerInfos(), |
| 631 | "base/s=spans corenlp/c=spans corenlp/ne=tokens" |
| 632 | + " corenlp/p=tokens corenlp/s=spans glemm/l=tokens" |
| 633 | + " mate/l=tokens mate/m=tokens mate/p=tokens" |
| 634 | + " opennlp/p=tokens opennlp/s=spans tt/l=tokens" |
| 635 | + " tt/p=tokens tt/s=spans"); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 636 | |
| 637 | assertEquals(fd.getCorpusTitle(), "Bonner Zeitungskorpus"); |
| 638 | assertNull(fd.getCorpusSubTitle()); |
| 639 | assertNull(fd.getCorpusAuthor()); |
| 640 | assertNull(fd.getCorpusEditor()); |
| 641 | |
| 642 | assertEquals(fd.getDocTitle(), "Neues Deutschland"); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 643 | assertEquals(fd.getDocSubTitle(), |
| 644 | "Organ des Zentralkomitees der Sozialistischen " |
| 645 | + "Einheitspartei Deutschlands"); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 646 | assertNull(fd.getDocEditor()); |
| 647 | assertNull(fd.getDocAuthor()); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 648 | |
| 649 | Krill ks = new Krill(new QueryBuilder("tokens").seg("mate/m:case:nom") |
| 650 | .with("mate/m:number:sg")); |
| Nils Diewald | 884dbcf | 2015-02-27 17:02:28 +0000 | [diff] [blame] | 651 | Result kr = ks.apply(ki); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 652 | |
| 653 | assertEquals(kr.getTotalResults(), 6); |
| 654 | assertEquals(0, kr.getStartIndex()); |
| 655 | assertEquals(25, kr.getItemsPerPage()); |
| Nils Diewald | 06368ba | 2014-11-03 20:53:27 +0000 | [diff] [blame] | 656 | }; |
| Nils Diewald | 7cf8c6d | 2014-05-28 18:37:38 +0000 | [diff] [blame] | 657 | |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 658 | |
| Nils Diewald | 7cf8c6d | 2014-05-28 18:37:38 +0000 | [diff] [blame] | 659 | @Test |
| Nils Diewald | 56dc258 | 2014-11-04 21:33:46 +0000 | [diff] [blame] | 660 | public void searchJSONcosmasBoundaryBug () throws IOException { |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 661 | // Construct index |
| Nils Diewald | a14ecd6 | 2015-02-26 21:00:20 +0000 | [diff] [blame] | 662 | KrillIndex ki = new KrillIndex(); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 663 | // Indexing test files |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 664 | FieldDocument fd = ki.addDoc(1, |
| 665 | getClass().getResourceAsStream("/bzk/D59-00089.json.gz"), true); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 666 | ki.commit(); |
| Nils Diewald | 56dc258 | 2014-11-04 21:33:46 +0000 | [diff] [blame] | 667 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 668 | String json = getString(getClass().getResource( |
| 669 | "/queries/bugs/cosmas_boundary.jsonld").getFile()); |
| Nils Diewald | 56dc258 | 2014-11-04 21:33:46 +0000 | [diff] [blame] | 670 | |
| Nils Diewald | 8904c1d | 2015-02-26 16:13:18 +0000 | [diff] [blame] | 671 | QueryBuilder kq = new QueryBuilder("tokens"); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 672 | Krill ks = new Krill(kq.focus(1, |
| 673 | kq.contains(kq.tag("base/s:s"), kq._(1, kq.seg("s:Leben"))))); |
| Nils Diewald | 56dc258 | 2014-11-04 21:33:46 +0000 | [diff] [blame] | 674 | |
| Nils Diewald | 884dbcf | 2015-02-27 17:02:28 +0000 | [diff] [blame] | 675 | Result kr = ks.apply(ki); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 676 | assertEquals(kr.getSerialQuery(), |
| 677 | "focus(1: spanContain(<tokens:base/s:s />, {1: tokens:s:Leben}))"); |
| margaretha | f70addb | 2015-04-27 13:17:18 +0200 | [diff] [blame] | 678 | assertEquals(40, kr.getMatch(0).getStartPos()); |
| 679 | assertEquals(41, kr.getMatch(0).getEndPos()); |
| 680 | |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 681 | assertEquals( |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 682 | kr.getMatch(0).getSnippetBrackets(), |
| 683 | "... Initiative\" eine neue politische Gruppierung ins " |
| 684 | + "[{1:Leben}] gerufen hatten. Pressemeldungen zufolge haben sich ..."); |
| Nils Diewald | 56dc258 | 2014-11-04 21:33:46 +0000 | [diff] [blame] | 685 | |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 686 | // Try with high class - don't highlight |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 687 | ks = new Krill(kq.focus(129, |
| 688 | kq.contains(kq.tag("base/s:s"), kq._(129, kq.seg("s:Leben"))))); |
| Nils Diewald | 56dc258 | 2014-11-04 21:33:46 +0000 | [diff] [blame] | 689 | |
| Nils Diewald | 3aa9e69 | 2015-02-20 22:20:11 +0000 | [diff] [blame] | 690 | kr = ks.apply(ki); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 691 | assertEquals(kr.getSerialQuery(), |
| 692 | "focus(129: spanContain(<tokens:base/s:s />, {129: tokens:s:Leben}))"); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 693 | assertEquals( |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 694 | kr.getMatch(0).getSnippetBrackets(), |
| 695 | "... Initiative\" eine neue politische Gruppierung ins " |
| 696 | + "[Leben] gerufen hatten. Pressemeldungen zufolge haben sich ..."); |
| Nils Diewald | 0fa2da2 | 2014-11-05 03:31:32 +0000 | [diff] [blame] | 697 | |
| Nils Diewald | bbd39a5 | 2015-02-23 19:56:57 +0000 | [diff] [blame] | 698 | ks = new Krill(json); |
| Nils Diewald | 3aa9e69 | 2015-02-20 22:20:11 +0000 | [diff] [blame] | 699 | kr = ks.apply(ki); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 700 | assertEquals( |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 701 | kr.getSerialQuery(), |
| 702 | "focus(129: spanElementDistance({129: tokens:s:Namen}, " |
| 703 | + "{129: tokens:s:Leben}, [(base/s:s[0:1], notOrdered, notExcluded)]))"); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 704 | assertEquals( |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 705 | kr.getMatch(0).getSnippetBrackets(), |
| 706 | "... ihren Austritt erklärt und unter dem [Namen \"Einheitsbewegung " |
| 707 | + "der sozialistischen Initiative\" eine neue politische Gruppierung " |
| 708 | + "ins Leben] gerufen hatten. Pressemeldungen zufolge haben sich ..."); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 709 | assertEquals(kr.getTotalResults(), 1); |
| 710 | assertEquals(0, kr.getStartIndex()); |
| Nils Diewald | 56dc258 | 2014-11-04 21:33:46 +0000 | [diff] [blame] | 711 | }; |
| 712 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 713 | |
| Nils Diewald | c7d08d9 | 2014-11-05 21:30:05 +0000 | [diff] [blame] | 714 | @Test |
| 715 | public void searchJSONmultipleClassesBug () throws IOException { |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 716 | // Construct index |
| Nils Diewald | a14ecd6 | 2015-02-26 21:00:20 +0000 | [diff] [blame] | 717 | KrillIndex ki = new KrillIndex(); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 718 | // Indexing test files |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 719 | ki.addDoc(1, getClass().getResourceAsStream("/bzk/D59-00089.json.gz"), |
| 720 | true); |
| 721 | ki.addDoc(2, getClass().getResourceAsStream("/bzk/D59-00089.json.gz"), |
| 722 | true); |
| Nils Diewald | c7d08d9 | 2014-11-05 21:30:05 +0000 | [diff] [blame] | 723 | |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 724 | ki.commit(); |
| Nils Diewald | c7d08d9 | 2014-11-05 21:30:05 +0000 | [diff] [blame] | 725 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 726 | String json = getString(getClass().getResource( |
| 727 | "/queries/bugs/multiple_classes.jsonld").getFile()); |
| 728 | |
| Nils Diewald | bbd39a5 | 2015-02-23 19:56:57 +0000 | [diff] [blame] | 729 | Krill ks = new Krill(json); |
| Nils Diewald | 884dbcf | 2015-02-27 17:02:28 +0000 | [diff] [blame] | 730 | Result kr = ks.apply(ki); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 731 | assertEquals(kr.getSerialQuery(), |
| 732 | "{4: spanNext({1: spanNext({2: tokens:s:ins}, " |
| 733 | + "{3: tokens:s:Leben})}, tokens:s:gerufen)}"); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 734 | assertEquals( |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 735 | kr.getMatch(0).getSnippetBrackets(), |
| 736 | "... sozialistischen Initiative\" eine neue politische" |
| 737 | + " Gruppierung [{4:{1:{2:ins} {3:Leben}} gerufen}] hatten. " |
| 738 | + "Pressemeldungen zufolge haben sich in ..."); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 739 | assertEquals(kr.getTotalResults(), 2); |
| 740 | assertEquals(0, kr.getStartIndex()); |
| Nils Diewald | c7d08d9 | 2014-11-05 21:30:05 +0000 | [diff] [blame] | 741 | }; |
| 742 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 743 | |
| Nils Diewald | 277e9ce | 2014-11-06 03:42:11 +0000 | [diff] [blame] | 744 | @Test |
| 745 | public void searchJSONmultipleClassesBugTokenList () throws IOException { |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 746 | // Construct index |
| Nils Diewald | a14ecd6 | 2015-02-26 21:00:20 +0000 | [diff] [blame] | 747 | KrillIndex ki = new KrillIndex(); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 748 | // Indexing test files |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 749 | ki.addDoc(1, getClass().getResourceAsStream("/goe/AGA-03828.json.gz"), |
| 750 | true); |
| 751 | ki.addDoc(2, getClass().getResourceAsStream("/bzk/D59-00089.json.gz"), |
| 752 | true); |
| Nils Diewald | c7d08d9 | 2014-11-05 21:30:05 +0000 | [diff] [blame] | 753 | |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 754 | ki.commit(); |
| Nils Diewald | 277e9ce | 2014-11-06 03:42:11 +0000 | [diff] [blame] | 755 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 756 | String json = getString(getClass().getResource( |
| 757 | "/queries/bugs/multiple_classes.jsonld").getFile()); |
| 758 | |
| Nils Diewald | bbd39a5 | 2015-02-23 19:56:57 +0000 | [diff] [blame] | 759 | Krill ks = new Krill(json); |
| Nils Diewald | 884dbcf | 2015-02-27 17:02:28 +0000 | [diff] [blame] | 760 | Result kr = ks.apply(ki); |
| Nils Diewald | 277e9ce | 2014-11-06 03:42:11 +0000 | [diff] [blame] | 761 | |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 762 | ObjectMapper mapper = new ObjectMapper(); |
| 763 | JsonNode res = mapper.readTree(kr.toTokenListJsonString()); |
| Nils Diewald | 277e9ce | 2014-11-06 03:42:11 +0000 | [diff] [blame] | 764 | |
| Akron | d504f21 | 2015-06-20 00:27:54 +0200 | [diff] [blame] | 765 | assertEquals(1, res.at("/meta/totalResults").asInt()); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 766 | assertEquals("{4: spanNext({1: spanNext({2: tokens:s:ins}, " |
| 767 | + "{3: tokens:s:Leben})}, tokens:s:gerufen)}", |
| Akron | d504f21 | 2015-06-20 00:27:54 +0200 | [diff] [blame] | 768 | res.at("/meta/serialQuery").asText()); |
| 769 | assertEquals(0, res.at("/meta/startIndex").asInt()); |
| 770 | assertEquals(25, res.at("/meta/itemsPerPage").asInt()); |
| Nils Diewald | 277e9ce | 2014-11-06 03:42:11 +0000 | [diff] [blame] | 771 | |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 772 | assertEquals("BZK_D59.00089", res.at("/matches/0/textSigle").asText()); |
| 773 | assertEquals(328, res.at("/matches/0/tokens/0/0").asInt()); |
| 774 | assertEquals(331, res.at("/matches/0/tokens/0/1").asInt()); |
| 775 | assertEquals(332, res.at("/matches/0/tokens/1/0").asInt()); |
| 776 | assertEquals(337, res.at("/matches/0/tokens/1/1").asInt()); |
| 777 | assertEquals(338, res.at("/matches/0/tokens/2/0").asInt()); |
| 778 | assertEquals(345, res.at("/matches/0/tokens/2/1").asInt()); |
| Nils Diewald | 277e9ce | 2014-11-06 03:42:11 +0000 | [diff] [blame] | 779 | }; |
| Nils Diewald | c7d08d9 | 2014-11-05 21:30:05 +0000 | [diff] [blame] | 780 | |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 781 | |
| Nils Diewald | b84e727 | 2014-11-07 01:27:38 +0000 | [diff] [blame] | 782 | @Test |
| 783 | public void searchJSONmultitermRewriteBug () throws IOException { |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 784 | // Construct index |
| Nils Diewald | a14ecd6 | 2015-02-26 21:00:20 +0000 | [diff] [blame] | 785 | KrillIndex ki = new KrillIndex(); |
| Nils Diewald | b84e727 | 2014-11-07 01:27:38 +0000 | [diff] [blame] | 786 | |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 787 | assertEquals(ki.numberOf("documents"), 0); |
| 788 | |
| 789 | // Indexing test files |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 790 | FieldDocument fd = ki.addDoc(1, |
| 791 | getClass().getResourceAsStream("/bzk/D59-00089.json.gz"), true); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 792 | ki.commit(); |
| 793 | |
| 794 | assertEquals(ki.numberOf("documents"), 1); |
| 795 | assertEquals("BZK", fd.getCorpusSigle()); |
| 796 | |
| 797 | // [tt/p="A.*"]{0,3}[tt/p="N.*"] |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 798 | String json = getString(getClass().getResource( |
| 799 | "/queries/bugs/multiterm_rewrite.jsonld").getFile()); |
| 800 | |
| Nils Diewald | bbd39a5 | 2015-02-23 19:56:57 +0000 | [diff] [blame] | 801 | Krill ks = new Krill(json); |
| Nils Diewald | 2d5f810 | 2015-02-26 21:07:54 +0000 | [diff] [blame] | 802 | KrillCollection kc = ks.getCollection(); |
| Nils Diewald | c471b18 | 2014-11-19 22:51:15 +0000 | [diff] [blame] | 803 | |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 804 | // No index was set |
| 805 | assertEquals(-1, kc.numberOf("documents")); |
| 806 | kc.setIndex(ki); |
| Nils Diewald | c471b18 | 2014-11-19 22:51:15 +0000 | [diff] [blame] | 807 | |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 808 | // Index was set but vc restricted to WPD |
| 809 | assertEquals(0, kc.numberOf("documents")); |
| Nils Diewald | c471b18 | 2014-11-19 22:51:15 +0000 | [diff] [blame] | 810 | |
| Akron | 176c9b1 | 2015-07-29 19:53:40 +0200 | [diff] [blame] | 811 | /* |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 812 | kc.extend(new CollectionBuilder().or("corpusSigle", "BZK")); |
| Akron | 176c9b1 | 2015-07-29 19:53:40 +0200 | [diff] [blame] | 813 | */ |
| 814 | CollectionBuilder cb = new CollectionBuilder(); |
| Akron | 4055017 | 2015-08-04 03:06:12 +0200 | [diff] [blame] | 815 | kc.fromBuilder(cb.orGroup().with(kc.getBuilder()) |
| 816 | .with(cb.term("corpusSigle", "BZK"))); |
| Akron | 176c9b1 | 2015-07-29 19:53:40 +0200 | [diff] [blame] | 817 | |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 818 | ks.setCollection(kc); |
| 819 | assertEquals(1, kc.numberOf("documents")); |
| Nils Diewald | 1220e3e | 2014-11-08 03:18:58 +0000 | [diff] [blame] | 820 | |
| Nils Diewald | 884dbcf | 2015-02-27 17:02:28 +0000 | [diff] [blame] | 821 | Result kr = ks.apply(ki); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 822 | |
| 823 | assertEquals(kr.getSerialQuery(), |
| 824 | "spanOr([SpanMultiTermQueryWrapper(tokens:/tt/p:N.*/), " |
| 825 | + "spanNext(spanRepetition(SpanMultiTermQueryWrapper" |
| 826 | + "(tokens:/tt/p:A.*/){1,3}), " |
| 827 | + "SpanMultiTermQueryWrapper(tokens:/tt/p:N.*/))])"); |
| Nils Diewald | b84e727 | 2014-11-07 01:27:38 +0000 | [diff] [blame] | 828 | |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 829 | assertEquals(kr.getTotalResults(), 58); |
| 830 | assertEquals(0, kr.getStartIndex()); |
| Nils Diewald | 5871e4d | 2014-11-07 03:48:25 +0000 | [diff] [blame] | 831 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 832 | assertEquals(kr.getMatch(0).getSnippetBrackets(), |
| 833 | "[Saragat-Partei] zerfällt Rom (ADN) die von dem"); |
| 834 | assertEquals(kr.getMatch(1).getSnippetBrackets(), |
| 835 | "[Saragat-Partei] zerfällt Rom (ADN) die von dem"); |
| 836 | assertEquals(kr.getMatch(2).getSnippetBrackets(), |
| 837 | "Saragat-Partei zerfällt [Rom] (ADN) " |
| 838 | + "die von dem Rechtssozialisten Saragat"); |
| 839 | assertEquals(kr.getMatch(3).getSnippetBrackets(), |
| 840 | "Saragat-Partei zerfällt Rom ([ADN]) " |
| 841 | + "die von dem Rechtssozialisten Saragat geführte"); |
| Nils Diewald | 5871e4d | 2014-11-07 03:48:25 +0000 | [diff] [blame] | 842 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 843 | assertEquals(kr.getMatch(23).getSnippetBrackets(), |
| 844 | "dem Namen \"Einheitsbewegung der sozialistischen " |
| 845 | + "Initiative\" [eine neue politische Gruppierung] " |
| 846 | + "ins Leben gerufen hatten. Pressemeldungen zufolge"); |
| Nils Diewald | b84e727 | 2014-11-07 01:27:38 +0000 | [diff] [blame] | 847 | }; |
| 848 | |
| 849 | |
| Nils Diewald | 56dc258 | 2014-11-04 21:33:46 +0000 | [diff] [blame] | 850 | @Test |
| Akron | e4fdce4 | 2015-11-13 16:06:10 +0100 | [diff] [blame] | 851 | public void searchJSONtokenDistanceSpanBug () throws IOException { |
| 852 | // Construct index |
| 853 | KrillIndex ki = new KrillIndex(); |
| 854 | ki.addDoc(1, getClass().getResourceAsStream("/goe/AGX-00002.json"), |
| 855 | false); |
| 856 | ki.addDoc(2, getClass().getResourceAsStream("/bzk/D59-00089.json.gz"), |
| 857 | true); |
| 858 | ki.commit(); |
| 859 | |
| 860 | // ({1:Sonne []* Erde} | {2: Erde []* Sonne}) |
| 861 | String json = getString(getClass().getResource( |
| 862 | "/queries/bugs/tokendistancespan_bug.jsonld").getFile() |
| 863 | ); |
| 864 | |
| 865 | Krill ks = new Krill(json); |
| 866 | Result kr = ks.apply(ki); |
| 867 | ObjectMapper mapper = new ObjectMapper(); |
| 868 | JsonNode res = mapper.readTree(kr.toJsonString()); |
| 869 | assertTrue(res.at("/errors").isMissingNode()); |
| 870 | }; |
| 871 | |
| 872 | |
| 873 | @Test |
| Nils Diewald | fb4d7b0 | 2014-04-09 17:56:17 +0000 | [diff] [blame] | 874 | public void searchJSONCollection () throws IOException { |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 875 | // Construct index |
| Nils Diewald | a14ecd6 | 2015-02-26 21:00:20 +0000 | [diff] [blame] | 876 | KrillIndex ki = new KrillIndex(); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 877 | // Indexing test files |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 878 | for (String i : new String[] { "00001", "00002", "00003", "00004", |
| 879 | "00005", "00006", "02439" }) { |
| Nils Diewald | 5033355 | 2015-03-02 15:54:46 +0000 | [diff] [blame] | 880 | ki.addDoc( |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 881 | getClass().getResourceAsStream("/wiki/" + i + ".json.gz"), |
| 882 | true); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 883 | }; |
| 884 | ki.commit(); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 885 | String json = getString(getClass().getResource( |
| 886 | "/queries/metaquery8-nocollection.jsonld").getFile()); |
| 887 | |
| Nils Diewald | bbd39a5 | 2015-02-23 19:56:57 +0000 | [diff] [blame] | 888 | Krill ks = new Krill(json); |
| Nils Diewald | 884dbcf | 2015-02-27 17:02:28 +0000 | [diff] [blame] | 889 | Result kr = ks.apply(ki); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 890 | assertEquals(kr.getTotalResults(), 276); |
| 891 | assertEquals(0, kr.getStartIndex()); |
| 892 | assertEquals(10, kr.getItemsPerPage()); |
| Nils Diewald | fb4d7b0 | 2014-04-09 17:56:17 +0000 | [diff] [blame] | 893 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 894 | json = getString(getClass().getResource("/queries/metaquery8.jsonld") |
| 895 | .getFile()); |
| 896 | |
| Nils Diewald | bbd39a5 | 2015-02-23 19:56:57 +0000 | [diff] [blame] | 897 | ks = new Krill(json); |
| Nils Diewald | 3aa9e69 | 2015-02-20 22:20:11 +0000 | [diff] [blame] | 898 | kr = ks.apply(ki); |
| Nils Diewald | fb4d7b0 | 2014-04-09 17:56:17 +0000 | [diff] [blame] | 899 | |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 900 | assertEquals(kr.getTotalResults(), 147); |
| 901 | assertEquals("WPD_AAA.00001", kr.getMatch(0).getDocID()); |
| 902 | assertEquals(0, kr.getStartIndex()); |
| 903 | assertEquals(10, kr.getItemsPerPage()); |
| Nils Diewald | fb4d7b0 | 2014-04-09 17:56:17 +0000 | [diff] [blame] | 904 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 905 | json = getString(getClass().getResource( |
| 906 | "/queries/metaquery8-filtered.jsonld").getFile()); |
| 907 | |
| Nils Diewald | bbd39a5 | 2015-02-23 19:56:57 +0000 | [diff] [blame] | 908 | ks = new Krill(json); |
| Nils Diewald | 3aa9e69 | 2015-02-20 22:20:11 +0000 | [diff] [blame] | 909 | kr = ks.apply(ki); |
| Nils Diewald | fb4d7b0 | 2014-04-09 17:56:17 +0000 | [diff] [blame] | 910 | |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 911 | assertEquals(kr.getTotalResults(), 28); |
| 912 | assertEquals("WPD_AAA.00002", kr.getMatch(0).getDocID()); |
| 913 | assertEquals(0, kr.getStartIndex()); |
| 914 | assertEquals(10, kr.getItemsPerPage()); |
| Nils Diewald | fb4d7b0 | 2014-04-09 17:56:17 +0000 | [diff] [blame] | 915 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 916 | json = getString(getClass().getResource( |
| 917 | "/queries/metaquery8-filtered-further.jsonld").getFile()); |
| 918 | |
| Nils Diewald | bbd39a5 | 2015-02-23 19:56:57 +0000 | [diff] [blame] | 919 | ks = new Krill(json); |
| Nils Diewald | 3aa9e69 | 2015-02-20 22:20:11 +0000 | [diff] [blame] | 920 | kr = ks.apply(ki); |
| Nils Diewald | fb4d7b0 | 2014-04-09 17:56:17 +0000 | [diff] [blame] | 921 | |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 922 | assertEquals(kr.getTotalResults(), 0); |
| 923 | assertEquals(0, kr.getStartIndex()); |
| 924 | assertEquals(10, kr.getItemsPerPage()); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 925 | |
| Akron | 176c9b1 | 2015-07-29 19:53:40 +0200 | [diff] [blame] | 926 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 927 | json = getString(getClass().getResource( |
| 928 | "/queries/metaquery8-filtered-nested.jsonld").getFile()); |
| 929 | |
| Nils Diewald | bbd39a5 | 2015-02-23 19:56:57 +0000 | [diff] [blame] | 930 | ks = new Krill(json); |
| Nils Diewald | 3aa9e69 | 2015-02-20 22:20:11 +0000 | [diff] [blame] | 931 | kr = ks.apply(ki); |
| Nils Diewald | fb4d7b0 | 2014-04-09 17:56:17 +0000 | [diff] [blame] | 932 | |
| Akron | 176c9b1 | 2015-07-29 19:53:40 +0200 | [diff] [blame] | 933 | /* |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 934 | assertEquals("filter with QueryWrapperFilter(" |
| 935 | + "+(ID:WPD_AAA.00003 (+tokens:s:die" |
| 936 | + " +tokens:s:Schriftzeichen)))", |
| 937 | ks.getCollection().getFilter(1).toString()); |
| Akron | 176c9b1 | 2015-07-29 19:53:40 +0200 | [diff] [blame] | 938 | */ |
| Akron | 4055017 | 2015-08-04 03:06:12 +0200 | [diff] [blame] | 939 | assertEquals( |
| 940 | "AndGroup(OrGroup(ID:WPD_AAA.00001 ID:WPD_AAA.00002) OrGroup(ID:WPD_AAA.00003 AndGroup(tokens:s:die tokens:s:Schriftzeichen)))", |
| 941 | ks.getCollection().toString()); |
| Nils Diewald | fb4d7b0 | 2014-04-09 17:56:17 +0000 | [diff] [blame] | 942 | |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 943 | assertEquals(kr.getTotalResults(), 119); |
| 944 | assertEquals(0, kr.getStartIndex()); |
| 945 | assertEquals(10, kr.getItemsPerPage()); |
| Nils Diewald | fb4d7b0 | 2014-04-09 17:56:17 +0000 | [diff] [blame] | 946 | }; |
| 947 | |
| Nils Diewald | 1e5d594 | 2014-05-20 13:29:53 +0000 | [diff] [blame] | 948 | |
| 949 | @Test |
| 950 | public void searchJSONSentenceContext () throws IOException { |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 951 | // Construct index |
| Nils Diewald | a14ecd6 | 2015-02-26 21:00:20 +0000 | [diff] [blame] | 952 | KrillIndex ki = new KrillIndex(); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 953 | // Indexing test files |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 954 | for (String i : new String[] { "00001", "00002", "00003", "00004", |
| 955 | "00005", "00006", "02439" }) { |
| Nils Diewald | 5033355 | 2015-03-02 15:54:46 +0000 | [diff] [blame] | 956 | ki.addDoc( |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 957 | getClass().getResourceAsStream("/wiki/" + i + ".json.gz"), |
| 958 | true); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 959 | }; |
| 960 | ki.commit(); |
| Nils Diewald | 1e5d594 | 2014-05-20 13:29:53 +0000 | [diff] [blame] | 961 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 962 | String json = getString(getClass().getResource( |
| 963 | "/queries/bsp-context-2.jsonld").getFile()); |
| 964 | |
| Nils Diewald | bbd39a5 | 2015-02-23 19:56:57 +0000 | [diff] [blame] | 965 | Krill ks = new Krill(json); |
| Nils Diewald | f5ab4b2 | 2015-02-25 20:55:16 +0000 | [diff] [blame] | 966 | ks.getMeta().setCutOff(false); |
| 967 | SearchContext sc = ks.getMeta().getContext(); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 968 | sc.left.setLength((short) 10); |
| 969 | sc.right.setLength((short) 10); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 970 | |
| Nils Diewald | 884dbcf | 2015-02-27 17:02:28 +0000 | [diff] [blame] | 971 | Result kr = ks.apply(ki); |
| Akron | fd05f50 | 2015-07-30 18:34:26 +0200 | [diff] [blame] | 972 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 973 | assertEquals(kr.getMatch(1).getSnippetBrackets(), |
| 974 | "... dezimalen [Wert] 65 sowohl ..."); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 975 | assertEquals(kr.getTotalResults(), 3); |
| 976 | assertEquals(0, kr.getStartIndex()); |
| 977 | assertEquals(25, kr.getItemsPerPage()); |
| 978 | assertFalse(kr.getContext().toJsonNode().toString().equals("\"s\"")); |
| Nils Diewald | 1e5d594 | 2014-05-20 13:29:53 +0000 | [diff] [blame] | 979 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 980 | json = getString(getClass().getResource( |
| 981 | "/queries/bsp-context-sentence.jsonld").getFile()); |
| Nils Diewald | 1e5d594 | 2014-05-20 13:29:53 +0000 | [diff] [blame] | 982 | |
| Nils Diewald | bbd39a5 | 2015-02-23 19:56:57 +0000 | [diff] [blame] | 983 | kr = new Krill(json).apply(ki); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 984 | assertEquals(kr.getMatch(0).getSnippetBrackets(), |
| 985 | "steht a für den dezimalen [Wert] 97 sowohl im ASCII-" |
| 986 | + " als auch im Unicode-Zeichensatz"); |
| 987 | assertEquals(kr.getMatch(1).getSnippetBrackets(), |
| 988 | "steht A für den dezimalen [Wert] 65 sowohl im ASCII-" |
| 989 | + " als auch im Unicode-Zeichensatz"); |
| 990 | assertEquals(kr.getMatch(2).getSnippetBrackets(), |
| 991 | "In einem Zahlensystem mit einer Basis größer " |
| 992 | + "als 10 steht A oder a häufig für den dezimalen" |
| 993 | + " [Wert] 10, siehe auch Hexadezimalsystem."); |
| Nils Diewald | 1e5d594 | 2014-05-20 13:29:53 +0000 | [diff] [blame] | 994 | |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 995 | assertEquals(kr.getContext().toJsonNode().toString(), "\"s\""); |
| Nils Diewald | 1e5d594 | 2014-05-20 13:29:53 +0000 | [diff] [blame] | 996 | }; |
| 997 | |
| 998 | |
| Nils Diewald | 2276e1c | 2014-04-10 15:01:59 +0000 | [diff] [blame] | 999 | @Test |
| Nils Diewald | 5418763 | 2014-06-11 14:39:29 +0000 | [diff] [blame] | 1000 | public void searchJSONbug () throws IOException { |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 1001 | // Construct index |
| Nils Diewald | a14ecd6 | 2015-02-26 21:00:20 +0000 | [diff] [blame] | 1002 | KrillIndex ki = new KrillIndex(); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 1003 | // Indexing test files |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 1004 | for (String i : new String[] { "00001", "00002", "00003", "00004", |
| 1005 | "00005", "00006", "02439" }) { |
| Nils Diewald | 5033355 | 2015-03-02 15:54:46 +0000 | [diff] [blame] | 1006 | ki.addDoc( |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 1007 | getClass().getResourceAsStream("/wiki/" + i + ".json.gz"), |
| 1008 | true); |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 1009 | }; |
| 1010 | ki.commit(); |
| Nils Diewald | 5418763 | 2014-06-11 14:39:29 +0000 | [diff] [blame] | 1011 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 1012 | String json = getString(getClass().getResource( |
| 1013 | "/queries/bsp-bug.jsonld").getFile()); |
| Nils Diewald | 5418763 | 2014-06-11 14:39:29 +0000 | [diff] [blame] | 1014 | |
| Nils Diewald | 884dbcf | 2015-02-27 17:02:28 +0000 | [diff] [blame] | 1015 | Result kr = new Krill(json).apply(ki); |
| Nils Diewald | c471b18 | 2014-11-19 22:51:15 +0000 | [diff] [blame] | 1016 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 1017 | assertEquals(kr.getError(0).getMessage(), |
| 1018 | "Operation needs operand list"); |
| Nils Diewald | 5418763 | 2014-06-11 14:39:29 +0000 | [diff] [blame] | 1019 | }; |
| 1020 | |
| Nils Diewald | afab8f3 | 2015-01-26 19:11:32 +0000 | [diff] [blame] | 1021 | |
| Nils Diewald | ef7124e | 2014-11-12 20:08:13 +0000 | [diff] [blame] | 1022 | /** |
| 1023 | * This is a breaking test for #179 |
| 1024 | */ |
| 1025 | @Test |
| 1026 | public void searchJSONexpansionBug () throws IOException { |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 1027 | // Construct index |
| 1028 | KrillIndex ki = new KrillIndex(); |
| 1029 | // Indexing test files |
| 1030 | ki.addDoc(getClass().getResourceAsStream("/wiki/00002.json.gz"), true); |
| 1031 | ki.commit(); |
| 1032 | |
| 1033 | // Expansion bug |
| 1034 | // der alte Digraph Aa durch Å |
| 1035 | String json = getString(getClass().getResource( |
| 1036 | "/queries/bugs/expansion_bug_2.jsonld").getFile()); |
| 1037 | |
| 1038 | Result kr = new Krill(json).apply(ki); |
| 1039 | assertEquals("... Buchstabe des Alphabetes. In Dänemark ist " |
| 1040 | + "[der alte Digraph Aa durch Å] ersetzt worden, " |
| 1041 | + "in Eigennamen und Ortsnamen ...", kr.getMatch(0) |
| 1042 | .getSnippetBrackets()); |
| 1043 | assertEquals("WPD_AAA.00002", kr.getMatch(0).getDocID()); |
| 1044 | assertEquals(kr.getTotalResults(), 1); |
| 1045 | |
| 1046 | // der alte Digraph Aa durch [] |
| 1047 | // Works with one document |
| 1048 | json = getString(getClass().getResource( |
| 1049 | "/queries/bugs/expansion_bug.jsonld").getFile()); |
| 1050 | |
| 1051 | kr = new Krill(json).apply(ki); |
| 1052 | |
| 1053 | assertEquals("... Buchstabe des Alphabetes. In Dänemark ist " |
| 1054 | + "[der alte Digraph Aa durch Å] ersetzt worden, " |
| 1055 | + "in Eigennamen und Ortsnamen ...", kr.getMatch(0) |
| 1056 | .getSnippetBrackets()); |
| 1057 | assertEquals("WPD_AAA.00002", kr.getMatch(0).getDocID()); |
| 1058 | assertEquals(kr.getTotalResults(), 1); |
| 1059 | |
| 1060 | // Now try with one file ahead |
| 1061 | ki = new KrillIndex(); |
| 1062 | for (String i : new String[] { "00001", "00002" }) { |
| 1063 | ki.addDoc( |
| 1064 | getClass().getResourceAsStream("/wiki/" + i + ".json.gz"), |
| 1065 | true); |
| 1066 | }; |
| 1067 | ki.commit(); |
| 1068 | |
| 1069 | // Expansion bug |
| 1070 | // der alte Digraph Aa durch Å |
| 1071 | json = getString(getClass().getResource( |
| 1072 | "/queries/bugs/expansion_bug_2.jsonld").getFile()); |
| 1073 | |
| 1074 | kr = new Krill(json).apply(ki); |
| 1075 | |
| 1076 | assertEquals("... Buchstabe des Alphabetes. In Dänemark ist " |
| 1077 | + "[der alte Digraph Aa durch Å] ersetzt worden, " |
| 1078 | + "in Eigennamen und Ortsnamen ...", kr.getMatch(0) |
| 1079 | .getSnippetBrackets()); |
| 1080 | assertEquals("WPD_AAA.00002", kr.getMatch(0).getDocID()); |
| 1081 | assertEquals(kr.getTotalResults(), 1); |
| 1082 | |
| 1083 | // der alte Digraph Aa durch [] |
| 1084 | json = getString(getClass().getResource( |
| 1085 | "/queries/bugs/expansion_bug.jsonld").getFile()); |
| 1086 | |
| 1087 | kr = new Krill(json).apply(ki); |
| 1088 | assertEquals("... Buchstabe des Alphabetes. In Dänemark ist " |
| 1089 | + "[der alte Digraph Aa durch Å] ersetzt worden, " |
| 1090 | + "in Eigennamen und Ortsnamen ...", kr.getMatch(0) |
| 1091 | .getSnippetBrackets()); |
| 1092 | assertEquals("WPD_AAA.00002", kr.getMatch(0).getDocID()); |
| 1093 | assertEquals(kr.getTotalResults(), 1); |
| Nils Diewald | ef7124e | 2014-11-12 20:08:13 +0000 | [diff] [blame] | 1094 | }; |
| Nils Diewald | c925b49 | 2013-12-03 23:56:10 +0000 | [diff] [blame] | 1095 | }; |