blob: 70f3f34a838445bde4c342715840aeb8de703a01 [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>" +
66 " <th>lebende</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>" +
96 " </tbody>" +
Akron70903c42018-02-05 12:31:10 +010097 " </table>";
98 var info = document.createElement('div');
99 info.appendChild(table);
100 return table;
Akron7cf33fd2017-07-03 17:33:39 +0200101};
102
Akronb46d8e32017-06-29 14:26:14 +0200103
Akron083ec572019-05-16 18:30:40 +0200104function matchTableCuttedFactory () {
105 var table = document.createElement('div');
106 table.className = 'matchtable';
107 table.innerHTML =
108 " <table>" +
109 " <thead>" +
110 " <tr>" +
111 " <th>Foundry</th>" +
112 " <th>Layer</th>" +
113 " <th>Baum</th>" +
114 " <th class=\"cutted\"></th>" +
115 " </tr>" +
116 " </thead>" +
117 " <tbody>" +
118 " <tr tabindex=\"0\">" +
119 " <th>corenlp</th>" +
120 " <th>p</th>" +
121 " <td>NN</td>" +
122 " <td></td>" +
123 " </tr>" +
124 " <tr tabindex=\"0\">" +
125 " <th>opennlp</th>" +
126 " <th>p</th>" +
127 " <td>NN</td>" +
128 " <td></td>" +
129 " </tr>" +
130 " </tbody>" +
131 " </table>";
132 var info = document.createElement('div');
133 info.appendChild(table);
134 return table;
135};
136
137
Akronb46d8e32017-06-29 14:26:14 +0200138define(['match/querycreator'], function (qcClass) {
139
140 describe('KorAP.QueryCreator', function () {
141
142 it('should be initializable', function () {
143 expect(
144 function() {
145 qcClass.create()
146 }
147 ).toThrow(new Error("Missing parameters"));
148
149 expect(
150 function() {
151 qcClass.create("Test")
152 }
153 ).toThrow(new Error("Requires element"));
154
Akron70903c42018-02-05 12:31:10 +0100155 expect(qcClass.create(matchTableFactory()).toString()).toEqual("");
Akronb46d8e32017-06-29 14:26:14 +0200156 });
157
158 it('should listen to click events', function () {
159
Akron70903c42018-02-05 12:31:10 +0100160 var matchTable = matchTableFactory();
161 var qc = qcClass.create(matchTable);
Akronb46d8e32017-06-29 14:26:14 +0200162
163 // Nothing to show
164 expect(qc.toString()).toEqual("");
165 expect(qc.shown()).toBe(false);
166 qc.show();
167 expect(qc.shown()).toBe(false);
Akron7dd32822018-10-01 19:38:31 +0200168 expect(qc.element().className).toEqual("query fragment");
Akronb46d8e32017-06-29 14:26:14 +0200169
170 // Click on cell 0:0 "Foundry"
Akron70903c42018-02-05 12:31:10 +0100171 var cell = matchTable.querySelector("thead > tr > th:first-child");
Akronbdcbbf42018-04-25 12:42:44 +0200172 expect(cell.innerString()).toEqual("Foundry");
Akronb46d8e32017-06-29 14:26:14 +0200173 cell.click();
174 expect(cell.classList.contains("chosen")).toBe(false);
175 expect(qc.toString()).toEqual("");
176 expect(qc.shown()).toBe(false);
177
178 // Click on cell 0:2 "Der"
Akron70903c42018-02-05 12:31:10 +0100179 cell = matchTable.querySelector("thead > tr > th:nth-child(3)")
Akronbdcbbf42018-04-25 12:42:44 +0200180 expect(cell.innerString()).toEqual("Der");
Akronb46d8e32017-06-29 14:26:14 +0200181 cell.click();
182 expect(cell.classList.contains("chosen")).toBeTruthy();
183 expect(qc.toString()).toEqual("[orth=Der]");
184 expect(qc.shown()).toBeTruthy();
185
186 // Click on cell 0:2 "Der" again - to hide
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")).toBe(false);
191 expect(qc.toString()).toEqual("");
192 expect(qc.shown()).toBe(false);
193 });
194
195 it('should create tokens in arbitrary order', function () {
Akron70903c42018-02-05 12:31:10 +0100196 var matchTable = matchTableFactory();
197 var qc = qcClass.create(matchTable);
Akronb46d8e32017-06-29 14:26:14 +0200198
Akron70903c42018-02-05 12:31:10 +0100199 var cell = matchTable.querySelector("tbody > tr:nth-child(2) > td:nth-child(4)");
Akronbdcbbf42018-04-25 12:42:44 +0200200 expect(cell.innerString()).toEqual("ADJA");
Akronb46d8e32017-06-29 14:26:14 +0200201 cell.click();
202 expect(qc.toString()).toEqual("[opennlp/p=ADJA]");
203
Akron70903c42018-02-05 12:31:10 +0100204 cell = matchTable.querySelector("thead > tr > th:nth-child(4)");
Akronbdcbbf42018-04-25 12:42:44 +0200205 expect(cell.innerString()).toEqual("älteste");
Akronb46d8e32017-06-29 14:26:14 +0200206 cell.click();
207 expect(qc.toString()).toEqual("[opennlp/p=ADJA & orth=älteste]");
208
Akron70903c42018-02-05 12:31:10 +0100209 cell = matchTable.querySelector("tbody > tr > td:nth-child(4)");
Akronbdcbbf42018-04-25 12:42:44 +0200210 expect(cell.innerString()).toEqual("ADJA");
Akronb46d8e32017-06-29 14:26:14 +0200211 cell.click();
212 expect(qc.toString()).toEqual("[corenlp/p=ADJA & opennlp/p=ADJA & orth=älteste]");
213 });
214
215 it('should create token sequences in arbitrary order', function () {
Akron70903c42018-02-05 12:31:10 +0100216 var matchTable = matchTableFactory();
217 var qc = qcClass.create(matchTable);
Akronb46d8e32017-06-29 14:26:14 +0200218
Akron70903c42018-02-05 12:31:10 +0100219 var cell = matchTable.querySelector("thead > tr > th:nth-child(5)");
Akronbdcbbf42018-04-25 12:42:44 +0200220 expect(cell.innerString()).toEqual("lebende");
Akronb46d8e32017-06-29 14:26:14 +0200221 cell.click();
222 expect(qc.toString()).toEqual("[orth=lebende]");
223
Akron70903c42018-02-05 12:31:10 +0100224 cell = matchTable.querySelector("tbody > tr:nth-child(2) > td:nth-child(3)");
Akronbdcbbf42018-04-25 12:42:44 +0200225 expect(cell.innerString()).toEqual("ART");
Akronb46d8e32017-06-29 14:26:14 +0200226 cell.click();
Akrone9be11d2017-06-29 20:10:58 +0200227 expect(qc.toString()).toEqual("[opennlp/p=ART][][orth=lebende]");
Akronb46d8e32017-06-29 14:26:14 +0200228
Akron70903c42018-02-05 12:31:10 +0100229 cell = matchTable.querySelector("tbody > tr > td:nth-child(4)");
Akronbdcbbf42018-04-25 12:42:44 +0200230 expect(cell.innerString()).toEqual("ADJA");
Akronb46d8e32017-06-29 14:26:14 +0200231 cell.click();
232 expect(qc.toString()).toEqual("[opennlp/p=ART][corenlp/p=ADJA][orth=lebende]");
233 });
234
235 it('should remove chosen elements again', function () {
Akron70903c42018-02-05 12:31:10 +0100236 var matchTable = matchTableFactory();
237 var qc = qcClass.create(matchTable);
Akronb46d8e32017-06-29 14:26:14 +0200238
Akron70903c42018-02-05 12:31:10 +0100239 var cell = matchTable.querySelector("tbody > tr:nth-child(2) > td:nth-child(4)");
Akronbdcbbf42018-04-25 12:42:44 +0200240 expect(cell.innerString()).toEqual("ADJA");
Akronb46d8e32017-06-29 14:26:14 +0200241 cell.click();
242 expect(qc.toString()).toEqual("[opennlp/p=ADJA]");
243 var cell1 = cell;
244
Akron70903c42018-02-05 12:31:10 +0100245 cell = matchTable.querySelector("thead > tr > th:nth-child(4)");
Akronbdcbbf42018-04-25 12:42:44 +0200246 expect(cell.innerString()).toEqual("älteste");
Akronb46d8e32017-06-29 14:26:14 +0200247 cell.click();
248 expect(qc.toString()).toEqual("[opennlp/p=ADJA & orth=älteste]");
249 var cell2 = cell;
250
Akron70903c42018-02-05 12:31:10 +0100251 cell = matchTable.querySelector("tbody > tr > td:nth-child(3)");
Akronbdcbbf42018-04-25 12:42:44 +0200252 expect(cell.innerString()).toEqual("ART");
Akronb46d8e32017-06-29 14:26:14 +0200253 cell.click();
254 expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA & orth=älteste]");
255 var cell3 = cell;
256
Akron70903c42018-02-05 12:31:10 +0100257 cell = matchTable.querySelector("thead > tr > th:nth-child(6)");
Akronbdcbbf42018-04-25 12:42:44 +0200258 expect(cell.innerString()).toEqual("Baum");
Akronb46d8e32017-06-29 14:26:14 +0200259 cell.click();
Akrone9be11d2017-06-29 20:10:58 +0200260 expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA & orth=älteste][][orth=Baum]");
Akronb46d8e32017-06-29 14:26:14 +0200261 var cell4 = cell;
262
Akron70903c42018-02-05 12:31:10 +0100263 cell = matchTable.querySelector("thead > tr > th:nth-child(5)");
Akronbdcbbf42018-04-25 12:42:44 +0200264 expect(cell.innerString()).toEqual("lebende");
Akronb46d8e32017-06-29 14:26:14 +0200265 cell.click();
266 expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA & orth=älteste][orth=lebende][orth=Baum]");
267 var cell5 = cell;
268
269
270 // Remove annotations again
271 expect(cell5.classList.contains("chosen")).toBeTruthy();
272 cell5.click()
273 expect(cell5.classList.contains("chosen")).toBe(false);
Akrone9be11d2017-06-29 20:10:58 +0200274 expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA & orth=älteste][][orth=Baum]");
Akronb46d8e32017-06-29 14:26:14 +0200275
276 expect(cell2.classList.contains("chosen")).toBeTruthy();
277 cell2.click()
278 expect(cell2.classList.contains("chosen")).toBe(false);
Akrone9be11d2017-06-29 20:10:58 +0200279 expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA][][orth=Baum]");
Akronb46d8e32017-06-29 14:26:14 +0200280
281 expect(cell1.classList.contains("chosen")).toBeTruthy();
282 cell1.click()
283 expect(cell1.classList.contains("chosen")).toBe(false);
Akrone9be11d2017-06-29 20:10:58 +0200284 expect(qc.toString()).toEqual("[corenlp/p=ART][]{2}[orth=Baum]");
Akronb46d8e32017-06-29 14:26:14 +0200285
286 // Re-add first cell at the same position
287 expect(cell1.classList.contains("chosen")).toBe(false);
288 cell1.click()
289 expect(cell1.classList.contains("chosen")).toBeTruthy();
Akrone9be11d2017-06-29 20:10:58 +0200290 expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA][][orth=Baum]");
Akronb46d8e32017-06-29 14:26:14 +0200291
292 expect(cell3.classList.contains("chosen")).toBeTruthy();
293 cell3.click()
294 expect(cell3.classList.contains("chosen")).toBe(false);
Akrone9be11d2017-06-29 20:10:58 +0200295 expect(qc.toString()).toEqual("[opennlp/p=ADJA][][orth=Baum]");
Akronb46d8e32017-06-29 14:26:14 +0200296
297 expect(cell4.classList.contains("chosen")).toBeTruthy();
298 cell4.click()
299 expect(cell4.classList.contains("chosen")).toBe(false);
300 expect(qc.toString()).toEqual("[opennlp/p=ADJA]");
301
302 // Remove last token
303 expect(qc.shown()).toBeTruthy();
304 expect(qc.element().innerHTML).toEqual("<span>New Query:</span><span>[opennlp/p=ADJA]</span>");
305 expect(cell1.classList.contains("chosen")).toBeTruthy();
306 cell1.click()
307 expect(cell1.classList.contains("chosen")).toBe(false);
308 expect(qc.toString()).toEqual("");
309 expect(qc.shown()).toBe(false);
310
311 // Re-add token
312 expect(cell4.classList.contains("chosen")).toBe(false);
313 cell4.click()
314 expect(cell4.classList.contains("chosen")).toBeTruthy();
315 expect(qc.toString()).toEqual("[orth=Baum]");
316 expect(qc.shown()).toBeTruthy();
317 expect(qc.element().innerHTML).toEqual("<span>New Query:</span><span>[orth=Baum]</span>");
318 });
319
Akronc8461bf2017-06-29 15:05:24 +0200320 it('should ignore empty terms', function () {
Akron70903c42018-02-05 12:31:10 +0100321 var matchTable = matchTableFactory();
322 var qc = qcClass.create(matchTable);
Akronb46d8e32017-06-29 14:26:14 +0200323
Akronc8461bf2017-06-29 15:05:24 +0200324 // Nothing to show
325 expect(qc.toString()).toEqual("");
326 expect(qc.shown()).toBe(false);
327 qc.show();
328 expect(qc.shown()).toBe(false);
Akron7dd32822018-10-01 19:38:31 +0200329 expect(qc.element().className).toEqual("query fragment");
Akronc8461bf2017-06-29 15:05:24 +0200330
Akron70903c42018-02-05 12:31:10 +0100331 var cell = matchTable.querySelector("tbody > tr:nth-child(2) > td:nth-child(4)");
Akronbdcbbf42018-04-25 12:42:44 +0200332 expect(cell.innerString()).toEqual("ADJA");
Akronc8461bf2017-06-29 15:05:24 +0200333 expect(cell.classList.contains("chosen")).toBe(false);
334 cell.click();
335 expect(cell.classList.contains("chosen")).toBeTruthy();
336 expect(qc.toString()).toEqual("[opennlp/p=ADJA]");
337
Akron70903c42018-02-05 12:31:10 +0100338 cell = matchTable.querySelector("tbody > tr:nth-child(2) > td:nth-child(5)");
Akronbdcbbf42018-04-25 12:42:44 +0200339 expect(cell.innerString()).toEqual("");
Akronc8461bf2017-06-29 15:05:24 +0200340 expect(cell.classList.contains("chosen")).toBe(false);
341 cell.click();
342 expect(cell.classList.contains("chosen")).toBe(false);
343 expect(qc.toString()).toEqual("[opennlp/p=ADJA]");
344
345 });
346
Akron7cf33fd2017-07-03 17:33:39 +0200347 it('should create or-groups for alternative terms', function () {
Akron70903c42018-02-05 12:31:10 +0100348 var matchTable = matchTableFactory();
349 var qc = qcClass.create(matchTable);
Akronc8461bf2017-06-29 15:05:24 +0200350
351 // Nothing to show
352 expect(qc.toString()).toEqual("");
353 expect(qc.shown()).toBe(false);
354 qc.show();
355 expect(qc.shown()).toBe(false);
Akron7dd32822018-10-01 19:38:31 +0200356 expect(qc.element().className).toEqual("query fragment");
Akronc8461bf2017-06-29 15:05:24 +0200357
Akron70903c42018-02-05 12:31:10 +0100358 var cell = matchTable.querySelector("thead > tr > th:nth-child(5)");
Akronbdcbbf42018-04-25 12:42:44 +0200359 expect(cell.innerString()).toEqual("lebende");
Akronc8461bf2017-06-29 15:05:24 +0200360 expect(cell.classList.contains("chosen")).toBe(false);
361 cell.click();
362 expect(cell.classList.contains("chosen")).toBeTruthy();
363 expect(qc.toString()).toEqual("[orth=lebende]");
364
Akron70903c42018-02-05 12:31:10 +0100365 cell = matchTable.querySelector("tbody > tr:nth-child(1) > td:nth-child(5)");
Akronbdcbbf42018-04-25 12:42:44 +0200366 expect(cell.innerString()).toEqual("ADJAADJD");
Akronc8461bf2017-06-29 15:05:24 +0200367 expect(cell.classList.contains("chosen")).toBe(false);
368 cell.click();
369 expect(cell.classList.contains("chosen")).toBeTruthy();
370 expect(qc.toString()).toEqual("[(corenlp/p=ADJA | corenlp/p=ADJD) & orth=lebende]");
371
372 // Remove or group again
373 expect(cell.classList.contains("chosen")).toBeTruthy();
374 cell.click();
375 expect(cell.classList.contains("chosen")).toBe(false);
376 expect(qc.toString()).toEqual("[orth=lebende]");
377 });
378
379
380 it('should add whole rows', function () {
Akron70903c42018-02-05 12:31:10 +0100381 var matchTable = matchTableFactory();
382 var qc = qcClass.create(matchTable);
Akronc8461bf2017-06-29 15:05:24 +0200383
384 // Nothing to show
385 expect(qc.toString()).toEqual("");
386 expect(qc.shown()).toBe(false);
387 qc.show();
388 expect(qc.shown()).toBe(false);
Akron7dd32822018-10-01 19:38:31 +0200389 expect(qc.element().className).toEqual("query fragment");
Akronc8461bf2017-06-29 15:05:24 +0200390
Akron70903c42018-02-05 12:31:10 +0100391 var corenlpRow = matchTable.querySelector("tbody > tr:nth-child(1)");
Akronc8461bf2017-06-29 15:05:24 +0200392
393 var cell = corenlpRow.querySelector("td:nth-child(4)");
Akronbdcbbf42018-04-25 12:42:44 +0200394 expect(cell.innerString()).toEqual("ADJA");
Akronc8461bf2017-06-29 15:05:24 +0200395 expect(cell.classList.contains("chosen")).toBe(false);
396 cell.click();
397 expect(cell.classList.contains("chosen")).toBeTruthy();
398
399 // Activate another cell in another row
Akron70903c42018-02-05 12:31:10 +0100400 cell = matchTable.querySelector("tbody > tr:nth-child(2) td:nth-child(3)");
Akronbdcbbf42018-04-25 12:42:44 +0200401 expect(cell.innerString()).toEqual("ART");
Akronc8461bf2017-06-29 15:05:24 +0200402 expect(cell.classList.contains("chosen")).toBe(false);
403 cell.click();
404 expect(cell.classList.contains("chosen")).toBeTruthy();
405
406 expect(corenlpRow.querySelector("td:nth-child(3).chosen")).toBeNull();
407 expect(corenlpRow.querySelector("td:nth-child(4).chosen")).toBeTruthy();
408 expect(corenlpRow.querySelector("td:nth-child(5).chosen")).toBeNull();
409 expect(corenlpRow.querySelector("td:nth-child(6).chosen")).toBeNull();
410
411 expect(qc.toString()).toEqual("[opennlp/p=ART][corenlp/p=ADJA]");
412
413 // Mark all corenlp lists
414 cell = corenlpRow.querySelector("th:nth-child(1)");
Akronbdcbbf42018-04-25 12:42:44 +0200415 expect(cell.innerString()).toEqual("corenlp");
Akronc8461bf2017-06-29 15:05:24 +0200416 expect(cell.classList.contains("chosen")).toBe(false);
417 cell.click();
418 expect(cell.classList.contains("chosen")).toBe(false);
419
420 expect(corenlpRow.querySelector("td:nth-child(3).chosen")).toBeTruthy();
421 expect(corenlpRow.querySelector("td:nth-child(4).chosen")).toBeTruthy();
422 expect(corenlpRow.querySelector("td:nth-child(5).chosen")).toBeTruthy();
423 expect(corenlpRow.querySelector("td:nth-child(6).chosen")).toBeTruthy();
424
425 // Replay the choice without any effect
426 cell = corenlpRow.querySelector("th:nth-child(1)");
Akronbdcbbf42018-04-25 12:42:44 +0200427 expect(cell.innerString()).toEqual("corenlp");
Akronc8461bf2017-06-29 15:05:24 +0200428 expect(cell.classList.contains("chosen")).toBe(false);
429 cell.click();
430 expect(cell.classList.contains("chosen")).toBe(false);
431
432 expect(corenlpRow.querySelector("td:nth-child(3).chosen")).toBeTruthy();
433 expect(corenlpRow.querySelector("td:nth-child(4).chosen")).toBeTruthy();
434 expect(corenlpRow.querySelector("td:nth-child(5).chosen")).toBeTruthy();
435 expect(corenlpRow.querySelector("td:nth-child(6).chosen")).toBeTruthy();
Akrone9be11d2017-06-29 20:10:58 +0200436 expect(corenlpRow.querySelector("td:nth-child(7).chosen")).toBeTruthy();
Akronc8461bf2017-06-29 15:05:24 +0200437
Akrone9be11d2017-06-29 20:10:58 +0200438 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 +0200439
440 // Remove one of the cells again
441 cell = corenlpRow.querySelector("td:nth-child(5).chosen");
Akronbdcbbf42018-04-25 12:42:44 +0200442 expect(cell.innerString()).toEqual("ADJAADJD");
Akronc8461bf2017-06-29 15:05:24 +0200443 expect(cell.classList.contains("chosen")).toBeTruthy();
444 cell.click();
445 expect(cell.classList.contains("chosen")).toBe(false);
Akrone9be11d2017-06-29 20:10:58 +0200446 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 +0200447
448 });
Akron8084cb52017-06-29 17:11:14 +0200449
450 it('should ignore empty terms in whole rows', function () {
Akron70903c42018-02-05 12:31:10 +0100451 var matchTable = matchTableFactory();
452 var qc = qcClass.create(matchTable);
Akron8084cb52017-06-29 17:11:14 +0200453 expect(qc.toString()).toEqual("");
454
Akron70903c42018-02-05 12:31:10 +0100455 var opennlpRow = matchTable.querySelector("tbody > tr:nth-child(2)");
Akron8084cb52017-06-29 17:11:14 +0200456
457 expect(opennlpRow.querySelector("td:nth-child(3).chosen")).toBeNull();
458 expect(opennlpRow.querySelector("td:nth-child(4).chosen")).toBeNull();
459 expect(opennlpRow.querySelector("td:nth-child(5).chosen")).toBeNull();
460 expect(opennlpRow.querySelector("td:nth-child(6).chosen")).toBeNull();
461
462 expect(qc.toString()).toEqual("");
463
464 // Mark all opennlp lists
465 cell = opennlpRow.querySelector("th:nth-child(1)");
Akronbdcbbf42018-04-25 12:42:44 +0200466 expect(cell.innerString()).toEqual("opennlp");
Akron8084cb52017-06-29 17:11:14 +0200467 expect(cell.classList.contains("chosen")).toBe(false);
468 cell.click();
469 expect(cell.classList.contains("chosen")).toBe(false);
470
471 expect(opennlpRow.querySelector("td:nth-child(3).chosen")).toBeTruthy();
472 expect(opennlpRow.querySelector("td:nth-child(4).chosen")).toBeTruthy();
473 expect(opennlpRow.querySelector("td:nth-child(5).chosen")).toBeNull();
474 expect(opennlpRow.querySelector("td:nth-child(6).chosen")).toBeTruthy();
Akron7cf33fd2017-07-03 17:33:39 +0200475
476 expect(qc.toString()).toEqual("[opennlp/p=ART][opennlp/p=ADJA][][opennlp/p=NN][opennlp/p=ADV]");
Akron8084cb52017-06-29 17:11:14 +0200477 });
Akrone9be11d2017-06-29 20:10:58 +0200478
479 it('should support multiple distances', function () {
Akron70903c42018-02-05 12:31:10 +0100480 var matchTable = matchTableFactory();
481 var qc = qcClass.create(matchTable);
Akrone9be11d2017-06-29 20:10:58 +0200482
Akron70903c42018-02-05 12:31:10 +0100483 var cell = matchTable.querySelector("thead > tr > th:nth-child(3)");
Akronbdcbbf42018-04-25 12:42:44 +0200484 expect(cell.innerString()).toEqual("Der");
Akrone9be11d2017-06-29 20:10:58 +0200485 cell.click();
486 expect(qc.toString()).toEqual("[orth=Der]");
487
Akron70903c42018-02-05 12:31:10 +0100488 cell = matchTable.querySelector("thead > tr > th:nth-child(7)");
Akronbdcbbf42018-04-25 12:42:44 +0200489 expect(cell.innerString()).toEqual("hier");
Akrone9be11d2017-06-29 20:10:58 +0200490 cell.click();
491 expect(qc.toString()).toEqual("[orth=Der][]{3}[orth=hier]");
492
Akron70903c42018-02-05 12:31:10 +0100493 cell = matchTable.querySelector("thead > tr > th:nth-child(5)");
Akronbdcbbf42018-04-25 12:42:44 +0200494 expect(cell.innerString()).toEqual("lebende");
Akrone9be11d2017-06-29 20:10:58 +0200495 cell.click();
496 expect(qc.toString()).toEqual("[orth=Der][][orth=lebende][][orth=hier]");
497 });
Akron7cf33fd2017-07-03 17:33:39 +0200498
499 it('should create and-groups for key-value terms', function () {
Akron70903c42018-02-05 12:31:10 +0100500 var matchTable = matchTableComplexFactory();
501 var qc = qcClass.create(matchTable);
Akron7cf33fd2017-07-03 17:33:39 +0200502
503 // Nothing to show
504 expect(qc.toString()).toEqual("");
505 expect(qc.shown()).toBe(false);
506 qc.show();
507 expect(qc.shown()).toBe(false);
Akron7dd32822018-10-01 19:38:31 +0200508 expect(qc.element().className).toEqual("query fragment");
Akron7cf33fd2017-07-03 17:33:39 +0200509
Akron70903c42018-02-05 12:31:10 +0100510 var cell = matchTable.querySelector("thead > tr > th:nth-child(5)");
Akronbdcbbf42018-04-25 12:42:44 +0200511 expect(cell.innerString()).toEqual("lebende");
Akron7cf33fd2017-07-03 17:33:39 +0200512 expect(cell.classList.contains("chosen")).toBe(false);
513 cell.click();
514 expect(cell.classList.contains("chosen")).toBeTruthy();
515 expect(qc.toString()).toEqual("[orth=lebende]");
516
517 // Check complex cell
Akron70903c42018-02-05 12:31:10 +0100518 cell = matchTable.querySelector("tbody > tr:nth-child(1) > td:nth-child(6)");
Akronbdcbbf42018-04-25 12:42:44 +0200519 expect(cell.innerString()).toMatch(/case:nom/);
Akron7cf33fd2017-07-03 17:33:39 +0200520 expect(cell.classList.contains("chosen")).toBe(false);
521 cell.click();
522 expect(cell.classList.contains("chosen")).toBe(false);
523 expect(qc.toString()).toEqual("[orth=lebende]");
524
525 // Check complex cell div
Akron70903c42018-02-05 12:31:10 +0100526 cell = matchTable.querySelector("tbody > tr:nth-child(1) > td:nth-child(6) > div:nth-child(1)");
Akronbdcbbf42018-04-25 12:42:44 +0200527 expect(cell.innerString()).toEqual('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(true);
531 expect(qc.toString()).toEqual("[orth=lebende][corenlp/p=case:nom]");
532 var cell = cell;
533
Akron70903c42018-02-05 12:31:10 +0100534 cell = matchTable.querySelector("tbody > tr:nth-child(1) > td:nth-child(6) > div:nth-child(3)");
Akronbdcbbf42018-04-25 12:42:44 +0200535 expect(cell.innerString()).toEqual('number:sg');
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);
539 expect(qc.toString()).toEqual("[orth=lebende][corenlp/p=case:nom & corenlp/p=number:sg]");
540 var cell2 = cell;
541
Akron70903c42018-02-05 12:31:10 +0100542 cell = matchTable.querySelector("tbody > tr:nth-child(1) > td:nth-child(6) > div:nth-child(2)");
Akronbdcbbf42018-04-25 12:42:44 +0200543 expect(cell.innerString()).toEqual('gender:mascgender:fem');
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);
547 expect(qc.toString()).toEqual("[orth=lebende][(corenlp/p=gender:fem | corenlp/p=gender:masc) & corenlp/p=case:nom & corenlp/p=number:sg]");
548 var cell3 = cell;
549
550 // Remove cell again
551 cell = cell2;
Akronbdcbbf42018-04-25 12:42:44 +0200552 expect(cell.innerString()).toEqual('number:sg');
Akron7cf33fd2017-07-03 17:33:39 +0200553 expect(cell.classList.contains("chosen")).toBe(true);
554 cell.click();
555 expect(cell.classList.contains("chosen")).toBe(false);
556 expect(qc.toString()).toEqual("[orth=lebende][(corenlp/p=gender:fem | corenlp/p=gender:masc) & corenlp/p=case:nom]");
557
558 // Remove cell again
559 cell = cell3;
Akronbdcbbf42018-04-25 12:42:44 +0200560 expect(cell.innerString()).toEqual('gender:mascgender:fem');
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);
564 expect(qc.toString()).toEqual("[orth=lebende][corenlp/p=case:nom]");
565 });
566
567
568 it('should create rows including key-value terms', function () {
Akron70903c42018-02-05 12:31:10 +0100569 var matchTable = matchTableComplexFactory();
570 var qc = qcClass.create(matchTable);
Akron7cf33fd2017-07-03 17:33:39 +0200571 expect(qc.toString()).toEqual("");
572
Akron70903c42018-02-05 12:31:10 +0100573 var corenlpRow = matchTable.querySelector("tbody > tr:nth-child(1)");
Akron7cf33fd2017-07-03 17:33:39 +0200574
575 expect(corenlpRow.querySelector("td:nth-child(3).chosen")).toBeNull();
576 expect(corenlpRow.querySelector("td:nth-child(4).chosen")).toBeNull();
577 expect(corenlpRow.querySelector("td:nth-child(5).chosen")).toBeNull();
578 expect(corenlpRow.querySelector("td:nth-child(6) *.chosen")).toBeNull();
579
580 expect(qc.toString()).toEqual("");
581
582 // Mark all opennlp lists
583 cell = corenlpRow.querySelector("th:nth-child(1)");
Akronbdcbbf42018-04-25 12:42:44 +0200584 expect(cell.innerString()).toEqual("corenlp");
Akron7cf33fd2017-07-03 17:33:39 +0200585 expect(cell.classList.contains("chosen")).toBe(false);
586 cell.click();
587 expect(cell.classList.contains("chosen")).toBe(false);
588
589 expect(corenlpRow.querySelector("td:nth-child(3).chosen")).toBeTruthy();
590 expect(corenlpRow.querySelector("td:nth-child(4).chosen")).toBeTruthy();
591 expect(corenlpRow.querySelector("td:nth-child(5).chosen")).toBeTruthy();
592 expect(corenlpRow.querySelector("td:nth-child(6) div:nth-child(1).chosen")).toBeTruthy();
593 expect(corenlpRow.querySelector("td:nth-child(6) div:nth-child(2).chosen")).toBeTruthy();
594 expect(corenlpRow.querySelector("td:nth-child(6) div:nth-child(3).chosen")).toBeTruthy();
595
596 expect(qc.toString()).toEqual(
597 "[corenlp/p=ART]"+
598 "[corenlp/p=ADJA]"+
599 "[(corenlp/p=ADJA | corenlp/p=ADJD)]"+
600 "[(corenlp/p=gender:fem | corenlp/p=gender:masc) & corenlp/p=case:nom & corenlp/p=number:sg]"
601 );
602 });
Akron72245b62018-07-23 10:59:08 +0200603
604 it('should support verbatim strings', function () {
605 var matchTable = matchTableComplexFactory();
606 var qc = qcClass.create(matchTable);
607 expect(qc.toString()).toEqual("");
608
609 // TODO:
610 // This does not respect keys vs values at the moment, but neither does Koral
611 var cell = matchTable.querySelector("tbody > tr:nth-child(2) > td > div:nth-child(4)");
612 expect(cell.innerString()).toEqual("morphemes:.::_SORSZ \\ZERO::NOM 'period::PUNCT'");
613 expect(cell.classList.contains("chosen")).toBe(false);
614 cell.click();
615 expect(cell.classList.contains("chosen")).toBeTruthy();
616 expect(qc.toString()).toEqual("[opennlp/p='morphemes:.::_SORSZ \\\\ZERO::NOM \\\'period::PUNCT\\\'']");
617 });
Akronaeeb8252018-09-19 18:51:00 +0200618
619 it('should respect marked elements', function () {
620 var matchTable = matchTableComplexFactory();
621 var qc = qcClass.create(matchTable);
622 expect(qc.toString()).toEqual("");
623
624 var cell = matchTable.querySelector("thead > tr > th:nth-child(6)");
625 expect(cell.classList.contains("mark")).toBeTruthy();
626 expect(cell.classList.contains("chosen")).toBeFalsy();
627
628 cell.click();
629 expect(cell.classList.contains("mark")).toBeTruthy();
630 expect(cell.classList.contains("chosen")).toBeTruthy();
631
632 cell.click();
633 expect(cell.classList.contains("mark")).toBeTruthy();
634 expect(cell.classList.contains("chosen")).toBeFalsy();
635 });
Akron083ec572019-05-16 18:30:40 +0200636
637 it('should ignore cutted columns', function () {
638 var matchTable = matchTableCuttedFactory();
639 var qc = qcClass.create(matchTable);
640 expect(qc.toString()).toEqual("");
641
642 var cell = matchTable.querySelector("thead > tr > th:nth-child(3)");
643 expect(cell.classList.contains("chosen")).toBeFalsy();
644 cell.click();
645 expect(cell.classList.contains("chosen")).toBeTruthy();
646 expect(qc.toString()).toEqual("[orth=Baum]");
647
648 cell = matchTable.querySelector("thead > tr > th:nth-child(4)");
649 expect(cell.classList.contains("chosen")).toBeFalsy();
650 expect(cell.classList.contains("cutted")).toBeTruthy();
651 cell.click();
652 expect(cell.classList.contains("chosen")).toBeFalsy();
653 expect(qc.toString()).toEqual("[orth=Baum]");
654 });
Akronb46d8e32017-06-29 14:26:14 +0200655 });
656});