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