blob: f520557e67382f39d6a614dc3c30e1e33418c28b [file] [log] [blame]
Nils Diewalda297f062015-04-02 00:23:46 +00001var available = [
2 'base/s=spans',
3 'corenlp/c=spans',
4 'corenlp/ne=tokens',
5 'corenlp/p=tokens',
6 'corenlp/s=spans',
7 'glemm/l=tokens',
8 'mate/l=tokens',
9 'mate/m=tokens',
10 'mate/p=tokens',
11 'opennlp/p=tokens',
12 'opennlp/s=spans',
13 'tt/l=tokens',
14 'tt/p=tokens',
15 'tt/s=spans'
16];
17
18var match = {
19 'corpusID' : 'WPD',
20 'docID' : 'UUU',
21 'textID' : '01912',
22 'matchID' : 'p121-122',
23 'available' : available
24};
25
26var snippet = "<span title=\"cnx/l:meist\">" +
27 " <span title=\"cnx/p:ADV\">" +
28 " <span title=\"cnx/syn:@PREMOD\">" +
29 " <span title=\"mate/l:meist\">" +
30 " <span title=\"mate/p:ADV\">" +
31 " <span title=\"opennlp/p:ADV\">meist</span>" +
32 " </span>" +
33 " </span>" +
34 " </span>" +
35 " </span>" +
36 "</span>" +
37 "<span title=\"cnx/l:deutlich\">" +
38 " <span title=\"cnx/p:A\">" +
39 " <span title=\"cnx/syn:@PREMOD\">" +
40 " <span title=\"mate/l:deutlich\">" +
41 " <span title=\"mate/m:degree:pos\">" +
42 " <span title=\"mate/p:ADJD\">" +
43 " <span title=\"opennlp/p:ADJD\">deutlich</span>" +
44 " </span>" +
45 " </span>" +
46 " </span>" +
47 " </span>" +
48 " </span>" +
49 "</span>" +
50 "<span title=\"cnx/l:fähig\">" +
51 " <span title=\"cnx/l:leistung\">" +
52 " <span title=\"cnx/p:A\">" +
53 " <span title=\"cnx/syn:@NH\">" +
54 " <span title=\"mate/l:leistungsfähig\">" +
55 " <span title=\"mate/m:degree:comp\">" +
56 " <span title=\"mate/p:ADJD\">" +
57 " <span title=\"opennlp/p:ADJD\">leistungsfähiger</span>" +
58 " </span>" +
59 " </span>" +
60 " </span>" +
61 " </span>" +
62 " </span>" +
63 " </span>" +
64 "</span>";
65
66var treeSnippet =
67 "<span class=\"context-left\"></span>" +
68 "<span class=\"match\">" +
69 " <span title=\"xip/c:MC\">" +
70 " <span title=\"xip/c:TOP\">" +
71 " <span title=\"xip/c:PP\">" +
72 " <span title=\"xip/c:PREP\">Mit</span>" +
73 " <span title=\"xip/c:NP\">" +
74 " <span title=\"xip/c:DET\">dieser</span>" +
75 " <span title=\"xip/c:NPA\">" +
76 " <span title=\"xip/c:NOUN\">Methode</span>" +
77 " </span>" +
78 " </span>" +
79 " </span>" +
80 " <span title=\"xip/c:VERB\">ist</span>" +
81 " <span title=\"xip/c:NP\">" +
82 " <span title=\"xip/c:PRON\">es</span>" +
83 " </span>" +
84 " <span title=\"xip/c:AP\">" +
85 " <span title=\"xip/c:ADV\">nun</span>" +
86 " <span title=\"xip/c:ADJ\">möglich</span>" +
87 " </span>" +
88 " <span title=\"xip/c:ADV\">z. B.</span>" +
89 " <span title=\"xip/c:NPA\">" +
90 " <span title=\"xip/c:NP\">" +
91 " <span title=\"xip/c:NOUN\">Voice</span>" +
92 " </span>" +
93 " </span>" + "(" +
94 " <span title=\"xip/c:INS\">" +
95 " <span title=\"xip/c:NPA\">" +
96 " <span title=\"xip/c:NP\">" +
97 " <span title=\"xip/c:NOUN\">Sprache</span>" +
98 " </span>" +
99 " </span>" +
100 " </span>" + ")" +
101 " <span title=\"xip/c:VERB\">bevorzugt</span>" +
102 " <span title=\"xip/c:PP\">" +
103 " <span title=\"xip/c:PREP\">in</span>" +
104 " <span title=\"xip/c:NP\">" +
105 " <span title=\"xip/c:PRON\">der</span>" +
106 " </span>" +
107 " <span title=\"xip/c:NPA\">" +
108 " <span title=\"xip/c:NP\">" +
109 " <span title=\"xip/c:NOUN\">Bridge</span>" +
110 " </span>" +
111 " </span>" +
112 " </span>" +
113 " <span title=\"xip/c:INFC\">" +
114 " <span title=\"xip/c:INS\">" +
115 " <span title=\"xip/c:VERB\">weiterzugeben</span>" +
116 " </span>" +
117 " </span>" +
118 " </span>" +
119 " </span>" +
120 "</span>" +
121 "<span class=\"context-right\"></span>";
122
123
124function matchElementFactory () {
125 var me = document.createElement('li');
126
127 me.setAttribute(
128 'data-available-info',
129 'base/s=spans corenlp/c=spans corenlp/ne=tokens corenlp/p=tokens' +
130 ' corenlp/s=spans glemm/l=tokens mate/l=tokens mate/m=tokens' +
131 ' mate/p=tokens opennlp/p=tokens opennlp/s=spans tt/l=tokens' +
132 ' tt/p=tokens tt/s=spans');
133
134 me.setAttribute('data-corpus-id', 'WPD');
135 me.setAttribute('data-doc-id', 'FFF');
136 me.setAttribute('data-text-id', '01460');
137 me.setAttribute('data-match-id', 'p119-120');
138 me.innerHTML = '<div><div class="snippet">check</div></div><p class="ref">me</p>';
139 return me;
140};
141
142
Nils Diewald58141332015-04-07 16:18:45 +0000143// Override getMatchInfo API call
144KorAP.API.getMatchInfo = function (x, param, cb) {
145 if (param['spans'] === undefined || param['spans'] === false)
146 cb({ "snippet": snippet });
147 else
148 cb({ "snippet": treeSnippet });
149};
150
151
Nils Diewalda297f062015-04-02 00:23:46 +0000152describe('KorAP.InfoLayer', function () {
153
154 it('should be initializable', function () {
155 expect(
156 function() { KorAP.InfoLayer.create() }
157 ).toThrow(new Error("Missing parameters"));
158
159 expect(
160 function() { KorAP.InfoLayer.create("base") }
161 ).toThrow(new Error("Missing parameters"));
162
163 var layer = KorAP.InfoLayer.create("base", "s");
164 expect(layer).toBeTruthy();
165 expect(layer.foundry).toEqual("base");
166 expect(layer.layer).toEqual("s");
167 expect(layer.type).toEqual("tokens");
168
169 layer = KorAP.InfoLayer.create("cnx", "syn", "spans");
170 expect(layer).toBeTruthy();
171 expect(layer.foundry).toEqual("cnx");
172 expect(layer.layer).toEqual("syn");
173 expect(layer.type).toEqual("spans");
174 });
175});
176
177
178describe('KorAP.Match', function () {
179 var match = {
180 'corpusID' : 'WPD',
181 'docID' : 'UUU',
182 'textID' : '01912',
183 'matchID' : 'p121-122',
184 'available' : available
185 };
186
187 it('should be initializable by Object', function () {
188 expect(function() {
189 KorAP.Match.create()
190 }).toThrow(new Error('Missing parameters'));
191
192 expect(KorAP.Match.create(match)).toBeTruthy();
193
194 var m = KorAP.Match.create(match);
195 expect(m.corpusID).toEqual("WPD");
196 expect(m.docID).toEqual("UUU");
197 expect(m.textID).toEqual("01912");
198 expect(m.matchID).toEqual("p121-122");
199
200 // /corpus/WPD/UUU.01912/p121-122/matchInfo?spans=false&foundry=*
201 var m = KorAP.Match.create(match);
202
203 // Spans:
204 var spans = m.getSpans();
205 expect(spans[0].foundry).toEqual("base");
206 expect(spans[0].layer).toEqual("s");
207
208 expect(spans[1].foundry).toEqual("corenlp");
209 expect(spans[1].layer).toEqual("c");
210
211 expect(spans[2].foundry).toEqual("corenlp");
212 expect(spans[2].layer).toEqual("s");
213
214 expect(spans[spans.length-1].foundry).toEqual("tt");
215 expect(spans[spans.length-1].layer).toEqual("s");
216
217 // Tokens:
218 var tokens = m.getTokens();
219 expect(tokens[0].foundry).toEqual("corenlp");
220 expect(tokens[0].layer).toEqual("ne");
221
222 expect(tokens[1].foundry).toEqual("corenlp");
223 expect(tokens[1].layer).toEqual("p");
224
225 expect(tokens[tokens.length-1].foundry).toEqual("tt");
226 expect(tokens[tokens.length-1].layer).toEqual("p");
227 });
228
229
230 it('should be initializable by Node', function () {
231 var m = KorAP.Match.create(matchElementFactory());
232 expect(m.corpusID).toEqual("WPD");
233 expect(m.docID).toEqual("FFF");
234 expect(m.textID).toEqual("01460");
235 expect(m.matchID).toEqual("p119-120");
236
237 // Spans:
238 var spans = m.getSpans();
239 expect(spans[0].foundry).toEqual("base");
240 expect(spans[0].layer).toEqual("s");
241
242 expect(spans[1].foundry).toEqual("corenlp");
243 expect(spans[1].layer).toEqual("c");
244
245 expect(spans[2].foundry).toEqual("corenlp");
246 expect(spans[2].layer).toEqual("s");
247
248 expect(spans[spans.length-1].foundry).toEqual("tt");
249 expect(spans[spans.length-1].layer).toEqual("s");
250
251 // Tokens:
252 var tokens = m.getTokens();
253 expect(tokens[0].foundry).toEqual("corenlp");
254 expect(tokens[0].layer).toEqual("ne");
255
256 expect(tokens[1].foundry).toEqual("corenlp");
257 expect(tokens[1].layer).toEqual("p");
258
259 expect(tokens[tokens.length-1].foundry).toEqual("tt");
260 expect(tokens[tokens.length-1].layer).toEqual("p");
261
262 });
263
264 it('should react to gui actions', function () {
265 var e = matchElementFactory();
266
267 expect(e.classList.contains('active')).toBe(false);
268 expect(e["_match"]).toBe(undefined);
269
270 var m = KorAP.Match.create(e);
271
272 expect(e.classList.contains('active')).toBe(false);
273 expect(e["_match"]).not.toBe(undefined);
274
275 // Open the match
276 m.open();
277
278 expect(e.classList.contains('active')).toBe(true);
279 expect(e["_match"]).not.toBe(undefined);
280
281 // Close the match
282 m.close();
283 expect(e.classList.contains('active')).toBe(false);
284 expect(e["_match"]).not.toBe(undefined);
285
286 });
287});
288
289
290describe('KorAP.MatchInfo', function () {
Nils Diewalda297f062015-04-02 00:23:46 +0000291
Nils Diewald58141332015-04-07 16:18:45 +0000292 var m = KorAP.Match.create(match);
293 var info = m.info();
294
295 it('should contain a valid info', function () {
Nils Diewalda297f062015-04-02 00:23:46 +0000296 expect(m._info).toEqual(info);
Nils Diewald58141332015-04-07 16:18:45 +0000297 });
Nils Diewalda297f062015-04-02 00:23:46 +0000298
Nils Diewald58141332015-04-07 16:18:45 +0000299 var table1, table2;
Nils Diewalda297f062015-04-02 00:23:46 +0000300
Nils Diewald58141332015-04-07 16:18:45 +0000301 // Async preparation
302 it('should fail to load a table async', function (done) {
303 expect(info).toBeTruthy();
Nils Diewalda297f062015-04-02 00:23:46 +0000304
Nils Diewald58141332015-04-07 16:18:45 +0000305 info.getTable([], function (tablen) {
306 table1 = tablen;
307 done();
308 });
309 });
Nils Diewalda297f062015-04-02 00:23:46 +0000310
Nils Diewald58141332015-04-07 16:18:45 +0000311 it('should\'nt be parsable (async)', function () {
312 expect(table1).not.toBeTruthy();
313 });
Nils Diewalda297f062015-04-02 00:23:46 +0000314
Nils Diewald58141332015-04-07 16:18:45 +0000315 it('should load a working table async', function(done) {
316 expect(info).toBeTruthy();
317 info.getTable(undefined, function (tablem) {
318 table2 = tablem;
319 done();
320 });
321 });
322
323 it('should parse into a table (async)', function () {
324 expect(table2).toBeTruthy();
Nils Diewalda297f062015-04-02 00:23:46 +0000325
Nils Diewald58141332015-04-07 16:18:45 +0000326 expect(table2.length()).toBe(3);
Nils Diewalda297f062015-04-02 00:23:46 +0000327
Nils Diewald58141332015-04-07 16:18:45 +0000328 expect(table2.getToken(0)).toBe("meist");
329 expect(table2.getToken(1)).toBe("deutlich");
330 expect(table2.getToken(2)).toBe("leistungsfähiger");
331
332 expect(table2.getValue(0, "cnx", "p")[0]).toBe("ADV");
333 expect(table2.getValue(0, "cnx", "syn")[0]).toBe("@PREMOD");
334
335 expect(table2.getValue(2, "cnx", "l")[0]).toBe("fähig");
336 expect(table2.getValue(2, "cnx", "l")[1]).toBe("leistung");
Nils Diewalda297f062015-04-02 00:23:46 +0000337 });
338
339
340 it('should parse into a table view', function () {
341 var matchElement = matchElementFactory();
342 expect(matchElement.tagName).toEqual('LI');
343
344 // Match
345 expect(matchElement.children[0].tagName).toEqual('DIV');
346
347 // snippet
348 expect(matchElement.children[0].children[0].tagName).toEqual('DIV');
349 expect(matchElement.children[0].children[0].classList.contains('snippet')).toBeTruthy();
350 expect(matchElement.children[0].children[0].firstChild.nodeValue).toEqual('check');
351
352 // reference
353 expect(matchElement.children[1].classList.contains('ref')).toBeTruthy();
354 expect(matchElement.children[1].firstChild.nodeValue).toEqual('me');
355
356 // not yet
357 expect(matchElement.children[0].children[1]).toBe(undefined);
358
359 var info = KorAP.Match.create(matchElement).info();
Nils Diewald5c5a7472015-04-02 22:13:38 +0000360 info.toggle();
Nils Diewalda297f062015-04-02 00:23:46 +0000361
362 // Match
363 expect(matchElement.children[0].tagName).toEqual('DIV');
364
365 // snippet
366 expect(matchElement.children[0].children[0].tagName).toEqual('DIV');
367 expect(matchElement.children[0].children[0].classList.contains('snippet')).toBeTruthy();
368 expect(matchElement.children[0].children[0].firstChild.nodeValue).toEqual('check');
369
370 // reference
371 expect(matchElement.children[1].classList.contains('ref')).toBeTruthy();
372 expect(matchElement.children[1].firstChild.nodeValue).toEqual('me');
373
374 // now
375 var infotable = matchElement.children[0].children[1];
376 expect(infotable.tagName).toEqual('DIV');
377 expect(infotable.classList.contains('matchinfo')).toBeTruthy();
378
379 expect(infotable.children[0].classList.contains('matchtable')).toBeTruthy();
380 expect(infotable.children[1].classList.contains('addtree')).toBeTruthy();
381 });
382
Nils Diewald58141332015-04-07 16:18:45 +0000383 var tree;
384 it('should parse into a tree (async) 1', function (done) {
Nils Diewalda297f062015-04-02 00:23:46 +0000385 var info = KorAP.Match.create(match).info();
Nils Diewald58141332015-04-07 16:18:45 +0000386 expect(info).toBeTruthy();
387 info.getTree(undefined, undefined, function (treem) {
388 tree = treem;
389 done();
390 });
391 });
Nils Diewalda297f062015-04-02 00:23:46 +0000392
Nils Diewald58141332015-04-07 16:18:45 +0000393 it('should parse into a tree (async) 2', function () {
Nils Diewalda297f062015-04-02 00:23:46 +0000394 expect(tree).toBeTruthy();
395 expect(tree.nodes()).toEqual(49);
396 });
397
398
Nils Diewald58141332015-04-07 16:18:45 +0000399 var info, matchElement;
Nils Diewalda297f062015-04-02 00:23:46 +0000400 it('should parse into a tree view', function () {
Nils Diewald58141332015-04-07 16:18:45 +0000401 matchElement = matchElementFactory();
Nils Diewalda297f062015-04-02 00:23:46 +0000402 expect(matchElement.tagName).toEqual('LI');
403
Nils Diewald58141332015-04-07 16:18:45 +0000404 info = KorAP.Match.create(matchElement).info();
Nils Diewald5c5a7472015-04-02 22:13:38 +0000405 info.toggle();
Nils Diewalda297f062015-04-02 00:23:46 +0000406
407 // Match
408 expect(matchElement.children[0].tagName).toEqual('DIV');
409
410 // snippet
411 expect(matchElement.children[0].children[0].tagName).toEqual('DIV');
412 expect(matchElement.children[0].children[0].classList.contains('snippet')).toBeTruthy();
413 expect(matchElement.children[0].children[0].firstChild.nodeValue).toEqual('check');
414
415 // reference
416 expect(matchElement.children[1].classList.contains('ref')).toBeTruthy();
417 expect(matchElement.children[1].firstChild.nodeValue).toEqual('me');
418
419 // now
420 var infotable = matchElement.children[0].children[1];
421 expect(infotable.tagName).toEqual('DIV');
422 expect(infotable.classList.contains('matchinfo')).toBeTruthy();
423 expect(infotable.children[0].classList.contains('matchtable')).toBeTruthy();
424 expect(infotable.children[1].classList.contains('addtree')).toBeTruthy();
Nils Diewald58141332015-04-07 16:18:45 +0000425 });
Nils Diewalda297f062015-04-02 00:23:46 +0000426
Nils Diewald58141332015-04-07 16:18:45 +0000427 it('should add a tree view async 1', function (done) {
428 expect(info).toBeTruthy();
429 info.addTree('mate', 'beebop', function () {
430 done();
431 });
432 });
Nils Diewalda297f062015-04-02 00:23:46 +0000433
Nils Diewald58141332015-04-07 16:18:45 +0000434 it('should add a tree view async 2', function () {
Nils Diewalda297f062015-04-02 00:23:46 +0000435 // With added tree
436 var infotable = matchElement.children[0].children[1];
437 expect(infotable.tagName).toEqual('DIV');
438 expect(infotable.classList.contains('matchinfo')).toBeTruthy();
439 expect(infotable.children[0].classList.contains('matchtable')).toBeTruthy();
440 expect(infotable.children[1].classList.contains('addtree')).toBe(false);
441
442 var tree = infotable.children[1];
443 expect(tree.tagName).toEqual('DIV');
444 expect(tree.classList.contains('matchtree')).toBeTruthy();
445 expect(tree.children[0].tagName).toEqual('H6');
446 expect(tree.children[0].children[0].tagName).toEqual('SPAN');
447 expect(tree.children[0].children[0].firstChild.nodeValue).toEqual('mate');
448 expect(tree.children[0].children[1].tagName).toEqual('SPAN');
449 expect(tree.children[0].children[1].firstChild.nodeValue).toEqual('beebop');
450
451 expect(tree.children[1].tagName).toEqual('DIV');
Nils Diewalda297f062015-04-02 00:23:46 +0000452 });
453});
454
455
456describe('KorAP.MatchTable', function () {
Nils Diewald58141332015-04-07 16:18:45 +0000457
458 var table;
459 it('should be retrieved async', function (done) {
Nils Diewalda297f062015-04-02 00:23:46 +0000460 var info = KorAP.Match.create(match).info();
Nils Diewald58141332015-04-07 16:18:45 +0000461 expect(info).toBeTruthy();
462 info.getTable(undefined, function (x) {
463 table = x;
464 done();
465 });
466 });
Nils Diewalda297f062015-04-02 00:23:46 +0000467
Nils Diewald58141332015-04-07 16:18:45 +0000468 it('should be rendered async', function () {
Nils Diewalda297f062015-04-02 00:23:46 +0000469 var e = table.element();
470
471 expect(e.nodeName).toBe('TABLE');
472 expect(e.children[0].nodeName).toBe('THEAD');
473 var tr = e.children[0].children[0];
474 expect(tr.nodeName).toBe('TR');
475 expect(tr.children[0].nodeName).toBe('TH');
476
477 expect(tr.children[0].firstChild.nodeValue).toBe('Foundry');
478 expect(tr.children[1].firstChild.nodeValue).toBe('Layer');
479 expect(tr.children[2].firstChild.nodeValue).toBe('meist');
480 expect(tr.children[3].firstChild.nodeValue).toBe('deutlich');
481 expect(tr.children[4].firstChild.nodeValue).toBe('leistungsfähiger');
482
483 // first row
484 tr = e.children[1].children[0];
485 expect(tr.nodeName).toBe('TR');
486 expect(tr.getAttribute('tabindex')).toEqual('0');
487 expect(tr.children[0].nodeName).toBe('TH');
488 expect(tr.children[0].firstChild.nodeValue).toEqual('cnx');
489 expect(tr.children[1].firstChild.nodeValue).toEqual('l');
490 expect(tr.children[2].firstChild.nodeValue).toEqual('meist');
491 expect(tr.children[3].firstChild.nodeValue).toEqual('deutlich');
492 expect(tr.children[4].firstChild.nodeValue).toEqual('fähig');
493 expect(tr.children[4].lastChild.nodeValue).toEqual('leistung');
494
495 // second row
496 tr = e.children[1].children[1];
497 expect(tr.nodeName).toBe('TR');
498 expect(tr.getAttribute('tabindex')).toEqual('0');
499 expect(tr.children[0].nodeName).toBe('TH');
500 expect(tr.children[0].firstChild.nodeValue).toEqual('cnx');
501 expect(tr.children[1].firstChild.nodeValue).toEqual('p');
502 expect(tr.children[2].firstChild.nodeValue).toEqual('ADV');
503 expect(tr.children[3].firstChild.nodeValue).toEqual('A');
504 expect(tr.children[4].firstChild.nodeValue).toEqual('A');
505 });
506});
507
508describe('KorAP.MatchTree', function () {
Nils Diewald58141332015-04-07 16:18:45 +0000509 var tree;
510
511 it('should be rendered async 1', function (done) {
Nils Diewalda297f062015-04-02 00:23:46 +0000512 var info = KorAP.Match.create(match).info();
Nils Diewald58141332015-04-07 16:18:45 +0000513 expect(info).toBeTruthy();
514 info.getTree(undefined, undefined, function (y) {
515 tree = y;
516 done();
517 });
518 });
Nils Diewalda297f062015-04-02 00:23:46 +0000519
Nils Diewald58141332015-04-07 16:18:45 +0000520 it('should be rendered async 2', function () {
Nils Diewalda297f062015-04-02 00:23:46 +0000521 var e = tree.element();
522 expect(e.nodeName).toEqual('svg');
523 expect(e.getElementsByTagName('g').length).toEqual(48);
524 });
525});
526
527
528describe('KorAP.MatchTreeItem', function () {
529 it('should be initializable', function () {
530 var mi = KorAP.MatchTreeItem.create(['cnx/c', 'cnx', 'c'])
531 expect(mi.element().firstChild.nodeValue).toEqual('cnx/c');
532 expect(mi.lcField()).toEqual(' cnx/c');
533 expect(mi.foundry()).toEqual('cnx');
534 expect(mi.layer()).toEqual('c');
535 });
536});
537
538
539describe('KorAP.MatchTreeMenu', function () {
540 it('should be initializable', function () {
541 var menu = KorAP.MatchTreeMenu.create(undefined, [
542 ['cnx/c', 'cnx', 'c'],
543 ['xip/c', 'xip', 'c']
544 ]);
545
546 expect(menu.itemClass()).toEqual(KorAP.MatchTreeItem);
547 expect(menu.element().nodeName).toEqual('UL');
548 expect(menu.element().style.opacity).toEqual("0");
549 expect(menu.limit()).toEqual(6);
550 menu.show();
551 expect(menu.item(0).active()).toBe(true);
552 });
553});
554
555// table = view.toTable();
556// table.sortBy('');
557// table.element();
558// tree = view.toTree();
559// tree.element();
560