blob: c3e041dccbe181d0b3ccb57e56a8ec2f16e4d46b [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>" +
75 " <td>ADJA</td>" +
76 " <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>" +
89 " <div>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\">" +
98 " <th>tt</th>" +
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>" +
Akron7cf33fd2017-07-03 17:33:39 +0200105 " </tbody>" +
Akron70903c42018-02-05 12:31:10 +0100106 " </table>";
107 var info = document.createElement('div');
108 info.appendChild(table);
109 return table;
Akron7cf33fd2017-07-03 17:33:39 +0200110};
111
Akronb46d8e32017-06-29 14:26:14 +0200112
Akron083ec572019-05-16 18:30:40 +0200113function matchTableCuttedFactory () {
114 var table = document.createElement('div');
115 table.className = 'matchtable';
116 table.innerHTML =
117 " <table>" +
118 " <thead>" +
119 " <tr>" +
120 " <th>Foundry</th>" +
121 " <th>Layer</th>" +
122 " <th>Baum</th>" +
123 " <th class=\"cutted\"></th>" +
124 " </tr>" +
125 " </thead>" +
126 " <tbody>" +
127 " <tr tabindex=\"0\">" +
128 " <th>corenlp</th>" +
129 " <th>p</th>" +
130 " <td>NN</td>" +
131 " <td></td>" +
132 " </tr>" +
133 " <tr tabindex=\"0\">" +
134 " <th>opennlp</th>" +
135 " <th>p</th>" +
136 " <td>NN</td>" +
137 " <td></td>" +
138 " </tr>" +
139 " </tbody>" +
140 " </table>";
141 var info = document.createElement('div');
142 info.appendChild(table);
143 return table;
144};
145
146
Akronb46d8e32017-06-29 14:26:14 +0200147define(['match/querycreator'], function (qcClass) {
148
149 describe('KorAP.QueryCreator', function () {
150
151 it('should be initializable', function () {
152 expect(
153 function() {
154 qcClass.create()
155 }
156 ).toThrow(new Error("Missing parameters"));
157
158 expect(
159 function() {
160 qcClass.create("Test")
161 }
162 ).toThrow(new Error("Requires element"));
163
Akron70903c42018-02-05 12:31:10 +0100164 expect(qcClass.create(matchTableFactory()).toString()).toEqual("");
Akronb46d8e32017-06-29 14:26:14 +0200165 });
166
167 it('should listen to click events', function () {
168
Akron70903c42018-02-05 12:31:10 +0100169 var matchTable = matchTableFactory();
170 var qc = qcClass.create(matchTable);
Akronb46d8e32017-06-29 14:26:14 +0200171
172 // Nothing to show
173 expect(qc.toString()).toEqual("");
174 expect(qc.shown()).toBe(false);
175 qc.show();
176 expect(qc.shown()).toBe(false);
Akron7dd32822018-10-01 19:38:31 +0200177 expect(qc.element().className).toEqual("query fragment");
Akronb46d8e32017-06-29 14:26:14 +0200178
179 // Click on cell 0:0 "Foundry"
Akron70903c42018-02-05 12:31:10 +0100180 var cell = matchTable.querySelector("thead > tr > th:first-child");
Akronbdcbbf42018-04-25 12:42:44 +0200181 expect(cell.innerString()).toEqual("Foundry");
Akronb46d8e32017-06-29 14:26:14 +0200182 cell.click();
183 expect(cell.classList.contains("chosen")).toBe(false);
184 expect(qc.toString()).toEqual("");
185 expect(qc.shown()).toBe(false);
186
187 // Click on cell 0:2 "Der"
Akron70903c42018-02-05 12:31:10 +0100188 cell = matchTable.querySelector("thead > tr > th:nth-child(3)")
Akronbdcbbf42018-04-25 12:42:44 +0200189 expect(cell.innerString()).toEqual("Der");
Akronb46d8e32017-06-29 14:26:14 +0200190 cell.click();
191 expect(cell.classList.contains("chosen")).toBeTruthy();
192 expect(qc.toString()).toEqual("[orth=Der]");
193 expect(qc.shown()).toBeTruthy();
194
195 // Click on cell 0:2 "Der" again - to hide
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")).toBe(false);
200 expect(qc.toString()).toEqual("");
201 expect(qc.shown()).toBe(false);
202 });
203
204 it('should create tokens in arbitrary order', function () {
Akron70903c42018-02-05 12:31:10 +0100205 var matchTable = matchTableFactory();
206 var qc = qcClass.create(matchTable);
Akronb46d8e32017-06-29 14:26:14 +0200207
Akron70903c42018-02-05 12:31:10 +0100208 var cell = matchTable.querySelector("tbody > tr:nth-child(2) > td:nth-child(4)");
Akronbdcbbf42018-04-25 12:42:44 +0200209 expect(cell.innerString()).toEqual("ADJA");
Akronb46d8e32017-06-29 14:26:14 +0200210 cell.click();
211 expect(qc.toString()).toEqual("[opennlp/p=ADJA]");
212
Akron70903c42018-02-05 12:31:10 +0100213 cell = matchTable.querySelector("thead > tr > th:nth-child(4)");
Akronbdcbbf42018-04-25 12:42:44 +0200214 expect(cell.innerString()).toEqual("älteste");
Akronb46d8e32017-06-29 14:26:14 +0200215 cell.click();
216 expect(qc.toString()).toEqual("[opennlp/p=ADJA & orth=älteste]");
217
Akron70903c42018-02-05 12:31:10 +0100218 cell = matchTable.querySelector("tbody > tr > td:nth-child(4)");
Akronbdcbbf42018-04-25 12:42:44 +0200219 expect(cell.innerString()).toEqual("ADJA");
Akronb46d8e32017-06-29 14:26:14 +0200220 cell.click();
221 expect(qc.toString()).toEqual("[corenlp/p=ADJA & opennlp/p=ADJA & orth=älteste]");
222 });
223
224 it('should create token sequences in arbitrary order', function () {
Akron70903c42018-02-05 12:31:10 +0100225 var matchTable = matchTableFactory();
226 var qc = qcClass.create(matchTable);
Akronb46d8e32017-06-29 14:26:14 +0200227
Akron70903c42018-02-05 12:31:10 +0100228 var cell = matchTable.querySelector("thead > tr > th:nth-child(5)");
Akronbdcbbf42018-04-25 12:42:44 +0200229 expect(cell.innerString()).toEqual("lebende");
Akronb46d8e32017-06-29 14:26:14 +0200230 cell.click();
231 expect(qc.toString()).toEqual("[orth=lebende]");
232
Akron70903c42018-02-05 12:31:10 +0100233 cell = matchTable.querySelector("tbody > tr:nth-child(2) > td:nth-child(3)");
Akronbdcbbf42018-04-25 12:42:44 +0200234 expect(cell.innerString()).toEqual("ART");
Akronb46d8e32017-06-29 14:26:14 +0200235 cell.click();
Akrone9be11d2017-06-29 20:10:58 +0200236 expect(qc.toString()).toEqual("[opennlp/p=ART][][orth=lebende]");
Akronb46d8e32017-06-29 14:26:14 +0200237
Akron70903c42018-02-05 12:31:10 +0100238 cell = matchTable.querySelector("tbody > tr > td:nth-child(4)");
Akronbdcbbf42018-04-25 12:42:44 +0200239 expect(cell.innerString()).toEqual("ADJA");
Akronb46d8e32017-06-29 14:26:14 +0200240 cell.click();
241 expect(qc.toString()).toEqual("[opennlp/p=ART][corenlp/p=ADJA][orth=lebende]");
242 });
243
244 it('should remove chosen elements again', function () {
Akron70903c42018-02-05 12:31:10 +0100245 var matchTable = matchTableFactory();
246 var qc = qcClass.create(matchTable);
Akronb46d8e32017-06-29 14:26:14 +0200247
Akron70903c42018-02-05 12:31:10 +0100248 var cell = matchTable.querySelector("tbody > tr:nth-child(2) > td:nth-child(4)");
Akronbdcbbf42018-04-25 12:42:44 +0200249 expect(cell.innerString()).toEqual("ADJA");
Akronb46d8e32017-06-29 14:26:14 +0200250 cell.click();
251 expect(qc.toString()).toEqual("[opennlp/p=ADJA]");
252 var cell1 = cell;
253
Akron70903c42018-02-05 12:31:10 +0100254 cell = matchTable.querySelector("thead > tr > th:nth-child(4)");
Akronbdcbbf42018-04-25 12:42:44 +0200255 expect(cell.innerString()).toEqual("älteste");
Akronb46d8e32017-06-29 14:26:14 +0200256 cell.click();
257 expect(qc.toString()).toEqual("[opennlp/p=ADJA & orth=älteste]");
258 var cell2 = cell;
259
Akron70903c42018-02-05 12:31:10 +0100260 cell = matchTable.querySelector("tbody > tr > td:nth-child(3)");
Akronbdcbbf42018-04-25 12:42:44 +0200261 expect(cell.innerString()).toEqual("ART");
Akronb46d8e32017-06-29 14:26:14 +0200262 cell.click();
263 expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA & orth=älteste]");
264 var cell3 = cell;
265
Akron70903c42018-02-05 12:31:10 +0100266 cell = matchTable.querySelector("thead > tr > th:nth-child(6)");
Akronbdcbbf42018-04-25 12:42:44 +0200267 expect(cell.innerString()).toEqual("Baum");
Akronb46d8e32017-06-29 14:26:14 +0200268 cell.click();
Akrone9be11d2017-06-29 20:10:58 +0200269 expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA & orth=älteste][][orth=Baum]");
Akronb46d8e32017-06-29 14:26:14 +0200270 var cell4 = cell;
271
Akron70903c42018-02-05 12:31:10 +0100272 cell = matchTable.querySelector("thead > tr > th:nth-child(5)");
Akronbdcbbf42018-04-25 12:42:44 +0200273 expect(cell.innerString()).toEqual("lebende");
Akronb46d8e32017-06-29 14:26:14 +0200274 cell.click();
275 expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA & orth=älteste][orth=lebende][orth=Baum]");
276 var cell5 = cell;
277
278
279 // Remove annotations again
280 expect(cell5.classList.contains("chosen")).toBeTruthy();
281 cell5.click()
282 expect(cell5.classList.contains("chosen")).toBe(false);
Akrone9be11d2017-06-29 20:10:58 +0200283 expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA & orth=älteste][][orth=Baum]");
Akronb46d8e32017-06-29 14:26:14 +0200284
285 expect(cell2.classList.contains("chosen")).toBeTruthy();
286 cell2.click()
287 expect(cell2.classList.contains("chosen")).toBe(false);
Akrone9be11d2017-06-29 20:10:58 +0200288 expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA][][orth=Baum]");
Akronb46d8e32017-06-29 14:26:14 +0200289
290 expect(cell1.classList.contains("chosen")).toBeTruthy();
291 cell1.click()
292 expect(cell1.classList.contains("chosen")).toBe(false);
Akrone9be11d2017-06-29 20:10:58 +0200293 expect(qc.toString()).toEqual("[corenlp/p=ART][]{2}[orth=Baum]");
Akronb46d8e32017-06-29 14:26:14 +0200294
295 // Re-add first cell at the same position
296 expect(cell1.classList.contains("chosen")).toBe(false);
297 cell1.click()
298 expect(cell1.classList.contains("chosen")).toBeTruthy();
Akrone9be11d2017-06-29 20:10:58 +0200299 expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA][][orth=Baum]");
Akronb46d8e32017-06-29 14:26:14 +0200300
301 expect(cell3.classList.contains("chosen")).toBeTruthy();
302 cell3.click()
303 expect(cell3.classList.contains("chosen")).toBe(false);
Akrone9be11d2017-06-29 20:10:58 +0200304 expect(qc.toString()).toEqual("[opennlp/p=ADJA][][orth=Baum]");
Akronb46d8e32017-06-29 14:26:14 +0200305
306 expect(cell4.classList.contains("chosen")).toBeTruthy();
307 cell4.click()
308 expect(cell4.classList.contains("chosen")).toBe(false);
309 expect(qc.toString()).toEqual("[opennlp/p=ADJA]");
310
311 // Remove last token
312 expect(qc.shown()).toBeTruthy();
313 expect(qc.element().innerHTML).toEqual("<span>New Query:</span><span>[opennlp/p=ADJA]</span>");
314 expect(cell1.classList.contains("chosen")).toBeTruthy();
315 cell1.click()
316 expect(cell1.classList.contains("chosen")).toBe(false);
317 expect(qc.toString()).toEqual("");
318 expect(qc.shown()).toBe(false);
319
320 // Re-add token
321 expect(cell4.classList.contains("chosen")).toBe(false);
322 cell4.click()
323 expect(cell4.classList.contains("chosen")).toBeTruthy();
324 expect(qc.toString()).toEqual("[orth=Baum]");
325 expect(qc.shown()).toBeTruthy();
326 expect(qc.element().innerHTML).toEqual("<span>New Query:</span><span>[orth=Baum]</span>");
327 });
328
Akronc8461bf2017-06-29 15:05:24 +0200329 it('should ignore empty terms', function () {
Akron70903c42018-02-05 12:31:10 +0100330 var matchTable = matchTableFactory();
331 var qc = qcClass.create(matchTable);
Akronb46d8e32017-06-29 14:26:14 +0200332
Akronc8461bf2017-06-29 15:05:24 +0200333 // Nothing to show
334 expect(qc.toString()).toEqual("");
335 expect(qc.shown()).toBe(false);
336 qc.show();
337 expect(qc.shown()).toBe(false);
Akron7dd32822018-10-01 19:38:31 +0200338 expect(qc.element().className).toEqual("query fragment");
Akronc8461bf2017-06-29 15:05:24 +0200339
Akron70903c42018-02-05 12:31:10 +0100340 var cell = matchTable.querySelector("tbody > tr:nth-child(2) > td:nth-child(4)");
Akronbdcbbf42018-04-25 12:42:44 +0200341 expect(cell.innerString()).toEqual("ADJA");
Akronc8461bf2017-06-29 15:05:24 +0200342 expect(cell.classList.contains("chosen")).toBe(false);
343 cell.click();
344 expect(cell.classList.contains("chosen")).toBeTruthy();
345 expect(qc.toString()).toEqual("[opennlp/p=ADJA]");
346
Akron70903c42018-02-05 12:31:10 +0100347 cell = matchTable.querySelector("tbody > tr:nth-child(2) > td:nth-child(5)");
Akronbdcbbf42018-04-25 12:42:44 +0200348 expect(cell.innerString()).toEqual("");
Akronc8461bf2017-06-29 15:05:24 +0200349 expect(cell.classList.contains("chosen")).toBe(false);
350 cell.click();
351 expect(cell.classList.contains("chosen")).toBe(false);
352 expect(qc.toString()).toEqual("[opennlp/p=ADJA]");
353
354 });
355
Akron7cf33fd2017-07-03 17:33:39 +0200356 it('should create or-groups for alternative terms', function () {
Akron70903c42018-02-05 12:31:10 +0100357 var matchTable = matchTableFactory();
358 var qc = qcClass.create(matchTable);
Akronc8461bf2017-06-29 15:05:24 +0200359
360 // Nothing to show
361 expect(qc.toString()).toEqual("");
362 expect(qc.shown()).toBe(false);
363 qc.show();
364 expect(qc.shown()).toBe(false);
Akron7dd32822018-10-01 19:38:31 +0200365 expect(qc.element().className).toEqual("query fragment");
Akronc8461bf2017-06-29 15:05:24 +0200366
Akron70903c42018-02-05 12:31:10 +0100367 var cell = matchTable.querySelector("thead > tr > th:nth-child(5)");
Akronbdcbbf42018-04-25 12:42:44 +0200368 expect(cell.innerString()).toEqual("lebende");
Akronc8461bf2017-06-29 15:05:24 +0200369 expect(cell.classList.contains("chosen")).toBe(false);
370 cell.click();
371 expect(cell.classList.contains("chosen")).toBeTruthy();
372 expect(qc.toString()).toEqual("[orth=lebende]");
373
Akron70903c42018-02-05 12:31:10 +0100374 cell = matchTable.querySelector("tbody > tr:nth-child(1) > td:nth-child(5)");
Akronbdcbbf42018-04-25 12:42:44 +0200375 expect(cell.innerString()).toEqual("ADJAADJD");
Akronc8461bf2017-06-29 15:05:24 +0200376 expect(cell.classList.contains("chosen")).toBe(false);
377 cell.click();
378 expect(cell.classList.contains("chosen")).toBeTruthy();
379 expect(qc.toString()).toEqual("[(corenlp/p=ADJA | corenlp/p=ADJD) & orth=lebende]");
380
381 // Remove or group again
382 expect(cell.classList.contains("chosen")).toBeTruthy();
383 cell.click();
384 expect(cell.classList.contains("chosen")).toBe(false);
385 expect(qc.toString()).toEqual("[orth=lebende]");
386 });
387
388
389 it('should add whole rows', function () {
Akron70903c42018-02-05 12:31:10 +0100390 var matchTable = matchTableFactory();
391 var qc = qcClass.create(matchTable);
Akronc8461bf2017-06-29 15:05:24 +0200392
393 // Nothing to show
394 expect(qc.toString()).toEqual("");
395 expect(qc.shown()).toBe(false);
396 qc.show();
397 expect(qc.shown()).toBe(false);
Akron7dd32822018-10-01 19:38:31 +0200398 expect(qc.element().className).toEqual("query fragment");
Akronc8461bf2017-06-29 15:05:24 +0200399
Akron70903c42018-02-05 12:31:10 +0100400 var corenlpRow = matchTable.querySelector("tbody > tr:nth-child(1)");
Akronc8461bf2017-06-29 15:05:24 +0200401
402 var cell = corenlpRow.querySelector("td:nth-child(4)");
Akronbdcbbf42018-04-25 12:42:44 +0200403 expect(cell.innerString()).toEqual("ADJA");
Akronc8461bf2017-06-29 15:05:24 +0200404 expect(cell.classList.contains("chosen")).toBe(false);
405 cell.click();
406 expect(cell.classList.contains("chosen")).toBeTruthy();
407
408 // Activate another cell in another row
Akron70903c42018-02-05 12:31:10 +0100409 cell = matchTable.querySelector("tbody > tr:nth-child(2) td:nth-child(3)");
Akronbdcbbf42018-04-25 12:42:44 +0200410 expect(cell.innerString()).toEqual("ART");
Akronc8461bf2017-06-29 15:05:24 +0200411 expect(cell.classList.contains("chosen")).toBe(false);
412 cell.click();
413 expect(cell.classList.contains("chosen")).toBeTruthy();
414
415 expect(corenlpRow.querySelector("td:nth-child(3).chosen")).toBeNull();
416 expect(corenlpRow.querySelector("td:nth-child(4).chosen")).toBeTruthy();
417 expect(corenlpRow.querySelector("td:nth-child(5).chosen")).toBeNull();
418 expect(corenlpRow.querySelector("td:nth-child(6).chosen")).toBeNull();
419
420 expect(qc.toString()).toEqual("[opennlp/p=ART][corenlp/p=ADJA]");
421
422 // Mark all corenlp lists
423 cell = corenlpRow.querySelector("th:nth-child(1)");
Akronbdcbbf42018-04-25 12:42:44 +0200424 expect(cell.innerString()).toEqual("corenlp");
Akronc8461bf2017-06-29 15:05:24 +0200425 expect(cell.classList.contains("chosen")).toBe(false);
426 cell.click();
427 expect(cell.classList.contains("chosen")).toBe(false);
428
429 expect(corenlpRow.querySelector("td:nth-child(3).chosen")).toBeTruthy();
430 expect(corenlpRow.querySelector("td:nth-child(4).chosen")).toBeTruthy();
431 expect(corenlpRow.querySelector("td:nth-child(5).chosen")).toBeTruthy();
432 expect(corenlpRow.querySelector("td:nth-child(6).chosen")).toBeTruthy();
433
434 // Replay the choice without any effect
435 cell = corenlpRow.querySelector("th:nth-child(1)");
Akronbdcbbf42018-04-25 12:42:44 +0200436 expect(cell.innerString()).toEqual("corenlp");
Akronc8461bf2017-06-29 15:05:24 +0200437 expect(cell.classList.contains("chosen")).toBe(false);
438 cell.click();
439 expect(cell.classList.contains("chosen")).toBe(false);
440
441 expect(corenlpRow.querySelector("td:nth-child(3).chosen")).toBeTruthy();
442 expect(corenlpRow.querySelector("td:nth-child(4).chosen")).toBeTruthy();
443 expect(corenlpRow.querySelector("td:nth-child(5).chosen")).toBeTruthy();
444 expect(corenlpRow.querySelector("td:nth-child(6).chosen")).toBeTruthy();
Akrone9be11d2017-06-29 20:10:58 +0200445 expect(corenlpRow.querySelector("td:nth-child(7).chosen")).toBeTruthy();
Akronc8461bf2017-06-29 15:05:24 +0200446
Akrone9be11d2017-06-29 20:10:58 +0200447 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 +0200448
449 // Remove one of the cells again
450 cell = corenlpRow.querySelector("td:nth-child(5).chosen");
Akronbdcbbf42018-04-25 12:42:44 +0200451 expect(cell.innerString()).toEqual("ADJAADJD");
Akronc8461bf2017-06-29 15:05:24 +0200452 expect(cell.classList.contains("chosen")).toBeTruthy();
453 cell.click();
454 expect(cell.classList.contains("chosen")).toBe(false);
Akrone9be11d2017-06-29 20:10:58 +0200455 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 +0200456
457 });
Akron8084cb52017-06-29 17:11:14 +0200458
459 it('should ignore empty terms in whole rows', function () {
Akron70903c42018-02-05 12:31:10 +0100460 var matchTable = matchTableFactory();
461 var qc = qcClass.create(matchTable);
Akron8084cb52017-06-29 17:11:14 +0200462 expect(qc.toString()).toEqual("");
463
Akron70903c42018-02-05 12:31:10 +0100464 var opennlpRow = matchTable.querySelector("tbody > tr:nth-child(2)");
Akron8084cb52017-06-29 17:11:14 +0200465
466 expect(opennlpRow.querySelector("td:nth-child(3).chosen")).toBeNull();
467 expect(opennlpRow.querySelector("td:nth-child(4).chosen")).toBeNull();
468 expect(opennlpRow.querySelector("td:nth-child(5).chosen")).toBeNull();
469 expect(opennlpRow.querySelector("td:nth-child(6).chosen")).toBeNull();
470
471 expect(qc.toString()).toEqual("");
472
473 // Mark all opennlp lists
474 cell = opennlpRow.querySelector("th:nth-child(1)");
Akronbdcbbf42018-04-25 12:42:44 +0200475 expect(cell.innerString()).toEqual("opennlp");
Akron8084cb52017-06-29 17:11:14 +0200476 expect(cell.classList.contains("chosen")).toBe(false);
477 cell.click();
478 expect(cell.classList.contains("chosen")).toBe(false);
479
480 expect(opennlpRow.querySelector("td:nth-child(3).chosen")).toBeTruthy();
481 expect(opennlpRow.querySelector("td:nth-child(4).chosen")).toBeTruthy();
482 expect(opennlpRow.querySelector("td:nth-child(5).chosen")).toBeNull();
483 expect(opennlpRow.querySelector("td:nth-child(6).chosen")).toBeTruthy();
Akron7cf33fd2017-07-03 17:33:39 +0200484
485 expect(qc.toString()).toEqual("[opennlp/p=ART][opennlp/p=ADJA][][opennlp/p=NN][opennlp/p=ADV]");
Akron8084cb52017-06-29 17:11:14 +0200486 });
Akrone9be11d2017-06-29 20:10:58 +0200487
488 it('should support multiple distances', function () {
Akron70903c42018-02-05 12:31:10 +0100489 var matchTable = matchTableFactory();
490 var qc = qcClass.create(matchTable);
Akrone9be11d2017-06-29 20:10:58 +0200491
Akron70903c42018-02-05 12:31:10 +0100492 var cell = matchTable.querySelector("thead > tr > th:nth-child(3)");
Akronbdcbbf42018-04-25 12:42:44 +0200493 expect(cell.innerString()).toEqual("Der");
Akrone9be11d2017-06-29 20:10:58 +0200494 cell.click();
495 expect(qc.toString()).toEqual("[orth=Der]");
496
Akron70903c42018-02-05 12:31:10 +0100497 cell = matchTable.querySelector("thead > tr > th:nth-child(7)");
Akronbdcbbf42018-04-25 12:42:44 +0200498 expect(cell.innerString()).toEqual("hier");
Akrone9be11d2017-06-29 20:10:58 +0200499 cell.click();
500 expect(qc.toString()).toEqual("[orth=Der][]{3}[orth=hier]");
501
Akron70903c42018-02-05 12:31:10 +0100502 cell = matchTable.querySelector("thead > tr > th:nth-child(5)");
Akronbdcbbf42018-04-25 12:42:44 +0200503 expect(cell.innerString()).toEqual("lebende");
Akrone9be11d2017-06-29 20:10:58 +0200504 cell.click();
505 expect(qc.toString()).toEqual("[orth=Der][][orth=lebende][][orth=hier]");
506 });
Akron7cf33fd2017-07-03 17:33:39 +0200507
508 it('should create and-groups for key-value terms', function () {
Akronefed2e22021-11-16 23:16:54 +0100509 const matchTable = matchTableComplexFactory();
510 const qc = qcClass.create(matchTable);
Akron7cf33fd2017-07-03 17:33:39 +0200511
512 // Nothing to show
513 expect(qc.toString()).toEqual("");
514 expect(qc.shown()).toBe(false);
515 qc.show();
516 expect(qc.shown()).toBe(false);
Akron7dd32822018-10-01 19:38:31 +0200517 expect(qc.element().className).toEqual("query fragment");
Akron7cf33fd2017-07-03 17:33:39 +0200518
Akronefed2e22021-11-16 23:16:54 +0100519 let cell = matchTable.querySelector("thead > tr > th:nth-child(5)");
Akron0d612d12019-05-21 16:45:49 +0200520 expect(cell.innerString()).toEqual("lebende und sterbende");
Akron7cf33fd2017-07-03 17:33:39 +0200521 expect(cell.classList.contains("chosen")).toBe(false);
522 cell.click();
523 expect(cell.classList.contains("chosen")).toBeTruthy();
Akron0d612d12019-05-21 16:45:49 +0200524 expect(qc.toString()).toEqual("[orth='lebende und sterbende']");
Akron7cf33fd2017-07-03 17:33:39 +0200525
526 // Check complex cell
Akron70903c42018-02-05 12:31:10 +0100527 cell = matchTable.querySelector("tbody > tr:nth-child(1) > td:nth-child(6)");
Akronbdcbbf42018-04-25 12:42:44 +0200528 expect(cell.innerString()).toMatch(/case:nom/);
Akron7cf33fd2017-07-03 17:33:39 +0200529 expect(cell.classList.contains("chosen")).toBe(false);
530 cell.click();
531 expect(cell.classList.contains("chosen")).toBe(false);
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 div
Akron70903c42018-02-05 12:31:10 +0100535 cell = matchTable.querySelector("tbody > tr:nth-child(1) > td:nth-child(6) > div:nth-child(1)");
Akronbdcbbf42018-04-25 12:42:44 +0200536 expect(cell.innerString()).toEqual('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(true);
Akron0d612d12019-05-21 16:45:49 +0200540 expect(qc.toString()).toEqual("[orth='lebende und sterbende'][corenlp/p=case:nom]");
Akron7cf33fd2017-07-03 17:33:39 +0200541
Akron70903c42018-02-05 12:31:10 +0100542 cell = matchTable.querySelector("tbody > tr:nth-child(1) > td:nth-child(6) > div:nth-child(3)");
Akronbdcbbf42018-04-25 12:42:44 +0200543 expect(cell.innerString()).toEqual('number:sg');
Akron7cf33fd2017-07-03 17:33:39 +0200544 expect(cell.classList.contains("chosen")).toBe(false);
545 cell.click();
546 expect(cell.classList.contains("chosen")).toBe(true);
Akron0d612d12019-05-21 16:45:49 +0200547 expect(qc.toString()).toEqual("[orth='lebende und sterbende'][corenlp/p=case:nom & corenlp/p=number:sg]");
Akronefed2e22021-11-16 23:16:54 +0100548 let cell2 = cell;
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(2)");
Akronbdcbbf42018-04-25 12:42:44 +0200551 expect(cell.innerString()).toEqual('gender:mascgender:fem');
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=gender:fem | corenlp/p=gender:masc) & corenlp/p=case:nom & corenlp/p=number:sg]");
Akronefed2e22021-11-16 23:16:54 +0100556 let cell3 = cell;
Akron7cf33fd2017-07-03 17:33:39 +0200557
558 // Remove cell again
559 cell = cell2;
Akronbdcbbf42018-04-25 12:42:44 +0200560 expect(cell.innerString()).toEqual('number:sg');
Akron7cf33fd2017-07-03 17:33:39 +0200561 expect(cell.classList.contains("chosen")).toBe(true);
562 cell.click();
563 expect(cell.classList.contains("chosen")).toBe(false);
Akron0d612d12019-05-21 16:45:49 +0200564 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 +0200565
566 // Remove cell again
567 cell = cell3;
Akronbdcbbf42018-04-25 12:42:44 +0200568 expect(cell.innerString()).toEqual('gender:mascgender:fem');
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=case:nom]");
Akron7cf33fd2017-07-03 17:33:39 +0200573 });
574
575
576 it('should create rows including key-value terms', function () {
Akron70903c42018-02-05 12:31:10 +0100577 var matchTable = matchTableComplexFactory();
578 var qc = qcClass.create(matchTable);
Akron7cf33fd2017-07-03 17:33:39 +0200579 expect(qc.toString()).toEqual("");
580
Akron70903c42018-02-05 12:31:10 +0100581 var corenlpRow = matchTable.querySelector("tbody > tr:nth-child(1)");
Akron7cf33fd2017-07-03 17:33:39 +0200582
583 expect(corenlpRow.querySelector("td:nth-child(3).chosen")).toBeNull();
584 expect(corenlpRow.querySelector("td:nth-child(4).chosen")).toBeNull();
585 expect(corenlpRow.querySelector("td:nth-child(5).chosen")).toBeNull();
586 expect(corenlpRow.querySelector("td:nth-child(6) *.chosen")).toBeNull();
587
588 expect(qc.toString()).toEqual("");
589
590 // Mark all opennlp lists
591 cell = corenlpRow.querySelector("th:nth-child(1)");
Akronbdcbbf42018-04-25 12:42:44 +0200592 expect(cell.innerString()).toEqual("corenlp");
Akron7cf33fd2017-07-03 17:33:39 +0200593 expect(cell.classList.contains("chosen")).toBe(false);
594 cell.click();
595 expect(cell.classList.contains("chosen")).toBe(false);
596
597 expect(corenlpRow.querySelector("td:nth-child(3).chosen")).toBeTruthy();
598 expect(corenlpRow.querySelector("td:nth-child(4).chosen")).toBeTruthy();
599 expect(corenlpRow.querySelector("td:nth-child(5).chosen")).toBeTruthy();
600 expect(corenlpRow.querySelector("td:nth-child(6) div:nth-child(1).chosen")).toBeTruthy();
601 expect(corenlpRow.querySelector("td:nth-child(6) div:nth-child(2).chosen")).toBeTruthy();
602 expect(corenlpRow.querySelector("td:nth-child(6) div:nth-child(3).chosen")).toBeTruthy();
603
604 expect(qc.toString()).toEqual(
605 "[corenlp/p=ART]"+
606 "[corenlp/p=ADJA]"+
607 "[(corenlp/p=ADJA | corenlp/p=ADJD)]"+
608 "[(corenlp/p=gender:fem | corenlp/p=gender:masc) & corenlp/p=case:nom & corenlp/p=number:sg]"
609 );
610 });
Akron72245b62018-07-23 10:59:08 +0200611
612 it('should support verbatim strings', function () {
613 var matchTable = matchTableComplexFactory();
614 var qc = qcClass.create(matchTable);
615 expect(qc.toString()).toEqual("");
616
617 // TODO:
618 // This does not respect keys vs values at the moment, but neither does Koral
Akronefed2e22021-11-16 23:16:54 +0100619 let cell = matchTable.querySelector("tbody > tr:nth-child(2) > td > div:nth-child(4)");
Akron72245b62018-07-23 10:59:08 +0200620 expect(cell.innerString()).toEqual("morphemes:.::_SORSZ \\ZERO::NOM 'period::PUNCT'");
621 expect(cell.classList.contains("chosen")).toBe(false);
622 cell.click();
623 expect(cell.classList.contains("chosen")).toBeTruthy();
624 expect(qc.toString()).toEqual("[opennlp/p='morphemes:.::_SORSZ \\\\ZERO::NOM \\\'period::PUNCT\\\'']");
Akron0d612d12019-05-21 16:45:49 +0200625 cell.click()
626 expect(cell.classList.contains("chosen")).toBe(false);
627 expect(qc.toString()).toEqual("");
628
629 cell = matchTable.querySelector("tbody > tr:nth-child(3) > td:nth-child(3)");
630 expect(cell.classList.contains("chosen")).toBe(false);
631 cell.click();
632 expect(cell.classList.contains("chosen")).toBeTruthy();
633 expect(qc.toString()).toEqual("[tt/l='Lese|Lesen']");
634 cell.click()
635 expect(cell.classList.contains("chosen")).toBe(false);
636 expect(qc.toString()).toEqual("");
637
638 cell = matchTable.querySelector("tbody > tr:nth-child(3) > td:nth-child(4)");
639 expect(cell.classList.contains("chosen")).toBe(false);
640 cell.click();
641 expect(cell.classList.contains("chosen")).toBeTruthy();
642 expect(qc.toString()).toEqual("[tt/l='a b']");
643 cell.click()
644 expect(cell.classList.contains("chosen")).toBe(false);
645 expect(qc.toString()).toEqual("");
Akronefed2e22021-11-16 23:16:54 +0100646
647 cell = matchTable.querySelector("tbody > tr:nth-child(2) > td > div:nth-child(5)");
648 expect(cell.innerString()).toEqual("morphemes:ZERO::NOM");
649 expect(cell.classList.contains("chosen")).toBe(false);
650 cell.click();
651 expect(cell.classList.contains("chosen")).toBeTruthy();
652 expect(qc.toString()).toEqual("[opennlp/p='morphemes:ZERO::NOM']");
653 cell.click()
654 expect(cell.classList.contains("chosen")).toBe(false);
655 expect(qc.toString()).toEqual("");
Akron72245b62018-07-23 10:59:08 +0200656 });
Akronaeeb8252018-09-19 18:51:00 +0200657
658 it('should respect marked elements', function () {
659 var matchTable = matchTableComplexFactory();
660 var qc = qcClass.create(matchTable);
661 expect(qc.toString()).toEqual("");
662
663 var cell = matchTable.querySelector("thead > tr > th:nth-child(6)");
664 expect(cell.classList.contains("mark")).toBeTruthy();
665 expect(cell.classList.contains("chosen")).toBeFalsy();
666
667 cell.click();
668 expect(cell.classList.contains("mark")).toBeTruthy();
669 expect(cell.classList.contains("chosen")).toBeTruthy();
670
671 cell.click();
672 expect(cell.classList.contains("mark")).toBeTruthy();
673 expect(cell.classList.contains("chosen")).toBeFalsy();
674 });
Akron083ec572019-05-16 18:30:40 +0200675
676 it('should ignore cutted columns', function () {
677 var matchTable = matchTableCuttedFactory();
678 var qc = qcClass.create(matchTable);
679 expect(qc.toString()).toEqual("");
680
681 var cell = matchTable.querySelector("thead > tr > th:nth-child(3)");
682 expect(cell.classList.contains("chosen")).toBeFalsy();
683 cell.click();
684 expect(cell.classList.contains("chosen")).toBeTruthy();
685 expect(qc.toString()).toEqual("[orth=Baum]");
686
687 cell = matchTable.querySelector("thead > tr > th:nth-child(4)");
688 expect(cell.classList.contains("chosen")).toBeFalsy();
689 expect(cell.classList.contains("cutted")).toBeTruthy();
690 cell.click();
691 expect(cell.classList.contains("chosen")).toBeFalsy();
692 expect(qc.toString()).toEqual("[orth=Baum]");
693 });
Akronb5163742020-10-12 15:31:41 +0200694
695 it('should add fragment to QueryBar', function () {
696 var matchTable = matchTableCuttedFactory();
697 var qc = qcClass.create(matchTable);
698 expect(qc.toString()).toEqual("");
699
700 var cell = matchTable.querySelector("thead > tr > th:nth-child(3)");
701 expect(cell.classList.contains("chosen")).toBeFalsy();
702 cell.click();
703 expect(cell.classList.contains("chosen")).toBeTruthy();
704 expect(qc.toString()).toEqual("[orth=Baum]");
705
706 // May break
707 qc._ql = document.createElement('select');
708 let opt = qc._ql.appendChild(document.createElement('option'));
709 opt.value='cosmas 2';
710 let opt2 = qc._ql.appendChild(document.createElement('option'));
711 opt2.value='poliqarp';
712
713 qc._q = document.createElement('input');
714
Akron24aa0052020-11-10 11:00:34 +0100715 qc._el.click();
Akronb5163742020-10-12 15:31:41 +0200716
717 expect(qc._ql.selectedIndex).toEqual(1);
718 expect(qc._q.value).toEqual("[orth=Baum]");
719 });
Akronb46d8e32017-06-29 14:26:14 +0200720 });
721});