blob: c0953ba9624f7065ba54e425648842083cfdb46b [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>" +
Akron7cf33fd2017-07-03 17:33:39 +020091 " </td>" +
92 " <td>ADJA</td>" +
93 " <td></td>" +
Akronaeeb8252018-09-19 18:51:00 +020094 " <td class=\"mark\">NN</td>" +
Akron7cf33fd2017-07-03 17:33:39 +020095 " </tr>" +
Akron0d612d12019-05-21 16:45:49 +020096 " <tr tabindex=\"0\">" +
97 " <th>tt</th>" +
98 " <th>l</th>" +
99 " <td>Lese|Lesen</td>" +
100 " <td>a b</td>" +
101 " <td></td>" +
102 " <td class=\"mark\">NN</td>" +
103 " </tr>" +
Akron7cf33fd2017-07-03 17:33:39 +0200104 " </tbody>" +
Akron70903c42018-02-05 12:31:10 +0100105 " </table>";
106 var info = document.createElement('div');
107 info.appendChild(table);
108 return table;
Akron7cf33fd2017-07-03 17:33:39 +0200109};
110
Akronb46d8e32017-06-29 14:26:14 +0200111
Akron083ec572019-05-16 18:30:40 +0200112function matchTableCuttedFactory () {
113 var table = document.createElement('div');
114 table.className = 'matchtable';
115 table.innerHTML =
116 " <table>" +
117 " <thead>" +
118 " <tr>" +
119 " <th>Foundry</th>" +
120 " <th>Layer</th>" +
121 " <th>Baum</th>" +
122 " <th class=\"cutted\"></th>" +
123 " </tr>" +
124 " </thead>" +
125 " <tbody>" +
126 " <tr tabindex=\"0\">" +
127 " <th>corenlp</th>" +
128 " <th>p</th>" +
129 " <td>NN</td>" +
130 " <td></td>" +
131 " </tr>" +
132 " <tr tabindex=\"0\">" +
133 " <th>opennlp</th>" +
134 " <th>p</th>" +
135 " <td>NN</td>" +
136 " <td></td>" +
137 " </tr>" +
138 " </tbody>" +
139 " </table>";
140 var info = document.createElement('div');
141 info.appendChild(table);
142 return table;
143};
144
145
Akronb46d8e32017-06-29 14:26:14 +0200146define(['match/querycreator'], function (qcClass) {
147
148 describe('KorAP.QueryCreator', function () {
149
150 it('should be initializable', function () {
151 expect(
152 function() {
153 qcClass.create()
154 }
155 ).toThrow(new Error("Missing parameters"));
156
157 expect(
158 function() {
159 qcClass.create("Test")
160 }
161 ).toThrow(new Error("Requires element"));
162
Akron70903c42018-02-05 12:31:10 +0100163 expect(qcClass.create(matchTableFactory()).toString()).toEqual("");
Akronb46d8e32017-06-29 14:26:14 +0200164 });
165
166 it('should listen to click events', function () {
167
Akron70903c42018-02-05 12:31:10 +0100168 var matchTable = matchTableFactory();
169 var qc = qcClass.create(matchTable);
Akronb46d8e32017-06-29 14:26:14 +0200170
171 // Nothing to show
172 expect(qc.toString()).toEqual("");
173 expect(qc.shown()).toBe(false);
174 qc.show();
175 expect(qc.shown()).toBe(false);
Akron7dd32822018-10-01 19:38:31 +0200176 expect(qc.element().className).toEqual("query fragment");
Akronb46d8e32017-06-29 14:26:14 +0200177
178 // Click on cell 0:0 "Foundry"
Akron70903c42018-02-05 12:31:10 +0100179 var cell = matchTable.querySelector("thead > tr > th:first-child");
Akronbdcbbf42018-04-25 12:42:44 +0200180 expect(cell.innerString()).toEqual("Foundry");
Akronb46d8e32017-06-29 14:26:14 +0200181 cell.click();
182 expect(cell.classList.contains("chosen")).toBe(false);
183 expect(qc.toString()).toEqual("");
184 expect(qc.shown()).toBe(false);
185
186 // Click on cell 0:2 "Der"
Akron70903c42018-02-05 12:31:10 +0100187 cell = matchTable.querySelector("thead > tr > th:nth-child(3)")
Akronbdcbbf42018-04-25 12:42:44 +0200188 expect(cell.innerString()).toEqual("Der");
Akronb46d8e32017-06-29 14:26:14 +0200189 cell.click();
190 expect(cell.classList.contains("chosen")).toBeTruthy();
191 expect(qc.toString()).toEqual("[orth=Der]");
192 expect(qc.shown()).toBeTruthy();
193
194 // Click on cell 0:2 "Der" again - to hide
Akron70903c42018-02-05 12:31:10 +0100195 cell = matchTable.querySelector("thead > tr > th:nth-child(3)")
Akronbdcbbf42018-04-25 12:42:44 +0200196 expect(cell.innerString()).toEqual("Der");
Akronb46d8e32017-06-29 14:26:14 +0200197 cell.click();
198 expect(cell.classList.contains("chosen")).toBe(false);
199 expect(qc.toString()).toEqual("");
200 expect(qc.shown()).toBe(false);
201 });
202
203 it('should create tokens in arbitrary order', function () {
Akron70903c42018-02-05 12:31:10 +0100204 var matchTable = matchTableFactory();
205 var qc = qcClass.create(matchTable);
Akronb46d8e32017-06-29 14:26:14 +0200206
Akron70903c42018-02-05 12:31:10 +0100207 var cell = matchTable.querySelector("tbody > tr:nth-child(2) > td:nth-child(4)");
Akronbdcbbf42018-04-25 12:42:44 +0200208 expect(cell.innerString()).toEqual("ADJA");
Akronb46d8e32017-06-29 14:26:14 +0200209 cell.click();
210 expect(qc.toString()).toEqual("[opennlp/p=ADJA]");
211
Akron70903c42018-02-05 12:31:10 +0100212 cell = matchTable.querySelector("thead > tr > th:nth-child(4)");
Akronbdcbbf42018-04-25 12:42:44 +0200213 expect(cell.innerString()).toEqual("älteste");
Akronb46d8e32017-06-29 14:26:14 +0200214 cell.click();
215 expect(qc.toString()).toEqual("[opennlp/p=ADJA & orth=älteste]");
216
Akron70903c42018-02-05 12:31:10 +0100217 cell = matchTable.querySelector("tbody > tr > td:nth-child(4)");
Akronbdcbbf42018-04-25 12:42:44 +0200218 expect(cell.innerString()).toEqual("ADJA");
Akronb46d8e32017-06-29 14:26:14 +0200219 cell.click();
220 expect(qc.toString()).toEqual("[corenlp/p=ADJA & opennlp/p=ADJA & orth=älteste]");
221 });
222
223 it('should create token sequences in arbitrary order', function () {
Akron70903c42018-02-05 12:31:10 +0100224 var matchTable = matchTableFactory();
225 var qc = qcClass.create(matchTable);
Akronb46d8e32017-06-29 14:26:14 +0200226
Akron70903c42018-02-05 12:31:10 +0100227 var cell = matchTable.querySelector("thead > tr > th:nth-child(5)");
Akronbdcbbf42018-04-25 12:42:44 +0200228 expect(cell.innerString()).toEqual("lebende");
Akronb46d8e32017-06-29 14:26:14 +0200229 cell.click();
230 expect(qc.toString()).toEqual("[orth=lebende]");
231
Akron70903c42018-02-05 12:31:10 +0100232 cell = matchTable.querySelector("tbody > tr:nth-child(2) > td:nth-child(3)");
Akronbdcbbf42018-04-25 12:42:44 +0200233 expect(cell.innerString()).toEqual("ART");
Akronb46d8e32017-06-29 14:26:14 +0200234 cell.click();
Akrone9be11d2017-06-29 20:10:58 +0200235 expect(qc.toString()).toEqual("[opennlp/p=ART][][orth=lebende]");
Akronb46d8e32017-06-29 14:26:14 +0200236
Akron70903c42018-02-05 12:31:10 +0100237 cell = matchTable.querySelector("tbody > tr > td:nth-child(4)");
Akronbdcbbf42018-04-25 12:42:44 +0200238 expect(cell.innerString()).toEqual("ADJA");
Akronb46d8e32017-06-29 14:26:14 +0200239 cell.click();
240 expect(qc.toString()).toEqual("[opennlp/p=ART][corenlp/p=ADJA][orth=lebende]");
241 });
242
243 it('should remove chosen elements again', function () {
Akron70903c42018-02-05 12:31:10 +0100244 var matchTable = matchTableFactory();
245 var qc = qcClass.create(matchTable);
Akronb46d8e32017-06-29 14:26:14 +0200246
Akron70903c42018-02-05 12:31:10 +0100247 var cell = matchTable.querySelector("tbody > tr:nth-child(2) > td:nth-child(4)");
Akronbdcbbf42018-04-25 12:42:44 +0200248 expect(cell.innerString()).toEqual("ADJA");
Akronb46d8e32017-06-29 14:26:14 +0200249 cell.click();
250 expect(qc.toString()).toEqual("[opennlp/p=ADJA]");
251 var cell1 = cell;
252
Akron70903c42018-02-05 12:31:10 +0100253 cell = matchTable.querySelector("thead > tr > th:nth-child(4)");
Akronbdcbbf42018-04-25 12:42:44 +0200254 expect(cell.innerString()).toEqual("älteste");
Akronb46d8e32017-06-29 14:26:14 +0200255 cell.click();
256 expect(qc.toString()).toEqual("[opennlp/p=ADJA & orth=älteste]");
257 var cell2 = cell;
258
Akron70903c42018-02-05 12:31:10 +0100259 cell = matchTable.querySelector("tbody > tr > td:nth-child(3)");
Akronbdcbbf42018-04-25 12:42:44 +0200260 expect(cell.innerString()).toEqual("ART");
Akronb46d8e32017-06-29 14:26:14 +0200261 cell.click();
262 expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA & orth=älteste]");
263 var cell3 = cell;
264
Akron70903c42018-02-05 12:31:10 +0100265 cell = matchTable.querySelector("thead > tr > th:nth-child(6)");
Akronbdcbbf42018-04-25 12:42:44 +0200266 expect(cell.innerString()).toEqual("Baum");
Akronb46d8e32017-06-29 14:26:14 +0200267 cell.click();
Akrone9be11d2017-06-29 20:10:58 +0200268 expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA & orth=älteste][][orth=Baum]");
Akronb46d8e32017-06-29 14:26:14 +0200269 var cell4 = cell;
270
Akron70903c42018-02-05 12:31:10 +0100271 cell = matchTable.querySelector("thead > tr > th:nth-child(5)");
Akronbdcbbf42018-04-25 12:42:44 +0200272 expect(cell.innerString()).toEqual("lebende");
Akronb46d8e32017-06-29 14:26:14 +0200273 cell.click();
274 expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA & orth=älteste][orth=lebende][orth=Baum]");
275 var cell5 = cell;
276
277
278 // Remove annotations again
279 expect(cell5.classList.contains("chosen")).toBeTruthy();
280 cell5.click()
281 expect(cell5.classList.contains("chosen")).toBe(false);
Akrone9be11d2017-06-29 20:10:58 +0200282 expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA & orth=älteste][][orth=Baum]");
Akronb46d8e32017-06-29 14:26:14 +0200283
284 expect(cell2.classList.contains("chosen")).toBeTruthy();
285 cell2.click()
286 expect(cell2.classList.contains("chosen")).toBe(false);
Akrone9be11d2017-06-29 20:10:58 +0200287 expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA][][orth=Baum]");
Akronb46d8e32017-06-29 14:26:14 +0200288
289 expect(cell1.classList.contains("chosen")).toBeTruthy();
290 cell1.click()
291 expect(cell1.classList.contains("chosen")).toBe(false);
Akrone9be11d2017-06-29 20:10:58 +0200292 expect(qc.toString()).toEqual("[corenlp/p=ART][]{2}[orth=Baum]");
Akronb46d8e32017-06-29 14:26:14 +0200293
294 // Re-add first cell at the same position
295 expect(cell1.classList.contains("chosen")).toBe(false);
296 cell1.click()
297 expect(cell1.classList.contains("chosen")).toBeTruthy();
Akrone9be11d2017-06-29 20:10:58 +0200298 expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA][][orth=Baum]");
Akronb46d8e32017-06-29 14:26:14 +0200299
300 expect(cell3.classList.contains("chosen")).toBeTruthy();
301 cell3.click()
302 expect(cell3.classList.contains("chosen")).toBe(false);
Akrone9be11d2017-06-29 20:10:58 +0200303 expect(qc.toString()).toEqual("[opennlp/p=ADJA][][orth=Baum]");
Akronb46d8e32017-06-29 14:26:14 +0200304
305 expect(cell4.classList.contains("chosen")).toBeTruthy();
306 cell4.click()
307 expect(cell4.classList.contains("chosen")).toBe(false);
308 expect(qc.toString()).toEqual("[opennlp/p=ADJA]");
309
310 // Remove last token
311 expect(qc.shown()).toBeTruthy();
312 expect(qc.element().innerHTML).toEqual("<span>New Query:</span><span>[opennlp/p=ADJA]</span>");
313 expect(cell1.classList.contains("chosen")).toBeTruthy();
314 cell1.click()
315 expect(cell1.classList.contains("chosen")).toBe(false);
316 expect(qc.toString()).toEqual("");
317 expect(qc.shown()).toBe(false);
318
319 // Re-add token
320 expect(cell4.classList.contains("chosen")).toBe(false);
321 cell4.click()
322 expect(cell4.classList.contains("chosen")).toBeTruthy();
323 expect(qc.toString()).toEqual("[orth=Baum]");
324 expect(qc.shown()).toBeTruthy();
325 expect(qc.element().innerHTML).toEqual("<span>New Query:</span><span>[orth=Baum]</span>");
326 });
327
Akronc8461bf2017-06-29 15:05:24 +0200328 it('should ignore empty terms', function () {
Akron70903c42018-02-05 12:31:10 +0100329 var matchTable = matchTableFactory();
330 var qc = qcClass.create(matchTable);
Akronb46d8e32017-06-29 14:26:14 +0200331
Akronc8461bf2017-06-29 15:05:24 +0200332 // Nothing to show
333 expect(qc.toString()).toEqual("");
334 expect(qc.shown()).toBe(false);
335 qc.show();
336 expect(qc.shown()).toBe(false);
Akron7dd32822018-10-01 19:38:31 +0200337 expect(qc.element().className).toEqual("query fragment");
Akronc8461bf2017-06-29 15:05:24 +0200338
Akron70903c42018-02-05 12:31:10 +0100339 var cell = matchTable.querySelector("tbody > tr:nth-child(2) > td:nth-child(4)");
Akronbdcbbf42018-04-25 12:42:44 +0200340 expect(cell.innerString()).toEqual("ADJA");
Akronc8461bf2017-06-29 15:05:24 +0200341 expect(cell.classList.contains("chosen")).toBe(false);
342 cell.click();
343 expect(cell.classList.contains("chosen")).toBeTruthy();
344 expect(qc.toString()).toEqual("[opennlp/p=ADJA]");
345
Akron70903c42018-02-05 12:31:10 +0100346 cell = matchTable.querySelector("tbody > tr:nth-child(2) > td:nth-child(5)");
Akronbdcbbf42018-04-25 12:42:44 +0200347 expect(cell.innerString()).toEqual("");
Akronc8461bf2017-06-29 15:05:24 +0200348 expect(cell.classList.contains("chosen")).toBe(false);
349 cell.click();
350 expect(cell.classList.contains("chosen")).toBe(false);
351 expect(qc.toString()).toEqual("[opennlp/p=ADJA]");
352
353 });
354
Akron7cf33fd2017-07-03 17:33:39 +0200355 it('should create or-groups for alternative terms', function () {
Akron70903c42018-02-05 12:31:10 +0100356 var matchTable = matchTableFactory();
357 var qc = qcClass.create(matchTable);
Akronc8461bf2017-06-29 15:05:24 +0200358
359 // Nothing to show
360 expect(qc.toString()).toEqual("");
361 expect(qc.shown()).toBe(false);
362 qc.show();
363 expect(qc.shown()).toBe(false);
Akron7dd32822018-10-01 19:38:31 +0200364 expect(qc.element().className).toEqual("query fragment");
Akronc8461bf2017-06-29 15:05:24 +0200365
Akron70903c42018-02-05 12:31:10 +0100366 var cell = matchTable.querySelector("thead > tr > th:nth-child(5)");
Akronbdcbbf42018-04-25 12:42:44 +0200367 expect(cell.innerString()).toEqual("lebende");
Akronc8461bf2017-06-29 15:05:24 +0200368 expect(cell.classList.contains("chosen")).toBe(false);
369 cell.click();
370 expect(cell.classList.contains("chosen")).toBeTruthy();
371 expect(qc.toString()).toEqual("[orth=lebende]");
372
Akron70903c42018-02-05 12:31:10 +0100373 cell = matchTable.querySelector("tbody > tr:nth-child(1) > td:nth-child(5)");
Akronbdcbbf42018-04-25 12:42:44 +0200374 expect(cell.innerString()).toEqual("ADJAADJD");
Akronc8461bf2017-06-29 15:05:24 +0200375 expect(cell.classList.contains("chosen")).toBe(false);
376 cell.click();
377 expect(cell.classList.contains("chosen")).toBeTruthy();
378 expect(qc.toString()).toEqual("[(corenlp/p=ADJA | corenlp/p=ADJD) & orth=lebende]");
379
380 // Remove or group again
381 expect(cell.classList.contains("chosen")).toBeTruthy();
382 cell.click();
383 expect(cell.classList.contains("chosen")).toBe(false);
384 expect(qc.toString()).toEqual("[orth=lebende]");
385 });
386
387
388 it('should add whole rows', function () {
Akron70903c42018-02-05 12:31:10 +0100389 var matchTable = matchTableFactory();
390 var qc = qcClass.create(matchTable);
Akronc8461bf2017-06-29 15:05:24 +0200391
392 // Nothing to show
393 expect(qc.toString()).toEqual("");
394 expect(qc.shown()).toBe(false);
395 qc.show();
396 expect(qc.shown()).toBe(false);
Akron7dd32822018-10-01 19:38:31 +0200397 expect(qc.element().className).toEqual("query fragment");
Akronc8461bf2017-06-29 15:05:24 +0200398
Akron70903c42018-02-05 12:31:10 +0100399 var corenlpRow = matchTable.querySelector("tbody > tr:nth-child(1)");
Akronc8461bf2017-06-29 15:05:24 +0200400
401 var cell = corenlpRow.querySelector("td:nth-child(4)");
Akronbdcbbf42018-04-25 12:42:44 +0200402 expect(cell.innerString()).toEqual("ADJA");
Akronc8461bf2017-06-29 15:05:24 +0200403 expect(cell.classList.contains("chosen")).toBe(false);
404 cell.click();
405 expect(cell.classList.contains("chosen")).toBeTruthy();
406
407 // Activate another cell in another row
Akron70903c42018-02-05 12:31:10 +0100408 cell = matchTable.querySelector("tbody > tr:nth-child(2) td:nth-child(3)");
Akronbdcbbf42018-04-25 12:42:44 +0200409 expect(cell.innerString()).toEqual("ART");
Akronc8461bf2017-06-29 15:05:24 +0200410 expect(cell.classList.contains("chosen")).toBe(false);
411 cell.click();
412 expect(cell.classList.contains("chosen")).toBeTruthy();
413
414 expect(corenlpRow.querySelector("td:nth-child(3).chosen")).toBeNull();
415 expect(corenlpRow.querySelector("td:nth-child(4).chosen")).toBeTruthy();
416 expect(corenlpRow.querySelector("td:nth-child(5).chosen")).toBeNull();
417 expect(corenlpRow.querySelector("td:nth-child(6).chosen")).toBeNull();
418
419 expect(qc.toString()).toEqual("[opennlp/p=ART][corenlp/p=ADJA]");
420
421 // Mark all corenlp lists
422 cell = corenlpRow.querySelector("th:nth-child(1)");
Akronbdcbbf42018-04-25 12:42:44 +0200423 expect(cell.innerString()).toEqual("corenlp");
Akronc8461bf2017-06-29 15:05:24 +0200424 expect(cell.classList.contains("chosen")).toBe(false);
425 cell.click();
426 expect(cell.classList.contains("chosen")).toBe(false);
427
428 expect(corenlpRow.querySelector("td:nth-child(3).chosen")).toBeTruthy();
429 expect(corenlpRow.querySelector("td:nth-child(4).chosen")).toBeTruthy();
430 expect(corenlpRow.querySelector("td:nth-child(5).chosen")).toBeTruthy();
431 expect(corenlpRow.querySelector("td:nth-child(6).chosen")).toBeTruthy();
432
433 // Replay the choice without any effect
434 cell = corenlpRow.querySelector("th:nth-child(1)");
Akronbdcbbf42018-04-25 12:42:44 +0200435 expect(cell.innerString()).toEqual("corenlp");
Akronc8461bf2017-06-29 15:05:24 +0200436 expect(cell.classList.contains("chosen")).toBe(false);
437 cell.click();
438 expect(cell.classList.contains("chosen")).toBe(false);
439
440 expect(corenlpRow.querySelector("td:nth-child(3).chosen")).toBeTruthy();
441 expect(corenlpRow.querySelector("td:nth-child(4).chosen")).toBeTruthy();
442 expect(corenlpRow.querySelector("td:nth-child(5).chosen")).toBeTruthy();
443 expect(corenlpRow.querySelector("td:nth-child(6).chosen")).toBeTruthy();
Akrone9be11d2017-06-29 20:10:58 +0200444 expect(corenlpRow.querySelector("td:nth-child(7).chosen")).toBeTruthy();
Akronc8461bf2017-06-29 15:05:24 +0200445
Akrone9be11d2017-06-29 20:10:58 +0200446 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 +0200447
448 // Remove one of the cells again
449 cell = corenlpRow.querySelector("td:nth-child(5).chosen");
Akronbdcbbf42018-04-25 12:42:44 +0200450 expect(cell.innerString()).toEqual("ADJAADJD");
Akronc8461bf2017-06-29 15:05:24 +0200451 expect(cell.classList.contains("chosen")).toBeTruthy();
452 cell.click();
453 expect(cell.classList.contains("chosen")).toBe(false);
Akrone9be11d2017-06-29 20:10:58 +0200454 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 +0200455
456 });
Akron8084cb52017-06-29 17:11:14 +0200457
458 it('should ignore empty terms in whole rows', function () {
Akron70903c42018-02-05 12:31:10 +0100459 var matchTable = matchTableFactory();
460 var qc = qcClass.create(matchTable);
Akron8084cb52017-06-29 17:11:14 +0200461 expect(qc.toString()).toEqual("");
462
Akron70903c42018-02-05 12:31:10 +0100463 var opennlpRow = matchTable.querySelector("tbody > tr:nth-child(2)");
Akron8084cb52017-06-29 17:11:14 +0200464
465 expect(opennlpRow.querySelector("td:nth-child(3).chosen")).toBeNull();
466 expect(opennlpRow.querySelector("td:nth-child(4).chosen")).toBeNull();
467 expect(opennlpRow.querySelector("td:nth-child(5).chosen")).toBeNull();
468 expect(opennlpRow.querySelector("td:nth-child(6).chosen")).toBeNull();
469
470 expect(qc.toString()).toEqual("");
471
472 // Mark all opennlp lists
473 cell = opennlpRow.querySelector("th:nth-child(1)");
Akronbdcbbf42018-04-25 12:42:44 +0200474 expect(cell.innerString()).toEqual("opennlp");
Akron8084cb52017-06-29 17:11:14 +0200475 expect(cell.classList.contains("chosen")).toBe(false);
476 cell.click();
477 expect(cell.classList.contains("chosen")).toBe(false);
478
479 expect(opennlpRow.querySelector("td:nth-child(3).chosen")).toBeTruthy();
480 expect(opennlpRow.querySelector("td:nth-child(4).chosen")).toBeTruthy();
481 expect(opennlpRow.querySelector("td:nth-child(5).chosen")).toBeNull();
482 expect(opennlpRow.querySelector("td:nth-child(6).chosen")).toBeTruthy();
Akron7cf33fd2017-07-03 17:33:39 +0200483
484 expect(qc.toString()).toEqual("[opennlp/p=ART][opennlp/p=ADJA][][opennlp/p=NN][opennlp/p=ADV]");
Akron8084cb52017-06-29 17:11:14 +0200485 });
Akrone9be11d2017-06-29 20:10:58 +0200486
487 it('should support multiple distances', function () {
Akron70903c42018-02-05 12:31:10 +0100488 var matchTable = matchTableFactory();
489 var qc = qcClass.create(matchTable);
Akrone9be11d2017-06-29 20:10:58 +0200490
Akron70903c42018-02-05 12:31:10 +0100491 var cell = matchTable.querySelector("thead > tr > th:nth-child(3)");
Akronbdcbbf42018-04-25 12:42:44 +0200492 expect(cell.innerString()).toEqual("Der");
Akrone9be11d2017-06-29 20:10:58 +0200493 cell.click();
494 expect(qc.toString()).toEqual("[orth=Der]");
495
Akron70903c42018-02-05 12:31:10 +0100496 cell = matchTable.querySelector("thead > tr > th:nth-child(7)");
Akronbdcbbf42018-04-25 12:42:44 +0200497 expect(cell.innerString()).toEqual("hier");
Akrone9be11d2017-06-29 20:10:58 +0200498 cell.click();
499 expect(qc.toString()).toEqual("[orth=Der][]{3}[orth=hier]");
500
Akron70903c42018-02-05 12:31:10 +0100501 cell = matchTable.querySelector("thead > tr > th:nth-child(5)");
Akronbdcbbf42018-04-25 12:42:44 +0200502 expect(cell.innerString()).toEqual("lebende");
Akrone9be11d2017-06-29 20:10:58 +0200503 cell.click();
504 expect(qc.toString()).toEqual("[orth=Der][][orth=lebende][][orth=hier]");
505 });
Akron7cf33fd2017-07-03 17:33:39 +0200506
507 it('should create and-groups for key-value terms', function () {
Akron70903c42018-02-05 12:31:10 +0100508 var matchTable = matchTableComplexFactory();
509 var qc = qcClass.create(matchTable);
Akron7cf33fd2017-07-03 17:33:39 +0200510
511 // Nothing to show
512 expect(qc.toString()).toEqual("");
513 expect(qc.shown()).toBe(false);
514 qc.show();
515 expect(qc.shown()).toBe(false);
Akron7dd32822018-10-01 19:38:31 +0200516 expect(qc.element().className).toEqual("query fragment");
Akron7cf33fd2017-07-03 17:33:39 +0200517
Akron70903c42018-02-05 12:31:10 +0100518 var cell = matchTable.querySelector("thead > tr > th:nth-child(5)");
Akron0d612d12019-05-21 16:45:49 +0200519 expect(cell.innerString()).toEqual("lebende und sterbende");
Akron7cf33fd2017-07-03 17:33:39 +0200520 expect(cell.classList.contains("chosen")).toBe(false);
521 cell.click();
522 expect(cell.classList.contains("chosen")).toBeTruthy();
Akron0d612d12019-05-21 16:45:49 +0200523 expect(qc.toString()).toEqual("[orth='lebende und sterbende']");
Akron7cf33fd2017-07-03 17:33:39 +0200524
525 // Check complex cell
Akron70903c42018-02-05 12:31:10 +0100526 cell = matchTable.querySelector("tbody > tr:nth-child(1) > td:nth-child(6)");
Akronbdcbbf42018-04-25 12:42:44 +0200527 expect(cell.innerString()).toMatch(/case:nom/);
Akron7cf33fd2017-07-03 17:33:39 +0200528 expect(cell.classList.contains("chosen")).toBe(false);
529 cell.click();
530 expect(cell.classList.contains("chosen")).toBe(false);
Akron0d612d12019-05-21 16:45:49 +0200531 expect(qc.toString()).toEqual("[orth='lebende und sterbende']");
Akron7cf33fd2017-07-03 17:33:39 +0200532
533 // Check complex cell div
Akron70903c42018-02-05 12:31:10 +0100534 cell = matchTable.querySelector("tbody > tr:nth-child(1) > td:nth-child(6) > div:nth-child(1)");
Akronbdcbbf42018-04-25 12:42:44 +0200535 expect(cell.innerString()).toEqual('case:nom');
Akron7cf33fd2017-07-03 17:33:39 +0200536 expect(cell.classList.contains("chosen")).toBe(false);
537 cell.click();
538 expect(cell.classList.contains("chosen")).toBe(true);
Akron0d612d12019-05-21 16:45:49 +0200539 expect(qc.toString()).toEqual("[orth='lebende und sterbende'][corenlp/p=case:nom]");
Akron7cf33fd2017-07-03 17:33:39 +0200540 var cell = cell;
541
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]");
Akron7cf33fd2017-07-03 17:33:39 +0200548 var cell2 = cell;
549
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]");
Akron7cf33fd2017-07-03 17:33:39 +0200556 var cell3 = cell;
557
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
619 var cell = matchTable.querySelector("tbody > tr:nth-child(2) > td > div:nth-child(4)");
620 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("");
Akron72245b62018-07-23 10:59:08 +0200646 });
Akronaeeb8252018-09-19 18:51:00 +0200647
648 it('should respect marked elements', function () {
649 var matchTable = matchTableComplexFactory();
650 var qc = qcClass.create(matchTable);
651 expect(qc.toString()).toEqual("");
652
653 var cell = matchTable.querySelector("thead > tr > th:nth-child(6)");
654 expect(cell.classList.contains("mark")).toBeTruthy();
655 expect(cell.classList.contains("chosen")).toBeFalsy();
656
657 cell.click();
658 expect(cell.classList.contains("mark")).toBeTruthy();
659 expect(cell.classList.contains("chosen")).toBeTruthy();
660
661 cell.click();
662 expect(cell.classList.contains("mark")).toBeTruthy();
663 expect(cell.classList.contains("chosen")).toBeFalsy();
664 });
Akron083ec572019-05-16 18:30:40 +0200665
666 it('should ignore cutted columns', function () {
667 var matchTable = matchTableCuttedFactory();
668 var qc = qcClass.create(matchTable);
669 expect(qc.toString()).toEqual("");
670
671 var cell = matchTable.querySelector("thead > tr > th:nth-child(3)");
672 expect(cell.classList.contains("chosen")).toBeFalsy();
673 cell.click();
674 expect(cell.classList.contains("chosen")).toBeTruthy();
675 expect(qc.toString()).toEqual("[orth=Baum]");
676
677 cell = matchTable.querySelector("thead > tr > th:nth-child(4)");
678 expect(cell.classList.contains("chosen")).toBeFalsy();
679 expect(cell.classList.contains("cutted")).toBeTruthy();
680 cell.click();
681 expect(cell.classList.contains("chosen")).toBeFalsy();
682 expect(qc.toString()).toEqual("[orth=Baum]");
683 });
Akronb46d8e32017-06-29 14:26:14 +0200684 });
685});