blob: a7e9860bbfe306dd41ec309523cf6f1f339d7dd3 [file] [log] [blame]
Akron72245b62018-07-23 10:59:08 +02001/**
2 * Specification for the query creator.
3 */
4
Akron7dd32822018-10-01 19:38:31 +02005
6Element.prototype.innerString = function () {
7 return this.innerText.split("\n").join("");
8};
9
Akron70903c42018-02-05 12:31:10 +010010function matchTableFactory () {
11 var table = document.createElement('div');
Akronbdcbbf42018-04-25 12:42:44 +020012
Akron70903c42018-02-05 12:31:10 +010013 table.className = 'matchtable';
14 table.innerHTML =
Akronb46d8e32017-06-29 14:26:14 +020015 " <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>" +
Akrone9be11d2017-06-29 20:10:58 +020024 " <th>hier</th>" +
Akronb46d8e32017-06-29 14:26:14 +020025 " </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>" +
Akrone9be11d2017-06-29 20:10:58 +020035 " <td>ADV</td>" +
Akronb46d8e32017-06-29 14:26:14 +020036 " </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>" +
Akrone9be11d2017-06-29 20:10:58 +020044 " <td>ADV</td>" +
Akronb46d8e32017-06-29 14:26:14 +020045 " </tr>" +
46 " </tbody>" +
47 " </table>" +
Akron70903c42018-02-05 12:31:10 +010048 " </div>";
Akronb46d8e32017-06-29 14:26:14 +020049
Akron70903c42018-02-05 12:31:10 +010050 var info = document.createElement('div');
51 info.appendChild(table);
52 return table;
Akronb46d8e32017-06-29 14:26:14 +020053};
54
Akron70903c42018-02-05 12:31:10 +010055function matchTableComplexFactory () {
56 var table = document.createElement('div');
57 table.className = 'matchtable';
58 table.innerHTML =
Akron7cf33fd2017-07-03 17:33:39 +020059 " <table>" +
60 " <thead>" +
61 " <tr>" +
62 " <th>Foundry</th>" +
63 " <th>Layer</th>" +
64 " <th>Der</th>" +
65 " <th>älteste</th>" +
Akron0d612d12019-05-21 16:45:49 +020066 " <th>lebende und sterbende</th>" +
Akronaeeb8252018-09-19 18:51:00 +020067 " <th class=\"mark\">Baum</th>" +
Akron7cf33fd2017-07-03 17:33:39 +020068 " </tr>" +
69 " </thead>" +
70 " <tbody>" +
71 " <tr tabindex=\"0\">" +
72 " <th>corenlp</th>" +
73 " <th>p</th>" +
74 " <td>ART</td>" +
Akron9fe23dc2025-06-11 11:43:50 +020075 " <td class=\"notinindex\">ADJA</td>" +
Akron7cf33fd2017-07-03 17:33:39 +020076 " <td>ADJA<br>ADJD</td>" +
Akronaeeb8252018-09-19 18:51:00 +020077 " <td class=\"matchkeyvalues mark\">" +
Akron7cf33fd2017-07-03 17:33:39 +020078 " <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>" +
Akron9fe23dc2025-06-11 11:43:50 +020089 " <div class=\"notinindex\">number:sg</div>" +
Akron72245b62018-07-23 10:59:08 +020090 " <div>morphemes:.::_SORSZ \\ZERO::NOM 'period::PUNCT'</div>" +
Akronefed2e22021-11-16 23:16:54 +010091 " <div>morphemes:ZERO::NOM</div>" +
Akron7cf33fd2017-07-03 17:33:39 +020092 " </td>" +
93 " <td>ADJA</td>" +
94 " <td></td>" +
Akronaeeb8252018-09-19 18:51:00 +020095 " <td class=\"mark\">NN</td>" +
Akron7cf33fd2017-07-03 17:33:39 +020096 " </tr>" +
Akron0d612d12019-05-21 16:45:49 +020097 " <tr tabindex=\"0\">" +
Helge7e05fb02026-03-24 12:01:37 +010098 " <th>gender</th>" +
Akron0d612d12019-05-21 16:45:49 +020099 " <th>l</th>" +
100 " <td>Lese|Lesen</td>" +
101 " <td>a b</td>" +
102 " <td></td>" +
103 " <td class=\"mark\">NN</td>" +
104 " </tr>" +
Helge7e05fb02026-03-24 12:01:37 +0100105 " <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>" +
Akron7cf33fd2017-07-03 17:33:39 +0200113 " </tbody>" +
Akron70903c42018-02-05 12:31:10 +0100114 " </table>";
115 var info = document.createElement('div');
116 info.appendChild(table);
117 return table;
Akron7cf33fd2017-07-03 17:33:39 +0200118};
119
Akronb46d8e32017-06-29 14:26:14 +0200120
Akron083ec572019-05-16 18:30:40 +0200121function 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
Akronb46d8e32017-06-29 14:26:14 +0200155define(['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
Akron70903c42018-02-05 12:31:10 +0100172 expect(qcClass.create(matchTableFactory()).toString()).toEqual("");
Akronb46d8e32017-06-29 14:26:14 +0200173 });
174
175 it('should listen to click events', function () {
176
Akron70903c42018-02-05 12:31:10 +0100177 var matchTable = matchTableFactory();
178 var qc = qcClass.create(matchTable);
Akronb46d8e32017-06-29 14:26:14 +0200179
180 // Nothing to show
181 expect(qc.toString()).toEqual("");
182 expect(qc.shown()).toBe(false);
183 qc.show();
184 expect(qc.shown()).toBe(false);
Akron7dd32822018-10-01 19:38:31 +0200185 expect(qc.element().className).toEqual("query fragment");
Akronb46d8e32017-06-29 14:26:14 +0200186
187 // Click on cell 0:0 "Foundry"
Akron70903c42018-02-05 12:31:10 +0100188 var cell = matchTable.querySelector("thead > tr > th:first-child");
Akronbdcbbf42018-04-25 12:42:44 +0200189 expect(cell.innerString()).toEqual("Foundry");
Akronb46d8e32017-06-29 14:26:14 +0200190 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"
Akron70903c42018-02-05 12:31:10 +0100196 cell = matchTable.querySelector("thead > tr > th:nth-child(3)")
Akronbdcbbf42018-04-25 12:42:44 +0200197 expect(cell.innerString()).toEqual("Der");
Akronb46d8e32017-06-29 14:26:14 +0200198 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
Akron70903c42018-02-05 12:31:10 +0100204 cell = matchTable.querySelector("thead > tr > th:nth-child(3)")
Akronbdcbbf42018-04-25 12:42:44 +0200205 expect(cell.innerString()).toEqual("Der");
Akronb46d8e32017-06-29 14:26:14 +0200206 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 () {
Akron70903c42018-02-05 12:31:10 +0100213 var matchTable = matchTableFactory();
214 var qc = qcClass.create(matchTable);
Akronb46d8e32017-06-29 14:26:14 +0200215
Akron70903c42018-02-05 12:31:10 +0100216 var cell = matchTable.querySelector("tbody > tr:nth-child(2) > td:nth-child(4)");
Akronbdcbbf42018-04-25 12:42:44 +0200217 expect(cell.innerString()).toEqual("ADJA");
Akronb46d8e32017-06-29 14:26:14 +0200218 cell.click();
219 expect(qc.toString()).toEqual("[opennlp/p=ADJA]");
220
Akron70903c42018-02-05 12:31:10 +0100221 cell = matchTable.querySelector("thead > tr > th:nth-child(4)");
Akronbdcbbf42018-04-25 12:42:44 +0200222 expect(cell.innerString()).toEqual("älteste");
Akronb46d8e32017-06-29 14:26:14 +0200223 cell.click();
224 expect(qc.toString()).toEqual("[opennlp/p=ADJA & orth=älteste]");
225
Akron70903c42018-02-05 12:31:10 +0100226 cell = matchTable.querySelector("tbody > tr > td:nth-child(4)");
Akronbdcbbf42018-04-25 12:42:44 +0200227 expect(cell.innerString()).toEqual("ADJA");
Akronb46d8e32017-06-29 14:26:14 +0200228 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 () {
Akron70903c42018-02-05 12:31:10 +0100233 var matchTable = matchTableFactory();
234 var qc = qcClass.create(matchTable);
Akronb46d8e32017-06-29 14:26:14 +0200235
Akron70903c42018-02-05 12:31:10 +0100236 var cell = matchTable.querySelector("thead > tr > th:nth-child(5)");
Akronbdcbbf42018-04-25 12:42:44 +0200237 expect(cell.innerString()).toEqual("lebende");
Akronb46d8e32017-06-29 14:26:14 +0200238 cell.click();
239 expect(qc.toString()).toEqual("[orth=lebende]");
240
Akron70903c42018-02-05 12:31:10 +0100241 cell = matchTable.querySelector("tbody > tr:nth-child(2) > td:nth-child(3)");
Akronbdcbbf42018-04-25 12:42:44 +0200242 expect(cell.innerString()).toEqual("ART");
Akronb46d8e32017-06-29 14:26:14 +0200243 cell.click();
Akrone9be11d2017-06-29 20:10:58 +0200244 expect(qc.toString()).toEqual("[opennlp/p=ART][][orth=lebende]");
Akronb46d8e32017-06-29 14:26:14 +0200245
Akron70903c42018-02-05 12:31:10 +0100246 cell = matchTable.querySelector("tbody > tr > td:nth-child(4)");
Akronbdcbbf42018-04-25 12:42:44 +0200247 expect(cell.innerString()).toEqual("ADJA");
Akronb46d8e32017-06-29 14:26:14 +0200248 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 () {
Akron70903c42018-02-05 12:31:10 +0100253 var matchTable = matchTableFactory();
254 var qc = qcClass.create(matchTable);
Akronb46d8e32017-06-29 14:26:14 +0200255
Akron70903c42018-02-05 12:31:10 +0100256 var cell = matchTable.querySelector("tbody > tr:nth-child(2) > td:nth-child(4)");
Akronbdcbbf42018-04-25 12:42:44 +0200257 expect(cell.innerString()).toEqual("ADJA");
Akronb46d8e32017-06-29 14:26:14 +0200258 cell.click();
259 expect(qc.toString()).toEqual("[opennlp/p=ADJA]");
260 var cell1 = cell;
261
Akron70903c42018-02-05 12:31:10 +0100262 cell = matchTable.querySelector("thead > tr > th:nth-child(4)");
Akronbdcbbf42018-04-25 12:42:44 +0200263 expect(cell.innerString()).toEqual("älteste");
Akronb46d8e32017-06-29 14:26:14 +0200264 cell.click();
265 expect(qc.toString()).toEqual("[opennlp/p=ADJA & orth=älteste]");
266 var cell2 = cell;
267
Akron70903c42018-02-05 12:31:10 +0100268 cell = matchTable.querySelector("tbody > tr > td:nth-child(3)");
Akronbdcbbf42018-04-25 12:42:44 +0200269 expect(cell.innerString()).toEqual("ART");
Akronb46d8e32017-06-29 14:26:14 +0200270 cell.click();
271 expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA & orth=älteste]");
272 var cell3 = cell;
273
Akron70903c42018-02-05 12:31:10 +0100274 cell = matchTable.querySelector("thead > tr > th:nth-child(6)");
Akronbdcbbf42018-04-25 12:42:44 +0200275 expect(cell.innerString()).toEqual("Baum");
Akronb46d8e32017-06-29 14:26:14 +0200276 cell.click();
Akrone9be11d2017-06-29 20:10:58 +0200277 expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA & orth=älteste][][orth=Baum]");
Akronb46d8e32017-06-29 14:26:14 +0200278 var cell4 = cell;
279
Akron70903c42018-02-05 12:31:10 +0100280 cell = matchTable.querySelector("thead > tr > th:nth-child(5)");
Akronbdcbbf42018-04-25 12:42:44 +0200281 expect(cell.innerString()).toEqual("lebende");
Akronb46d8e32017-06-29 14:26:14 +0200282 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);
Akrone9be11d2017-06-29 20:10:58 +0200291 expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA & orth=älteste][][orth=Baum]");
Akronb46d8e32017-06-29 14:26:14 +0200292
293 expect(cell2.classList.contains("chosen")).toBeTruthy();
294 cell2.click()
295 expect(cell2.classList.contains("chosen")).toBe(false);
Akrone9be11d2017-06-29 20:10:58 +0200296 expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA][][orth=Baum]");
Akronb46d8e32017-06-29 14:26:14 +0200297
298 expect(cell1.classList.contains("chosen")).toBeTruthy();
299 cell1.click()
300 expect(cell1.classList.contains("chosen")).toBe(false);
Akrone9be11d2017-06-29 20:10:58 +0200301 expect(qc.toString()).toEqual("[corenlp/p=ART][]{2}[orth=Baum]");
Akronb46d8e32017-06-29 14:26:14 +0200302
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();
Akrone9be11d2017-06-29 20:10:58 +0200307 expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA][][orth=Baum]");
Akronb46d8e32017-06-29 14:26:14 +0200308
309 expect(cell3.classList.contains("chosen")).toBeTruthy();
310 cell3.click()
311 expect(cell3.classList.contains("chosen")).toBe(false);
Akrone9be11d2017-06-29 20:10:58 +0200312 expect(qc.toString()).toEqual("[opennlp/p=ADJA][][orth=Baum]");
Akronb46d8e32017-06-29 14:26:14 +0200313
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
Akronc8461bf2017-06-29 15:05:24 +0200337 it('should ignore empty terms', function () {
Akron70903c42018-02-05 12:31:10 +0100338 var matchTable = matchTableFactory();
339 var qc = qcClass.create(matchTable);
Akronb46d8e32017-06-29 14:26:14 +0200340
Akronc8461bf2017-06-29 15:05:24 +0200341 // Nothing to show
342 expect(qc.toString()).toEqual("");
343 expect(qc.shown()).toBe(false);
344 qc.show();
345 expect(qc.shown()).toBe(false);
Akron7dd32822018-10-01 19:38:31 +0200346 expect(qc.element().className).toEqual("query fragment");
Akronc8461bf2017-06-29 15:05:24 +0200347
Akron70903c42018-02-05 12:31:10 +0100348 var cell = matchTable.querySelector("tbody > tr:nth-child(2) > td:nth-child(4)");
Akronbdcbbf42018-04-25 12:42:44 +0200349 expect(cell.innerString()).toEqual("ADJA");
Akronc8461bf2017-06-29 15:05:24 +0200350 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
Akron70903c42018-02-05 12:31:10 +0100355 cell = matchTable.querySelector("tbody > tr:nth-child(2) > td:nth-child(5)");
Akronbdcbbf42018-04-25 12:42:44 +0200356 expect(cell.innerString()).toEqual("");
Akronc8461bf2017-06-29 15:05:24 +0200357 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
Akron7cf33fd2017-07-03 17:33:39 +0200364 it('should create or-groups for alternative terms', function () {
Akron70903c42018-02-05 12:31:10 +0100365 var matchTable = matchTableFactory();
366 var qc = qcClass.create(matchTable);
Akronc8461bf2017-06-29 15:05:24 +0200367
368 // Nothing to show
369 expect(qc.toString()).toEqual("");
370 expect(qc.shown()).toBe(false);
371 qc.show();
372 expect(qc.shown()).toBe(false);
Akron7dd32822018-10-01 19:38:31 +0200373 expect(qc.element().className).toEqual("query fragment");
Akronc8461bf2017-06-29 15:05:24 +0200374
Akron70903c42018-02-05 12:31:10 +0100375 var cell = matchTable.querySelector("thead > tr > th:nth-child(5)");
Akronbdcbbf42018-04-25 12:42:44 +0200376 expect(cell.innerString()).toEqual("lebende");
Akronc8461bf2017-06-29 15:05:24 +0200377 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
Akron70903c42018-02-05 12:31:10 +0100382 cell = matchTable.querySelector("tbody > tr:nth-child(1) > td:nth-child(5)");
Akronbdcbbf42018-04-25 12:42:44 +0200383 expect(cell.innerString()).toEqual("ADJAADJD");
Akronc8461bf2017-06-29 15:05:24 +0200384 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 () {
Akron70903c42018-02-05 12:31:10 +0100398 var matchTable = matchTableFactory();
399 var qc = qcClass.create(matchTable);
Akronc8461bf2017-06-29 15:05:24 +0200400
401 // Nothing to show
402 expect(qc.toString()).toEqual("");
403 expect(qc.shown()).toBe(false);
404 qc.show();
405 expect(qc.shown()).toBe(false);
Akron7dd32822018-10-01 19:38:31 +0200406 expect(qc.element().className).toEqual("query fragment");
Akronc8461bf2017-06-29 15:05:24 +0200407
Akron70903c42018-02-05 12:31:10 +0100408 var corenlpRow = matchTable.querySelector("tbody > tr:nth-child(1)");
Akronc8461bf2017-06-29 15:05:24 +0200409
410 var cell = corenlpRow.querySelector("td:nth-child(4)");
Akronbdcbbf42018-04-25 12:42:44 +0200411 expect(cell.innerString()).toEqual("ADJA");
Akronc8461bf2017-06-29 15:05:24 +0200412 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
Akron70903c42018-02-05 12:31:10 +0100417 cell = matchTable.querySelector("tbody > tr:nth-child(2) td:nth-child(3)");
Akronbdcbbf42018-04-25 12:42:44 +0200418 expect(cell.innerString()).toEqual("ART");
Akronc8461bf2017-06-29 15:05:24 +0200419 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)");
Akronbdcbbf42018-04-25 12:42:44 +0200432 expect(cell.innerString()).toEqual("corenlp");
Akronc8461bf2017-06-29 15:05:24 +0200433 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)");
Akronbdcbbf42018-04-25 12:42:44 +0200444 expect(cell.innerString()).toEqual("corenlp");
Akronc8461bf2017-06-29 15:05:24 +0200445 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();
Akrone9be11d2017-06-29 20:10:58 +0200453 expect(corenlpRow.querySelector("td:nth-child(7).chosen")).toBeTruthy();
Akronc8461bf2017-06-29 15:05:24 +0200454
Akrone9be11d2017-06-29 20:10:58 +0200455 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]");
Akronc8461bf2017-06-29 15:05:24 +0200456
457 // Remove one of the cells again
458 cell = corenlpRow.querySelector("td:nth-child(5).chosen");
Akronbdcbbf42018-04-25 12:42:44 +0200459 expect(cell.innerString()).toEqual("ADJAADJD");
Akronc8461bf2017-06-29 15:05:24 +0200460 expect(cell.classList.contains("chosen")).toBeTruthy();
461 cell.click();
462 expect(cell.classList.contains("chosen")).toBe(false);
Akrone9be11d2017-06-29 20:10:58 +0200463 expect(qc.toString()).toEqual("[corenlp/p=ART & opennlp/p=ART][corenlp/p=ADJA][][corenlp/p=NN][corenlp/p=ADV]");
Akronc8461bf2017-06-29 15:05:24 +0200464
465 });
Akron8084cb52017-06-29 17:11:14 +0200466
467 it('should ignore empty terms in whole rows', function () {
Akron70903c42018-02-05 12:31:10 +0100468 var matchTable = matchTableFactory();
469 var qc = qcClass.create(matchTable);
Akron8084cb52017-06-29 17:11:14 +0200470 expect(qc.toString()).toEqual("");
471
Akron70903c42018-02-05 12:31:10 +0100472 var opennlpRow = matchTable.querySelector("tbody > tr:nth-child(2)");
Akron8084cb52017-06-29 17:11:14 +0200473
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)");
Akronbdcbbf42018-04-25 12:42:44 +0200483 expect(cell.innerString()).toEqual("opennlp");
Akron8084cb52017-06-29 17:11:14 +0200484 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();
Akron7cf33fd2017-07-03 17:33:39 +0200492
493 expect(qc.toString()).toEqual("[opennlp/p=ART][opennlp/p=ADJA][][opennlp/p=NN][opennlp/p=ADV]");
Akron8084cb52017-06-29 17:11:14 +0200494 });
Akrone9be11d2017-06-29 20:10:58 +0200495
496 it('should support multiple distances', function () {
Akron70903c42018-02-05 12:31:10 +0100497 var matchTable = matchTableFactory();
498 var qc = qcClass.create(matchTable);
Akrone9be11d2017-06-29 20:10:58 +0200499
Akron70903c42018-02-05 12:31:10 +0100500 var cell = matchTable.querySelector("thead > tr > th:nth-child(3)");
Akronbdcbbf42018-04-25 12:42:44 +0200501 expect(cell.innerString()).toEqual("Der");
Akrone9be11d2017-06-29 20:10:58 +0200502 cell.click();
503 expect(qc.toString()).toEqual("[orth=Der]");
504
Akron70903c42018-02-05 12:31:10 +0100505 cell = matchTable.querySelector("thead > tr > th:nth-child(7)");
Akronbdcbbf42018-04-25 12:42:44 +0200506 expect(cell.innerString()).toEqual("hier");
Akrone9be11d2017-06-29 20:10:58 +0200507 cell.click();
508 expect(qc.toString()).toEqual("[orth=Der][]{3}[orth=hier]");
509
Akron70903c42018-02-05 12:31:10 +0100510 cell = matchTable.querySelector("thead > tr > th:nth-child(5)");
Akronbdcbbf42018-04-25 12:42:44 +0200511 expect(cell.innerString()).toEqual("lebende");
Akrone9be11d2017-06-29 20:10:58 +0200512 cell.click();
513 expect(qc.toString()).toEqual("[orth=Der][][orth=lebende][][orth=hier]");
514 });
Akron7cf33fd2017-07-03 17:33:39 +0200515
516 it('should create and-groups for key-value terms', function () {
Akronefed2e22021-11-16 23:16:54 +0100517 const matchTable = matchTableComplexFactory();
518 const qc = qcClass.create(matchTable);
Akron7cf33fd2017-07-03 17:33:39 +0200519
520 // Nothing to show
521 expect(qc.toString()).toEqual("");
522 expect(qc.shown()).toBe(false);
523 qc.show();
524 expect(qc.shown()).toBe(false);
Akron7dd32822018-10-01 19:38:31 +0200525 expect(qc.element().className).toEqual("query fragment");
Akron7cf33fd2017-07-03 17:33:39 +0200526
Akronefed2e22021-11-16 23:16:54 +0100527 let cell = matchTable.querySelector("thead > tr > th:nth-child(5)");
Akron0d612d12019-05-21 16:45:49 +0200528 expect(cell.innerString()).toEqual("lebende und sterbende");
Akron7cf33fd2017-07-03 17:33:39 +0200529 expect(cell.classList.contains("chosen")).toBe(false);
530 cell.click();
531 expect(cell.classList.contains("chosen")).toBeTruthy();
Akron0d612d12019-05-21 16:45:49 +0200532 expect(qc.toString()).toEqual("[orth='lebende und sterbende']");
Akron7cf33fd2017-07-03 17:33:39 +0200533
534 // Check complex cell
Akron70903c42018-02-05 12:31:10 +0100535 cell = matchTable.querySelector("tbody > tr:nth-child(1) > td:nth-child(6)");
Akronbdcbbf42018-04-25 12:42:44 +0200536 expect(cell.innerString()).toMatch(/case:nom/);
Akron7cf33fd2017-07-03 17:33:39 +0200537 expect(cell.classList.contains("chosen")).toBe(false);
538 cell.click();
539 expect(cell.classList.contains("chosen")).toBe(false);
Akron0d612d12019-05-21 16:45:49 +0200540 expect(qc.toString()).toEqual("[orth='lebende und sterbende']");
Akron7cf33fd2017-07-03 17:33:39 +0200541
542 // Check complex cell div
Akron70903c42018-02-05 12:31:10 +0100543 cell = matchTable.querySelector("tbody > tr:nth-child(1) > td:nth-child(6) > div:nth-child(1)");
Akronbdcbbf42018-04-25 12:42:44 +0200544 expect(cell.innerString()).toEqual('case:nom');
Akron7cf33fd2017-07-03 17:33:39 +0200545 expect(cell.classList.contains("chosen")).toBe(false);
546 cell.click();
547 expect(cell.classList.contains("chosen")).toBe(true);
Akron0d612d12019-05-21 16:45:49 +0200548 expect(qc.toString()).toEqual("[orth='lebende und sterbende'][corenlp/p=case:nom]");
Akron7cf33fd2017-07-03 17:33:39 +0200549
Akron70903c42018-02-05 12:31:10 +0100550 cell = matchTable.querySelector("tbody > tr:nth-child(1) > td:nth-child(6) > div:nth-child(3)");
Akronbdcbbf42018-04-25 12:42:44 +0200551 expect(cell.innerString()).toEqual('number:sg');
Akron7cf33fd2017-07-03 17:33:39 +0200552 expect(cell.classList.contains("chosen")).toBe(false);
553 cell.click();
554 expect(cell.classList.contains("chosen")).toBe(true);
Akron0d612d12019-05-21 16:45:49 +0200555 expect(qc.toString()).toEqual("[orth='lebende und sterbende'][corenlp/p=case:nom & corenlp/p=number:sg]");
Akronefed2e22021-11-16 23:16:54 +0100556 let cell2 = cell;
Akron7cf33fd2017-07-03 17:33:39 +0200557
Akron70903c42018-02-05 12:31:10 +0100558 cell = matchTable.querySelector("tbody > tr:nth-child(1) > td:nth-child(6) > div:nth-child(2)");
Akronbdcbbf42018-04-25 12:42:44 +0200559 expect(cell.innerString()).toEqual('gender:mascgender:fem');
Akron7cf33fd2017-07-03 17:33:39 +0200560 expect(cell.classList.contains("chosen")).toBe(false);
561 cell.click();
562 expect(cell.classList.contains("chosen")).toBe(true);
Akron0d612d12019-05-21 16:45:49 +0200563 expect(qc.toString()).toEqual("[orth='lebende und sterbende'][(corenlp/p=gender:fem | corenlp/p=gender:masc) & corenlp/p=case:nom & corenlp/p=number:sg]");
Akronefed2e22021-11-16 23:16:54 +0100564 let cell3 = cell;
Akron7cf33fd2017-07-03 17:33:39 +0200565
566 // Remove cell again
567 cell = cell2;
Akronbdcbbf42018-04-25 12:42:44 +0200568 expect(cell.innerString()).toEqual('number:sg');
Akron7cf33fd2017-07-03 17:33:39 +0200569 expect(cell.classList.contains("chosen")).toBe(true);
570 cell.click();
571 expect(cell.classList.contains("chosen")).toBe(false);
Akron0d612d12019-05-21 16:45:49 +0200572 expect(qc.toString()).toEqual("[orth='lebende und sterbende'][(corenlp/p=gender:fem | corenlp/p=gender:masc) & corenlp/p=case:nom]");
Akron7cf33fd2017-07-03 17:33:39 +0200573
574 // Remove cell again
575 cell = cell3;
Akronbdcbbf42018-04-25 12:42:44 +0200576 expect(cell.innerString()).toEqual('gender:mascgender:fem');
Akron7cf33fd2017-07-03 17:33:39 +0200577 expect(cell.classList.contains("chosen")).toBe(true);
578 cell.click();
579 expect(cell.classList.contains("chosen")).toBe(false);
Akron0d612d12019-05-21 16:45:49 +0200580 expect(qc.toString()).toEqual("[orth='lebende und sterbende'][corenlp/p=case:nom]");
Akron7cf33fd2017-07-03 17:33:39 +0200581 });
582
583
584 it('should create rows including key-value terms', function () {
Akron70903c42018-02-05 12:31:10 +0100585 var matchTable = matchTableComplexFactory();
586 var qc = qcClass.create(matchTable);
Akron7cf33fd2017-07-03 17:33:39 +0200587 expect(qc.toString()).toEqual("");
588
Akron70903c42018-02-05 12:31:10 +0100589 var corenlpRow = matchTable.querySelector("tbody > tr:nth-child(1)");
Akron7cf33fd2017-07-03 17:33:39 +0200590
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)");
Akronbdcbbf42018-04-25 12:42:44 +0200600 expect(cell.innerString()).toEqual("corenlp");
Akron7cf33fd2017-07-03 17:33:39 +0200601 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 });
Akron72245b62018-07-23 10:59:08 +0200619
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
Akronefed2e22021-11-16 23:16:54 +0100627 let cell = matchTable.querySelector("tbody > tr:nth-child(2) > td > div:nth-child(4)");
Akron72245b62018-07-23 10:59:08 +0200628 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\\\'']");
Akron0d612d12019-05-21 16:45:49 +0200633 cell.click()
634 expect(cell.classList.contains("chosen")).toBe(false);
635 expect(qc.toString()).toEqual("");
636
Akron9fe23dc2025-06-11 11:43:50 +0200637 // 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
Akron0d612d12019-05-21 16:45:49 +0200658 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();
Helge7e05fb02026-03-24 12:01:37 +0100662 expect(qc.toString()).toEqual("[gender/l='Lese|Lesen']");
Akron0d612d12019-05-21 16:45:49 +0200663 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();
Helge7e05fb02026-03-24 12:01:37 +0100671 expect(qc.toString()).toEqual("[gender/l='a b']");
Akron0d612d12019-05-21 16:45:49 +0200672 cell.click()
673 expect(cell.classList.contains("chosen")).toBe(false);
674 expect(qc.toString()).toEqual("");
Akronefed2e22021-11-16 23:16:54 +0100675
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("");
Helge7e05fb02026-03-24 12:01:37 +0100685
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("");
Akron72245b62018-07-23 10:59:08 +0200703 });
Akronaeeb8252018-09-19 18:51:00 +0200704
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 });
Akron083ec572019-05-16 18:30:40 +0200722
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 });
Akronb5163742020-10-12 15:31:41 +0200741
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
Akron24aa0052020-11-10 11:00:34 +0100762 qc._el.click();
Akronb5163742020-10-12 15:31:41 +0200763
764 expect(qc._ql.selectedIndex).toEqual(1);
765 expect(qc._q.value).toEqual("[orth=Baum]");
766 });
Akronb46d8e32017-06-29 14:26:14 +0200767 });
768});