blob: 59547eff86ec033e928af9c087ed98d2dcdc229c [file] [log] [blame]
Akron72245b62018-07-23 10:59:08 +02001/**
2 * Specification for the query creator.
3 */
4
Akron70903c42018-02-05 12:31:10 +01005function matchTableFactory () {
6 var table = document.createElement('div');
Akronbdcbbf42018-04-25 12:42:44 +02007
8 Element.prototype.innerString = function () {
9 return this.innerText.split("\n").join("");
10 };
11
12
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>" +
67 " <th>Baum</th>" +
68 " </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>" +
77 " <td class=\"matchkeyvalues\">" +
78 " <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>" +
94 " <td>NN</td>" +
95 " </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
104define(['match/querycreator'], function (qcClass) {
105
106 describe('KorAP.QueryCreator', function () {
107
108 it('should be initializable', function () {
109 expect(
110 function() {
111 qcClass.create()
112 }
113 ).toThrow(new Error("Missing parameters"));
114
115 expect(
116 function() {
117 qcClass.create("Test")
118 }
119 ).toThrow(new Error("Requires element"));
120
Akron70903c42018-02-05 12:31:10 +0100121 expect(qcClass.create(matchTableFactory()).toString()).toEqual("");
Akronb46d8e32017-06-29 14:26:14 +0200122 });
123
124 it('should listen to click events', function () {
125
Akron70903c42018-02-05 12:31:10 +0100126 var matchTable = matchTableFactory();
127 var qc = qcClass.create(matchTable);
Akronb46d8e32017-06-29 14:26:14 +0200128
129 // Nothing to show
130 expect(qc.toString()).toEqual("");
131 expect(qc.shown()).toBe(false);
132 qc.show();
133 expect(qc.shown()).toBe(false);
134 expect(qc.element().className).toEqual("queryfragment");
135
136 // Click on cell 0:0 "Foundry"
Akron70903c42018-02-05 12:31:10 +0100137 var cell = matchTable.querySelector("thead > tr > th:first-child");
Akronbdcbbf42018-04-25 12:42:44 +0200138 expect(cell.innerString()).toEqual("Foundry");
Akronb46d8e32017-06-29 14:26:14 +0200139 cell.click();
140 expect(cell.classList.contains("chosen")).toBe(false);
141 expect(qc.toString()).toEqual("");
142 expect(qc.shown()).toBe(false);
143
144 // Click on cell 0:2 "Der"
Akron70903c42018-02-05 12:31:10 +0100145 cell = matchTable.querySelector("thead > tr > th:nth-child(3)")
Akronbdcbbf42018-04-25 12:42:44 +0200146 expect(cell.innerString()).toEqual("Der");
Akronb46d8e32017-06-29 14:26:14 +0200147 cell.click();
148 expect(cell.classList.contains("chosen")).toBeTruthy();
149 expect(qc.toString()).toEqual("[orth=Der]");
150 expect(qc.shown()).toBeTruthy();
151
152 // Click on cell 0:2 "Der" again - to hide
Akron70903c42018-02-05 12:31:10 +0100153 cell = matchTable.querySelector("thead > tr > th:nth-child(3)")
Akronbdcbbf42018-04-25 12:42:44 +0200154 expect(cell.innerString()).toEqual("Der");
Akronb46d8e32017-06-29 14:26:14 +0200155 cell.click();
156 expect(cell.classList.contains("chosen")).toBe(false);
157 expect(qc.toString()).toEqual("");
158 expect(qc.shown()).toBe(false);
159 });
160
161 it('should create tokens in arbitrary order', function () {
Akron70903c42018-02-05 12:31:10 +0100162 var matchTable = matchTableFactory();
163 var qc = qcClass.create(matchTable);
Akronb46d8e32017-06-29 14:26:14 +0200164
Akron70903c42018-02-05 12:31:10 +0100165 var cell = matchTable.querySelector("tbody > tr:nth-child(2) > td:nth-child(4)");
Akronbdcbbf42018-04-25 12:42:44 +0200166 expect(cell.innerString()).toEqual("ADJA");
Akronb46d8e32017-06-29 14:26:14 +0200167 cell.click();
168 expect(qc.toString()).toEqual("[opennlp/p=ADJA]");
169
Akron70903c42018-02-05 12:31:10 +0100170 cell = matchTable.querySelector("thead > tr > th:nth-child(4)");
Akronbdcbbf42018-04-25 12:42:44 +0200171 expect(cell.innerString()).toEqual("älteste");
Akronb46d8e32017-06-29 14:26:14 +0200172 cell.click();
173 expect(qc.toString()).toEqual("[opennlp/p=ADJA & orth=älteste]");
174
Akron70903c42018-02-05 12:31:10 +0100175 cell = matchTable.querySelector("tbody > tr > td:nth-child(4)");
Akronbdcbbf42018-04-25 12:42:44 +0200176 expect(cell.innerString()).toEqual("ADJA");
Akronb46d8e32017-06-29 14:26:14 +0200177 cell.click();
178 expect(qc.toString()).toEqual("[corenlp/p=ADJA & opennlp/p=ADJA & orth=älteste]");
179 });
180
181 it('should create token sequences in arbitrary order', function () {
Akron70903c42018-02-05 12:31:10 +0100182 var matchTable = matchTableFactory();
183 var qc = qcClass.create(matchTable);
Akronb46d8e32017-06-29 14:26:14 +0200184
Akron70903c42018-02-05 12:31:10 +0100185 var cell = matchTable.querySelector("thead > tr > th:nth-child(5)");
Akronbdcbbf42018-04-25 12:42:44 +0200186 expect(cell.innerString()).toEqual("lebende");
Akronb46d8e32017-06-29 14:26:14 +0200187 cell.click();
188 expect(qc.toString()).toEqual("[orth=lebende]");
189
Akron70903c42018-02-05 12:31:10 +0100190 cell = matchTable.querySelector("tbody > tr:nth-child(2) > td:nth-child(3)");
Akronbdcbbf42018-04-25 12:42:44 +0200191 expect(cell.innerString()).toEqual("ART");
Akronb46d8e32017-06-29 14:26:14 +0200192 cell.click();
Akrone9be11d2017-06-29 20:10:58 +0200193 expect(qc.toString()).toEqual("[opennlp/p=ART][][orth=lebende]");
Akronb46d8e32017-06-29 14:26:14 +0200194
Akron70903c42018-02-05 12:31:10 +0100195 cell = matchTable.querySelector("tbody > tr > td:nth-child(4)");
Akronbdcbbf42018-04-25 12:42:44 +0200196 expect(cell.innerString()).toEqual("ADJA");
Akronb46d8e32017-06-29 14:26:14 +0200197 cell.click();
198 expect(qc.toString()).toEqual("[opennlp/p=ART][corenlp/p=ADJA][orth=lebende]");
199 });
200
201 it('should remove chosen elements again', function () {
Akron70903c42018-02-05 12:31:10 +0100202 var matchTable = matchTableFactory();
203 var qc = qcClass.create(matchTable);
Akronb46d8e32017-06-29 14:26:14 +0200204
Akron70903c42018-02-05 12:31:10 +0100205 var cell = matchTable.querySelector("tbody > tr:nth-child(2) > td:nth-child(4)");
Akronbdcbbf42018-04-25 12:42:44 +0200206 expect(cell.innerString()).toEqual("ADJA");
Akronb46d8e32017-06-29 14:26:14 +0200207 cell.click();
208 expect(qc.toString()).toEqual("[opennlp/p=ADJA]");
209 var cell1 = cell;
210
Akron70903c42018-02-05 12:31:10 +0100211 cell = matchTable.querySelector("thead > tr > th:nth-child(4)");
Akronbdcbbf42018-04-25 12:42:44 +0200212 expect(cell.innerString()).toEqual("älteste");
Akronb46d8e32017-06-29 14:26:14 +0200213 cell.click();
214 expect(qc.toString()).toEqual("[opennlp/p=ADJA & orth=älteste]");
215 var cell2 = cell;
216
Akron70903c42018-02-05 12:31:10 +0100217 cell = matchTable.querySelector("tbody > tr > td:nth-child(3)");
Akronbdcbbf42018-04-25 12:42:44 +0200218 expect(cell.innerString()).toEqual("ART");
Akronb46d8e32017-06-29 14:26:14 +0200219 cell.click();
220 expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA & orth=älteste]");
221 var cell3 = cell;
222
Akron70903c42018-02-05 12:31:10 +0100223 cell = matchTable.querySelector("thead > tr > th:nth-child(6)");
Akronbdcbbf42018-04-25 12:42:44 +0200224 expect(cell.innerString()).toEqual("Baum");
Akronb46d8e32017-06-29 14:26:14 +0200225 cell.click();
Akrone9be11d2017-06-29 20:10:58 +0200226 expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA & orth=älteste][][orth=Baum]");
Akronb46d8e32017-06-29 14:26:14 +0200227 var cell4 = cell;
228
Akron70903c42018-02-05 12:31:10 +0100229 cell = matchTable.querySelector("thead > tr > th:nth-child(5)");
Akronbdcbbf42018-04-25 12:42:44 +0200230 expect(cell.innerString()).toEqual("lebende");
Akronb46d8e32017-06-29 14:26:14 +0200231 cell.click();
232 expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA & orth=älteste][orth=lebende][orth=Baum]");
233 var cell5 = cell;
234
235
236 // Remove annotations again
237 expect(cell5.classList.contains("chosen")).toBeTruthy();
238 cell5.click()
239 expect(cell5.classList.contains("chosen")).toBe(false);
Akrone9be11d2017-06-29 20:10:58 +0200240 expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA & orth=älteste][][orth=Baum]");
Akronb46d8e32017-06-29 14:26:14 +0200241
242 expect(cell2.classList.contains("chosen")).toBeTruthy();
243 cell2.click()
244 expect(cell2.classList.contains("chosen")).toBe(false);
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(cell1.classList.contains("chosen")).toBeTruthy();
248 cell1.click()
249 expect(cell1.classList.contains("chosen")).toBe(false);
Akrone9be11d2017-06-29 20:10:58 +0200250 expect(qc.toString()).toEqual("[corenlp/p=ART][]{2}[orth=Baum]");
Akronb46d8e32017-06-29 14:26:14 +0200251
252 // Re-add first cell at the same position
253 expect(cell1.classList.contains("chosen")).toBe(false);
254 cell1.click()
255 expect(cell1.classList.contains("chosen")).toBeTruthy();
Akrone9be11d2017-06-29 20:10:58 +0200256 expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA][][orth=Baum]");
Akronb46d8e32017-06-29 14:26:14 +0200257
258 expect(cell3.classList.contains("chosen")).toBeTruthy();
259 cell3.click()
260 expect(cell3.classList.contains("chosen")).toBe(false);
Akrone9be11d2017-06-29 20:10:58 +0200261 expect(qc.toString()).toEqual("[opennlp/p=ADJA][][orth=Baum]");
Akronb46d8e32017-06-29 14:26:14 +0200262
263 expect(cell4.classList.contains("chosen")).toBeTruthy();
264 cell4.click()
265 expect(cell4.classList.contains("chosen")).toBe(false);
266 expect(qc.toString()).toEqual("[opennlp/p=ADJA]");
267
268 // Remove last token
269 expect(qc.shown()).toBeTruthy();
270 expect(qc.element().innerHTML).toEqual("<span>New Query:</span><span>[opennlp/p=ADJA]</span>");
271 expect(cell1.classList.contains("chosen")).toBeTruthy();
272 cell1.click()
273 expect(cell1.classList.contains("chosen")).toBe(false);
274 expect(qc.toString()).toEqual("");
275 expect(qc.shown()).toBe(false);
276
277 // Re-add token
278 expect(cell4.classList.contains("chosen")).toBe(false);
279 cell4.click()
280 expect(cell4.classList.contains("chosen")).toBeTruthy();
281 expect(qc.toString()).toEqual("[orth=Baum]");
282 expect(qc.shown()).toBeTruthy();
283 expect(qc.element().innerHTML).toEqual("<span>New Query:</span><span>[orth=Baum]</span>");
284 });
285
Akronc8461bf2017-06-29 15:05:24 +0200286 it('should ignore empty terms', function () {
Akron70903c42018-02-05 12:31:10 +0100287 var matchTable = matchTableFactory();
288 var qc = qcClass.create(matchTable);
Akronb46d8e32017-06-29 14:26:14 +0200289
Akronc8461bf2017-06-29 15:05:24 +0200290 // Nothing to show
291 expect(qc.toString()).toEqual("");
292 expect(qc.shown()).toBe(false);
293 qc.show();
294 expect(qc.shown()).toBe(false);
295 expect(qc.element().className).toEqual("queryfragment");
296
Akron70903c42018-02-05 12:31:10 +0100297 var cell = matchTable.querySelector("tbody > tr:nth-child(2) > td:nth-child(4)");
Akronbdcbbf42018-04-25 12:42:44 +0200298 expect(cell.innerString()).toEqual("ADJA");
Akronc8461bf2017-06-29 15:05:24 +0200299 expect(cell.classList.contains("chosen")).toBe(false);
300 cell.click();
301 expect(cell.classList.contains("chosen")).toBeTruthy();
302 expect(qc.toString()).toEqual("[opennlp/p=ADJA]");
303
Akron70903c42018-02-05 12:31:10 +0100304 cell = matchTable.querySelector("tbody > tr:nth-child(2) > td:nth-child(5)");
Akronbdcbbf42018-04-25 12:42:44 +0200305 expect(cell.innerString()).toEqual("");
Akronc8461bf2017-06-29 15:05:24 +0200306 expect(cell.classList.contains("chosen")).toBe(false);
307 cell.click();
308 expect(cell.classList.contains("chosen")).toBe(false);
309 expect(qc.toString()).toEqual("[opennlp/p=ADJA]");
310
311 });
312
Akron7cf33fd2017-07-03 17:33:39 +0200313 it('should create or-groups for alternative terms', function () {
Akron70903c42018-02-05 12:31:10 +0100314 var matchTable = matchTableFactory();
315 var qc = qcClass.create(matchTable);
Akronc8461bf2017-06-29 15:05:24 +0200316
317 // Nothing to show
318 expect(qc.toString()).toEqual("");
319 expect(qc.shown()).toBe(false);
320 qc.show();
321 expect(qc.shown()).toBe(false);
322 expect(qc.element().className).toEqual("queryfragment");
323
Akron70903c42018-02-05 12:31:10 +0100324 var cell = matchTable.querySelector("thead > tr > th:nth-child(5)");
Akronbdcbbf42018-04-25 12:42:44 +0200325 expect(cell.innerString()).toEqual("lebende");
Akronc8461bf2017-06-29 15:05:24 +0200326 expect(cell.classList.contains("chosen")).toBe(false);
327 cell.click();
328 expect(cell.classList.contains("chosen")).toBeTruthy();
329 expect(qc.toString()).toEqual("[orth=lebende]");
330
Akron70903c42018-02-05 12:31:10 +0100331 cell = matchTable.querySelector("tbody > tr:nth-child(1) > td:nth-child(5)");
Akronbdcbbf42018-04-25 12:42:44 +0200332 expect(cell.innerString()).toEqual("ADJAADJD");
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("[(corenlp/p=ADJA | corenlp/p=ADJD) & orth=lebende]");
337
338 // Remove or group again
339 expect(cell.classList.contains("chosen")).toBeTruthy();
340 cell.click();
341 expect(cell.classList.contains("chosen")).toBe(false);
342 expect(qc.toString()).toEqual("[orth=lebende]");
343 });
344
345
346 it('should add whole rows', function () {
Akron70903c42018-02-05 12:31:10 +0100347 var matchTable = matchTableFactory();
348 var qc = qcClass.create(matchTable);
Akronc8461bf2017-06-29 15:05:24 +0200349
350 // Nothing to show
351 expect(qc.toString()).toEqual("");
352 expect(qc.shown()).toBe(false);
353 qc.show();
354 expect(qc.shown()).toBe(false);
355 expect(qc.element().className).toEqual("queryfragment");
356
Akron70903c42018-02-05 12:31:10 +0100357 var corenlpRow = matchTable.querySelector("tbody > tr:nth-child(1)");
Akronc8461bf2017-06-29 15:05:24 +0200358
359 var cell = corenlpRow.querySelector("td:nth-child(4)");
Akronbdcbbf42018-04-25 12:42:44 +0200360 expect(cell.innerString()).toEqual("ADJA");
Akronc8461bf2017-06-29 15:05:24 +0200361 expect(cell.classList.contains("chosen")).toBe(false);
362 cell.click();
363 expect(cell.classList.contains("chosen")).toBeTruthy();
364
365 // Activate another cell in another row
Akron70903c42018-02-05 12:31:10 +0100366 cell = matchTable.querySelector("tbody > tr:nth-child(2) td:nth-child(3)");
Akronbdcbbf42018-04-25 12:42:44 +0200367 expect(cell.innerString()).toEqual("ART");
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
372 expect(corenlpRow.querySelector("td:nth-child(3).chosen")).toBeNull();
373 expect(corenlpRow.querySelector("td:nth-child(4).chosen")).toBeTruthy();
374 expect(corenlpRow.querySelector("td:nth-child(5).chosen")).toBeNull();
375 expect(corenlpRow.querySelector("td:nth-child(6).chosen")).toBeNull();
376
377 expect(qc.toString()).toEqual("[opennlp/p=ART][corenlp/p=ADJA]");
378
379 // Mark all corenlp lists
380 cell = corenlpRow.querySelector("th:nth-child(1)");
Akronbdcbbf42018-04-25 12:42:44 +0200381 expect(cell.innerString()).toEqual("corenlp");
Akronc8461bf2017-06-29 15:05:24 +0200382 expect(cell.classList.contains("chosen")).toBe(false);
383 cell.click();
384 expect(cell.classList.contains("chosen")).toBe(false);
385
386 expect(corenlpRow.querySelector("td:nth-child(3).chosen")).toBeTruthy();
387 expect(corenlpRow.querySelector("td:nth-child(4).chosen")).toBeTruthy();
388 expect(corenlpRow.querySelector("td:nth-child(5).chosen")).toBeTruthy();
389 expect(corenlpRow.querySelector("td:nth-child(6).chosen")).toBeTruthy();
390
391 // Replay the choice without any effect
392 cell = corenlpRow.querySelector("th:nth-child(1)");
Akronbdcbbf42018-04-25 12:42:44 +0200393 expect(cell.innerString()).toEqual("corenlp");
Akronc8461bf2017-06-29 15:05:24 +0200394 expect(cell.classList.contains("chosen")).toBe(false);
395 cell.click();
396 expect(cell.classList.contains("chosen")).toBe(false);
397
398 expect(corenlpRow.querySelector("td:nth-child(3).chosen")).toBeTruthy();
399 expect(corenlpRow.querySelector("td:nth-child(4).chosen")).toBeTruthy();
400 expect(corenlpRow.querySelector("td:nth-child(5).chosen")).toBeTruthy();
401 expect(corenlpRow.querySelector("td:nth-child(6).chosen")).toBeTruthy();
Akrone9be11d2017-06-29 20:10:58 +0200402 expect(corenlpRow.querySelector("td:nth-child(7).chosen")).toBeTruthy();
Akronc8461bf2017-06-29 15:05:24 +0200403
Akrone9be11d2017-06-29 20:10:58 +0200404 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 +0200405
406 // Remove one of the cells again
407 cell = corenlpRow.querySelector("td:nth-child(5).chosen");
Akronbdcbbf42018-04-25 12:42:44 +0200408 expect(cell.innerString()).toEqual("ADJAADJD");
Akronc8461bf2017-06-29 15:05:24 +0200409 expect(cell.classList.contains("chosen")).toBeTruthy();
410 cell.click();
411 expect(cell.classList.contains("chosen")).toBe(false);
Akrone9be11d2017-06-29 20:10:58 +0200412 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 +0200413
414 });
Akron8084cb52017-06-29 17:11:14 +0200415
416 it('should ignore empty terms in whole rows', function () {
Akron70903c42018-02-05 12:31:10 +0100417 var matchTable = matchTableFactory();
418 var qc = qcClass.create(matchTable);
Akron8084cb52017-06-29 17:11:14 +0200419 expect(qc.toString()).toEqual("");
420
Akron70903c42018-02-05 12:31:10 +0100421 var opennlpRow = matchTable.querySelector("tbody > tr:nth-child(2)");
Akron8084cb52017-06-29 17:11:14 +0200422
423 expect(opennlpRow.querySelector("td:nth-child(3).chosen")).toBeNull();
424 expect(opennlpRow.querySelector("td:nth-child(4).chosen")).toBeNull();
425 expect(opennlpRow.querySelector("td:nth-child(5).chosen")).toBeNull();
426 expect(opennlpRow.querySelector("td:nth-child(6).chosen")).toBeNull();
427
428 expect(qc.toString()).toEqual("");
429
430 // Mark all opennlp lists
431 cell = opennlpRow.querySelector("th:nth-child(1)");
Akronbdcbbf42018-04-25 12:42:44 +0200432 expect(cell.innerString()).toEqual("opennlp");
Akron8084cb52017-06-29 17:11:14 +0200433 expect(cell.classList.contains("chosen")).toBe(false);
434 cell.click();
435 expect(cell.classList.contains("chosen")).toBe(false);
436
437 expect(opennlpRow.querySelector("td:nth-child(3).chosen")).toBeTruthy();
438 expect(opennlpRow.querySelector("td:nth-child(4).chosen")).toBeTruthy();
439 expect(opennlpRow.querySelector("td:nth-child(5).chosen")).toBeNull();
440 expect(opennlpRow.querySelector("td:nth-child(6).chosen")).toBeTruthy();
Akron7cf33fd2017-07-03 17:33:39 +0200441
442 expect(qc.toString()).toEqual("[opennlp/p=ART][opennlp/p=ADJA][][opennlp/p=NN][opennlp/p=ADV]");
Akron8084cb52017-06-29 17:11:14 +0200443 });
Akrone9be11d2017-06-29 20:10:58 +0200444
445 it('should support multiple distances', function () {
Akron70903c42018-02-05 12:31:10 +0100446 var matchTable = matchTableFactory();
447 var qc = qcClass.create(matchTable);
Akrone9be11d2017-06-29 20:10:58 +0200448
Akron70903c42018-02-05 12:31:10 +0100449 var cell = matchTable.querySelector("thead > tr > th:nth-child(3)");
Akronbdcbbf42018-04-25 12:42:44 +0200450 expect(cell.innerString()).toEqual("Der");
Akrone9be11d2017-06-29 20:10:58 +0200451 cell.click();
452 expect(qc.toString()).toEqual("[orth=Der]");
453
Akron70903c42018-02-05 12:31:10 +0100454 cell = matchTable.querySelector("thead > tr > th:nth-child(7)");
Akronbdcbbf42018-04-25 12:42:44 +0200455 expect(cell.innerString()).toEqual("hier");
Akrone9be11d2017-06-29 20:10:58 +0200456 cell.click();
457 expect(qc.toString()).toEqual("[orth=Der][]{3}[orth=hier]");
458
Akron70903c42018-02-05 12:31:10 +0100459 cell = matchTable.querySelector("thead > tr > th:nth-child(5)");
Akronbdcbbf42018-04-25 12:42:44 +0200460 expect(cell.innerString()).toEqual("lebende");
Akrone9be11d2017-06-29 20:10:58 +0200461 cell.click();
462 expect(qc.toString()).toEqual("[orth=Der][][orth=lebende][][orth=hier]");
463 });
Akron7cf33fd2017-07-03 17:33:39 +0200464
465 it('should create and-groups for key-value terms', function () {
Akron70903c42018-02-05 12:31:10 +0100466 var matchTable = matchTableComplexFactory();
467 var qc = qcClass.create(matchTable);
Akron7cf33fd2017-07-03 17:33:39 +0200468
469 // Nothing to show
470 expect(qc.toString()).toEqual("");
471 expect(qc.shown()).toBe(false);
472 qc.show();
473 expect(qc.shown()).toBe(false);
474 expect(qc.element().className).toEqual("queryfragment");
475
Akron70903c42018-02-05 12:31:10 +0100476 var cell = matchTable.querySelector("thead > tr > th:nth-child(5)");
Akronbdcbbf42018-04-25 12:42:44 +0200477 expect(cell.innerString()).toEqual("lebende");
Akron7cf33fd2017-07-03 17:33:39 +0200478 expect(cell.classList.contains("chosen")).toBe(false);
479 cell.click();
480 expect(cell.classList.contains("chosen")).toBeTruthy();
481 expect(qc.toString()).toEqual("[orth=lebende]");
482
483 // Check complex cell
Akron70903c42018-02-05 12:31:10 +0100484 cell = matchTable.querySelector("tbody > tr:nth-child(1) > td:nth-child(6)");
Akronbdcbbf42018-04-25 12:42:44 +0200485 expect(cell.innerString()).toMatch(/case:nom/);
Akron7cf33fd2017-07-03 17:33:39 +0200486 expect(cell.classList.contains("chosen")).toBe(false);
487 cell.click();
488 expect(cell.classList.contains("chosen")).toBe(false);
489 expect(qc.toString()).toEqual("[orth=lebende]");
490
491 // Check complex cell div
Akron70903c42018-02-05 12:31:10 +0100492 cell = matchTable.querySelector("tbody > tr:nth-child(1) > td:nth-child(6) > div:nth-child(1)");
Akronbdcbbf42018-04-25 12:42:44 +0200493 expect(cell.innerString()).toEqual('case:nom');
Akron7cf33fd2017-07-03 17:33:39 +0200494 expect(cell.classList.contains("chosen")).toBe(false);
495 cell.click();
496 expect(cell.classList.contains("chosen")).toBe(true);
497 expect(qc.toString()).toEqual("[orth=lebende][corenlp/p=case:nom]");
498 var cell = cell;
499
Akron70903c42018-02-05 12:31:10 +0100500 cell = matchTable.querySelector("tbody > tr:nth-child(1) > td:nth-child(6) > div:nth-child(3)");
Akronbdcbbf42018-04-25 12:42:44 +0200501 expect(cell.innerString()).toEqual('number:sg');
Akron7cf33fd2017-07-03 17:33:39 +0200502 expect(cell.classList.contains("chosen")).toBe(false);
503 cell.click();
504 expect(cell.classList.contains("chosen")).toBe(true);
505 expect(qc.toString()).toEqual("[orth=lebende][corenlp/p=case:nom & corenlp/p=number:sg]");
506 var cell2 = cell;
507
Akron70903c42018-02-05 12:31:10 +0100508 cell = matchTable.querySelector("tbody > tr:nth-child(1) > td:nth-child(6) > div:nth-child(2)");
Akronbdcbbf42018-04-25 12:42:44 +0200509 expect(cell.innerString()).toEqual('gender:mascgender:fem');
Akron7cf33fd2017-07-03 17:33:39 +0200510 expect(cell.classList.contains("chosen")).toBe(false);
511 cell.click();
512 expect(cell.classList.contains("chosen")).toBe(true);
513 expect(qc.toString()).toEqual("[orth=lebende][(corenlp/p=gender:fem | corenlp/p=gender:masc) & corenlp/p=case:nom & corenlp/p=number:sg]");
514 var cell3 = cell;
515
516 // Remove cell again
517 cell = cell2;
Akronbdcbbf42018-04-25 12:42:44 +0200518 expect(cell.innerString()).toEqual('number:sg');
Akron7cf33fd2017-07-03 17:33:39 +0200519 expect(cell.classList.contains("chosen")).toBe(true);
520 cell.click();
521 expect(cell.classList.contains("chosen")).toBe(false);
522 expect(qc.toString()).toEqual("[orth=lebende][(corenlp/p=gender:fem | corenlp/p=gender:masc) & corenlp/p=case:nom]");
523
524 // Remove cell again
525 cell = cell3;
Akronbdcbbf42018-04-25 12:42:44 +0200526 expect(cell.innerString()).toEqual('gender:mascgender:fem');
Akron7cf33fd2017-07-03 17:33:39 +0200527 expect(cell.classList.contains("chosen")).toBe(true);
528 cell.click();
529 expect(cell.classList.contains("chosen")).toBe(false);
530 expect(qc.toString()).toEqual("[orth=lebende][corenlp/p=case:nom]");
531 });
532
533
534 it('should create rows including key-value terms', function () {
Akron70903c42018-02-05 12:31:10 +0100535 var matchTable = matchTableComplexFactory();
536 var qc = qcClass.create(matchTable);
Akron7cf33fd2017-07-03 17:33:39 +0200537 expect(qc.toString()).toEqual("");
538
Akron70903c42018-02-05 12:31:10 +0100539 var corenlpRow = matchTable.querySelector("tbody > tr:nth-child(1)");
Akron7cf33fd2017-07-03 17:33:39 +0200540
541 expect(corenlpRow.querySelector("td:nth-child(3).chosen")).toBeNull();
542 expect(corenlpRow.querySelector("td:nth-child(4).chosen")).toBeNull();
543 expect(corenlpRow.querySelector("td:nth-child(5).chosen")).toBeNull();
544 expect(corenlpRow.querySelector("td:nth-child(6) *.chosen")).toBeNull();
545
546 expect(qc.toString()).toEqual("");
547
548 // Mark all opennlp lists
549 cell = corenlpRow.querySelector("th:nth-child(1)");
Akronbdcbbf42018-04-25 12:42:44 +0200550 expect(cell.innerString()).toEqual("corenlp");
Akron7cf33fd2017-07-03 17:33:39 +0200551 expect(cell.classList.contains("chosen")).toBe(false);
552 cell.click();
553 expect(cell.classList.contains("chosen")).toBe(false);
554
555 expect(corenlpRow.querySelector("td:nth-child(3).chosen")).toBeTruthy();
556 expect(corenlpRow.querySelector("td:nth-child(4).chosen")).toBeTruthy();
557 expect(corenlpRow.querySelector("td:nth-child(5).chosen")).toBeTruthy();
558 expect(corenlpRow.querySelector("td:nth-child(6) div:nth-child(1).chosen")).toBeTruthy();
559 expect(corenlpRow.querySelector("td:nth-child(6) div:nth-child(2).chosen")).toBeTruthy();
560 expect(corenlpRow.querySelector("td:nth-child(6) div:nth-child(3).chosen")).toBeTruthy();
561
562 expect(qc.toString()).toEqual(
563 "[corenlp/p=ART]"+
564 "[corenlp/p=ADJA]"+
565 "[(corenlp/p=ADJA | corenlp/p=ADJD)]"+
566 "[(corenlp/p=gender:fem | corenlp/p=gender:masc) & corenlp/p=case:nom & corenlp/p=number:sg]"
567 );
568 });
Akron72245b62018-07-23 10:59:08 +0200569
570 it('should support verbatim strings', function () {
571 var matchTable = matchTableComplexFactory();
572 var qc = qcClass.create(matchTable);
573 expect(qc.toString()).toEqual("");
574
575 // TODO:
576 // This does not respect keys vs values at the moment, but neither does Koral
577 var cell = matchTable.querySelector("tbody > tr:nth-child(2) > td > div:nth-child(4)");
578 expect(cell.innerString()).toEqual("morphemes:.::_SORSZ \\ZERO::NOM 'period::PUNCT'");
579 expect(cell.classList.contains("chosen")).toBe(false);
580 cell.click();
581 expect(cell.classList.contains("chosen")).toBeTruthy();
582 expect(qc.toString()).toEqual("[opennlp/p='morphemes:.::_SORSZ \\\\ZERO::NOM \\\'period::PUNCT\\\'']");
583 });
Akronb46d8e32017-06-29 14:26:14 +0200584 });
585});