Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 1 | function matchTableFactory () { |
| 2 | var table = document.createElement('div'); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame^] | 3 | |
| 4 | Element.prototype.innerString = function () { |
| 5 | return this.innerText.split("\n").join(""); |
| 6 | }; |
| 7 | |
| 8 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 9 | table.className = 'matchtable'; |
| 10 | table.innerHTML = |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 11 | " <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>" + |
Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 20 | " <th>hier</th>" + |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 21 | " </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>" + |
Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 31 | " <td>ADV</td>" + |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 32 | " </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>" + |
Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 40 | " <td>ADV</td>" + |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 41 | " </tr>" + |
| 42 | " </tbody>" + |
| 43 | " </table>" + |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 44 | " </div>"; |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 45 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 46 | var info = document.createElement('div'); |
| 47 | info.appendChild(table); |
| 48 | return table; |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 49 | }; |
| 50 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 51 | function matchTableComplexFactory () { |
| 52 | var table = document.createElement('div'); |
| 53 | table.className = 'matchtable'; |
| 54 | table.innerHTML = |
Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 55 | " <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>" + |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 92 | " </table>"; |
| 93 | var info = document.createElement('div'); |
| 94 | info.appendChild(table); |
| 95 | return table; |
Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 96 | }; |
| 97 | |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 98 | |
| 99 | define(['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 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 116 | expect(qcClass.create(matchTableFactory()).toString()).toEqual(""); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 117 | }); |
| 118 | |
| 119 | it('should listen to click events', function () { |
| 120 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 121 | var matchTable = matchTableFactory(); |
| 122 | var qc = qcClass.create(matchTable); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 123 | |
| 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" |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 132 | var cell = matchTable.querySelector("thead > tr > th:first-child"); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame^] | 133 | expect(cell.innerString()).toEqual("Foundry"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 134 | 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" |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 140 | cell = matchTable.querySelector("thead > tr > th:nth-child(3)") |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame^] | 141 | expect(cell.innerString()).toEqual("Der"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 142 | 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 |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 148 | cell = matchTable.querySelector("thead > tr > th:nth-child(3)") |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame^] | 149 | expect(cell.innerString()).toEqual("Der"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 150 | 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 () { |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 157 | var matchTable = matchTableFactory(); |
| 158 | var qc = qcClass.create(matchTable); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 159 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 160 | var cell = matchTable.querySelector("tbody > tr:nth-child(2) > td:nth-child(4)"); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame^] | 161 | expect(cell.innerString()).toEqual("ADJA"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 162 | cell.click(); |
| 163 | expect(qc.toString()).toEqual("[opennlp/p=ADJA]"); |
| 164 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 165 | cell = matchTable.querySelector("thead > tr > th:nth-child(4)"); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame^] | 166 | expect(cell.innerString()).toEqual("älteste"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 167 | cell.click(); |
| 168 | expect(qc.toString()).toEqual("[opennlp/p=ADJA & orth=älteste]"); |
| 169 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 170 | cell = matchTable.querySelector("tbody > tr > td:nth-child(4)"); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame^] | 171 | expect(cell.innerString()).toEqual("ADJA"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 172 | 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 () { |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 177 | var matchTable = matchTableFactory(); |
| 178 | var qc = qcClass.create(matchTable); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 179 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 180 | var cell = matchTable.querySelector("thead > tr > th:nth-child(5)"); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame^] | 181 | expect(cell.innerString()).toEqual("lebende"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 182 | cell.click(); |
| 183 | expect(qc.toString()).toEqual("[orth=lebende]"); |
| 184 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 185 | cell = matchTable.querySelector("tbody > tr:nth-child(2) > td:nth-child(3)"); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame^] | 186 | expect(cell.innerString()).toEqual("ART"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 187 | cell.click(); |
Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 188 | expect(qc.toString()).toEqual("[opennlp/p=ART][][orth=lebende]"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 189 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 190 | cell = matchTable.querySelector("tbody > tr > td:nth-child(4)"); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame^] | 191 | expect(cell.innerString()).toEqual("ADJA"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 192 | 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 () { |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 197 | var matchTable = matchTableFactory(); |
| 198 | var qc = qcClass.create(matchTable); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 199 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 200 | var cell = matchTable.querySelector("tbody > tr:nth-child(2) > td:nth-child(4)"); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame^] | 201 | expect(cell.innerString()).toEqual("ADJA"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 202 | cell.click(); |
| 203 | expect(qc.toString()).toEqual("[opennlp/p=ADJA]"); |
| 204 | var cell1 = cell; |
| 205 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 206 | cell = matchTable.querySelector("thead > tr > th:nth-child(4)"); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame^] | 207 | expect(cell.innerString()).toEqual("älteste"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 208 | cell.click(); |
| 209 | expect(qc.toString()).toEqual("[opennlp/p=ADJA & orth=älteste]"); |
| 210 | var cell2 = cell; |
| 211 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 212 | cell = matchTable.querySelector("tbody > tr > td:nth-child(3)"); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame^] | 213 | expect(cell.innerString()).toEqual("ART"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 214 | cell.click(); |
| 215 | expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA & orth=älteste]"); |
| 216 | var cell3 = cell; |
| 217 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 218 | cell = matchTable.querySelector("thead > tr > th:nth-child(6)"); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame^] | 219 | expect(cell.innerString()).toEqual("Baum"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 220 | cell.click(); |
Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 221 | expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA & orth=älteste][][orth=Baum]"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 222 | var cell4 = cell; |
| 223 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 224 | cell = matchTable.querySelector("thead > tr > th:nth-child(5)"); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame^] | 225 | expect(cell.innerString()).toEqual("lebende"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 226 | 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); |
Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 235 | expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA & orth=älteste][][orth=Baum]"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 236 | |
| 237 | expect(cell2.classList.contains("chosen")).toBeTruthy(); |
| 238 | cell2.click() |
| 239 | expect(cell2.classList.contains("chosen")).toBe(false); |
Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 240 | expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA][][orth=Baum]"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 241 | |
| 242 | expect(cell1.classList.contains("chosen")).toBeTruthy(); |
| 243 | cell1.click() |
| 244 | expect(cell1.classList.contains("chosen")).toBe(false); |
Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 245 | expect(qc.toString()).toEqual("[corenlp/p=ART][]{2}[orth=Baum]"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 246 | |
| 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(); |
Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 251 | expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA][][orth=Baum]"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 252 | |
| 253 | expect(cell3.classList.contains("chosen")).toBeTruthy(); |
| 254 | cell3.click() |
| 255 | expect(cell3.classList.contains("chosen")).toBe(false); |
Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 256 | expect(qc.toString()).toEqual("[opennlp/p=ADJA][][orth=Baum]"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 257 | |
| 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 | |
Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 281 | it('should ignore empty terms', function () { |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 282 | var matchTable = matchTableFactory(); |
| 283 | var qc = qcClass.create(matchTable); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 284 | |
Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 285 | // 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 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 292 | var cell = matchTable.querySelector("tbody > tr:nth-child(2) > td:nth-child(4)"); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame^] | 293 | expect(cell.innerString()).toEqual("ADJA"); |
Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 294 | 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 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 299 | cell = matchTable.querySelector("tbody > tr:nth-child(2) > td:nth-child(5)"); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame^] | 300 | expect(cell.innerString()).toEqual(""); |
Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 301 | 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 | |
Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 308 | it('should create or-groups for alternative terms', function () { |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 309 | var matchTable = matchTableFactory(); |
| 310 | var qc = qcClass.create(matchTable); |
Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 311 | |
| 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 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 319 | var cell = matchTable.querySelector("thead > tr > th:nth-child(5)"); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame^] | 320 | expect(cell.innerString()).toEqual("lebende"); |
Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 321 | 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 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 326 | cell = matchTable.querySelector("tbody > tr:nth-child(1) > td:nth-child(5)"); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame^] | 327 | expect(cell.innerString()).toEqual("ADJAADJD"); |
Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 328 | 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 () { |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 342 | var matchTable = matchTableFactory(); |
| 343 | var qc = qcClass.create(matchTable); |
Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 344 | |
| 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 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 352 | var corenlpRow = matchTable.querySelector("tbody > tr:nth-child(1)"); |
Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 353 | |
| 354 | var cell = corenlpRow.querySelector("td:nth-child(4)"); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame^] | 355 | expect(cell.innerString()).toEqual("ADJA"); |
Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 356 | 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 |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 361 | cell = matchTable.querySelector("tbody > tr:nth-child(2) td:nth-child(3)"); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame^] | 362 | expect(cell.innerString()).toEqual("ART"); |
Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 363 | 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)"); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame^] | 376 | expect(cell.innerString()).toEqual("corenlp"); |
Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 377 | 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)"); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame^] | 388 | expect(cell.innerString()).toEqual("corenlp"); |
Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 389 | 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(); |
Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 397 | expect(corenlpRow.querySelector("td:nth-child(7).chosen")).toBeTruthy(); |
Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 398 | |
Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 399 | 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]"); |
Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 400 | |
| 401 | // Remove one of the cells again |
| 402 | cell = corenlpRow.querySelector("td:nth-child(5).chosen"); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame^] | 403 | expect(cell.innerString()).toEqual("ADJAADJD"); |
Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 404 | expect(cell.classList.contains("chosen")).toBeTruthy(); |
| 405 | cell.click(); |
| 406 | expect(cell.classList.contains("chosen")).toBe(false); |
Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 407 | expect(qc.toString()).toEqual("[corenlp/p=ART & opennlp/p=ART][corenlp/p=ADJA][][corenlp/p=NN][corenlp/p=ADV]"); |
Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 408 | |
| 409 | }); |
Akron | 8084cb5 | 2017-06-29 17:11:14 +0200 | [diff] [blame] | 410 | |
| 411 | it('should ignore empty terms in whole rows', function () { |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 412 | var matchTable = matchTableFactory(); |
| 413 | var qc = qcClass.create(matchTable); |
Akron | 8084cb5 | 2017-06-29 17:11:14 +0200 | [diff] [blame] | 414 | expect(qc.toString()).toEqual(""); |
| 415 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 416 | var opennlpRow = matchTable.querySelector("tbody > tr:nth-child(2)"); |
Akron | 8084cb5 | 2017-06-29 17:11:14 +0200 | [diff] [blame] | 417 | |
| 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)"); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame^] | 427 | expect(cell.innerString()).toEqual("opennlp"); |
Akron | 8084cb5 | 2017-06-29 17:11:14 +0200 | [diff] [blame] | 428 | 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(); |
Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 436 | |
| 437 | expect(qc.toString()).toEqual("[opennlp/p=ART][opennlp/p=ADJA][][opennlp/p=NN][opennlp/p=ADV]"); |
Akron | 8084cb5 | 2017-06-29 17:11:14 +0200 | [diff] [blame] | 438 | }); |
Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 439 | |
| 440 | it('should support multiple distances', function () { |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 441 | var matchTable = matchTableFactory(); |
| 442 | var qc = qcClass.create(matchTable); |
Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 443 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 444 | var cell = matchTable.querySelector("thead > tr > th:nth-child(3)"); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame^] | 445 | expect(cell.innerString()).toEqual("Der"); |
Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 446 | cell.click(); |
| 447 | expect(qc.toString()).toEqual("[orth=Der]"); |
| 448 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 449 | cell = matchTable.querySelector("thead > tr > th:nth-child(7)"); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame^] | 450 | expect(cell.innerString()).toEqual("hier"); |
Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 451 | cell.click(); |
| 452 | expect(qc.toString()).toEqual("[orth=Der][]{3}[orth=hier]"); |
| 453 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 454 | cell = matchTable.querySelector("thead > tr > th:nth-child(5)"); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame^] | 455 | expect(cell.innerString()).toEqual("lebende"); |
Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 456 | cell.click(); |
| 457 | expect(qc.toString()).toEqual("[orth=Der][][orth=lebende][][orth=hier]"); |
| 458 | }); |
Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 459 | |
| 460 | it('should create and-groups for key-value terms', function () { |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 461 | var matchTable = matchTableComplexFactory(); |
| 462 | var qc = qcClass.create(matchTable); |
Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 463 | |
| 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 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 471 | var cell = matchTable.querySelector("thead > tr > th:nth-child(5)"); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame^] | 472 | expect(cell.innerString()).toEqual("lebende"); |
Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 473 | 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 |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 479 | cell = matchTable.querySelector("tbody > tr:nth-child(1) > td:nth-child(6)"); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame^] | 480 | expect(cell.innerString()).toMatch(/case:nom/); |
Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 481 | 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 |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 487 | cell = matchTable.querySelector("tbody > tr:nth-child(1) > td:nth-child(6) > div:nth-child(1)"); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame^] | 488 | expect(cell.innerString()).toEqual('case:nom'); |
Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 489 | 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 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 495 | cell = matchTable.querySelector("tbody > tr:nth-child(1) > td:nth-child(6) > div:nth-child(3)"); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame^] | 496 | expect(cell.innerString()).toEqual('number:sg'); |
Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 497 | 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 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 503 | cell = matchTable.querySelector("tbody > tr:nth-child(1) > td:nth-child(6) > div:nth-child(2)"); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame^] | 504 | expect(cell.innerString()).toEqual('gender:mascgender:fem'); |
Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 505 | 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; |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame^] | 513 | expect(cell.innerString()).toEqual('number:sg'); |
Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 514 | 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; |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame^] | 521 | expect(cell.innerString()).toEqual('gender:mascgender:fem'); |
Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 522 | 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 () { |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 530 | var matchTable = matchTableComplexFactory(); |
| 531 | var qc = qcClass.create(matchTable); |
Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 532 | expect(qc.toString()).toEqual(""); |
| 533 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 534 | var corenlpRow = matchTable.querySelector("tbody > tr:nth-child(1)"); |
Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 535 | |
| 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)"); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame^] | 545 | expect(cell.innerString()).toEqual("corenlp"); |
Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 546 | 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 | }); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 564 | }); |
| 565 | }); |