| Akron | 72245b6 | 2018-07-23 10:59:08 +0200 | [diff] [blame] | 1 | /** |
| 2 | * Specification for the query creator. |
| 3 | */ |
| 4 | |
| Akron | 7dd3282 | 2018-10-01 19:38:31 +0200 | [diff] [blame] | 5 | |
| 6 | Element.prototype.innerString = function () { |
| 7 | return this.innerText.split("\n").join(""); |
| 8 | }; |
| 9 | |
| Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 10 | function matchTableFactory () { |
| 11 | var table = document.createElement('div'); |
| Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 12 | |
| Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 13 | table.className = 'matchtable'; |
| 14 | table.innerHTML = |
| Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 15 | " <table>" + |
| 16 | " <thead>" + |
| 17 | " <tr>" + |
| 18 | " <th>Foundry</th>" + |
| 19 | " <th>Layer</th>" + |
| 20 | " <th>Der</th>" + |
| 21 | " <th>älteste</th>" + |
| 22 | " <th>lebende</th>" + |
| 23 | " <th>Baum</th>" + |
| Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 24 | " <th>hier</th>" + |
| Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 25 | " </tr>" + |
| 26 | " </thead>" + |
| 27 | " <tbody>" + |
| 28 | " <tr tabindex=\"0\">" + |
| 29 | " <th>corenlp</th>" + |
| 30 | " <th>p</th>" + |
| 31 | " <td>ART</td>" + |
| 32 | " <td>ADJA</td>" + |
| 33 | " <td>ADJA<br>ADJD</td>" + |
| 34 | " <td>NN</td>" + |
| Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 35 | " <td>ADV</td>" + |
| Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 36 | " </tr>" + |
| 37 | " <tr tabindex=\"0\">" + |
| 38 | " <th>opennlp</th>" + |
| 39 | " <th>p</th>" + |
| 40 | " <td>ART</td>" + |
| 41 | " <td>ADJA</td>" + |
| 42 | " <td></td>" + |
| 43 | " <td>NN</td>" + |
| Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 44 | " <td>ADV</td>" + |
| Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 45 | " </tr>" + |
| 46 | " </tbody>" + |
| 47 | " </table>" + |
| Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 48 | " </div>"; |
| Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 49 | |
| Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 50 | var info = document.createElement('div'); |
| 51 | info.appendChild(table); |
| 52 | return table; |
| Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 53 | }; |
| 54 | |
| Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 55 | function matchTableComplexFactory () { |
| 56 | var table = document.createElement('div'); |
| 57 | table.className = 'matchtable'; |
| 58 | table.innerHTML = |
| Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 59 | " <table>" + |
| 60 | " <thead>" + |
| 61 | " <tr>" + |
| 62 | " <th>Foundry</th>" + |
| 63 | " <th>Layer</th>" + |
| 64 | " <th>Der</th>" + |
| 65 | " <th>älteste</th>" + |
| Akron | 0d612d1 | 2019-05-21 16:45:49 +0200 | [diff] [blame] | 66 | " <th>lebende und sterbende</th>" + |
| Akron | aeeb825 | 2018-09-19 18:51:00 +0200 | [diff] [blame] | 67 | " <th class=\"mark\">Baum</th>" + |
| Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 68 | " </tr>" + |
| 69 | " </thead>" + |
| 70 | " <tbody>" + |
| 71 | " <tr tabindex=\"0\">" + |
| 72 | " <th>corenlp</th>" + |
| 73 | " <th>p</th>" + |
| 74 | " <td>ART</td>" + |
| Akron | 9fe23dc | 2025-06-11 11:43:50 +0200 | [diff] [blame] | 75 | " <td class=\"notinindex\">ADJA</td>" + |
| Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 76 | " <td>ADJA<br>ADJD</td>" + |
| Akron | aeeb825 | 2018-09-19 18:51:00 +0200 | [diff] [blame] | 77 | " <td class=\"matchkeyvalues mark\">" + |
| Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 78 | " <div>case:nom</div>" + |
| 79 | " <div>gender:masc<br/>gender:fem</div>" + |
| 80 | " <div>number:sg</div>" + |
| 81 | " </td>" + |
| 82 | " </tr>" + |
| 83 | " <tr tabindex=\"0\">" + |
| 84 | " <th>opennlp</th>" + |
| 85 | " <th>p</th>" + |
| 86 | " <td class=\"matchkeyvalues\">" + |
| 87 | " <div>case:nom</div>" + |
| 88 | " <div>gender:masc</div>" + |
| Akron | 9fe23dc | 2025-06-11 11:43:50 +0200 | [diff] [blame] | 89 | " <div class=\"notinindex\">number:sg</div>" + |
| Akron | 72245b6 | 2018-07-23 10:59:08 +0200 | [diff] [blame] | 90 | " <div>morphemes:.::_SORSZ \\ZERO::NOM 'period::PUNCT'</div>" + |
| Akron | efed2e2 | 2021-11-16 23:16:54 +0100 | [diff] [blame] | 91 | " <div>morphemes:ZERO::NOM</div>" + |
| Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 92 | " </td>" + |
| 93 | " <td>ADJA</td>" + |
| 94 | " <td></td>" + |
| Akron | aeeb825 | 2018-09-19 18:51:00 +0200 | [diff] [blame] | 95 | " <td class=\"mark\">NN</td>" + |
| Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 96 | " </tr>" + |
| Akron | 0d612d1 | 2019-05-21 16:45:49 +0200 | [diff] [blame] | 97 | " <tr tabindex=\"0\">" + |
| Helge | 7e05fb0 | 2026-03-24 12:01:37 +0100 | [diff] [blame^] | 98 | " <th>gender</th>" + |
| Akron | 0d612d1 | 2019-05-21 16:45:49 +0200 | [diff] [blame] | 99 | " <th>l</th>" + |
| 100 | " <td>Lese|Lesen</td>" + |
| 101 | " <td>a b</td>" + |
| 102 | " <td></td>" + |
| 103 | " <td class=\"mark\">NN</td>" + |
| 104 | " </tr>" + |
| Helge | 7e05fb0 | 2026-03-24 12:01:37 +0100 | [diff] [blame^] | 105 | " <tr tabindex=\"0\">" + |
| 106 | " <th>tt</th>" + |
| 107 | " <th>l</th>" + |
| 108 | " <td>Lehrer*in</td>" + |
| 109 | " <td>gender:fem,masc,nonbin</td>" + |
| 110 | " <td></td>" + |
| 111 | " <td class=\"mark\">NN</td>" + |
| 112 | " </tr>" + |
| Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 113 | " </tbody>" + |
| Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 114 | " </table>"; |
| 115 | var info = document.createElement('div'); |
| 116 | info.appendChild(table); |
| 117 | return table; |
| Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 118 | }; |
| 119 | |
| Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 120 | |
| Akron | 083ec57 | 2019-05-16 18:30:40 +0200 | [diff] [blame] | 121 | function matchTableCuttedFactory () { |
| 122 | var table = document.createElement('div'); |
| 123 | table.className = 'matchtable'; |
| 124 | table.innerHTML = |
| 125 | " <table>" + |
| 126 | " <thead>" + |
| 127 | " <tr>" + |
| 128 | " <th>Foundry</th>" + |
| 129 | " <th>Layer</th>" + |
| 130 | " <th>Baum</th>" + |
| 131 | " <th class=\"cutted\"></th>" + |
| 132 | " </tr>" + |
| 133 | " </thead>" + |
| 134 | " <tbody>" + |
| 135 | " <tr tabindex=\"0\">" + |
| 136 | " <th>corenlp</th>" + |
| 137 | " <th>p</th>" + |
| 138 | " <td>NN</td>" + |
| 139 | " <td></td>" + |
| 140 | " </tr>" + |
| 141 | " <tr tabindex=\"0\">" + |
| 142 | " <th>opennlp</th>" + |
| 143 | " <th>p</th>" + |
| 144 | " <td>NN</td>" + |
| 145 | " <td></td>" + |
| 146 | " </tr>" + |
| 147 | " </tbody>" + |
| 148 | " </table>"; |
| 149 | var info = document.createElement('div'); |
| 150 | info.appendChild(table); |
| 151 | return table; |
| 152 | }; |
| 153 | |
| 154 | |
| Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 155 | define(['match/querycreator'], function (qcClass) { |
| 156 | |
| 157 | describe('KorAP.QueryCreator', function () { |
| 158 | |
| 159 | it('should be initializable', function () { |
| 160 | expect( |
| 161 | function() { |
| 162 | qcClass.create() |
| 163 | } |
| 164 | ).toThrow(new Error("Missing parameters")); |
| 165 | |
| 166 | expect( |
| 167 | function() { |
| 168 | qcClass.create("Test") |
| 169 | } |
| 170 | ).toThrow(new Error("Requires element")); |
| 171 | |
| Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 172 | expect(qcClass.create(matchTableFactory()).toString()).toEqual(""); |
| Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 173 | }); |
| 174 | |
| 175 | it('should listen to click events', function () { |
| 176 | |
| Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 177 | var matchTable = matchTableFactory(); |
| 178 | var qc = qcClass.create(matchTable); |
| Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 179 | |
| 180 | // Nothing to show |
| 181 | expect(qc.toString()).toEqual(""); |
| 182 | expect(qc.shown()).toBe(false); |
| 183 | qc.show(); |
| 184 | expect(qc.shown()).toBe(false); |
| Akron | 7dd3282 | 2018-10-01 19:38:31 +0200 | [diff] [blame] | 185 | expect(qc.element().className).toEqual("query fragment"); |
| Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 186 | |
| 187 | // Click on cell 0:0 "Foundry" |
| Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 188 | var cell = matchTable.querySelector("thead > tr > th:first-child"); |
| Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 189 | expect(cell.innerString()).toEqual("Foundry"); |
| Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 190 | cell.click(); |
| 191 | expect(cell.classList.contains("chosen")).toBe(false); |
| 192 | expect(qc.toString()).toEqual(""); |
| 193 | expect(qc.shown()).toBe(false); |
| 194 | |
| 195 | // Click on cell 0:2 "Der" |
| Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 196 | cell = matchTable.querySelector("thead > tr > th:nth-child(3)") |
| Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 197 | expect(cell.innerString()).toEqual("Der"); |
| Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 198 | cell.click(); |
| 199 | expect(cell.classList.contains("chosen")).toBeTruthy(); |
| 200 | expect(qc.toString()).toEqual("[orth=Der]"); |
| 201 | expect(qc.shown()).toBeTruthy(); |
| 202 | |
| 203 | // Click on cell 0:2 "Der" again - to hide |
| Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 204 | cell = matchTable.querySelector("thead > tr > th:nth-child(3)") |
| Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 205 | expect(cell.innerString()).toEqual("Der"); |
| Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 206 | cell.click(); |
| 207 | expect(cell.classList.contains("chosen")).toBe(false); |
| 208 | expect(qc.toString()).toEqual(""); |
| 209 | expect(qc.shown()).toBe(false); |
| 210 | }); |
| 211 | |
| 212 | it('should create tokens in arbitrary order', function () { |
| Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 213 | var matchTable = matchTableFactory(); |
| 214 | var qc = qcClass.create(matchTable); |
| Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 215 | |
| Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 216 | var cell = matchTable.querySelector("tbody > tr:nth-child(2) > td:nth-child(4)"); |
| Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 217 | expect(cell.innerString()).toEqual("ADJA"); |
| Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 218 | cell.click(); |
| 219 | expect(qc.toString()).toEqual("[opennlp/p=ADJA]"); |
| 220 | |
| Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 221 | cell = matchTable.querySelector("thead > tr > th:nth-child(4)"); |
| Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 222 | expect(cell.innerString()).toEqual("älteste"); |
| Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 223 | cell.click(); |
| 224 | expect(qc.toString()).toEqual("[opennlp/p=ADJA & orth=älteste]"); |
| 225 | |
| Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 226 | cell = matchTable.querySelector("tbody > tr > td:nth-child(4)"); |
| Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 227 | expect(cell.innerString()).toEqual("ADJA"); |
| Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 228 | cell.click(); |
| 229 | expect(qc.toString()).toEqual("[corenlp/p=ADJA & opennlp/p=ADJA & orth=älteste]"); |
| 230 | }); |
| 231 | |
| 232 | it('should create token sequences in arbitrary order', function () { |
| Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 233 | var matchTable = matchTableFactory(); |
| 234 | var qc = qcClass.create(matchTable); |
| Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 235 | |
| Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 236 | var cell = matchTable.querySelector("thead > tr > th:nth-child(5)"); |
| Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 237 | expect(cell.innerString()).toEqual("lebende"); |
| Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 238 | cell.click(); |
| 239 | expect(qc.toString()).toEqual("[orth=lebende]"); |
| 240 | |
| Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 241 | cell = matchTable.querySelector("tbody > tr:nth-child(2) > td:nth-child(3)"); |
| Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 242 | expect(cell.innerString()).toEqual("ART"); |
| Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 243 | cell.click(); |
| Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 244 | expect(qc.toString()).toEqual("[opennlp/p=ART][][orth=lebende]"); |
| Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 245 | |
| Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 246 | cell = matchTable.querySelector("tbody > tr > td:nth-child(4)"); |
| Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 247 | expect(cell.innerString()).toEqual("ADJA"); |
| Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 248 | cell.click(); |
| 249 | expect(qc.toString()).toEqual("[opennlp/p=ART][corenlp/p=ADJA][orth=lebende]"); |
| 250 | }); |
| 251 | |
| 252 | it('should remove chosen elements again', function () { |
| Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 253 | var matchTable = matchTableFactory(); |
| 254 | var qc = qcClass.create(matchTable); |
| Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 255 | |
| Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 256 | var cell = matchTable.querySelector("tbody > tr:nth-child(2) > td:nth-child(4)"); |
| Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 257 | expect(cell.innerString()).toEqual("ADJA"); |
| Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 258 | cell.click(); |
| 259 | expect(qc.toString()).toEqual("[opennlp/p=ADJA]"); |
| 260 | var cell1 = cell; |
| 261 | |
| Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 262 | cell = matchTable.querySelector("thead > tr > th:nth-child(4)"); |
| Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 263 | expect(cell.innerString()).toEqual("älteste"); |
| Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 264 | cell.click(); |
| 265 | expect(qc.toString()).toEqual("[opennlp/p=ADJA & orth=älteste]"); |
| 266 | var cell2 = cell; |
| 267 | |
| Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 268 | cell = matchTable.querySelector("tbody > tr > td:nth-child(3)"); |
| Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 269 | expect(cell.innerString()).toEqual("ART"); |
| Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 270 | cell.click(); |
| 271 | expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA & orth=älteste]"); |
| 272 | var cell3 = cell; |
| 273 | |
| Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 274 | cell = matchTable.querySelector("thead > tr > th:nth-child(6)"); |
| Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 275 | expect(cell.innerString()).toEqual("Baum"); |
| Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 276 | cell.click(); |
| Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 277 | expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA & orth=älteste][][orth=Baum]"); |
| Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 278 | var cell4 = cell; |
| 279 | |
| Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 280 | cell = matchTable.querySelector("thead > tr > th:nth-child(5)"); |
| Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 281 | expect(cell.innerString()).toEqual("lebende"); |
| Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 282 | cell.click(); |
| 283 | expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA & orth=älteste][orth=lebende][orth=Baum]"); |
| 284 | var cell5 = cell; |
| 285 | |
| 286 | |
| 287 | // Remove annotations again |
| 288 | expect(cell5.classList.contains("chosen")).toBeTruthy(); |
| 289 | cell5.click() |
| 290 | expect(cell5.classList.contains("chosen")).toBe(false); |
| Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 291 | expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA & orth=älteste][][orth=Baum]"); |
| Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 292 | |
| 293 | expect(cell2.classList.contains("chosen")).toBeTruthy(); |
| 294 | cell2.click() |
| 295 | expect(cell2.classList.contains("chosen")).toBe(false); |
| Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 296 | expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA][][orth=Baum]"); |
| Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 297 | |
| 298 | expect(cell1.classList.contains("chosen")).toBeTruthy(); |
| 299 | cell1.click() |
| 300 | expect(cell1.classList.contains("chosen")).toBe(false); |
| Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 301 | expect(qc.toString()).toEqual("[corenlp/p=ART][]{2}[orth=Baum]"); |
| Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 302 | |
| 303 | // Re-add first cell at the same position |
| 304 | expect(cell1.classList.contains("chosen")).toBe(false); |
| 305 | cell1.click() |
| 306 | expect(cell1.classList.contains("chosen")).toBeTruthy(); |
| Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 307 | expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA][][orth=Baum]"); |
| Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 308 | |
| 309 | expect(cell3.classList.contains("chosen")).toBeTruthy(); |
| 310 | cell3.click() |
| 311 | expect(cell3.classList.contains("chosen")).toBe(false); |
| Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 312 | expect(qc.toString()).toEqual("[opennlp/p=ADJA][][orth=Baum]"); |
| Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 313 | |
| 314 | expect(cell4.classList.contains("chosen")).toBeTruthy(); |
| 315 | cell4.click() |
| 316 | expect(cell4.classList.contains("chosen")).toBe(false); |
| 317 | expect(qc.toString()).toEqual("[opennlp/p=ADJA]"); |
| 318 | |
| 319 | // Remove last token |
| 320 | expect(qc.shown()).toBeTruthy(); |
| 321 | expect(qc.element().innerHTML).toEqual("<span>New Query:</span><span>[opennlp/p=ADJA]</span>"); |
| 322 | expect(cell1.classList.contains("chosen")).toBeTruthy(); |
| 323 | cell1.click() |
| 324 | expect(cell1.classList.contains("chosen")).toBe(false); |
| 325 | expect(qc.toString()).toEqual(""); |
| 326 | expect(qc.shown()).toBe(false); |
| 327 | |
| 328 | // Re-add token |
| 329 | expect(cell4.classList.contains("chosen")).toBe(false); |
| 330 | cell4.click() |
| 331 | expect(cell4.classList.contains("chosen")).toBeTruthy(); |
| 332 | expect(qc.toString()).toEqual("[orth=Baum]"); |
| 333 | expect(qc.shown()).toBeTruthy(); |
| 334 | expect(qc.element().innerHTML).toEqual("<span>New Query:</span><span>[orth=Baum]</span>"); |
| 335 | }); |
| 336 | |
| Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 337 | it('should ignore empty terms', function () { |
| Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 338 | var matchTable = matchTableFactory(); |
| 339 | var qc = qcClass.create(matchTable); |
| Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 340 | |
| Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 341 | // Nothing to show |
| 342 | expect(qc.toString()).toEqual(""); |
| 343 | expect(qc.shown()).toBe(false); |
| 344 | qc.show(); |
| 345 | expect(qc.shown()).toBe(false); |
| Akron | 7dd3282 | 2018-10-01 19:38:31 +0200 | [diff] [blame] | 346 | expect(qc.element().className).toEqual("query fragment"); |
| Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 347 | |
| Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 348 | var cell = matchTable.querySelector("tbody > tr:nth-child(2) > td:nth-child(4)"); |
| Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 349 | expect(cell.innerString()).toEqual("ADJA"); |
| Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 350 | expect(cell.classList.contains("chosen")).toBe(false); |
| 351 | cell.click(); |
| 352 | expect(cell.classList.contains("chosen")).toBeTruthy(); |
| 353 | expect(qc.toString()).toEqual("[opennlp/p=ADJA]"); |
| 354 | |
| Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 355 | cell = matchTable.querySelector("tbody > tr:nth-child(2) > td:nth-child(5)"); |
| Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 356 | expect(cell.innerString()).toEqual(""); |
| Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 357 | expect(cell.classList.contains("chosen")).toBe(false); |
| 358 | cell.click(); |
| 359 | expect(cell.classList.contains("chosen")).toBe(false); |
| 360 | expect(qc.toString()).toEqual("[opennlp/p=ADJA]"); |
| 361 | |
| 362 | }); |
| 363 | |
| Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 364 | it('should create or-groups for alternative terms', function () { |
| Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 365 | var matchTable = matchTableFactory(); |
| 366 | var qc = qcClass.create(matchTable); |
| Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 367 | |
| 368 | // Nothing to show |
| 369 | expect(qc.toString()).toEqual(""); |
| 370 | expect(qc.shown()).toBe(false); |
| 371 | qc.show(); |
| 372 | expect(qc.shown()).toBe(false); |
| Akron | 7dd3282 | 2018-10-01 19:38:31 +0200 | [diff] [blame] | 373 | expect(qc.element().className).toEqual("query fragment"); |
| Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 374 | |
| Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 375 | var cell = matchTable.querySelector("thead > tr > th:nth-child(5)"); |
| Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 376 | expect(cell.innerString()).toEqual("lebende"); |
| Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 377 | expect(cell.classList.contains("chosen")).toBe(false); |
| 378 | cell.click(); |
| 379 | expect(cell.classList.contains("chosen")).toBeTruthy(); |
| 380 | expect(qc.toString()).toEqual("[orth=lebende]"); |
| 381 | |
| Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 382 | cell = matchTable.querySelector("tbody > tr:nth-child(1) > td:nth-child(5)"); |
| Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 383 | expect(cell.innerString()).toEqual("ADJAADJD"); |
| Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 384 | expect(cell.classList.contains("chosen")).toBe(false); |
| 385 | cell.click(); |
| 386 | expect(cell.classList.contains("chosen")).toBeTruthy(); |
| 387 | expect(qc.toString()).toEqual("[(corenlp/p=ADJA | corenlp/p=ADJD) & orth=lebende]"); |
| 388 | |
| 389 | // Remove or group again |
| 390 | expect(cell.classList.contains("chosen")).toBeTruthy(); |
| 391 | cell.click(); |
| 392 | expect(cell.classList.contains("chosen")).toBe(false); |
| 393 | expect(qc.toString()).toEqual("[orth=lebende]"); |
| 394 | }); |
| 395 | |
| 396 | |
| 397 | it('should add whole rows', function () { |
| Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 398 | var matchTable = matchTableFactory(); |
| 399 | var qc = qcClass.create(matchTable); |
| Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 400 | |
| 401 | // Nothing to show |
| 402 | expect(qc.toString()).toEqual(""); |
| 403 | expect(qc.shown()).toBe(false); |
| 404 | qc.show(); |
| 405 | expect(qc.shown()).toBe(false); |
| Akron | 7dd3282 | 2018-10-01 19:38:31 +0200 | [diff] [blame] | 406 | expect(qc.element().className).toEqual("query fragment"); |
| Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 407 | |
| Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 408 | var corenlpRow = matchTable.querySelector("tbody > tr:nth-child(1)"); |
| Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 409 | |
| 410 | var cell = corenlpRow.querySelector("td:nth-child(4)"); |
| Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 411 | expect(cell.innerString()).toEqual("ADJA"); |
| Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 412 | expect(cell.classList.contains("chosen")).toBe(false); |
| 413 | cell.click(); |
| 414 | expect(cell.classList.contains("chosen")).toBeTruthy(); |
| 415 | |
| 416 | // Activate another cell in another row |
| Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 417 | cell = matchTable.querySelector("tbody > tr:nth-child(2) td:nth-child(3)"); |
| Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 418 | expect(cell.innerString()).toEqual("ART"); |
| Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 419 | expect(cell.classList.contains("chosen")).toBe(false); |
| 420 | cell.click(); |
| 421 | expect(cell.classList.contains("chosen")).toBeTruthy(); |
| 422 | |
| 423 | expect(corenlpRow.querySelector("td:nth-child(3).chosen")).toBeNull(); |
| 424 | expect(corenlpRow.querySelector("td:nth-child(4).chosen")).toBeTruthy(); |
| 425 | expect(corenlpRow.querySelector("td:nth-child(5).chosen")).toBeNull(); |
| 426 | expect(corenlpRow.querySelector("td:nth-child(6).chosen")).toBeNull(); |
| 427 | |
| 428 | expect(qc.toString()).toEqual("[opennlp/p=ART][corenlp/p=ADJA]"); |
| 429 | |
| 430 | // Mark all corenlp lists |
| 431 | cell = corenlpRow.querySelector("th:nth-child(1)"); |
| Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 432 | expect(cell.innerString()).toEqual("corenlp"); |
| Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 433 | expect(cell.classList.contains("chosen")).toBe(false); |
| 434 | cell.click(); |
| 435 | expect(cell.classList.contains("chosen")).toBe(false); |
| 436 | |
| 437 | expect(corenlpRow.querySelector("td:nth-child(3).chosen")).toBeTruthy(); |
| 438 | expect(corenlpRow.querySelector("td:nth-child(4).chosen")).toBeTruthy(); |
| 439 | expect(corenlpRow.querySelector("td:nth-child(5).chosen")).toBeTruthy(); |
| 440 | expect(corenlpRow.querySelector("td:nth-child(6).chosen")).toBeTruthy(); |
| 441 | |
| 442 | // Replay the choice without any effect |
| 443 | cell = corenlpRow.querySelector("th:nth-child(1)"); |
| Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 444 | expect(cell.innerString()).toEqual("corenlp"); |
| Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 445 | expect(cell.classList.contains("chosen")).toBe(false); |
| 446 | cell.click(); |
| 447 | expect(cell.classList.contains("chosen")).toBe(false); |
| 448 | |
| 449 | expect(corenlpRow.querySelector("td:nth-child(3).chosen")).toBeTruthy(); |
| 450 | expect(corenlpRow.querySelector("td:nth-child(4).chosen")).toBeTruthy(); |
| 451 | expect(corenlpRow.querySelector("td:nth-child(5).chosen")).toBeTruthy(); |
| 452 | expect(corenlpRow.querySelector("td:nth-child(6).chosen")).toBeTruthy(); |
| Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 453 | expect(corenlpRow.querySelector("td:nth-child(7).chosen")).toBeTruthy(); |
| Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 454 | |
| Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 455 | expect(qc.toString()).toEqual("[corenlp/p=ART & opennlp/p=ART][corenlp/p=ADJA][(corenlp/p=ADJA | corenlp/p=ADJD)][corenlp/p=NN][corenlp/p=ADV]"); |
| Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 456 | |
| 457 | // Remove one of the cells again |
| 458 | cell = corenlpRow.querySelector("td:nth-child(5).chosen"); |
| Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 459 | expect(cell.innerString()).toEqual("ADJAADJD"); |
| Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 460 | expect(cell.classList.contains("chosen")).toBeTruthy(); |
| 461 | cell.click(); |
| 462 | expect(cell.classList.contains("chosen")).toBe(false); |
| Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 463 | expect(qc.toString()).toEqual("[corenlp/p=ART & opennlp/p=ART][corenlp/p=ADJA][][corenlp/p=NN][corenlp/p=ADV]"); |
| Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 464 | |
| 465 | }); |
| Akron | 8084cb5 | 2017-06-29 17:11:14 +0200 | [diff] [blame] | 466 | |
| 467 | it('should ignore empty terms in whole rows', function () { |
| Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 468 | var matchTable = matchTableFactory(); |
| 469 | var qc = qcClass.create(matchTable); |
| Akron | 8084cb5 | 2017-06-29 17:11:14 +0200 | [diff] [blame] | 470 | expect(qc.toString()).toEqual(""); |
| 471 | |
| Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 472 | var opennlpRow = matchTable.querySelector("tbody > tr:nth-child(2)"); |
| Akron | 8084cb5 | 2017-06-29 17:11:14 +0200 | [diff] [blame] | 473 | |
| 474 | expect(opennlpRow.querySelector("td:nth-child(3).chosen")).toBeNull(); |
| 475 | expect(opennlpRow.querySelector("td:nth-child(4).chosen")).toBeNull(); |
| 476 | expect(opennlpRow.querySelector("td:nth-child(5).chosen")).toBeNull(); |
| 477 | expect(opennlpRow.querySelector("td:nth-child(6).chosen")).toBeNull(); |
| 478 | |
| 479 | expect(qc.toString()).toEqual(""); |
| 480 | |
| 481 | // Mark all opennlp lists |
| 482 | cell = opennlpRow.querySelector("th:nth-child(1)"); |
| Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 483 | expect(cell.innerString()).toEqual("opennlp"); |
| Akron | 8084cb5 | 2017-06-29 17:11:14 +0200 | [diff] [blame] | 484 | expect(cell.classList.contains("chosen")).toBe(false); |
| 485 | cell.click(); |
| 486 | expect(cell.classList.contains("chosen")).toBe(false); |
| 487 | |
| 488 | expect(opennlpRow.querySelector("td:nth-child(3).chosen")).toBeTruthy(); |
| 489 | expect(opennlpRow.querySelector("td:nth-child(4).chosen")).toBeTruthy(); |
| 490 | expect(opennlpRow.querySelector("td:nth-child(5).chosen")).toBeNull(); |
| 491 | expect(opennlpRow.querySelector("td:nth-child(6).chosen")).toBeTruthy(); |
| Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 492 | |
| 493 | expect(qc.toString()).toEqual("[opennlp/p=ART][opennlp/p=ADJA][][opennlp/p=NN][opennlp/p=ADV]"); |
| Akron | 8084cb5 | 2017-06-29 17:11:14 +0200 | [diff] [blame] | 494 | }); |
| Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 495 | |
| 496 | it('should support multiple distances', function () { |
| Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 497 | var matchTable = matchTableFactory(); |
| 498 | var qc = qcClass.create(matchTable); |
| Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 499 | |
| Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 500 | var cell = matchTable.querySelector("thead > tr > th:nth-child(3)"); |
| Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 501 | expect(cell.innerString()).toEqual("Der"); |
| Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 502 | cell.click(); |
| 503 | expect(qc.toString()).toEqual("[orth=Der]"); |
| 504 | |
| Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 505 | cell = matchTable.querySelector("thead > tr > th:nth-child(7)"); |
| Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 506 | expect(cell.innerString()).toEqual("hier"); |
| Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 507 | cell.click(); |
| 508 | expect(qc.toString()).toEqual("[orth=Der][]{3}[orth=hier]"); |
| 509 | |
| Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 510 | cell = matchTable.querySelector("thead > tr > th:nth-child(5)"); |
| Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 511 | expect(cell.innerString()).toEqual("lebende"); |
| Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 512 | cell.click(); |
| 513 | expect(qc.toString()).toEqual("[orth=Der][][orth=lebende][][orth=hier]"); |
| 514 | }); |
| Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 515 | |
| 516 | it('should create and-groups for key-value terms', function () { |
| Akron | efed2e2 | 2021-11-16 23:16:54 +0100 | [diff] [blame] | 517 | const matchTable = matchTableComplexFactory(); |
| 518 | const qc = qcClass.create(matchTable); |
| Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 519 | |
| 520 | // Nothing to show |
| 521 | expect(qc.toString()).toEqual(""); |
| 522 | expect(qc.shown()).toBe(false); |
| 523 | qc.show(); |
| 524 | expect(qc.shown()).toBe(false); |
| Akron | 7dd3282 | 2018-10-01 19:38:31 +0200 | [diff] [blame] | 525 | expect(qc.element().className).toEqual("query fragment"); |
| Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 526 | |
| Akron | efed2e2 | 2021-11-16 23:16:54 +0100 | [diff] [blame] | 527 | let cell = matchTable.querySelector("thead > tr > th:nth-child(5)"); |
| Akron | 0d612d1 | 2019-05-21 16:45:49 +0200 | [diff] [blame] | 528 | expect(cell.innerString()).toEqual("lebende und sterbende"); |
| Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 529 | expect(cell.classList.contains("chosen")).toBe(false); |
| 530 | cell.click(); |
| 531 | expect(cell.classList.contains("chosen")).toBeTruthy(); |
| Akron | 0d612d1 | 2019-05-21 16:45:49 +0200 | [diff] [blame] | 532 | expect(qc.toString()).toEqual("[orth='lebende und sterbende']"); |
| Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 533 | |
| 534 | // Check complex cell |
| Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 535 | cell = matchTable.querySelector("tbody > tr:nth-child(1) > td:nth-child(6)"); |
| Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 536 | expect(cell.innerString()).toMatch(/case:nom/); |
| Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 537 | expect(cell.classList.contains("chosen")).toBe(false); |
| 538 | cell.click(); |
| 539 | expect(cell.classList.contains("chosen")).toBe(false); |
| Akron | 0d612d1 | 2019-05-21 16:45:49 +0200 | [diff] [blame] | 540 | expect(qc.toString()).toEqual("[orth='lebende und sterbende']"); |
| Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 541 | |
| 542 | // Check complex cell div |
| Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 543 | cell = matchTable.querySelector("tbody > tr:nth-child(1) > td:nth-child(6) > div:nth-child(1)"); |
| Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 544 | expect(cell.innerString()).toEqual('case:nom'); |
| Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 545 | expect(cell.classList.contains("chosen")).toBe(false); |
| 546 | cell.click(); |
| 547 | expect(cell.classList.contains("chosen")).toBe(true); |
| Akron | 0d612d1 | 2019-05-21 16:45:49 +0200 | [diff] [blame] | 548 | expect(qc.toString()).toEqual("[orth='lebende und sterbende'][corenlp/p=case:nom]"); |
| Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 549 | |
| Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 550 | cell = matchTable.querySelector("tbody > tr:nth-child(1) > td:nth-child(6) > div:nth-child(3)"); |
| Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 551 | expect(cell.innerString()).toEqual('number:sg'); |
| Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 552 | expect(cell.classList.contains("chosen")).toBe(false); |
| 553 | cell.click(); |
| 554 | expect(cell.classList.contains("chosen")).toBe(true); |
| Akron | 0d612d1 | 2019-05-21 16:45:49 +0200 | [diff] [blame] | 555 | expect(qc.toString()).toEqual("[orth='lebende und sterbende'][corenlp/p=case:nom & corenlp/p=number:sg]"); |
| Akron | efed2e2 | 2021-11-16 23:16:54 +0100 | [diff] [blame] | 556 | let cell2 = cell; |
| Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 557 | |
| Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 558 | cell = matchTable.querySelector("tbody > tr:nth-child(1) > td:nth-child(6) > div:nth-child(2)"); |
| Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 559 | expect(cell.innerString()).toEqual('gender:mascgender:fem'); |
| Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 560 | expect(cell.classList.contains("chosen")).toBe(false); |
| 561 | cell.click(); |
| 562 | expect(cell.classList.contains("chosen")).toBe(true); |
| Akron | 0d612d1 | 2019-05-21 16:45:49 +0200 | [diff] [blame] | 563 | expect(qc.toString()).toEqual("[orth='lebende und sterbende'][(corenlp/p=gender:fem | corenlp/p=gender:masc) & corenlp/p=case:nom & corenlp/p=number:sg]"); |
| Akron | efed2e2 | 2021-11-16 23:16:54 +0100 | [diff] [blame] | 564 | let cell3 = cell; |
| Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 565 | |
| 566 | // Remove cell again |
| 567 | cell = cell2; |
| Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 568 | expect(cell.innerString()).toEqual('number:sg'); |
| Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 569 | expect(cell.classList.contains("chosen")).toBe(true); |
| 570 | cell.click(); |
| 571 | expect(cell.classList.contains("chosen")).toBe(false); |
| Akron | 0d612d1 | 2019-05-21 16:45:49 +0200 | [diff] [blame] | 572 | expect(qc.toString()).toEqual("[orth='lebende und sterbende'][(corenlp/p=gender:fem | corenlp/p=gender:masc) & corenlp/p=case:nom]"); |
| Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 573 | |
| 574 | // Remove cell again |
| 575 | cell = cell3; |
| Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 576 | expect(cell.innerString()).toEqual('gender:mascgender:fem'); |
| Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 577 | expect(cell.classList.contains("chosen")).toBe(true); |
| 578 | cell.click(); |
| 579 | expect(cell.classList.contains("chosen")).toBe(false); |
| Akron | 0d612d1 | 2019-05-21 16:45:49 +0200 | [diff] [blame] | 580 | expect(qc.toString()).toEqual("[orth='lebende und sterbende'][corenlp/p=case:nom]"); |
| Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 581 | }); |
| 582 | |
| 583 | |
| 584 | it('should create rows including key-value terms', function () { |
| Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 585 | var matchTable = matchTableComplexFactory(); |
| 586 | var qc = qcClass.create(matchTable); |
| Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 587 | expect(qc.toString()).toEqual(""); |
| 588 | |
| Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 589 | var corenlpRow = matchTable.querySelector("tbody > tr:nth-child(1)"); |
| Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 590 | |
| 591 | expect(corenlpRow.querySelector("td:nth-child(3).chosen")).toBeNull(); |
| 592 | expect(corenlpRow.querySelector("td:nth-child(4).chosen")).toBeNull(); |
| 593 | expect(corenlpRow.querySelector("td:nth-child(5).chosen")).toBeNull(); |
| 594 | expect(corenlpRow.querySelector("td:nth-child(6) *.chosen")).toBeNull(); |
| 595 | |
| 596 | expect(qc.toString()).toEqual(""); |
| 597 | |
| 598 | // Mark all opennlp lists |
| 599 | cell = corenlpRow.querySelector("th:nth-child(1)"); |
| Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 600 | expect(cell.innerString()).toEqual("corenlp"); |
| Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 601 | expect(cell.classList.contains("chosen")).toBe(false); |
| 602 | cell.click(); |
| 603 | expect(cell.classList.contains("chosen")).toBe(false); |
| 604 | |
| 605 | expect(corenlpRow.querySelector("td:nth-child(3).chosen")).toBeTruthy(); |
| 606 | expect(corenlpRow.querySelector("td:nth-child(4).chosen")).toBeTruthy(); |
| 607 | expect(corenlpRow.querySelector("td:nth-child(5).chosen")).toBeTruthy(); |
| 608 | expect(corenlpRow.querySelector("td:nth-child(6) div:nth-child(1).chosen")).toBeTruthy(); |
| 609 | expect(corenlpRow.querySelector("td:nth-child(6) div:nth-child(2).chosen")).toBeTruthy(); |
| 610 | expect(corenlpRow.querySelector("td:nth-child(6) div:nth-child(3).chosen")).toBeTruthy(); |
| 611 | |
| 612 | expect(qc.toString()).toEqual( |
| 613 | "[corenlp/p=ART]"+ |
| 614 | "[corenlp/p=ADJA]"+ |
| 615 | "[(corenlp/p=ADJA | corenlp/p=ADJD)]"+ |
| 616 | "[(corenlp/p=gender:fem | corenlp/p=gender:masc) & corenlp/p=case:nom & corenlp/p=number:sg]" |
| 617 | ); |
| 618 | }); |
| Akron | 72245b6 | 2018-07-23 10:59:08 +0200 | [diff] [blame] | 619 | |
| 620 | it('should support verbatim strings', function () { |
| 621 | var matchTable = matchTableComplexFactory(); |
| 622 | var qc = qcClass.create(matchTable); |
| 623 | expect(qc.toString()).toEqual(""); |
| 624 | |
| 625 | // TODO: |
| 626 | // This does not respect keys vs values at the moment, but neither does Koral |
| Akron | efed2e2 | 2021-11-16 23:16:54 +0100 | [diff] [blame] | 627 | let cell = matchTable.querySelector("tbody > tr:nth-child(2) > td > div:nth-child(4)"); |
| Akron | 72245b6 | 2018-07-23 10:59:08 +0200 | [diff] [blame] | 628 | expect(cell.innerString()).toEqual("morphemes:.::_SORSZ \\ZERO::NOM 'period::PUNCT'"); |
| 629 | expect(cell.classList.contains("chosen")).toBe(false); |
| 630 | cell.click(); |
| 631 | expect(cell.classList.contains("chosen")).toBeTruthy(); |
| 632 | expect(qc.toString()).toEqual("[opennlp/p='morphemes:.::_SORSZ \\\\ZERO::NOM \\\'period::PUNCT\\\'']"); |
| Akron | 0d612d1 | 2019-05-21 16:45:49 +0200 | [diff] [blame] | 633 | cell.click() |
| 634 | expect(cell.classList.contains("chosen")).toBe(false); |
| 635 | expect(qc.toString()).toEqual(""); |
| 636 | |
| Akron | 9fe23dc | 2025-06-11 11:43:50 +0200 | [diff] [blame] | 637 | // notinindex |
| 638 | cell = matchTable.querySelector("tbody > tr:nth-child(2) > td > div:nth-child(3)"); |
| 639 | expect(cell.innerString()).toEqual("number:sg"); |
| 640 | expect(cell.classList.contains("chosen")).toBe(false); |
| 641 | cell.click(); |
| 642 | expect(cell.classList.contains("chosen")).toBe(false); |
| 643 | expect(qc.toString()).toEqual(""); |
| 644 | cell.click() |
| 645 | expect(cell.classList.contains("chosen")).toBe(false); |
| 646 | expect(qc.toString()).toEqual(""); |
| 647 | |
| 648 | cell = matchTable.querySelector("tbody > tr:nth-child(1) > td.notinindex"); |
| 649 | expect(cell.innerString()).toEqual("ADJA"); |
| 650 | expect(cell.classList.contains("chosen")).toBe(false); |
| 651 | cell.click(); |
| 652 | expect(cell.classList.contains("chosen")).toBe(false); |
| 653 | expect(qc.toString()).toEqual(""); |
| 654 | cell.click() |
| 655 | expect(cell.classList.contains("chosen")).toBe(false); |
| 656 | expect(qc.toString()).toEqual(""); |
| 657 | |
| Akron | 0d612d1 | 2019-05-21 16:45:49 +0200 | [diff] [blame] | 658 | cell = matchTable.querySelector("tbody > tr:nth-child(3) > td:nth-child(3)"); |
| 659 | expect(cell.classList.contains("chosen")).toBe(false); |
| 660 | cell.click(); |
| 661 | expect(cell.classList.contains("chosen")).toBeTruthy(); |
| Helge | 7e05fb0 | 2026-03-24 12:01:37 +0100 | [diff] [blame^] | 662 | expect(qc.toString()).toEqual("[gender/l='Lese|Lesen']"); |
| Akron | 0d612d1 | 2019-05-21 16:45:49 +0200 | [diff] [blame] | 663 | cell.click() |
| 664 | expect(cell.classList.contains("chosen")).toBe(false); |
| 665 | expect(qc.toString()).toEqual(""); |
| 666 | |
| 667 | cell = matchTable.querySelector("tbody > tr:nth-child(3) > td:nth-child(4)"); |
| 668 | expect(cell.classList.contains("chosen")).toBe(false); |
| 669 | cell.click(); |
| 670 | expect(cell.classList.contains("chosen")).toBeTruthy(); |
| Helge | 7e05fb0 | 2026-03-24 12:01:37 +0100 | [diff] [blame^] | 671 | expect(qc.toString()).toEqual("[gender/l='a b']"); |
| Akron | 0d612d1 | 2019-05-21 16:45:49 +0200 | [diff] [blame] | 672 | cell.click() |
| 673 | expect(cell.classList.contains("chosen")).toBe(false); |
| 674 | expect(qc.toString()).toEqual(""); |
| Akron | efed2e2 | 2021-11-16 23:16:54 +0100 | [diff] [blame] | 675 | |
| 676 | cell = matchTable.querySelector("tbody > tr:nth-child(2) > td > div:nth-child(5)"); |
| 677 | expect(cell.innerString()).toEqual("morphemes:ZERO::NOM"); |
| 678 | expect(cell.classList.contains("chosen")).toBe(false); |
| 679 | cell.click(); |
| 680 | expect(cell.classList.contains("chosen")).toBeTruthy(); |
| 681 | expect(qc.toString()).toEqual("[opennlp/p='morphemes:ZERO::NOM']"); |
| 682 | cell.click() |
| 683 | expect(cell.classList.contains("chosen")).toBe(false); |
| 684 | expect(qc.toString()).toEqual(""); |
| Helge | 7e05fb0 | 2026-03-24 12:01:37 +0100 | [diff] [blame^] | 685 | |
| 686 | cell = matchTable.querySelector("tbody > tr:nth-child(4) > td:nth-child(3)"); |
| 687 | expect(cell.classList.contains("chosen")).toBe(false); |
| 688 | cell.click(); |
| 689 | expect(cell.classList.contains("chosen")).toBeTruthy(); |
| 690 | expect(qc.toString()).toEqual("[tt/l='Lehrer*in']"); |
| 691 | cell.click() |
| 692 | expect(cell.classList.contains("chosen")).toBe(false); |
| 693 | expect(qc.toString()).toEqual(""); |
| 694 | |
| 695 | cell = matchTable.querySelector("tbody > tr:nth-child(4) > td:nth-child(4)"); |
| 696 | expect(cell.classList.contains("chosen")).toBe(false); |
| 697 | cell.click(); |
| 698 | expect(cell.classList.contains("chosen")).toBeTruthy(); |
| 699 | expect(qc.toString()).toEqual("[tt/l='gender:fem,masc,nonbin']"); |
| 700 | cell.click() |
| 701 | expect(cell.classList.contains("chosen")).toBe(false); |
| 702 | expect(qc.toString()).toEqual(""); |
| Akron | 72245b6 | 2018-07-23 10:59:08 +0200 | [diff] [blame] | 703 | }); |
| Akron | aeeb825 | 2018-09-19 18:51:00 +0200 | [diff] [blame] | 704 | |
| 705 | it('should respect marked elements', function () { |
| 706 | var matchTable = matchTableComplexFactory(); |
| 707 | var qc = qcClass.create(matchTable); |
| 708 | expect(qc.toString()).toEqual(""); |
| 709 | |
| 710 | var cell = matchTable.querySelector("thead > tr > th:nth-child(6)"); |
| 711 | expect(cell.classList.contains("mark")).toBeTruthy(); |
| 712 | expect(cell.classList.contains("chosen")).toBeFalsy(); |
| 713 | |
| 714 | cell.click(); |
| 715 | expect(cell.classList.contains("mark")).toBeTruthy(); |
| 716 | expect(cell.classList.contains("chosen")).toBeTruthy(); |
| 717 | |
| 718 | cell.click(); |
| 719 | expect(cell.classList.contains("mark")).toBeTruthy(); |
| 720 | expect(cell.classList.contains("chosen")).toBeFalsy(); |
| 721 | }); |
| Akron | 083ec57 | 2019-05-16 18:30:40 +0200 | [diff] [blame] | 722 | |
| 723 | it('should ignore cutted columns', function () { |
| 724 | var matchTable = matchTableCuttedFactory(); |
| 725 | var qc = qcClass.create(matchTable); |
| 726 | expect(qc.toString()).toEqual(""); |
| 727 | |
| 728 | var cell = matchTable.querySelector("thead > tr > th:nth-child(3)"); |
| 729 | expect(cell.classList.contains("chosen")).toBeFalsy(); |
| 730 | cell.click(); |
| 731 | expect(cell.classList.contains("chosen")).toBeTruthy(); |
| 732 | expect(qc.toString()).toEqual("[orth=Baum]"); |
| 733 | |
| 734 | cell = matchTable.querySelector("thead > tr > th:nth-child(4)"); |
| 735 | expect(cell.classList.contains("chosen")).toBeFalsy(); |
| 736 | expect(cell.classList.contains("cutted")).toBeTruthy(); |
| 737 | cell.click(); |
| 738 | expect(cell.classList.contains("chosen")).toBeFalsy(); |
| 739 | expect(qc.toString()).toEqual("[orth=Baum]"); |
| 740 | }); |
| Akron | b516374 | 2020-10-12 15:31:41 +0200 | [diff] [blame] | 741 | |
| 742 | it('should add fragment to QueryBar', function () { |
| 743 | var matchTable = matchTableCuttedFactory(); |
| 744 | var qc = qcClass.create(matchTable); |
| 745 | expect(qc.toString()).toEqual(""); |
| 746 | |
| 747 | var cell = matchTable.querySelector("thead > tr > th:nth-child(3)"); |
| 748 | expect(cell.classList.contains("chosen")).toBeFalsy(); |
| 749 | cell.click(); |
| 750 | expect(cell.classList.contains("chosen")).toBeTruthy(); |
| 751 | expect(qc.toString()).toEqual("[orth=Baum]"); |
| 752 | |
| 753 | // May break |
| 754 | qc._ql = document.createElement('select'); |
| 755 | let opt = qc._ql.appendChild(document.createElement('option')); |
| 756 | opt.value='cosmas 2'; |
| 757 | let opt2 = qc._ql.appendChild(document.createElement('option')); |
| 758 | opt2.value='poliqarp'; |
| 759 | |
| 760 | qc._q = document.createElement('input'); |
| 761 | |
| Akron | 24aa005 | 2020-11-10 11:00:34 +0100 | [diff] [blame] | 762 | qc._el.click(); |
| Akron | b516374 | 2020-10-12 15:31:41 +0200 | [diff] [blame] | 763 | |
| 764 | expect(qc._ql.selectedIndex).toEqual(1); |
| 765 | expect(qc._q.value).toEqual("[orth=Baum]"); |
| 766 | }); |
| Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 767 | }); |
| 768 | }); |