Akron | 72245b6 | 2018-07-23 10:59:08 +0200 | [diff] [blame] | 1 | /** |
| 2 | * Specification for the query creator. |
| 3 | */ |
| 4 | |
Akron | 7dd3282 | 2018-10-01 19:38:31 +0200 | [diff] [blame] | 5 | |
| 6 | Element.prototype.innerString = function () { |
| 7 | return this.innerText.split("\n").join(""); |
| 8 | }; |
| 9 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 10 | function matchTableFactory () { |
| 11 | var table = document.createElement('div'); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 12 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 13 | table.className = 'matchtable'; |
| 14 | table.innerHTML = |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 15 | " <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>" + |
Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 24 | " <th>hier</th>" + |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 25 | " </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>" + |
Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 35 | " <td>ADV</td>" + |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 36 | " </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>" + |
Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 44 | " <td>ADV</td>" + |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 45 | " </tr>" + |
| 46 | " </tbody>" + |
| 47 | " </table>" + |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 48 | " </div>"; |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 49 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 50 | var info = document.createElement('div'); |
| 51 | info.appendChild(table); |
| 52 | return table; |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 53 | }; |
| 54 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 55 | function matchTableComplexFactory () { |
| 56 | var table = document.createElement('div'); |
| 57 | table.className = 'matchtable'; |
| 58 | table.innerHTML = |
Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 59 | " <table>" + |
| 60 | " <thead>" + |
| 61 | " <tr>" + |
| 62 | " <th>Foundry</th>" + |
| 63 | " <th>Layer</th>" + |
| 64 | " <th>Der</th>" + |
| 65 | " <th>älteste</th>" + |
Akron | 0d612d1 | 2019-05-21 16:45:49 +0200 | [diff] [blame] | 66 | " <th>lebende und sterbende</th>" + |
Akron | aeeb825 | 2018-09-19 18:51:00 +0200 | [diff] [blame] | 67 | " <th class=\"mark\">Baum</th>" + |
Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 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>" + |
Akron | aeeb825 | 2018-09-19 18:51:00 +0200 | [diff] [blame] | 77 | " <td class=\"matchkeyvalues mark\">" + |
Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 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>" + |
Akron | 72245b6 | 2018-07-23 10:59:08 +0200 | [diff] [blame] | 90 | " <div>morphemes:.::_SORSZ \\ZERO::NOM 'period::PUNCT'</div>" + |
Akron | efed2e2 | 2021-11-16 23:16:54 +0100 | [diff] [blame] | 91 | " <div>morphemes:ZERO::NOM</div>" + |
Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 92 | " </td>" + |
| 93 | " <td>ADJA</td>" + |
| 94 | " <td></td>" + |
Akron | aeeb825 | 2018-09-19 18:51:00 +0200 | [diff] [blame] | 95 | " <td class=\"mark\">NN</td>" + |
Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 96 | " </tr>" + |
Akron | 0d612d1 | 2019-05-21 16:45:49 +0200 | [diff] [blame] | 97 | " <tr tabindex=\"0\">" + |
| 98 | " <th>tt</th>" + |
| 99 | " <th>l</th>" + |
| 100 | " <td>Lese|Lesen</td>" + |
| 101 | " <td>a b</td>" + |
| 102 | " <td></td>" + |
| 103 | " <td class=\"mark\">NN</td>" + |
| 104 | " </tr>" + |
Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 105 | " </tbody>" + |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 106 | " </table>"; |
| 107 | var info = document.createElement('div'); |
| 108 | info.appendChild(table); |
| 109 | return table; |
Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 110 | }; |
| 111 | |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 112 | |
Akron | 083ec57 | 2019-05-16 18:30:40 +0200 | [diff] [blame] | 113 | function matchTableCuttedFactory () { |
| 114 | var table = document.createElement('div'); |
| 115 | table.className = 'matchtable'; |
| 116 | table.innerHTML = |
| 117 | " <table>" + |
| 118 | " <thead>" + |
| 119 | " <tr>" + |
| 120 | " <th>Foundry</th>" + |
| 121 | " <th>Layer</th>" + |
| 122 | " <th>Baum</th>" + |
| 123 | " <th class=\"cutted\"></th>" + |
| 124 | " </tr>" + |
| 125 | " </thead>" + |
| 126 | " <tbody>" + |
| 127 | " <tr tabindex=\"0\">" + |
| 128 | " <th>corenlp</th>" + |
| 129 | " <th>p</th>" + |
| 130 | " <td>NN</td>" + |
| 131 | " <td></td>" + |
| 132 | " </tr>" + |
| 133 | " <tr tabindex=\"0\">" + |
| 134 | " <th>opennlp</th>" + |
| 135 | " <th>p</th>" + |
| 136 | " <td>NN</td>" + |
| 137 | " <td></td>" + |
| 138 | " </tr>" + |
| 139 | " </tbody>" + |
| 140 | " </table>"; |
| 141 | var info = document.createElement('div'); |
| 142 | info.appendChild(table); |
| 143 | return table; |
| 144 | }; |
| 145 | |
| 146 | |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 147 | define(['match/querycreator'], function (qcClass) { |
| 148 | |
| 149 | describe('KorAP.QueryCreator', function () { |
| 150 | |
| 151 | it('should be initializable', function () { |
| 152 | expect( |
| 153 | function() { |
| 154 | qcClass.create() |
| 155 | } |
| 156 | ).toThrow(new Error("Missing parameters")); |
| 157 | |
| 158 | expect( |
| 159 | function() { |
| 160 | qcClass.create("Test") |
| 161 | } |
| 162 | ).toThrow(new Error("Requires element")); |
| 163 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 164 | expect(qcClass.create(matchTableFactory()).toString()).toEqual(""); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 165 | }); |
| 166 | |
| 167 | it('should listen to click events', function () { |
| 168 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 169 | var matchTable = matchTableFactory(); |
| 170 | var qc = qcClass.create(matchTable); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 171 | |
| 172 | // Nothing to show |
| 173 | expect(qc.toString()).toEqual(""); |
| 174 | expect(qc.shown()).toBe(false); |
| 175 | qc.show(); |
| 176 | expect(qc.shown()).toBe(false); |
Akron | 7dd3282 | 2018-10-01 19:38:31 +0200 | [diff] [blame] | 177 | expect(qc.element().className).toEqual("query fragment"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 178 | |
| 179 | // Click on cell 0:0 "Foundry" |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 180 | var cell = matchTable.querySelector("thead > tr > th:first-child"); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 181 | expect(cell.innerString()).toEqual("Foundry"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 182 | cell.click(); |
| 183 | expect(cell.classList.contains("chosen")).toBe(false); |
| 184 | expect(qc.toString()).toEqual(""); |
| 185 | expect(qc.shown()).toBe(false); |
| 186 | |
| 187 | // Click on cell 0:2 "Der" |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 188 | cell = matchTable.querySelector("thead > tr > th:nth-child(3)") |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 189 | expect(cell.innerString()).toEqual("Der"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 190 | cell.click(); |
| 191 | expect(cell.classList.contains("chosen")).toBeTruthy(); |
| 192 | expect(qc.toString()).toEqual("[orth=Der]"); |
| 193 | expect(qc.shown()).toBeTruthy(); |
| 194 | |
| 195 | // Click on cell 0:2 "Der" again - to hide |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 196 | cell = matchTable.querySelector("thead > tr > th:nth-child(3)") |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 197 | expect(cell.innerString()).toEqual("Der"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 198 | cell.click(); |
| 199 | expect(cell.classList.contains("chosen")).toBe(false); |
| 200 | expect(qc.toString()).toEqual(""); |
| 201 | expect(qc.shown()).toBe(false); |
| 202 | }); |
| 203 | |
| 204 | it('should create tokens in arbitrary order', function () { |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 205 | var matchTable = matchTableFactory(); |
| 206 | var qc = qcClass.create(matchTable); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 207 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 208 | var cell = matchTable.querySelector("tbody > tr:nth-child(2) > td:nth-child(4)"); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 209 | expect(cell.innerString()).toEqual("ADJA"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 210 | cell.click(); |
| 211 | expect(qc.toString()).toEqual("[opennlp/p=ADJA]"); |
| 212 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 213 | cell = matchTable.querySelector("thead > tr > th:nth-child(4)"); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 214 | expect(cell.innerString()).toEqual("älteste"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 215 | cell.click(); |
| 216 | expect(qc.toString()).toEqual("[opennlp/p=ADJA & orth=älteste]"); |
| 217 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 218 | cell = matchTable.querySelector("tbody > tr > td:nth-child(4)"); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 219 | expect(cell.innerString()).toEqual("ADJA"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 220 | cell.click(); |
| 221 | expect(qc.toString()).toEqual("[corenlp/p=ADJA & opennlp/p=ADJA & orth=älteste]"); |
| 222 | }); |
| 223 | |
| 224 | it('should create token sequences in arbitrary order', function () { |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 225 | var matchTable = matchTableFactory(); |
| 226 | var qc = qcClass.create(matchTable); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 227 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 228 | var cell = matchTable.querySelector("thead > tr > th:nth-child(5)"); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 229 | expect(cell.innerString()).toEqual("lebende"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 230 | cell.click(); |
| 231 | expect(qc.toString()).toEqual("[orth=lebende]"); |
| 232 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 233 | cell = matchTable.querySelector("tbody > tr:nth-child(2) > td:nth-child(3)"); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 234 | expect(cell.innerString()).toEqual("ART"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 235 | cell.click(); |
Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 236 | expect(qc.toString()).toEqual("[opennlp/p=ART][][orth=lebende]"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 237 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 238 | cell = matchTable.querySelector("tbody > tr > td:nth-child(4)"); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 239 | expect(cell.innerString()).toEqual("ADJA"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 240 | cell.click(); |
| 241 | expect(qc.toString()).toEqual("[opennlp/p=ART][corenlp/p=ADJA][orth=lebende]"); |
| 242 | }); |
| 243 | |
| 244 | it('should remove chosen elements again', function () { |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 245 | var matchTable = matchTableFactory(); |
| 246 | var qc = qcClass.create(matchTable); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 247 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 248 | var cell = matchTable.querySelector("tbody > tr:nth-child(2) > td:nth-child(4)"); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 249 | expect(cell.innerString()).toEqual("ADJA"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 250 | cell.click(); |
| 251 | expect(qc.toString()).toEqual("[opennlp/p=ADJA]"); |
| 252 | var cell1 = cell; |
| 253 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 254 | cell = matchTable.querySelector("thead > tr > th:nth-child(4)"); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 255 | expect(cell.innerString()).toEqual("älteste"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 256 | cell.click(); |
| 257 | expect(qc.toString()).toEqual("[opennlp/p=ADJA & orth=älteste]"); |
| 258 | var cell2 = cell; |
| 259 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 260 | cell = matchTable.querySelector("tbody > tr > td:nth-child(3)"); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 261 | expect(cell.innerString()).toEqual("ART"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 262 | cell.click(); |
| 263 | expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA & orth=älteste]"); |
| 264 | var cell3 = cell; |
| 265 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 266 | cell = matchTable.querySelector("thead > tr > th:nth-child(6)"); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 267 | expect(cell.innerString()).toEqual("Baum"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 268 | cell.click(); |
Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 269 | 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] | 270 | var cell4 = cell; |
| 271 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 272 | cell = matchTable.querySelector("thead > tr > th:nth-child(5)"); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 273 | expect(cell.innerString()).toEqual("lebende"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 274 | cell.click(); |
| 275 | expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA & orth=älteste][orth=lebende][orth=Baum]"); |
| 276 | var cell5 = cell; |
| 277 | |
| 278 | |
| 279 | // Remove annotations again |
| 280 | expect(cell5.classList.contains("chosen")).toBeTruthy(); |
| 281 | cell5.click() |
| 282 | expect(cell5.classList.contains("chosen")).toBe(false); |
Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 283 | 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] | 284 | |
| 285 | expect(cell2.classList.contains("chosen")).toBeTruthy(); |
| 286 | cell2.click() |
| 287 | expect(cell2.classList.contains("chosen")).toBe(false); |
Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 288 | expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA][][orth=Baum]"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 289 | |
| 290 | expect(cell1.classList.contains("chosen")).toBeTruthy(); |
| 291 | cell1.click() |
| 292 | expect(cell1.classList.contains("chosen")).toBe(false); |
Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 293 | expect(qc.toString()).toEqual("[corenlp/p=ART][]{2}[orth=Baum]"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 294 | |
| 295 | // Re-add first cell at the same position |
| 296 | expect(cell1.classList.contains("chosen")).toBe(false); |
| 297 | cell1.click() |
| 298 | expect(cell1.classList.contains("chosen")).toBeTruthy(); |
Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 299 | expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA][][orth=Baum]"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 300 | |
| 301 | expect(cell3.classList.contains("chosen")).toBeTruthy(); |
| 302 | cell3.click() |
| 303 | expect(cell3.classList.contains("chosen")).toBe(false); |
Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 304 | expect(qc.toString()).toEqual("[opennlp/p=ADJA][][orth=Baum]"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 305 | |
| 306 | expect(cell4.classList.contains("chosen")).toBeTruthy(); |
| 307 | cell4.click() |
| 308 | expect(cell4.classList.contains("chosen")).toBe(false); |
| 309 | expect(qc.toString()).toEqual("[opennlp/p=ADJA]"); |
| 310 | |
| 311 | // Remove last token |
| 312 | expect(qc.shown()).toBeTruthy(); |
| 313 | expect(qc.element().innerHTML).toEqual("<span>New Query:</span><span>[opennlp/p=ADJA]</span>"); |
| 314 | expect(cell1.classList.contains("chosen")).toBeTruthy(); |
| 315 | cell1.click() |
| 316 | expect(cell1.classList.contains("chosen")).toBe(false); |
| 317 | expect(qc.toString()).toEqual(""); |
| 318 | expect(qc.shown()).toBe(false); |
| 319 | |
| 320 | // Re-add token |
| 321 | expect(cell4.classList.contains("chosen")).toBe(false); |
| 322 | cell4.click() |
| 323 | expect(cell4.classList.contains("chosen")).toBeTruthy(); |
| 324 | expect(qc.toString()).toEqual("[orth=Baum]"); |
| 325 | expect(qc.shown()).toBeTruthy(); |
| 326 | expect(qc.element().innerHTML).toEqual("<span>New Query:</span><span>[orth=Baum]</span>"); |
| 327 | }); |
| 328 | |
Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 329 | it('should ignore empty terms', function () { |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 330 | var matchTable = matchTableFactory(); |
| 331 | var qc = qcClass.create(matchTable); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 332 | |
Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 333 | // Nothing to show |
| 334 | expect(qc.toString()).toEqual(""); |
| 335 | expect(qc.shown()).toBe(false); |
| 336 | qc.show(); |
| 337 | expect(qc.shown()).toBe(false); |
Akron | 7dd3282 | 2018-10-01 19:38:31 +0200 | [diff] [blame] | 338 | expect(qc.element().className).toEqual("query fragment"); |
Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 339 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 340 | var cell = matchTable.querySelector("tbody > tr:nth-child(2) > td:nth-child(4)"); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 341 | expect(cell.innerString()).toEqual("ADJA"); |
Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 342 | expect(cell.classList.contains("chosen")).toBe(false); |
| 343 | cell.click(); |
| 344 | expect(cell.classList.contains("chosen")).toBeTruthy(); |
| 345 | expect(qc.toString()).toEqual("[opennlp/p=ADJA]"); |
| 346 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 347 | cell = matchTable.querySelector("tbody > tr:nth-child(2) > td:nth-child(5)"); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 348 | expect(cell.innerString()).toEqual(""); |
Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 349 | expect(cell.classList.contains("chosen")).toBe(false); |
| 350 | cell.click(); |
| 351 | expect(cell.classList.contains("chosen")).toBe(false); |
| 352 | expect(qc.toString()).toEqual("[opennlp/p=ADJA]"); |
| 353 | |
| 354 | }); |
| 355 | |
Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 356 | it('should create or-groups for alternative terms', function () { |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 357 | var matchTable = matchTableFactory(); |
| 358 | var qc = qcClass.create(matchTable); |
Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 359 | |
| 360 | // Nothing to show |
| 361 | expect(qc.toString()).toEqual(""); |
| 362 | expect(qc.shown()).toBe(false); |
| 363 | qc.show(); |
| 364 | expect(qc.shown()).toBe(false); |
Akron | 7dd3282 | 2018-10-01 19:38:31 +0200 | [diff] [blame] | 365 | expect(qc.element().className).toEqual("query fragment"); |
Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 366 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 367 | var cell = matchTable.querySelector("thead > tr > th:nth-child(5)"); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 368 | expect(cell.innerString()).toEqual("lebende"); |
Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 369 | expect(cell.classList.contains("chosen")).toBe(false); |
| 370 | cell.click(); |
| 371 | expect(cell.classList.contains("chosen")).toBeTruthy(); |
| 372 | expect(qc.toString()).toEqual("[orth=lebende]"); |
| 373 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 374 | cell = matchTable.querySelector("tbody > tr:nth-child(1) > td:nth-child(5)"); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 375 | expect(cell.innerString()).toEqual("ADJAADJD"); |
Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 376 | expect(cell.classList.contains("chosen")).toBe(false); |
| 377 | cell.click(); |
| 378 | expect(cell.classList.contains("chosen")).toBeTruthy(); |
| 379 | expect(qc.toString()).toEqual("[(corenlp/p=ADJA | corenlp/p=ADJD) & orth=lebende]"); |
| 380 | |
| 381 | // Remove or group again |
| 382 | expect(cell.classList.contains("chosen")).toBeTruthy(); |
| 383 | cell.click(); |
| 384 | expect(cell.classList.contains("chosen")).toBe(false); |
| 385 | expect(qc.toString()).toEqual("[orth=lebende]"); |
| 386 | }); |
| 387 | |
| 388 | |
| 389 | it('should add whole rows', function () { |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 390 | var matchTable = matchTableFactory(); |
| 391 | var qc = qcClass.create(matchTable); |
Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 392 | |
| 393 | // Nothing to show |
| 394 | expect(qc.toString()).toEqual(""); |
| 395 | expect(qc.shown()).toBe(false); |
| 396 | qc.show(); |
| 397 | expect(qc.shown()).toBe(false); |
Akron | 7dd3282 | 2018-10-01 19:38:31 +0200 | [diff] [blame] | 398 | expect(qc.element().className).toEqual("query fragment"); |
Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 399 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 400 | var corenlpRow = matchTable.querySelector("tbody > tr:nth-child(1)"); |
Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 401 | |
| 402 | var cell = corenlpRow.querySelector("td:nth-child(4)"); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 403 | expect(cell.innerString()).toEqual("ADJA"); |
Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 404 | expect(cell.classList.contains("chosen")).toBe(false); |
| 405 | cell.click(); |
| 406 | expect(cell.classList.contains("chosen")).toBeTruthy(); |
| 407 | |
| 408 | // Activate another cell in another row |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 409 | cell = matchTable.querySelector("tbody > tr:nth-child(2) td:nth-child(3)"); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 410 | expect(cell.innerString()).toEqual("ART"); |
Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 411 | expect(cell.classList.contains("chosen")).toBe(false); |
| 412 | cell.click(); |
| 413 | expect(cell.classList.contains("chosen")).toBeTruthy(); |
| 414 | |
| 415 | expect(corenlpRow.querySelector("td:nth-child(3).chosen")).toBeNull(); |
| 416 | expect(corenlpRow.querySelector("td:nth-child(4).chosen")).toBeTruthy(); |
| 417 | expect(corenlpRow.querySelector("td:nth-child(5).chosen")).toBeNull(); |
| 418 | expect(corenlpRow.querySelector("td:nth-child(6).chosen")).toBeNull(); |
| 419 | |
| 420 | expect(qc.toString()).toEqual("[opennlp/p=ART][corenlp/p=ADJA]"); |
| 421 | |
| 422 | // Mark all corenlp lists |
| 423 | cell = corenlpRow.querySelector("th:nth-child(1)"); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 424 | expect(cell.innerString()).toEqual("corenlp"); |
Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 425 | expect(cell.classList.contains("chosen")).toBe(false); |
| 426 | cell.click(); |
| 427 | expect(cell.classList.contains("chosen")).toBe(false); |
| 428 | |
| 429 | expect(corenlpRow.querySelector("td:nth-child(3).chosen")).toBeTruthy(); |
| 430 | expect(corenlpRow.querySelector("td:nth-child(4).chosen")).toBeTruthy(); |
| 431 | expect(corenlpRow.querySelector("td:nth-child(5).chosen")).toBeTruthy(); |
| 432 | expect(corenlpRow.querySelector("td:nth-child(6).chosen")).toBeTruthy(); |
| 433 | |
| 434 | // Replay the choice without any effect |
| 435 | cell = corenlpRow.querySelector("th:nth-child(1)"); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 436 | expect(cell.innerString()).toEqual("corenlp"); |
Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 437 | expect(cell.classList.contains("chosen")).toBe(false); |
| 438 | cell.click(); |
| 439 | expect(cell.classList.contains("chosen")).toBe(false); |
| 440 | |
| 441 | expect(corenlpRow.querySelector("td:nth-child(3).chosen")).toBeTruthy(); |
| 442 | expect(corenlpRow.querySelector("td:nth-child(4).chosen")).toBeTruthy(); |
| 443 | expect(corenlpRow.querySelector("td:nth-child(5).chosen")).toBeTruthy(); |
| 444 | expect(corenlpRow.querySelector("td:nth-child(6).chosen")).toBeTruthy(); |
Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 445 | expect(corenlpRow.querySelector("td:nth-child(7).chosen")).toBeTruthy(); |
Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 446 | |
Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 447 | 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] | 448 | |
| 449 | // Remove one of the cells again |
| 450 | cell = corenlpRow.querySelector("td:nth-child(5).chosen"); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 451 | expect(cell.innerString()).toEqual("ADJAADJD"); |
Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 452 | expect(cell.classList.contains("chosen")).toBeTruthy(); |
| 453 | cell.click(); |
| 454 | expect(cell.classList.contains("chosen")).toBe(false); |
Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 455 | 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] | 456 | |
| 457 | }); |
Akron | 8084cb5 | 2017-06-29 17:11:14 +0200 | [diff] [blame] | 458 | |
| 459 | it('should ignore empty terms in whole rows', function () { |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 460 | var matchTable = matchTableFactory(); |
| 461 | var qc = qcClass.create(matchTable); |
Akron | 8084cb5 | 2017-06-29 17:11:14 +0200 | [diff] [blame] | 462 | expect(qc.toString()).toEqual(""); |
| 463 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 464 | var opennlpRow = matchTable.querySelector("tbody > tr:nth-child(2)"); |
Akron | 8084cb5 | 2017-06-29 17:11:14 +0200 | [diff] [blame] | 465 | |
| 466 | expect(opennlpRow.querySelector("td:nth-child(3).chosen")).toBeNull(); |
| 467 | expect(opennlpRow.querySelector("td:nth-child(4).chosen")).toBeNull(); |
| 468 | expect(opennlpRow.querySelector("td:nth-child(5).chosen")).toBeNull(); |
| 469 | expect(opennlpRow.querySelector("td:nth-child(6).chosen")).toBeNull(); |
| 470 | |
| 471 | expect(qc.toString()).toEqual(""); |
| 472 | |
| 473 | // Mark all opennlp lists |
| 474 | cell = opennlpRow.querySelector("th:nth-child(1)"); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 475 | expect(cell.innerString()).toEqual("opennlp"); |
Akron | 8084cb5 | 2017-06-29 17:11:14 +0200 | [diff] [blame] | 476 | expect(cell.classList.contains("chosen")).toBe(false); |
| 477 | cell.click(); |
| 478 | expect(cell.classList.contains("chosen")).toBe(false); |
| 479 | |
| 480 | expect(opennlpRow.querySelector("td:nth-child(3).chosen")).toBeTruthy(); |
| 481 | expect(opennlpRow.querySelector("td:nth-child(4).chosen")).toBeTruthy(); |
| 482 | expect(opennlpRow.querySelector("td:nth-child(5).chosen")).toBeNull(); |
| 483 | expect(opennlpRow.querySelector("td:nth-child(6).chosen")).toBeTruthy(); |
Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 484 | |
| 485 | 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] | 486 | }); |
Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 487 | |
| 488 | it('should support multiple distances', function () { |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 489 | var matchTable = matchTableFactory(); |
| 490 | var qc = qcClass.create(matchTable); |
Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 491 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 492 | var cell = matchTable.querySelector("thead > tr > th:nth-child(3)"); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 493 | expect(cell.innerString()).toEqual("Der"); |
Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 494 | cell.click(); |
| 495 | expect(qc.toString()).toEqual("[orth=Der]"); |
| 496 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 497 | cell = matchTable.querySelector("thead > tr > th:nth-child(7)"); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 498 | expect(cell.innerString()).toEqual("hier"); |
Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 499 | cell.click(); |
| 500 | expect(qc.toString()).toEqual("[orth=Der][]{3}[orth=hier]"); |
| 501 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 502 | cell = matchTable.querySelector("thead > tr > th:nth-child(5)"); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 503 | expect(cell.innerString()).toEqual("lebende"); |
Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 504 | cell.click(); |
| 505 | expect(qc.toString()).toEqual("[orth=Der][][orth=lebende][][orth=hier]"); |
| 506 | }); |
Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 507 | |
| 508 | it('should create and-groups for key-value terms', function () { |
Akron | efed2e2 | 2021-11-16 23:16:54 +0100 | [diff] [blame] | 509 | const matchTable = matchTableComplexFactory(); |
| 510 | const qc = qcClass.create(matchTable); |
Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 511 | |
| 512 | // Nothing to show |
| 513 | expect(qc.toString()).toEqual(""); |
| 514 | expect(qc.shown()).toBe(false); |
| 515 | qc.show(); |
| 516 | expect(qc.shown()).toBe(false); |
Akron | 7dd3282 | 2018-10-01 19:38:31 +0200 | [diff] [blame] | 517 | expect(qc.element().className).toEqual("query fragment"); |
Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 518 | |
Akron | efed2e2 | 2021-11-16 23:16:54 +0100 | [diff] [blame] | 519 | let cell = matchTable.querySelector("thead > tr > th:nth-child(5)"); |
Akron | 0d612d1 | 2019-05-21 16:45:49 +0200 | [diff] [blame] | 520 | expect(cell.innerString()).toEqual("lebende und sterbende"); |
Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 521 | expect(cell.classList.contains("chosen")).toBe(false); |
| 522 | cell.click(); |
| 523 | expect(cell.classList.contains("chosen")).toBeTruthy(); |
Akron | 0d612d1 | 2019-05-21 16:45:49 +0200 | [diff] [blame] | 524 | expect(qc.toString()).toEqual("[orth='lebende und sterbende']"); |
Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 525 | |
| 526 | // Check complex cell |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 527 | cell = matchTable.querySelector("tbody > tr:nth-child(1) > td:nth-child(6)"); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 528 | expect(cell.innerString()).toMatch(/case:nom/); |
Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 529 | expect(cell.classList.contains("chosen")).toBe(false); |
| 530 | cell.click(); |
| 531 | expect(cell.classList.contains("chosen")).toBe(false); |
Akron | 0d612d1 | 2019-05-21 16:45:49 +0200 | [diff] [blame] | 532 | expect(qc.toString()).toEqual("[orth='lebende und sterbende']"); |
Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 533 | |
| 534 | // Check complex cell div |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 535 | 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] | 536 | expect(cell.innerString()).toEqual('case:nom'); |
Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 537 | expect(cell.classList.contains("chosen")).toBe(false); |
| 538 | cell.click(); |
| 539 | expect(cell.classList.contains("chosen")).toBe(true); |
Akron | 0d612d1 | 2019-05-21 16:45:49 +0200 | [diff] [blame] | 540 | expect(qc.toString()).toEqual("[orth='lebende und sterbende'][corenlp/p=case:nom]"); |
Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 541 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 542 | 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] | 543 | expect(cell.innerString()).toEqual('number:sg'); |
Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 544 | expect(cell.classList.contains("chosen")).toBe(false); |
| 545 | cell.click(); |
| 546 | expect(cell.classList.contains("chosen")).toBe(true); |
Akron | 0d612d1 | 2019-05-21 16:45:49 +0200 | [diff] [blame] | 547 | expect(qc.toString()).toEqual("[orth='lebende und sterbende'][corenlp/p=case:nom & corenlp/p=number:sg]"); |
Akron | efed2e2 | 2021-11-16 23:16:54 +0100 | [diff] [blame] | 548 | let cell2 = cell; |
Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 549 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 550 | 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] | 551 | expect(cell.innerString()).toEqual('gender:mascgender:fem'); |
Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 552 | expect(cell.classList.contains("chosen")).toBe(false); |
| 553 | cell.click(); |
| 554 | expect(cell.classList.contains("chosen")).toBe(true); |
Akron | 0d612d1 | 2019-05-21 16:45:49 +0200 | [diff] [blame] | 555 | expect(qc.toString()).toEqual("[orth='lebende und sterbende'][(corenlp/p=gender:fem | corenlp/p=gender:masc) & corenlp/p=case:nom & corenlp/p=number:sg]"); |
Akron | efed2e2 | 2021-11-16 23:16:54 +0100 | [diff] [blame] | 556 | let cell3 = cell; |
Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 557 | |
| 558 | // Remove cell again |
| 559 | cell = cell2; |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 560 | expect(cell.innerString()).toEqual('number:sg'); |
Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 561 | expect(cell.classList.contains("chosen")).toBe(true); |
| 562 | cell.click(); |
| 563 | expect(cell.classList.contains("chosen")).toBe(false); |
Akron | 0d612d1 | 2019-05-21 16:45:49 +0200 | [diff] [blame] | 564 | expect(qc.toString()).toEqual("[orth='lebende und sterbende'][(corenlp/p=gender:fem | corenlp/p=gender:masc) & corenlp/p=case:nom]"); |
Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 565 | |
| 566 | // Remove cell again |
| 567 | cell = cell3; |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 568 | expect(cell.innerString()).toEqual('gender:mascgender:fem'); |
Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 569 | expect(cell.classList.contains("chosen")).toBe(true); |
| 570 | cell.click(); |
| 571 | expect(cell.classList.contains("chosen")).toBe(false); |
Akron | 0d612d1 | 2019-05-21 16:45:49 +0200 | [diff] [blame] | 572 | expect(qc.toString()).toEqual("[orth='lebende und sterbende'][corenlp/p=case:nom]"); |
Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 573 | }); |
| 574 | |
| 575 | |
| 576 | it('should create rows including key-value terms', function () { |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 577 | var matchTable = matchTableComplexFactory(); |
| 578 | var qc = qcClass.create(matchTable); |
Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 579 | expect(qc.toString()).toEqual(""); |
| 580 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 581 | var corenlpRow = matchTable.querySelector("tbody > tr:nth-child(1)"); |
Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 582 | |
| 583 | expect(corenlpRow.querySelector("td:nth-child(3).chosen")).toBeNull(); |
| 584 | expect(corenlpRow.querySelector("td:nth-child(4).chosen")).toBeNull(); |
| 585 | expect(corenlpRow.querySelector("td:nth-child(5).chosen")).toBeNull(); |
| 586 | expect(corenlpRow.querySelector("td:nth-child(6) *.chosen")).toBeNull(); |
| 587 | |
| 588 | expect(qc.toString()).toEqual(""); |
| 589 | |
| 590 | // Mark all opennlp lists |
| 591 | cell = corenlpRow.querySelector("th:nth-child(1)"); |
Akron | bdcbbf4 | 2018-04-25 12:42:44 +0200 | [diff] [blame] | 592 | expect(cell.innerString()).toEqual("corenlp"); |
Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 593 | expect(cell.classList.contains("chosen")).toBe(false); |
| 594 | cell.click(); |
| 595 | expect(cell.classList.contains("chosen")).toBe(false); |
| 596 | |
| 597 | expect(corenlpRow.querySelector("td:nth-child(3).chosen")).toBeTruthy(); |
| 598 | expect(corenlpRow.querySelector("td:nth-child(4).chosen")).toBeTruthy(); |
| 599 | expect(corenlpRow.querySelector("td:nth-child(5).chosen")).toBeTruthy(); |
| 600 | expect(corenlpRow.querySelector("td:nth-child(6) div:nth-child(1).chosen")).toBeTruthy(); |
| 601 | expect(corenlpRow.querySelector("td:nth-child(6) div:nth-child(2).chosen")).toBeTruthy(); |
| 602 | expect(corenlpRow.querySelector("td:nth-child(6) div:nth-child(3).chosen")).toBeTruthy(); |
| 603 | |
| 604 | expect(qc.toString()).toEqual( |
| 605 | "[corenlp/p=ART]"+ |
| 606 | "[corenlp/p=ADJA]"+ |
| 607 | "[(corenlp/p=ADJA | corenlp/p=ADJD)]"+ |
| 608 | "[(corenlp/p=gender:fem | corenlp/p=gender:masc) & corenlp/p=case:nom & corenlp/p=number:sg]" |
| 609 | ); |
| 610 | }); |
Akron | 72245b6 | 2018-07-23 10:59:08 +0200 | [diff] [blame] | 611 | |
| 612 | it('should support verbatim strings', function () { |
| 613 | var matchTable = matchTableComplexFactory(); |
| 614 | var qc = qcClass.create(matchTable); |
| 615 | expect(qc.toString()).toEqual(""); |
| 616 | |
| 617 | // TODO: |
| 618 | // This does not respect keys vs values at the moment, but neither does Koral |
Akron | efed2e2 | 2021-11-16 23:16:54 +0100 | [diff] [blame] | 619 | let cell = matchTable.querySelector("tbody > tr:nth-child(2) > td > div:nth-child(4)"); |
Akron | 72245b6 | 2018-07-23 10:59:08 +0200 | [diff] [blame] | 620 | expect(cell.innerString()).toEqual("morphemes:.::_SORSZ \\ZERO::NOM 'period::PUNCT'"); |
| 621 | expect(cell.classList.contains("chosen")).toBe(false); |
| 622 | cell.click(); |
| 623 | expect(cell.classList.contains("chosen")).toBeTruthy(); |
| 624 | expect(qc.toString()).toEqual("[opennlp/p='morphemes:.::_SORSZ \\\\ZERO::NOM \\\'period::PUNCT\\\'']"); |
Akron | 0d612d1 | 2019-05-21 16:45:49 +0200 | [diff] [blame] | 625 | cell.click() |
| 626 | expect(cell.classList.contains("chosen")).toBe(false); |
| 627 | expect(qc.toString()).toEqual(""); |
| 628 | |
| 629 | cell = matchTable.querySelector("tbody > tr:nth-child(3) > td:nth-child(3)"); |
| 630 | expect(cell.classList.contains("chosen")).toBe(false); |
| 631 | cell.click(); |
| 632 | expect(cell.classList.contains("chosen")).toBeTruthy(); |
| 633 | expect(qc.toString()).toEqual("[tt/l='Lese|Lesen']"); |
| 634 | cell.click() |
| 635 | expect(cell.classList.contains("chosen")).toBe(false); |
| 636 | expect(qc.toString()).toEqual(""); |
| 637 | |
| 638 | cell = matchTable.querySelector("tbody > tr:nth-child(3) > td:nth-child(4)"); |
| 639 | expect(cell.classList.contains("chosen")).toBe(false); |
| 640 | cell.click(); |
| 641 | expect(cell.classList.contains("chosen")).toBeTruthy(); |
| 642 | expect(qc.toString()).toEqual("[tt/l='a b']"); |
| 643 | cell.click() |
| 644 | expect(cell.classList.contains("chosen")).toBe(false); |
| 645 | expect(qc.toString()).toEqual(""); |
Akron | efed2e2 | 2021-11-16 23:16:54 +0100 | [diff] [blame] | 646 | |
| 647 | cell = matchTable.querySelector("tbody > tr:nth-child(2) > td > div:nth-child(5)"); |
| 648 | expect(cell.innerString()).toEqual("morphemes:ZERO::NOM"); |
| 649 | expect(cell.classList.contains("chosen")).toBe(false); |
| 650 | cell.click(); |
| 651 | expect(cell.classList.contains("chosen")).toBeTruthy(); |
| 652 | expect(qc.toString()).toEqual("[opennlp/p='morphemes:ZERO::NOM']"); |
| 653 | cell.click() |
| 654 | expect(cell.classList.contains("chosen")).toBe(false); |
| 655 | expect(qc.toString()).toEqual(""); |
Akron | 72245b6 | 2018-07-23 10:59:08 +0200 | [diff] [blame] | 656 | }); |
Akron | aeeb825 | 2018-09-19 18:51:00 +0200 | [diff] [blame] | 657 | |
| 658 | it('should respect marked elements', function () { |
| 659 | var matchTable = matchTableComplexFactory(); |
| 660 | var qc = qcClass.create(matchTable); |
| 661 | expect(qc.toString()).toEqual(""); |
| 662 | |
| 663 | var cell = matchTable.querySelector("thead > tr > th:nth-child(6)"); |
| 664 | expect(cell.classList.contains("mark")).toBeTruthy(); |
| 665 | expect(cell.classList.contains("chosen")).toBeFalsy(); |
| 666 | |
| 667 | cell.click(); |
| 668 | expect(cell.classList.contains("mark")).toBeTruthy(); |
| 669 | expect(cell.classList.contains("chosen")).toBeTruthy(); |
| 670 | |
| 671 | cell.click(); |
| 672 | expect(cell.classList.contains("mark")).toBeTruthy(); |
| 673 | expect(cell.classList.contains("chosen")).toBeFalsy(); |
| 674 | }); |
Akron | 083ec57 | 2019-05-16 18:30:40 +0200 | [diff] [blame] | 675 | |
| 676 | it('should ignore cutted columns', function () { |
| 677 | var matchTable = matchTableCuttedFactory(); |
| 678 | var qc = qcClass.create(matchTable); |
| 679 | expect(qc.toString()).toEqual(""); |
| 680 | |
| 681 | var cell = matchTable.querySelector("thead > tr > th:nth-child(3)"); |
| 682 | expect(cell.classList.contains("chosen")).toBeFalsy(); |
| 683 | cell.click(); |
| 684 | expect(cell.classList.contains("chosen")).toBeTruthy(); |
| 685 | expect(qc.toString()).toEqual("[orth=Baum]"); |
| 686 | |
| 687 | cell = matchTable.querySelector("thead > tr > th:nth-child(4)"); |
| 688 | expect(cell.classList.contains("chosen")).toBeFalsy(); |
| 689 | expect(cell.classList.contains("cutted")).toBeTruthy(); |
| 690 | cell.click(); |
| 691 | expect(cell.classList.contains("chosen")).toBeFalsy(); |
| 692 | expect(qc.toString()).toEqual("[orth=Baum]"); |
| 693 | }); |
Akron | b516374 | 2020-10-12 15:31:41 +0200 | [diff] [blame] | 694 | |
| 695 | it('should add fragment to QueryBar', function () { |
| 696 | var matchTable = matchTableCuttedFactory(); |
| 697 | var qc = qcClass.create(matchTable); |
| 698 | expect(qc.toString()).toEqual(""); |
| 699 | |
| 700 | var cell = matchTable.querySelector("thead > tr > th:nth-child(3)"); |
| 701 | expect(cell.classList.contains("chosen")).toBeFalsy(); |
| 702 | cell.click(); |
| 703 | expect(cell.classList.contains("chosen")).toBeTruthy(); |
| 704 | expect(qc.toString()).toEqual("[orth=Baum]"); |
| 705 | |
| 706 | // May break |
| 707 | qc._ql = document.createElement('select'); |
| 708 | let opt = qc._ql.appendChild(document.createElement('option')); |
| 709 | opt.value='cosmas 2'; |
| 710 | let opt2 = qc._ql.appendChild(document.createElement('option')); |
| 711 | opt2.value='poliqarp'; |
| 712 | |
| 713 | qc._q = document.createElement('input'); |
| 714 | |
Akron | 24aa005 | 2020-11-10 11:00:34 +0100 | [diff] [blame] | 715 | qc._el.click(); |
Akron | b516374 | 2020-10-12 15:31:41 +0200 | [diff] [blame] | 716 | |
| 717 | expect(qc._ql.selectedIndex).toEqual(1); |
| 718 | expect(qc._q.value).toEqual("[orth=Baum]"); |
| 719 | }); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 720 | }); |
| 721 | }); |