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