blob: dffd3d3219f0838a9020eddf4b7eb7af8b0803af [file] [log] [blame]
Akron70903c42018-02-05 12:31:10 +01001function matchTableFactory () {
2 var table = document.createElement('div');
Akronbdcbbf42018-04-25 12:42:44 +02003
4 Element.prototype.innerString = function () {
5 return this.innerText.split("\n").join("");
6 };
7
8
Akron70903c42018-02-05 12:31:10 +01009 table.className = 'matchtable';
10 table.innerHTML =
Akronb46d8e32017-06-29 14:26:14 +020011 " <table>" +
12 " <thead>" +
13 " <tr>" +
14 " <th>Foundry</th>" +
15 " <th>Layer</th>" +
16 " <th>Der</th>" +
17 " <th>älteste</th>" +
18 " <th>lebende</th>" +
19 " <th>Baum</th>" +
Akrone9be11d2017-06-29 20:10:58 +020020 " <th>hier</th>" +
Akronb46d8e32017-06-29 14:26:14 +020021 " </tr>" +
22 " </thead>" +
23 " <tbody>" +
24 " <tr tabindex=\"0\">" +
25 " <th>corenlp</th>" +
26 " <th>p</th>" +
27 " <td>ART</td>" +
28 " <td>ADJA</td>" +
29 " <td>ADJA<br>ADJD</td>" +
30 " <td>NN</td>" +
Akrone9be11d2017-06-29 20:10:58 +020031 " <td>ADV</td>" +
Akronb46d8e32017-06-29 14:26:14 +020032 " </tr>" +
33 " <tr tabindex=\"0\">" +
34 " <th>opennlp</th>" +
35 " <th>p</th>" +
36 " <td>ART</td>" +
37 " <td>ADJA</td>" +
38 " <td></td>" +
39 " <td>NN</td>" +
Akrone9be11d2017-06-29 20:10:58 +020040 " <td>ADV</td>" +
Akronb46d8e32017-06-29 14:26:14 +020041 " </tr>" +
42 " </tbody>" +
43 " </table>" +
Akron70903c42018-02-05 12:31:10 +010044 " </div>";
Akronb46d8e32017-06-29 14:26:14 +020045
Akron70903c42018-02-05 12:31:10 +010046 var info = document.createElement('div');
47 info.appendChild(table);
48 return table;
Akronb46d8e32017-06-29 14:26:14 +020049};
50
Akron70903c42018-02-05 12:31:10 +010051function matchTableComplexFactory () {
52 var table = document.createElement('div');
53 table.className = 'matchtable';
54 table.innerHTML =
Akron7cf33fd2017-07-03 17:33:39 +020055 " <table>" +
56 " <thead>" +
57 " <tr>" +
58 " <th>Foundry</th>" +
59 " <th>Layer</th>" +
60 " <th>Der</th>" +
61 " <th>älteste</th>" +
62 " <th>lebende</th>" +
63 " <th>Baum</th>" +
64 " </tr>" +
65 " </thead>" +
66 " <tbody>" +
67 " <tr tabindex=\"0\">" +
68 " <th>corenlp</th>" +
69 " <th>p</th>" +
70 " <td>ART</td>" +
71 " <td>ADJA</td>" +
72 " <td>ADJA<br>ADJD</td>" +
73 " <td class=\"matchkeyvalues\">" +
74 " <div>case:nom</div>" +
75 " <div>gender:masc<br/>gender:fem</div>" +
76 " <div>number:sg</div>" +
77 " </td>" +
78 " </tr>" +
79 " <tr tabindex=\"0\">" +
80 " <th>opennlp</th>" +
81 " <th>p</th>" +
82 " <td class=\"matchkeyvalues\">" +
83 " <div>case:nom</div>" +
84 " <div>gender:masc</div>" +
85 " <div>number:sg</div>" +
86 " </td>" +
87 " <td>ADJA</td>" +
88 " <td></td>" +
89 " <td>NN</td>" +
90 " </tr>" +
91 " </tbody>" +
Akron70903c42018-02-05 12:31:10 +010092 " </table>";
93 var info = document.createElement('div');
94 info.appendChild(table);
95 return table;
Akron7cf33fd2017-07-03 17:33:39 +020096};
97
Akronb46d8e32017-06-29 14:26:14 +020098
99define(['match/querycreator'], function (qcClass) {
100
101 describe('KorAP.QueryCreator', function () {
102
103 it('should be initializable', function () {
104 expect(
105 function() {
106 qcClass.create()
107 }
108 ).toThrow(new Error("Missing parameters"));
109
110 expect(
111 function() {
112 qcClass.create("Test")
113 }
114 ).toThrow(new Error("Requires element"));
115
Akron70903c42018-02-05 12:31:10 +0100116 expect(qcClass.create(matchTableFactory()).toString()).toEqual("");
Akronb46d8e32017-06-29 14:26:14 +0200117 });
118
119 it('should listen to click events', function () {
120
Akron70903c42018-02-05 12:31:10 +0100121 var matchTable = matchTableFactory();
122 var qc = qcClass.create(matchTable);
Akronb46d8e32017-06-29 14:26:14 +0200123
124 // Nothing to show
125 expect(qc.toString()).toEqual("");
126 expect(qc.shown()).toBe(false);
127 qc.show();
128 expect(qc.shown()).toBe(false);
129 expect(qc.element().className).toEqual("queryfragment");
130
131 // Click on cell 0:0 "Foundry"
Akron70903c42018-02-05 12:31:10 +0100132 var cell = matchTable.querySelector("thead > tr > th:first-child");
Akronbdcbbf42018-04-25 12:42:44 +0200133 expect(cell.innerString()).toEqual("Foundry");
Akronb46d8e32017-06-29 14:26:14 +0200134 cell.click();
135 expect(cell.classList.contains("chosen")).toBe(false);
136 expect(qc.toString()).toEqual("");
137 expect(qc.shown()).toBe(false);
138
139 // Click on cell 0:2 "Der"
Akron70903c42018-02-05 12:31:10 +0100140 cell = matchTable.querySelector("thead > tr > th:nth-child(3)")
Akronbdcbbf42018-04-25 12:42:44 +0200141 expect(cell.innerString()).toEqual("Der");
Akronb46d8e32017-06-29 14:26:14 +0200142 cell.click();
143 expect(cell.classList.contains("chosen")).toBeTruthy();
144 expect(qc.toString()).toEqual("[orth=Der]");
145 expect(qc.shown()).toBeTruthy();
146
147 // Click on cell 0:2 "Der" again - to hide
Akron70903c42018-02-05 12:31:10 +0100148 cell = matchTable.querySelector("thead > tr > th:nth-child(3)")
Akronbdcbbf42018-04-25 12:42:44 +0200149 expect(cell.innerString()).toEqual("Der");
Akronb46d8e32017-06-29 14:26:14 +0200150 cell.click();
151 expect(cell.classList.contains("chosen")).toBe(false);
152 expect(qc.toString()).toEqual("");
153 expect(qc.shown()).toBe(false);
154 });
155
156 it('should create tokens in arbitrary order', function () {
Akron70903c42018-02-05 12:31:10 +0100157 var matchTable = matchTableFactory();
158 var qc = qcClass.create(matchTable);
Akronb46d8e32017-06-29 14:26:14 +0200159
Akron70903c42018-02-05 12:31:10 +0100160 var cell = matchTable.querySelector("tbody > tr:nth-child(2) > td:nth-child(4)");
Akronbdcbbf42018-04-25 12:42:44 +0200161 expect(cell.innerString()).toEqual("ADJA");
Akronb46d8e32017-06-29 14:26:14 +0200162 cell.click();
163 expect(qc.toString()).toEqual("[opennlp/p=ADJA]");
164
Akron70903c42018-02-05 12:31:10 +0100165 cell = matchTable.querySelector("thead > tr > th:nth-child(4)");
Akronbdcbbf42018-04-25 12:42:44 +0200166 expect(cell.innerString()).toEqual("älteste");
Akronb46d8e32017-06-29 14:26:14 +0200167 cell.click();
168 expect(qc.toString()).toEqual("[opennlp/p=ADJA & orth=älteste]");
169
Akron70903c42018-02-05 12:31:10 +0100170 cell = matchTable.querySelector("tbody > tr > td:nth-child(4)");
Akronbdcbbf42018-04-25 12:42:44 +0200171 expect(cell.innerString()).toEqual("ADJA");
Akronb46d8e32017-06-29 14:26:14 +0200172 cell.click();
173 expect(qc.toString()).toEqual("[corenlp/p=ADJA & opennlp/p=ADJA & orth=älteste]");
174 });
175
176 it('should create token sequences in arbitrary order', function () {
Akron70903c42018-02-05 12:31:10 +0100177 var matchTable = matchTableFactory();
178 var qc = qcClass.create(matchTable);
Akronb46d8e32017-06-29 14:26:14 +0200179
Akron70903c42018-02-05 12:31:10 +0100180 var cell = matchTable.querySelector("thead > tr > th:nth-child(5)");
Akronbdcbbf42018-04-25 12:42:44 +0200181 expect(cell.innerString()).toEqual("lebende");
Akronb46d8e32017-06-29 14:26:14 +0200182 cell.click();
183 expect(qc.toString()).toEqual("[orth=lebende]");
184
Akron70903c42018-02-05 12:31:10 +0100185 cell = matchTable.querySelector("tbody > tr:nth-child(2) > td:nth-child(3)");
Akronbdcbbf42018-04-25 12:42:44 +0200186 expect(cell.innerString()).toEqual("ART");
Akronb46d8e32017-06-29 14:26:14 +0200187 cell.click();
Akrone9be11d2017-06-29 20:10:58 +0200188 expect(qc.toString()).toEqual("[opennlp/p=ART][][orth=lebende]");
Akronb46d8e32017-06-29 14:26:14 +0200189
Akron70903c42018-02-05 12:31:10 +0100190 cell = matchTable.querySelector("tbody > tr > td:nth-child(4)");
Akronbdcbbf42018-04-25 12:42:44 +0200191 expect(cell.innerString()).toEqual("ADJA");
Akronb46d8e32017-06-29 14:26:14 +0200192 cell.click();
193 expect(qc.toString()).toEqual("[opennlp/p=ART][corenlp/p=ADJA][orth=lebende]");
194 });
195
196 it('should remove chosen elements again', function () {
Akron70903c42018-02-05 12:31:10 +0100197 var matchTable = matchTableFactory();
198 var qc = qcClass.create(matchTable);
Akronb46d8e32017-06-29 14:26:14 +0200199
Akron70903c42018-02-05 12:31:10 +0100200 var cell = matchTable.querySelector("tbody > tr:nth-child(2) > td:nth-child(4)");
Akronbdcbbf42018-04-25 12:42:44 +0200201 expect(cell.innerString()).toEqual("ADJA");
Akronb46d8e32017-06-29 14:26:14 +0200202 cell.click();
203 expect(qc.toString()).toEqual("[opennlp/p=ADJA]");
204 var cell1 = cell;
205
Akron70903c42018-02-05 12:31:10 +0100206 cell = matchTable.querySelector("thead > tr > th:nth-child(4)");
Akronbdcbbf42018-04-25 12:42:44 +0200207 expect(cell.innerString()).toEqual("älteste");
Akronb46d8e32017-06-29 14:26:14 +0200208 cell.click();
209 expect(qc.toString()).toEqual("[opennlp/p=ADJA & orth=älteste]");
210 var cell2 = cell;
211
Akron70903c42018-02-05 12:31:10 +0100212 cell = matchTable.querySelector("tbody > tr > td:nth-child(3)");
Akronbdcbbf42018-04-25 12:42:44 +0200213 expect(cell.innerString()).toEqual("ART");
Akronb46d8e32017-06-29 14:26:14 +0200214 cell.click();
215 expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA & orth=älteste]");
216 var cell3 = cell;
217
Akron70903c42018-02-05 12:31:10 +0100218 cell = matchTable.querySelector("thead > tr > th:nth-child(6)");
Akronbdcbbf42018-04-25 12:42:44 +0200219 expect(cell.innerString()).toEqual("Baum");
Akronb46d8e32017-06-29 14:26:14 +0200220 cell.click();
Akrone9be11d2017-06-29 20:10:58 +0200221 expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA & orth=älteste][][orth=Baum]");
Akronb46d8e32017-06-29 14:26:14 +0200222 var cell4 = cell;
223
Akron70903c42018-02-05 12:31:10 +0100224 cell = matchTable.querySelector("thead > tr > th:nth-child(5)");
Akronbdcbbf42018-04-25 12:42:44 +0200225 expect(cell.innerString()).toEqual("lebende");
Akronb46d8e32017-06-29 14:26:14 +0200226 cell.click();
227 expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA & orth=älteste][orth=lebende][orth=Baum]");
228 var cell5 = cell;
229
230
231 // Remove annotations again
232 expect(cell5.classList.contains("chosen")).toBeTruthy();
233 cell5.click()
234 expect(cell5.classList.contains("chosen")).toBe(false);
Akrone9be11d2017-06-29 20:10:58 +0200235 expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA & orth=älteste][][orth=Baum]");
Akronb46d8e32017-06-29 14:26:14 +0200236
237 expect(cell2.classList.contains("chosen")).toBeTruthy();
238 cell2.click()
239 expect(cell2.classList.contains("chosen")).toBe(false);
Akrone9be11d2017-06-29 20:10:58 +0200240 expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA][][orth=Baum]");
Akronb46d8e32017-06-29 14:26:14 +0200241
242 expect(cell1.classList.contains("chosen")).toBeTruthy();
243 cell1.click()
244 expect(cell1.classList.contains("chosen")).toBe(false);
Akrone9be11d2017-06-29 20:10:58 +0200245 expect(qc.toString()).toEqual("[corenlp/p=ART][]{2}[orth=Baum]");
Akronb46d8e32017-06-29 14:26:14 +0200246
247 // Re-add first cell at the same position
248 expect(cell1.classList.contains("chosen")).toBe(false);
249 cell1.click()
250 expect(cell1.classList.contains("chosen")).toBeTruthy();
Akrone9be11d2017-06-29 20:10:58 +0200251 expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA][][orth=Baum]");
Akronb46d8e32017-06-29 14:26:14 +0200252
253 expect(cell3.classList.contains("chosen")).toBeTruthy();
254 cell3.click()
255 expect(cell3.classList.contains("chosen")).toBe(false);
Akrone9be11d2017-06-29 20:10:58 +0200256 expect(qc.toString()).toEqual("[opennlp/p=ADJA][][orth=Baum]");
Akronb46d8e32017-06-29 14:26:14 +0200257
258 expect(cell4.classList.contains("chosen")).toBeTruthy();
259 cell4.click()
260 expect(cell4.classList.contains("chosen")).toBe(false);
261 expect(qc.toString()).toEqual("[opennlp/p=ADJA]");
262
263 // Remove last token
264 expect(qc.shown()).toBeTruthy();
265 expect(qc.element().innerHTML).toEqual("<span>New Query:</span><span>[opennlp/p=ADJA]</span>");
266 expect(cell1.classList.contains("chosen")).toBeTruthy();
267 cell1.click()
268 expect(cell1.classList.contains("chosen")).toBe(false);
269 expect(qc.toString()).toEqual("");
270 expect(qc.shown()).toBe(false);
271
272 // Re-add token
273 expect(cell4.classList.contains("chosen")).toBe(false);
274 cell4.click()
275 expect(cell4.classList.contains("chosen")).toBeTruthy();
276 expect(qc.toString()).toEqual("[orth=Baum]");
277 expect(qc.shown()).toBeTruthy();
278 expect(qc.element().innerHTML).toEqual("<span>New Query:</span><span>[orth=Baum]</span>");
279 });
280
Akronc8461bf2017-06-29 15:05:24 +0200281 it('should ignore empty terms', function () {
Akron70903c42018-02-05 12:31:10 +0100282 var matchTable = matchTableFactory();
283 var qc = qcClass.create(matchTable);
Akronb46d8e32017-06-29 14:26:14 +0200284
Akronc8461bf2017-06-29 15:05:24 +0200285 // Nothing to show
286 expect(qc.toString()).toEqual("");
287 expect(qc.shown()).toBe(false);
288 qc.show();
289 expect(qc.shown()).toBe(false);
290 expect(qc.element().className).toEqual("queryfragment");
291
Akron70903c42018-02-05 12:31:10 +0100292 var cell = matchTable.querySelector("tbody > tr:nth-child(2) > td:nth-child(4)");
Akronbdcbbf42018-04-25 12:42:44 +0200293 expect(cell.innerString()).toEqual("ADJA");
Akronc8461bf2017-06-29 15:05:24 +0200294 expect(cell.classList.contains("chosen")).toBe(false);
295 cell.click();
296 expect(cell.classList.contains("chosen")).toBeTruthy();
297 expect(qc.toString()).toEqual("[opennlp/p=ADJA]");
298
Akron70903c42018-02-05 12:31:10 +0100299 cell = matchTable.querySelector("tbody > tr:nth-child(2) > td:nth-child(5)");
Akronbdcbbf42018-04-25 12:42:44 +0200300 expect(cell.innerString()).toEqual("");
Akronc8461bf2017-06-29 15:05:24 +0200301 expect(cell.classList.contains("chosen")).toBe(false);
302 cell.click();
303 expect(cell.classList.contains("chosen")).toBe(false);
304 expect(qc.toString()).toEqual("[opennlp/p=ADJA]");
305
306 });
307
Akron7cf33fd2017-07-03 17:33:39 +0200308 it('should create or-groups for alternative terms', function () {
Akron70903c42018-02-05 12:31:10 +0100309 var matchTable = matchTableFactory();
310 var qc = qcClass.create(matchTable);
Akronc8461bf2017-06-29 15:05:24 +0200311
312 // Nothing to show
313 expect(qc.toString()).toEqual("");
314 expect(qc.shown()).toBe(false);
315 qc.show();
316 expect(qc.shown()).toBe(false);
317 expect(qc.element().className).toEqual("queryfragment");
318
Akron70903c42018-02-05 12:31:10 +0100319 var cell = matchTable.querySelector("thead > tr > th:nth-child(5)");
Akronbdcbbf42018-04-25 12:42:44 +0200320 expect(cell.innerString()).toEqual("lebende");
Akronc8461bf2017-06-29 15:05:24 +0200321 expect(cell.classList.contains("chosen")).toBe(false);
322 cell.click();
323 expect(cell.classList.contains("chosen")).toBeTruthy();
324 expect(qc.toString()).toEqual("[orth=lebende]");
325
Akron70903c42018-02-05 12:31:10 +0100326 cell = matchTable.querySelector("tbody > tr:nth-child(1) > td:nth-child(5)");
Akronbdcbbf42018-04-25 12:42:44 +0200327 expect(cell.innerString()).toEqual("ADJAADJD");
Akronc8461bf2017-06-29 15:05:24 +0200328 expect(cell.classList.contains("chosen")).toBe(false);
329 cell.click();
330 expect(cell.classList.contains("chosen")).toBeTruthy();
331 expect(qc.toString()).toEqual("[(corenlp/p=ADJA | corenlp/p=ADJD) & orth=lebende]");
332
333 // Remove or group again
334 expect(cell.classList.contains("chosen")).toBeTruthy();
335 cell.click();
336 expect(cell.classList.contains("chosen")).toBe(false);
337 expect(qc.toString()).toEqual("[orth=lebende]");
338 });
339
340
341 it('should add whole rows', function () {
Akron70903c42018-02-05 12:31:10 +0100342 var matchTable = matchTableFactory();
343 var qc = qcClass.create(matchTable);
Akronc8461bf2017-06-29 15:05:24 +0200344
345 // Nothing to show
346 expect(qc.toString()).toEqual("");
347 expect(qc.shown()).toBe(false);
348 qc.show();
349 expect(qc.shown()).toBe(false);
350 expect(qc.element().className).toEqual("queryfragment");
351
Akron70903c42018-02-05 12:31:10 +0100352 var corenlpRow = matchTable.querySelector("tbody > tr:nth-child(1)");
Akronc8461bf2017-06-29 15:05:24 +0200353
354 var cell = corenlpRow.querySelector("td:nth-child(4)");
Akronbdcbbf42018-04-25 12:42:44 +0200355 expect(cell.innerString()).toEqual("ADJA");
Akronc8461bf2017-06-29 15:05:24 +0200356 expect(cell.classList.contains("chosen")).toBe(false);
357 cell.click();
358 expect(cell.classList.contains("chosen")).toBeTruthy();
359
360 // Activate another cell in another row
Akron70903c42018-02-05 12:31:10 +0100361 cell = matchTable.querySelector("tbody > tr:nth-child(2) td:nth-child(3)");
Akronbdcbbf42018-04-25 12:42:44 +0200362 expect(cell.innerString()).toEqual("ART");
Akronc8461bf2017-06-29 15:05:24 +0200363 expect(cell.classList.contains("chosen")).toBe(false);
364 cell.click();
365 expect(cell.classList.contains("chosen")).toBeTruthy();
366
367 expect(corenlpRow.querySelector("td:nth-child(3).chosen")).toBeNull();
368 expect(corenlpRow.querySelector("td:nth-child(4).chosen")).toBeTruthy();
369 expect(corenlpRow.querySelector("td:nth-child(5).chosen")).toBeNull();
370 expect(corenlpRow.querySelector("td:nth-child(6).chosen")).toBeNull();
371
372 expect(qc.toString()).toEqual("[opennlp/p=ART][corenlp/p=ADJA]");
373
374 // Mark all corenlp lists
375 cell = corenlpRow.querySelector("th:nth-child(1)");
Akronbdcbbf42018-04-25 12:42:44 +0200376 expect(cell.innerString()).toEqual("corenlp");
Akronc8461bf2017-06-29 15:05:24 +0200377 expect(cell.classList.contains("chosen")).toBe(false);
378 cell.click();
379 expect(cell.classList.contains("chosen")).toBe(false);
380
381 expect(corenlpRow.querySelector("td:nth-child(3).chosen")).toBeTruthy();
382 expect(corenlpRow.querySelector("td:nth-child(4).chosen")).toBeTruthy();
383 expect(corenlpRow.querySelector("td:nth-child(5).chosen")).toBeTruthy();
384 expect(corenlpRow.querySelector("td:nth-child(6).chosen")).toBeTruthy();
385
386 // Replay the choice without any effect
387 cell = corenlpRow.querySelector("th:nth-child(1)");
Akronbdcbbf42018-04-25 12:42:44 +0200388 expect(cell.innerString()).toEqual("corenlp");
Akronc8461bf2017-06-29 15:05:24 +0200389 expect(cell.classList.contains("chosen")).toBe(false);
390 cell.click();
391 expect(cell.classList.contains("chosen")).toBe(false);
392
393 expect(corenlpRow.querySelector("td:nth-child(3).chosen")).toBeTruthy();
394 expect(corenlpRow.querySelector("td:nth-child(4).chosen")).toBeTruthy();
395 expect(corenlpRow.querySelector("td:nth-child(5).chosen")).toBeTruthy();
396 expect(corenlpRow.querySelector("td:nth-child(6).chosen")).toBeTruthy();
Akrone9be11d2017-06-29 20:10:58 +0200397 expect(corenlpRow.querySelector("td:nth-child(7).chosen")).toBeTruthy();
Akronc8461bf2017-06-29 15:05:24 +0200398
Akrone9be11d2017-06-29 20:10:58 +0200399 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 +0200400
401 // Remove one of the cells again
402 cell = corenlpRow.querySelector("td:nth-child(5).chosen");
Akronbdcbbf42018-04-25 12:42:44 +0200403 expect(cell.innerString()).toEqual("ADJAADJD");
Akronc8461bf2017-06-29 15:05:24 +0200404 expect(cell.classList.contains("chosen")).toBeTruthy();
405 cell.click();
406 expect(cell.classList.contains("chosen")).toBe(false);
Akrone9be11d2017-06-29 20:10:58 +0200407 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 +0200408
409 });
Akron8084cb52017-06-29 17:11:14 +0200410
411 it('should ignore empty terms in whole rows', function () {
Akron70903c42018-02-05 12:31:10 +0100412 var matchTable = matchTableFactory();
413 var qc = qcClass.create(matchTable);
Akron8084cb52017-06-29 17:11:14 +0200414 expect(qc.toString()).toEqual("");
415
Akron70903c42018-02-05 12:31:10 +0100416 var opennlpRow = matchTable.querySelector("tbody > tr:nth-child(2)");
Akron8084cb52017-06-29 17:11:14 +0200417
418 expect(opennlpRow.querySelector("td:nth-child(3).chosen")).toBeNull();
419 expect(opennlpRow.querySelector("td:nth-child(4).chosen")).toBeNull();
420 expect(opennlpRow.querySelector("td:nth-child(5).chosen")).toBeNull();
421 expect(opennlpRow.querySelector("td:nth-child(6).chosen")).toBeNull();
422
423 expect(qc.toString()).toEqual("");
424
425 // Mark all opennlp lists
426 cell = opennlpRow.querySelector("th:nth-child(1)");
Akronbdcbbf42018-04-25 12:42:44 +0200427 expect(cell.innerString()).toEqual("opennlp");
Akron8084cb52017-06-29 17:11:14 +0200428 expect(cell.classList.contains("chosen")).toBe(false);
429 cell.click();
430 expect(cell.classList.contains("chosen")).toBe(false);
431
432 expect(opennlpRow.querySelector("td:nth-child(3).chosen")).toBeTruthy();
433 expect(opennlpRow.querySelector("td:nth-child(4).chosen")).toBeTruthy();
434 expect(opennlpRow.querySelector("td:nth-child(5).chosen")).toBeNull();
435 expect(opennlpRow.querySelector("td:nth-child(6).chosen")).toBeTruthy();
Akron7cf33fd2017-07-03 17:33:39 +0200436
437 expect(qc.toString()).toEqual("[opennlp/p=ART][opennlp/p=ADJA][][opennlp/p=NN][opennlp/p=ADV]");
Akron8084cb52017-06-29 17:11:14 +0200438 });
Akrone9be11d2017-06-29 20:10:58 +0200439
440 it('should support multiple distances', function () {
Akron70903c42018-02-05 12:31:10 +0100441 var matchTable = matchTableFactory();
442 var qc = qcClass.create(matchTable);
Akrone9be11d2017-06-29 20:10:58 +0200443
Akron70903c42018-02-05 12:31:10 +0100444 var cell = matchTable.querySelector("thead > tr > th:nth-child(3)");
Akronbdcbbf42018-04-25 12:42:44 +0200445 expect(cell.innerString()).toEqual("Der");
Akrone9be11d2017-06-29 20:10:58 +0200446 cell.click();
447 expect(qc.toString()).toEqual("[orth=Der]");
448
Akron70903c42018-02-05 12:31:10 +0100449 cell = matchTable.querySelector("thead > tr > th:nth-child(7)");
Akronbdcbbf42018-04-25 12:42:44 +0200450 expect(cell.innerString()).toEqual("hier");
Akrone9be11d2017-06-29 20:10:58 +0200451 cell.click();
452 expect(qc.toString()).toEqual("[orth=Der][]{3}[orth=hier]");
453
Akron70903c42018-02-05 12:31:10 +0100454 cell = matchTable.querySelector("thead > tr > th:nth-child(5)");
Akronbdcbbf42018-04-25 12:42:44 +0200455 expect(cell.innerString()).toEqual("lebende");
Akrone9be11d2017-06-29 20:10:58 +0200456 cell.click();
457 expect(qc.toString()).toEqual("[orth=Der][][orth=lebende][][orth=hier]");
458 });
Akron7cf33fd2017-07-03 17:33:39 +0200459
460 it('should create and-groups for key-value terms', function () {
Akron70903c42018-02-05 12:31:10 +0100461 var matchTable = matchTableComplexFactory();
462 var qc = qcClass.create(matchTable);
Akron7cf33fd2017-07-03 17:33:39 +0200463
464 // Nothing to show
465 expect(qc.toString()).toEqual("");
466 expect(qc.shown()).toBe(false);
467 qc.show();
468 expect(qc.shown()).toBe(false);
469 expect(qc.element().className).toEqual("queryfragment");
470
Akron70903c42018-02-05 12:31:10 +0100471 var cell = matchTable.querySelector("thead > tr > th:nth-child(5)");
Akronbdcbbf42018-04-25 12:42:44 +0200472 expect(cell.innerString()).toEqual("lebende");
Akron7cf33fd2017-07-03 17:33:39 +0200473 expect(cell.classList.contains("chosen")).toBe(false);
474 cell.click();
475 expect(cell.classList.contains("chosen")).toBeTruthy();
476 expect(qc.toString()).toEqual("[orth=lebende]");
477
478 // Check complex cell
Akron70903c42018-02-05 12:31:10 +0100479 cell = matchTable.querySelector("tbody > tr:nth-child(1) > td:nth-child(6)");
Akronbdcbbf42018-04-25 12:42:44 +0200480 expect(cell.innerString()).toMatch(/case:nom/);
Akron7cf33fd2017-07-03 17:33:39 +0200481 expect(cell.classList.contains("chosen")).toBe(false);
482 cell.click();
483 expect(cell.classList.contains("chosen")).toBe(false);
484 expect(qc.toString()).toEqual("[orth=lebende]");
485
486 // Check complex cell div
Akron70903c42018-02-05 12:31:10 +0100487 cell = matchTable.querySelector("tbody > tr:nth-child(1) > td:nth-child(6) > div:nth-child(1)");
Akronbdcbbf42018-04-25 12:42:44 +0200488 expect(cell.innerString()).toEqual('case:nom');
Akron7cf33fd2017-07-03 17:33:39 +0200489 expect(cell.classList.contains("chosen")).toBe(false);
490 cell.click();
491 expect(cell.classList.contains("chosen")).toBe(true);
492 expect(qc.toString()).toEqual("[orth=lebende][corenlp/p=case:nom]");
493 var cell = cell;
494
Akron70903c42018-02-05 12:31:10 +0100495 cell = matchTable.querySelector("tbody > tr:nth-child(1) > td:nth-child(6) > div:nth-child(3)");
Akronbdcbbf42018-04-25 12:42:44 +0200496 expect(cell.innerString()).toEqual('number:sg');
Akron7cf33fd2017-07-03 17:33:39 +0200497 expect(cell.classList.contains("chosen")).toBe(false);
498 cell.click();
499 expect(cell.classList.contains("chosen")).toBe(true);
500 expect(qc.toString()).toEqual("[orth=lebende][corenlp/p=case:nom & corenlp/p=number:sg]");
501 var cell2 = cell;
502
Akron70903c42018-02-05 12:31:10 +0100503 cell = matchTable.querySelector("tbody > tr:nth-child(1) > td:nth-child(6) > div:nth-child(2)");
Akronbdcbbf42018-04-25 12:42:44 +0200504 expect(cell.innerString()).toEqual('gender:mascgender:fem');
Akron7cf33fd2017-07-03 17:33:39 +0200505 expect(cell.classList.contains("chosen")).toBe(false);
506 cell.click();
507 expect(cell.classList.contains("chosen")).toBe(true);
508 expect(qc.toString()).toEqual("[orth=lebende][(corenlp/p=gender:fem | corenlp/p=gender:masc) & corenlp/p=case:nom & corenlp/p=number:sg]");
509 var cell3 = cell;
510
511 // Remove cell again
512 cell = cell2;
Akronbdcbbf42018-04-25 12:42:44 +0200513 expect(cell.innerString()).toEqual('number:sg');
Akron7cf33fd2017-07-03 17:33:39 +0200514 expect(cell.classList.contains("chosen")).toBe(true);
515 cell.click();
516 expect(cell.classList.contains("chosen")).toBe(false);
517 expect(qc.toString()).toEqual("[orth=lebende][(corenlp/p=gender:fem | corenlp/p=gender:masc) & corenlp/p=case:nom]");
518
519 // Remove cell again
520 cell = cell3;
Akronbdcbbf42018-04-25 12:42:44 +0200521 expect(cell.innerString()).toEqual('gender:mascgender:fem');
Akron7cf33fd2017-07-03 17:33:39 +0200522 expect(cell.classList.contains("chosen")).toBe(true);
523 cell.click();
524 expect(cell.classList.contains("chosen")).toBe(false);
525 expect(qc.toString()).toEqual("[orth=lebende][corenlp/p=case:nom]");
526 });
527
528
529 it('should create rows including key-value terms', function () {
Akron70903c42018-02-05 12:31:10 +0100530 var matchTable = matchTableComplexFactory();
531 var qc = qcClass.create(matchTable);
Akron7cf33fd2017-07-03 17:33:39 +0200532 expect(qc.toString()).toEqual("");
533
Akron70903c42018-02-05 12:31:10 +0100534 var corenlpRow = matchTable.querySelector("tbody > tr:nth-child(1)");
Akron7cf33fd2017-07-03 17:33:39 +0200535
536 expect(corenlpRow.querySelector("td:nth-child(3).chosen")).toBeNull();
537 expect(corenlpRow.querySelector("td:nth-child(4).chosen")).toBeNull();
538 expect(corenlpRow.querySelector("td:nth-child(5).chosen")).toBeNull();
539 expect(corenlpRow.querySelector("td:nth-child(6) *.chosen")).toBeNull();
540
541 expect(qc.toString()).toEqual("");
542
543 // Mark all opennlp lists
544 cell = corenlpRow.querySelector("th:nth-child(1)");
Akronbdcbbf42018-04-25 12:42:44 +0200545 expect(cell.innerString()).toEqual("corenlp");
Akron7cf33fd2017-07-03 17:33:39 +0200546 expect(cell.classList.contains("chosen")).toBe(false);
547 cell.click();
548 expect(cell.classList.contains("chosen")).toBe(false);
549
550 expect(corenlpRow.querySelector("td:nth-child(3).chosen")).toBeTruthy();
551 expect(corenlpRow.querySelector("td:nth-child(4).chosen")).toBeTruthy();
552 expect(corenlpRow.querySelector("td:nth-child(5).chosen")).toBeTruthy();
553 expect(corenlpRow.querySelector("td:nth-child(6) div:nth-child(1).chosen")).toBeTruthy();
554 expect(corenlpRow.querySelector("td:nth-child(6) div:nth-child(2).chosen")).toBeTruthy();
555 expect(corenlpRow.querySelector("td:nth-child(6) div:nth-child(3).chosen")).toBeTruthy();
556
557 expect(qc.toString()).toEqual(
558 "[corenlp/p=ART]"+
559 "[corenlp/p=ADJA]"+
560 "[(corenlp/p=ADJA | corenlp/p=ADJD)]"+
561 "[(corenlp/p=gender:fem | corenlp/p=gender:masc) & corenlp/p=case:nom & corenlp/p=number:sg]"
562 );
563 });
Akronb46d8e32017-06-29 14:26:14 +0200564 });
565});