blob: 8b79fbe50ee25b9bcfd6f738cb43c4ff4c4805de [file] [log] [blame]
Akron70903c42018-02-05 12:31:10 +01001function matchTableFactory () {
2 var table = document.createElement('div');
3 table.className = 'matchtable';
4 table.innerHTML =
Akronb46d8e32017-06-29 14:26:14 +02005 " <table>" +
6 " <thead>" +
7 " <tr>" +
8 " <th>Foundry</th>" +
9 " <th>Layer</th>" +
10 " <th>Der</th>" +
11 " <th>älteste</th>" +
12 " <th>lebende</th>" +
13 " <th>Baum</th>" +
Akrone9be11d2017-06-29 20:10:58 +020014 " <th>hier</th>" +
Akronb46d8e32017-06-29 14:26:14 +020015 " </tr>" +
16 " </thead>" +
17 " <tbody>" +
18 " <tr tabindex=\"0\">" +
19 " <th>corenlp</th>" +
20 " <th>p</th>" +
21 " <td>ART</td>" +
22 " <td>ADJA</td>" +
23 " <td>ADJA<br>ADJD</td>" +
24 " <td>NN</td>" +
Akrone9be11d2017-06-29 20:10:58 +020025 " <td>ADV</td>" +
Akronb46d8e32017-06-29 14:26:14 +020026 " </tr>" +
27 " <tr tabindex=\"0\">" +
28 " <th>opennlp</th>" +
29 " <th>p</th>" +
30 " <td>ART</td>" +
31 " <td>ADJA</td>" +
32 " <td></td>" +
33 " <td>NN</td>" +
Akrone9be11d2017-06-29 20:10:58 +020034 " <td>ADV</td>" +
Akronb46d8e32017-06-29 14:26:14 +020035 " </tr>" +
36 " </tbody>" +
37 " </table>" +
Akron70903c42018-02-05 12:31:10 +010038 " </div>";
Akronb46d8e32017-06-29 14:26:14 +020039
Akron70903c42018-02-05 12:31:10 +010040 var info = document.createElement('div');
41 info.appendChild(table);
42 return table;
Akronb46d8e32017-06-29 14:26:14 +020043};
44
Akron70903c42018-02-05 12:31:10 +010045function matchTableComplexFactory () {
46 var table = document.createElement('div');
47 table.className = 'matchtable';
48 table.innerHTML =
Akron7cf33fd2017-07-03 17:33:39 +020049 " <table>" +
50 " <thead>" +
51 " <tr>" +
52 " <th>Foundry</th>" +
53 " <th>Layer</th>" +
54 " <th>Der</th>" +
55 " <th>älteste</th>" +
56 " <th>lebende</th>" +
57 " <th>Baum</th>" +
58 " </tr>" +
59 " </thead>" +
60 " <tbody>" +
61 " <tr tabindex=\"0\">" +
62 " <th>corenlp</th>" +
63 " <th>p</th>" +
64 " <td>ART</td>" +
65 " <td>ADJA</td>" +
66 " <td>ADJA<br>ADJD</td>" +
67 " <td class=\"matchkeyvalues\">" +
68 " <div>case:nom</div>" +
69 " <div>gender:masc<br/>gender:fem</div>" +
70 " <div>number:sg</div>" +
71 " </td>" +
72 " </tr>" +
73 " <tr tabindex=\"0\">" +
74 " <th>opennlp</th>" +
75 " <th>p</th>" +
76 " <td class=\"matchkeyvalues\">" +
77 " <div>case:nom</div>" +
78 " <div>gender:masc</div>" +
79 " <div>number:sg</div>" +
80 " </td>" +
81 " <td>ADJA</td>" +
82 " <td></td>" +
83 " <td>NN</td>" +
84 " </tr>" +
85 " </tbody>" +
Akron70903c42018-02-05 12:31:10 +010086 " </table>";
87 var info = document.createElement('div');
88 info.appendChild(table);
89 return table;
Akron7cf33fd2017-07-03 17:33:39 +020090};
91
Akronb46d8e32017-06-29 14:26:14 +020092
93define(['match/querycreator'], function (qcClass) {
94
95 describe('KorAP.QueryCreator', function () {
96
97 it('should be initializable', function () {
98 expect(
99 function() {
100 qcClass.create()
101 }
102 ).toThrow(new Error("Missing parameters"));
103
104 expect(
105 function() {
106 qcClass.create("Test")
107 }
108 ).toThrow(new Error("Requires element"));
109
Akron70903c42018-02-05 12:31:10 +0100110 expect(qcClass.create(matchTableFactory()).toString()).toEqual("");
Akronb46d8e32017-06-29 14:26:14 +0200111 });
112
113 it('should listen to click events', function () {
114
Akron70903c42018-02-05 12:31:10 +0100115 var matchTable = matchTableFactory();
116 var qc = qcClass.create(matchTable);
Akronb46d8e32017-06-29 14:26:14 +0200117
118 // Nothing to show
119 expect(qc.toString()).toEqual("");
120 expect(qc.shown()).toBe(false);
121 qc.show();
122 expect(qc.shown()).toBe(false);
123 expect(qc.element().className).toEqual("queryfragment");
124
125 // Click on cell 0:0 "Foundry"
Akron70903c42018-02-05 12:31:10 +0100126 var cell = matchTable.querySelector("thead > tr > th:first-child");
Akronb46d8e32017-06-29 14:26:14 +0200127 expect(cell.innerText).toEqual("Foundry");
128 cell.click();
129 expect(cell.classList.contains("chosen")).toBe(false);
130 expect(qc.toString()).toEqual("");
131 expect(qc.shown()).toBe(false);
132
133 // Click on cell 0:2 "Der"
Akron70903c42018-02-05 12:31:10 +0100134 cell = matchTable.querySelector("thead > tr > th:nth-child(3)")
Akronb46d8e32017-06-29 14:26:14 +0200135 expect(cell.innerText).toEqual("Der");
136 cell.click();
137 expect(cell.classList.contains("chosen")).toBeTruthy();
138 expect(qc.toString()).toEqual("[orth=Der]");
139 expect(qc.shown()).toBeTruthy();
140
141 // Click on cell 0:2 "Der" again - to hide
Akron70903c42018-02-05 12:31:10 +0100142 cell = matchTable.querySelector("thead > tr > th:nth-child(3)")
Akronb46d8e32017-06-29 14:26:14 +0200143 expect(cell.innerText).toEqual("Der");
144 cell.click();
145 expect(cell.classList.contains("chosen")).toBe(false);
146 expect(qc.toString()).toEqual("");
147 expect(qc.shown()).toBe(false);
148 });
149
150 it('should create tokens in arbitrary order', function () {
Akron70903c42018-02-05 12:31:10 +0100151 var matchTable = matchTableFactory();
152 var qc = qcClass.create(matchTable);
Akronb46d8e32017-06-29 14:26:14 +0200153
Akron70903c42018-02-05 12:31:10 +0100154 var cell = matchTable.querySelector("tbody > tr:nth-child(2) > td:nth-child(4)");
Akronb46d8e32017-06-29 14:26:14 +0200155 expect(cell.innerText).toEqual("ADJA");
156 cell.click();
157 expect(qc.toString()).toEqual("[opennlp/p=ADJA]");
158
Akron70903c42018-02-05 12:31:10 +0100159 cell = matchTable.querySelector("thead > tr > th:nth-child(4)");
Akronb46d8e32017-06-29 14:26:14 +0200160 expect(cell.innerText).toEqual("älteste");
161 cell.click();
162 expect(qc.toString()).toEqual("[opennlp/p=ADJA & orth=älteste]");
163
Akron70903c42018-02-05 12:31:10 +0100164 cell = matchTable.querySelector("tbody > tr > td:nth-child(4)");
Akronb46d8e32017-06-29 14:26:14 +0200165 expect(cell.innerText).toEqual("ADJA");
166 cell.click();
167 expect(qc.toString()).toEqual("[corenlp/p=ADJA & opennlp/p=ADJA & orth=älteste]");
168 });
169
170 it('should create token sequences in arbitrary order', function () {
Akron70903c42018-02-05 12:31:10 +0100171 var matchTable = matchTableFactory();
172 var qc = qcClass.create(matchTable);
Akronb46d8e32017-06-29 14:26:14 +0200173
Akron70903c42018-02-05 12:31:10 +0100174 var cell = matchTable.querySelector("thead > tr > th:nth-child(5)");
Akronb46d8e32017-06-29 14:26:14 +0200175 expect(cell.innerText).toEqual("lebende");
176 cell.click();
177 expect(qc.toString()).toEqual("[orth=lebende]");
178
Akron70903c42018-02-05 12:31:10 +0100179 cell = matchTable.querySelector("tbody > tr:nth-child(2) > td:nth-child(3)");
Akronb46d8e32017-06-29 14:26:14 +0200180 expect(cell.innerText).toEqual("ART");
181 cell.click();
Akrone9be11d2017-06-29 20:10:58 +0200182 expect(qc.toString()).toEqual("[opennlp/p=ART][][orth=lebende]");
Akronb46d8e32017-06-29 14:26:14 +0200183
Akron70903c42018-02-05 12:31:10 +0100184 cell = matchTable.querySelector("tbody > tr > td:nth-child(4)");
Akronb46d8e32017-06-29 14:26:14 +0200185 expect(cell.innerText).toEqual("ADJA");
186 cell.click();
187 expect(qc.toString()).toEqual("[opennlp/p=ART][corenlp/p=ADJA][orth=lebende]");
188 });
189
190 it('should remove chosen elements again', function () {
Akron70903c42018-02-05 12:31:10 +0100191 var matchTable = matchTableFactory();
192 var qc = qcClass.create(matchTable);
Akronb46d8e32017-06-29 14:26:14 +0200193
Akron70903c42018-02-05 12:31:10 +0100194 var cell = matchTable.querySelector("tbody > tr:nth-child(2) > td:nth-child(4)");
Akronb46d8e32017-06-29 14:26:14 +0200195 expect(cell.innerText).toEqual("ADJA");
196 cell.click();
197 expect(qc.toString()).toEqual("[opennlp/p=ADJA]");
198 var cell1 = cell;
199
Akron70903c42018-02-05 12:31:10 +0100200 cell = matchTable.querySelector("thead > tr > th:nth-child(4)");
Akronb46d8e32017-06-29 14:26:14 +0200201 expect(cell.innerText).toEqual("älteste");
202 cell.click();
203 expect(qc.toString()).toEqual("[opennlp/p=ADJA & orth=älteste]");
204 var cell2 = cell;
205
Akron70903c42018-02-05 12:31:10 +0100206 cell = matchTable.querySelector("tbody > tr > td:nth-child(3)");
Akronb46d8e32017-06-29 14:26:14 +0200207 expect(cell.innerText).toEqual("ART");
208 cell.click();
209 expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA & orth=älteste]");
210 var cell3 = cell;
211
Akron70903c42018-02-05 12:31:10 +0100212 cell = matchTable.querySelector("thead > tr > th:nth-child(6)");
Akronb46d8e32017-06-29 14:26:14 +0200213 expect(cell.innerText).toEqual("Baum");
214 cell.click();
Akrone9be11d2017-06-29 20:10:58 +0200215 expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA & orth=älteste][][orth=Baum]");
Akronb46d8e32017-06-29 14:26:14 +0200216 var cell4 = cell;
217
Akron70903c42018-02-05 12:31:10 +0100218 cell = matchTable.querySelector("thead > tr > th:nth-child(5)");
Akronb46d8e32017-06-29 14:26:14 +0200219 expect(cell.innerText).toEqual("lebende");
220 cell.click();
221 expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA & orth=älteste][orth=lebende][orth=Baum]");
222 var cell5 = cell;
223
224
225 // Remove annotations again
226 expect(cell5.classList.contains("chosen")).toBeTruthy();
227 cell5.click()
228 expect(cell5.classList.contains("chosen")).toBe(false);
Akrone9be11d2017-06-29 20:10:58 +0200229 expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA & orth=älteste][][orth=Baum]");
Akronb46d8e32017-06-29 14:26:14 +0200230
231 expect(cell2.classList.contains("chosen")).toBeTruthy();
232 cell2.click()
233 expect(cell2.classList.contains("chosen")).toBe(false);
Akrone9be11d2017-06-29 20:10:58 +0200234 expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA][][orth=Baum]");
Akronb46d8e32017-06-29 14:26:14 +0200235
236 expect(cell1.classList.contains("chosen")).toBeTruthy();
237 cell1.click()
238 expect(cell1.classList.contains("chosen")).toBe(false);
Akrone9be11d2017-06-29 20:10:58 +0200239 expect(qc.toString()).toEqual("[corenlp/p=ART][]{2}[orth=Baum]");
Akronb46d8e32017-06-29 14:26:14 +0200240
241 // Re-add first cell at the same position
242 expect(cell1.classList.contains("chosen")).toBe(false);
243 cell1.click()
244 expect(cell1.classList.contains("chosen")).toBeTruthy();
Akrone9be11d2017-06-29 20:10:58 +0200245 expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA][][orth=Baum]");
Akronb46d8e32017-06-29 14:26:14 +0200246
247 expect(cell3.classList.contains("chosen")).toBeTruthy();
248 cell3.click()
249 expect(cell3.classList.contains("chosen")).toBe(false);
Akrone9be11d2017-06-29 20:10:58 +0200250 expect(qc.toString()).toEqual("[opennlp/p=ADJA][][orth=Baum]");
Akronb46d8e32017-06-29 14:26:14 +0200251
252 expect(cell4.classList.contains("chosen")).toBeTruthy();
253 cell4.click()
254 expect(cell4.classList.contains("chosen")).toBe(false);
255 expect(qc.toString()).toEqual("[opennlp/p=ADJA]");
256
257 // Remove last token
258 expect(qc.shown()).toBeTruthy();
259 expect(qc.element().innerHTML).toEqual("<span>New Query:</span><span>[opennlp/p=ADJA]</span>");
260 expect(cell1.classList.contains("chosen")).toBeTruthy();
261 cell1.click()
262 expect(cell1.classList.contains("chosen")).toBe(false);
263 expect(qc.toString()).toEqual("");
264 expect(qc.shown()).toBe(false);
265
266 // Re-add token
267 expect(cell4.classList.contains("chosen")).toBe(false);
268 cell4.click()
269 expect(cell4.classList.contains("chosen")).toBeTruthy();
270 expect(qc.toString()).toEqual("[orth=Baum]");
271 expect(qc.shown()).toBeTruthy();
272 expect(qc.element().innerHTML).toEqual("<span>New Query:</span><span>[orth=Baum]</span>");
273 });
274
Akronc8461bf2017-06-29 15:05:24 +0200275 it('should ignore empty terms', function () {
Akron70903c42018-02-05 12:31:10 +0100276 var matchTable = matchTableFactory();
277 var qc = qcClass.create(matchTable);
Akronb46d8e32017-06-29 14:26:14 +0200278
Akronc8461bf2017-06-29 15:05:24 +0200279 // Nothing to show
280 expect(qc.toString()).toEqual("");
281 expect(qc.shown()).toBe(false);
282 qc.show();
283 expect(qc.shown()).toBe(false);
284 expect(qc.element().className).toEqual("queryfragment");
285
Akron70903c42018-02-05 12:31:10 +0100286 var cell = matchTable.querySelector("tbody > tr:nth-child(2) > td:nth-child(4)");
Akronc8461bf2017-06-29 15:05:24 +0200287 expect(cell.innerText).toEqual("ADJA");
288 expect(cell.classList.contains("chosen")).toBe(false);
289 cell.click();
290 expect(cell.classList.contains("chosen")).toBeTruthy();
291 expect(qc.toString()).toEqual("[opennlp/p=ADJA]");
292
Akron70903c42018-02-05 12:31:10 +0100293 cell = matchTable.querySelector("tbody > tr:nth-child(2) > td:nth-child(5)");
Akronc8461bf2017-06-29 15:05:24 +0200294 expect(cell.innerText).toEqual("");
295 expect(cell.classList.contains("chosen")).toBe(false);
296 cell.click();
297 expect(cell.classList.contains("chosen")).toBe(false);
298 expect(qc.toString()).toEqual("[opennlp/p=ADJA]");
299
300 });
301
Akron7cf33fd2017-07-03 17:33:39 +0200302 it('should create or-groups for alternative terms', function () {
Akron70903c42018-02-05 12:31:10 +0100303 var matchTable = matchTableFactory();
304 var qc = qcClass.create(matchTable);
Akronc8461bf2017-06-29 15:05:24 +0200305
306 // Nothing to show
307 expect(qc.toString()).toEqual("");
308 expect(qc.shown()).toBe(false);
309 qc.show();
310 expect(qc.shown()).toBe(false);
311 expect(qc.element().className).toEqual("queryfragment");
312
Akron70903c42018-02-05 12:31:10 +0100313 var cell = matchTable.querySelector("thead > tr > th:nth-child(5)");
Akronc8461bf2017-06-29 15:05:24 +0200314 expect(cell.innerText).toEqual("lebende");
315 expect(cell.classList.contains("chosen")).toBe(false);
316 cell.click();
317 expect(cell.classList.contains("chosen")).toBeTruthy();
318 expect(qc.toString()).toEqual("[orth=lebende]");
319
Akron70903c42018-02-05 12:31:10 +0100320 cell = matchTable.querySelector("tbody > tr:nth-child(1) > td:nth-child(5)");
Akronc8461bf2017-06-29 15:05:24 +0200321 expect(cell.innerText).toEqual("ADJAADJD");
322 expect(cell.classList.contains("chosen")).toBe(false);
323 cell.click();
324 expect(cell.classList.contains("chosen")).toBeTruthy();
325 expect(qc.toString()).toEqual("[(corenlp/p=ADJA | corenlp/p=ADJD) & orth=lebende]");
326
327 // Remove or group again
328 expect(cell.classList.contains("chosen")).toBeTruthy();
329 cell.click();
330 expect(cell.classList.contains("chosen")).toBe(false);
331 expect(qc.toString()).toEqual("[orth=lebende]");
332 });
333
334
335 it('should add whole rows', function () {
Akron70903c42018-02-05 12:31:10 +0100336 var matchTable = matchTableFactory();
337 var qc = qcClass.create(matchTable);
Akronc8461bf2017-06-29 15:05:24 +0200338
339 // Nothing to show
340 expect(qc.toString()).toEqual("");
341 expect(qc.shown()).toBe(false);
342 qc.show();
343 expect(qc.shown()).toBe(false);
344 expect(qc.element().className).toEqual("queryfragment");
345
Akron70903c42018-02-05 12:31:10 +0100346 var corenlpRow = matchTable.querySelector("tbody > tr:nth-child(1)");
Akronc8461bf2017-06-29 15:05:24 +0200347
348 var cell = corenlpRow.querySelector("td:nth-child(4)");
349 expect(cell.innerText).toEqual("ADJA");
350 expect(cell.classList.contains("chosen")).toBe(false);
351 cell.click();
352 expect(cell.classList.contains("chosen")).toBeTruthy();
353
354 // Activate another cell in another row
Akron70903c42018-02-05 12:31:10 +0100355 cell = matchTable.querySelector("tbody > tr:nth-child(2) td:nth-child(3)");
Akronc8461bf2017-06-29 15:05:24 +0200356 expect(cell.innerText).toEqual("ART");
357 expect(cell.classList.contains("chosen")).toBe(false);
358 cell.click();
359 expect(cell.classList.contains("chosen")).toBeTruthy();
360
361 expect(corenlpRow.querySelector("td:nth-child(3).chosen")).toBeNull();
362 expect(corenlpRow.querySelector("td:nth-child(4).chosen")).toBeTruthy();
363 expect(corenlpRow.querySelector("td:nth-child(5).chosen")).toBeNull();
364 expect(corenlpRow.querySelector("td:nth-child(6).chosen")).toBeNull();
365
366 expect(qc.toString()).toEqual("[opennlp/p=ART][corenlp/p=ADJA]");
367
368 // Mark all corenlp lists
369 cell = corenlpRow.querySelector("th:nth-child(1)");
370 expect(cell.innerText).toEqual("corenlp");
371 expect(cell.classList.contains("chosen")).toBe(false);
372 cell.click();
373 expect(cell.classList.contains("chosen")).toBe(false);
374
375 expect(corenlpRow.querySelector("td:nth-child(3).chosen")).toBeTruthy();
376 expect(corenlpRow.querySelector("td:nth-child(4).chosen")).toBeTruthy();
377 expect(corenlpRow.querySelector("td:nth-child(5).chosen")).toBeTruthy();
378 expect(corenlpRow.querySelector("td:nth-child(6).chosen")).toBeTruthy();
379
380 // Replay the choice without any effect
381 cell = corenlpRow.querySelector("th:nth-child(1)");
382 expect(cell.innerText).toEqual("corenlp");
383 expect(cell.classList.contains("chosen")).toBe(false);
384 cell.click();
385 expect(cell.classList.contains("chosen")).toBe(false);
386
387 expect(corenlpRow.querySelector("td:nth-child(3).chosen")).toBeTruthy();
388 expect(corenlpRow.querySelector("td:nth-child(4).chosen")).toBeTruthy();
389 expect(corenlpRow.querySelector("td:nth-child(5).chosen")).toBeTruthy();
390 expect(corenlpRow.querySelector("td:nth-child(6).chosen")).toBeTruthy();
Akrone9be11d2017-06-29 20:10:58 +0200391 expect(corenlpRow.querySelector("td:nth-child(7).chosen")).toBeTruthy();
Akronc8461bf2017-06-29 15:05:24 +0200392
Akrone9be11d2017-06-29 20:10:58 +0200393 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 +0200394
395 // Remove one of the cells again
396 cell = corenlpRow.querySelector("td:nth-child(5).chosen");
397 expect(cell.innerText).toEqual("ADJAADJD");
398 expect(cell.classList.contains("chosen")).toBeTruthy();
399 cell.click();
400 expect(cell.classList.contains("chosen")).toBe(false);
Akrone9be11d2017-06-29 20:10:58 +0200401 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 +0200402
403 });
Akron8084cb52017-06-29 17:11:14 +0200404
405 it('should ignore empty terms in whole rows', function () {
Akron70903c42018-02-05 12:31:10 +0100406 var matchTable = matchTableFactory();
407 var qc = qcClass.create(matchTable);
Akron8084cb52017-06-29 17:11:14 +0200408 expect(qc.toString()).toEqual("");
409
Akron70903c42018-02-05 12:31:10 +0100410 var opennlpRow = matchTable.querySelector("tbody > tr:nth-child(2)");
Akron8084cb52017-06-29 17:11:14 +0200411
412 expect(opennlpRow.querySelector("td:nth-child(3).chosen")).toBeNull();
413 expect(opennlpRow.querySelector("td:nth-child(4).chosen")).toBeNull();
414 expect(opennlpRow.querySelector("td:nth-child(5).chosen")).toBeNull();
415 expect(opennlpRow.querySelector("td:nth-child(6).chosen")).toBeNull();
416
417 expect(qc.toString()).toEqual("");
418
419 // Mark all opennlp lists
420 cell = opennlpRow.querySelector("th:nth-child(1)");
421 expect(cell.innerText).toEqual("opennlp");
422 expect(cell.classList.contains("chosen")).toBe(false);
423 cell.click();
424 expect(cell.classList.contains("chosen")).toBe(false);
425
426 expect(opennlpRow.querySelector("td:nth-child(3).chosen")).toBeTruthy();
427 expect(opennlpRow.querySelector("td:nth-child(4).chosen")).toBeTruthy();
428 expect(opennlpRow.querySelector("td:nth-child(5).chosen")).toBeNull();
429 expect(opennlpRow.querySelector("td:nth-child(6).chosen")).toBeTruthy();
Akron7cf33fd2017-07-03 17:33:39 +0200430
431 expect(qc.toString()).toEqual("[opennlp/p=ART][opennlp/p=ADJA][][opennlp/p=NN][opennlp/p=ADV]");
Akron8084cb52017-06-29 17:11:14 +0200432 });
Akrone9be11d2017-06-29 20:10:58 +0200433
434 it('should support multiple distances', function () {
Akron70903c42018-02-05 12:31:10 +0100435 var matchTable = matchTableFactory();
436 var qc = qcClass.create(matchTable);
Akrone9be11d2017-06-29 20:10:58 +0200437
Akron70903c42018-02-05 12:31:10 +0100438 var cell = matchTable.querySelector("thead > tr > th:nth-child(3)");
Akrone9be11d2017-06-29 20:10:58 +0200439 expect(cell.innerText).toEqual("Der");
440 cell.click();
441 expect(qc.toString()).toEqual("[orth=Der]");
442
Akron70903c42018-02-05 12:31:10 +0100443 cell = matchTable.querySelector("thead > tr > th:nth-child(7)");
Akrone9be11d2017-06-29 20:10:58 +0200444 expect(cell.innerText).toEqual("hier");
445 cell.click();
446 expect(qc.toString()).toEqual("[orth=Der][]{3}[orth=hier]");
447
Akron70903c42018-02-05 12:31:10 +0100448 cell = matchTable.querySelector("thead > tr > th:nth-child(5)");
Akrone9be11d2017-06-29 20:10:58 +0200449 expect(cell.innerText).toEqual("lebende");
450 cell.click();
451 expect(qc.toString()).toEqual("[orth=Der][][orth=lebende][][orth=hier]");
452 });
Akron7cf33fd2017-07-03 17:33:39 +0200453
454 it('should create and-groups for key-value terms', function () {
Akron70903c42018-02-05 12:31:10 +0100455 var matchTable = matchTableComplexFactory();
456 var qc = qcClass.create(matchTable);
Akron7cf33fd2017-07-03 17:33:39 +0200457
458 // Nothing to show
459 expect(qc.toString()).toEqual("");
460 expect(qc.shown()).toBe(false);
461 qc.show();
462 expect(qc.shown()).toBe(false);
463 expect(qc.element().className).toEqual("queryfragment");
464
Akron70903c42018-02-05 12:31:10 +0100465 var cell = matchTable.querySelector("thead > tr > th:nth-child(5)");
Akron7cf33fd2017-07-03 17:33:39 +0200466 expect(cell.innerText).toEqual("lebende");
467 expect(cell.classList.contains("chosen")).toBe(false);
468 cell.click();
469 expect(cell.classList.contains("chosen")).toBeTruthy();
470 expect(qc.toString()).toEqual("[orth=lebende]");
471
472 // Check complex cell
Akron70903c42018-02-05 12:31:10 +0100473 cell = matchTable.querySelector("tbody > tr:nth-child(1) > td:nth-child(6)");
Akron7cf33fd2017-07-03 17:33:39 +0200474 expect(cell.innerText).toMatch(/case:nom/);
475 expect(cell.classList.contains("chosen")).toBe(false);
476 cell.click();
477 expect(cell.classList.contains("chosen")).toBe(false);
478 expect(qc.toString()).toEqual("[orth=lebende]");
479
480 // Check complex cell div
Akron70903c42018-02-05 12:31:10 +0100481 cell = matchTable.querySelector("tbody > tr:nth-child(1) > td:nth-child(6) > div:nth-child(1)");
Akron7cf33fd2017-07-03 17:33:39 +0200482 expect(cell.innerText).toEqual('case:nom');
483 expect(cell.classList.contains("chosen")).toBe(false);
484 cell.click();
485 expect(cell.classList.contains("chosen")).toBe(true);
486 expect(qc.toString()).toEqual("[orth=lebende][corenlp/p=case:nom]");
487 var cell = cell;
488
Akron70903c42018-02-05 12:31:10 +0100489 cell = matchTable.querySelector("tbody > tr:nth-child(1) > td:nth-child(6) > div:nth-child(3)");
Akron7cf33fd2017-07-03 17:33:39 +0200490 expect(cell.innerText).toEqual('number:sg');
491 expect(cell.classList.contains("chosen")).toBe(false);
492 cell.click();
493 expect(cell.classList.contains("chosen")).toBe(true);
494 expect(qc.toString()).toEqual("[orth=lebende][corenlp/p=case:nom & corenlp/p=number:sg]");
495 var cell2 = cell;
496
Akron70903c42018-02-05 12:31:10 +0100497 cell = matchTable.querySelector("tbody > tr:nth-child(1) > td:nth-child(6) > div:nth-child(2)");
Akron7cf33fd2017-07-03 17:33:39 +0200498 expect(cell.innerText).toEqual('gender:mascgender:fem');
499 expect(cell.classList.contains("chosen")).toBe(false);
500 cell.click();
501 expect(cell.classList.contains("chosen")).toBe(true);
502 expect(qc.toString()).toEqual("[orth=lebende][(corenlp/p=gender:fem | corenlp/p=gender:masc) & corenlp/p=case:nom & corenlp/p=number:sg]");
503 var cell3 = cell;
504
505 // Remove cell again
506 cell = cell2;
507 expect(cell.innerText).toEqual('number:sg');
508 expect(cell.classList.contains("chosen")).toBe(true);
509 cell.click();
510 expect(cell.classList.contains("chosen")).toBe(false);
511 expect(qc.toString()).toEqual("[orth=lebende][(corenlp/p=gender:fem | corenlp/p=gender:masc) & corenlp/p=case:nom]");
512
513 // Remove cell again
514 cell = cell3;
515 expect(cell.innerText).toEqual('gender:mascgender:fem');
516 expect(cell.classList.contains("chosen")).toBe(true);
517 cell.click();
518 expect(cell.classList.contains("chosen")).toBe(false);
519 expect(qc.toString()).toEqual("[orth=lebende][corenlp/p=case:nom]");
520 });
521
522
523 it('should create rows including key-value terms', function () {
Akron70903c42018-02-05 12:31:10 +0100524 var matchTable = matchTableComplexFactory();
525 var qc = qcClass.create(matchTable);
Akron7cf33fd2017-07-03 17:33:39 +0200526 expect(qc.toString()).toEqual("");
527
Akron70903c42018-02-05 12:31:10 +0100528 var corenlpRow = matchTable.querySelector("tbody > tr:nth-child(1)");
Akron7cf33fd2017-07-03 17:33:39 +0200529
530 expect(corenlpRow.querySelector("td:nth-child(3).chosen")).toBeNull();
531 expect(corenlpRow.querySelector("td:nth-child(4).chosen")).toBeNull();
532 expect(corenlpRow.querySelector("td:nth-child(5).chosen")).toBeNull();
533 expect(corenlpRow.querySelector("td:nth-child(6) *.chosen")).toBeNull();
534
535 expect(qc.toString()).toEqual("");
536
537 // Mark all opennlp lists
538 cell = corenlpRow.querySelector("th:nth-child(1)");
539 expect(cell.innerText).toEqual("corenlp");
540 expect(cell.classList.contains("chosen")).toBe(false);
541 cell.click();
542 expect(cell.classList.contains("chosen")).toBe(false);
543
544 expect(corenlpRow.querySelector("td:nth-child(3).chosen")).toBeTruthy();
545 expect(corenlpRow.querySelector("td:nth-child(4).chosen")).toBeTruthy();
546 expect(corenlpRow.querySelector("td:nth-child(5).chosen")).toBeTruthy();
547 expect(corenlpRow.querySelector("td:nth-child(6) div:nth-child(1).chosen")).toBeTruthy();
548 expect(corenlpRow.querySelector("td:nth-child(6) div:nth-child(2).chosen")).toBeTruthy();
549 expect(corenlpRow.querySelector("td:nth-child(6) div:nth-child(3).chosen")).toBeTruthy();
550
551 expect(qc.toString()).toEqual(
552 "[corenlp/p=ART]"+
553 "[corenlp/p=ADJA]"+
554 "[(corenlp/p=ADJA | corenlp/p=ADJD)]"+
555 "[(corenlp/p=gender:fem | corenlp/p=gender:masc) & corenlp/p=case:nom & corenlp/p=number:sg]"
556 );
557 });
Akronb46d8e32017-06-29 14:26:14 +0200558 });
559});