blob: dc54dc6e0441ff48719bbf29b97995637e7ac144 [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
143describe('KorAP.InfoLayer', function () {
144
145 it('should be initializable', function () {
146 expect(
147 function() { KorAP.InfoLayer.create() }
148 ).toThrow(new Error("Missing parameters"));
149
150 expect(
151 function() { KorAP.InfoLayer.create("base") }
152 ).toThrow(new Error("Missing parameters"));
153
154 var layer = KorAP.InfoLayer.create("base", "s");
155 expect(layer).toBeTruthy();
156 expect(layer.foundry).toEqual("base");
157 expect(layer.layer).toEqual("s");
158 expect(layer.type).toEqual("tokens");
159
160 layer = KorAP.InfoLayer.create("cnx", "syn", "spans");
161 expect(layer).toBeTruthy();
162 expect(layer.foundry).toEqual("cnx");
163 expect(layer.layer).toEqual("syn");
164 expect(layer.type).toEqual("spans");
165 });
166});
167
168
169describe('KorAP.Match', function () {
170 var match = {
171 'corpusID' : 'WPD',
172 'docID' : 'UUU',
173 'textID' : '01912',
174 'matchID' : 'p121-122',
175 'available' : available
176 };
177
178 it('should be initializable by Object', function () {
179 expect(function() {
180 KorAP.Match.create()
181 }).toThrow(new Error('Missing parameters'));
182
183 expect(KorAP.Match.create(match)).toBeTruthy();
184
185 var m = KorAP.Match.create(match);
186 expect(m.corpusID).toEqual("WPD");
187 expect(m.docID).toEqual("UUU");
188 expect(m.textID).toEqual("01912");
189 expect(m.matchID).toEqual("p121-122");
190
191 // /corpus/WPD/UUU.01912/p121-122/matchInfo?spans=false&foundry=*
192 var m = KorAP.Match.create(match);
193
194 // Spans:
195 var spans = m.getSpans();
196 expect(spans[0].foundry).toEqual("base");
197 expect(spans[0].layer).toEqual("s");
198
199 expect(spans[1].foundry).toEqual("corenlp");
200 expect(spans[1].layer).toEqual("c");
201
202 expect(spans[2].foundry).toEqual("corenlp");
203 expect(spans[2].layer).toEqual("s");
204
205 expect(spans[spans.length-1].foundry).toEqual("tt");
206 expect(spans[spans.length-1].layer).toEqual("s");
207
208 // Tokens:
209 var tokens = m.getTokens();
210 expect(tokens[0].foundry).toEqual("corenlp");
211 expect(tokens[0].layer).toEqual("ne");
212
213 expect(tokens[1].foundry).toEqual("corenlp");
214 expect(tokens[1].layer).toEqual("p");
215
216 expect(tokens[tokens.length-1].foundry).toEqual("tt");
217 expect(tokens[tokens.length-1].layer).toEqual("p");
218 });
219
220
221 it('should be initializable by Node', function () {
222 var m = KorAP.Match.create(matchElementFactory());
223 expect(m.corpusID).toEqual("WPD");
224 expect(m.docID).toEqual("FFF");
225 expect(m.textID).toEqual("01460");
226 expect(m.matchID).toEqual("p119-120");
227
228 // Spans:
229 var spans = m.getSpans();
230 expect(spans[0].foundry).toEqual("base");
231 expect(spans[0].layer).toEqual("s");
232
233 expect(spans[1].foundry).toEqual("corenlp");
234 expect(spans[1].layer).toEqual("c");
235
236 expect(spans[2].foundry).toEqual("corenlp");
237 expect(spans[2].layer).toEqual("s");
238
239 expect(spans[spans.length-1].foundry).toEqual("tt");
240 expect(spans[spans.length-1].layer).toEqual("s");
241
242 // Tokens:
243 var tokens = m.getTokens();
244 expect(tokens[0].foundry).toEqual("corenlp");
245 expect(tokens[0].layer).toEqual("ne");
246
247 expect(tokens[1].foundry).toEqual("corenlp");
248 expect(tokens[1].layer).toEqual("p");
249
250 expect(tokens[tokens.length-1].foundry).toEqual("tt");
251 expect(tokens[tokens.length-1].layer).toEqual("p");
252
253 });
254
255 it('should react to gui actions', function () {
256 var e = matchElementFactory();
257
258 expect(e.classList.contains('active')).toBe(false);
259 expect(e["_match"]).toBe(undefined);
260
261 var m = KorAP.Match.create(e);
262
263 expect(e.classList.contains('active')).toBe(false);
264 expect(e["_match"]).not.toBe(undefined);
265
266 // Open the match
267 m.open();
268
269 expect(e.classList.contains('active')).toBe(true);
270 expect(e["_match"]).not.toBe(undefined);
271
272 // Close the match
273 m.close();
274 expect(e.classList.contains('active')).toBe(false);
275 expect(e["_match"]).not.toBe(undefined);
276
277 });
278});
279
280
281describe('KorAP.MatchInfo', function () {
282 it('should parse into a table', function () {
283
284 var m = KorAP.Match.create(match);
285 var info = m.info();
286 expect(m._info).toEqual(info);
287
288 expect(info.getTable('base/s')).not.toBeTruthy();
289
290 // Override getMatchInfo API call
291 KorAP.API.getMatchInfo = function () {
292 return { "snippet": snippet };
293 };
294
295 var table = info.getTable();
296 expect(table).toBeTruthy();
297
298 expect(table.length()).toBe(3);
299
300 expect(table.getToken(0)).toBe("meist");
301 expect(table.getToken(1)).toBe("deutlich");
302 expect(table.getToken(2)).toBe("leistungsfähiger");
303
304 expect(table.getValue(0, "cnx", "p")[0]).toBe("ADV");
305 expect(table.getValue(0, "cnx", "syn")[0]).toBe("@PREMOD");
306
307 expect(table.getValue(2, "cnx", "l")[0]).toBe("fähig");
308 expect(table.getValue(2, "cnx", "l")[1]).toBe("leistung");
309 });
310
311
312 it('should parse into a table view', function () {
313 var matchElement = matchElementFactory();
314 expect(matchElement.tagName).toEqual('LI');
315
316 // Match
317 expect(matchElement.children[0].tagName).toEqual('DIV');
318
319 // snippet
320 expect(matchElement.children[0].children[0].tagName).toEqual('DIV');
321 expect(matchElement.children[0].children[0].classList.contains('snippet')).toBeTruthy();
322 expect(matchElement.children[0].children[0].firstChild.nodeValue).toEqual('check');
323
324 // reference
325 expect(matchElement.children[1].classList.contains('ref')).toBeTruthy();
326 expect(matchElement.children[1].firstChild.nodeValue).toEqual('me');
327
328 // not yet
329 expect(matchElement.children[0].children[1]).toBe(undefined);
330
331 var info = KorAP.Match.create(matchElement).info();
332
333 // Match
334 expect(matchElement.children[0].tagName).toEqual('DIV');
335
336 // snippet
337 expect(matchElement.children[0].children[0].tagName).toEqual('DIV');
338 expect(matchElement.children[0].children[0].classList.contains('snippet')).toBeTruthy();
339 expect(matchElement.children[0].children[0].firstChild.nodeValue).toEqual('check');
340
341 // reference
342 expect(matchElement.children[1].classList.contains('ref')).toBeTruthy();
343 expect(matchElement.children[1].firstChild.nodeValue).toEqual('me');
344
345 // now
346 var infotable = matchElement.children[0].children[1];
347 expect(infotable.tagName).toEqual('DIV');
348 expect(infotable.classList.contains('matchinfo')).toBeTruthy();
349
350 expect(infotable.children[0].classList.contains('matchtable')).toBeTruthy();
351 expect(infotable.children[1].classList.contains('addtree')).toBeTruthy();
352 });
353
354
355 it('should parse into a tree', function () {
356 var info = KorAP.Match.create(match).info();
357
358 // Override getMatchInfo API call
359 KorAP.API.getMatchInfo = function () {
360 return { "snippet": treeSnippet };
361 };
362
363 var tree = info.getTree();
364 expect(tree).toBeTruthy();
365 expect(tree.nodes()).toEqual(49);
366 });
367
368
369 it('should parse into a tree view', function () {
370 var matchElement = matchElementFactory();
371 expect(matchElement.tagName).toEqual('LI');
372
373 var info = KorAP.Match.create(matchElement).info();
374
375 // Match
376 expect(matchElement.children[0].tagName).toEqual('DIV');
377
378 // snippet
379 expect(matchElement.children[0].children[0].tagName).toEqual('DIV');
380 expect(matchElement.children[0].children[0].classList.contains('snippet')).toBeTruthy();
381 expect(matchElement.children[0].children[0].firstChild.nodeValue).toEqual('check');
382
383 // reference
384 expect(matchElement.children[1].classList.contains('ref')).toBeTruthy();
385 expect(matchElement.children[1].firstChild.nodeValue).toEqual('me');
386
387 // now
388 var infotable = matchElement.children[0].children[1];
389 expect(infotable.tagName).toEqual('DIV');
390 expect(infotable.classList.contains('matchinfo')).toBeTruthy();
391 expect(infotable.children[0].classList.contains('matchtable')).toBeTruthy();
392 expect(infotable.children[1].classList.contains('addtree')).toBeTruthy();
393
394 // Override getMatchInfo API call
395 KorAP.API.getMatchInfo = function () {
396 return { "snippet": treeSnippet };
397 };
398
399 info.addTree('mate', 'beebop');
400
401 // With added tree
402 var infotable = matchElement.children[0].children[1];
403 expect(infotable.tagName).toEqual('DIV');
404 expect(infotable.classList.contains('matchinfo')).toBeTruthy();
405 expect(infotable.children[0].classList.contains('matchtable')).toBeTruthy();
406 expect(infotable.children[1].classList.contains('addtree')).toBe(false);
407
408 var tree = infotable.children[1];
409 expect(tree.tagName).toEqual('DIV');
410 expect(tree.classList.contains('matchtree')).toBeTruthy();
411 expect(tree.children[0].tagName).toEqual('H6');
412 expect(tree.children[0].children[0].tagName).toEqual('SPAN');
413 expect(tree.children[0].children[0].firstChild.nodeValue).toEqual('mate');
414 expect(tree.children[0].children[1].tagName).toEqual('SPAN');
415 expect(tree.children[0].children[1].firstChild.nodeValue).toEqual('beebop');
416
417 expect(tree.children[1].tagName).toEqual('DIV');
418
419 });
420});
421
422
423describe('KorAP.MatchTable', function () {
424 it('should be rendered', function () {
425 var info = KorAP.Match.create(match).info();
426
427 // Override getMatchInfo API call
428 KorAP.API.getMatchInfo = function() {
429 return { "snippet": snippet };
430 };
431
432 var table = info.getTable();
433 var e = table.element();
434
435 expect(e.nodeName).toBe('TABLE');
436 expect(e.children[0].nodeName).toBe('THEAD');
437 var tr = e.children[0].children[0];
438 expect(tr.nodeName).toBe('TR');
439 expect(tr.children[0].nodeName).toBe('TH');
440
441 expect(tr.children[0].firstChild.nodeValue).toBe('Foundry');
442 expect(tr.children[1].firstChild.nodeValue).toBe('Layer');
443 expect(tr.children[2].firstChild.nodeValue).toBe('meist');
444 expect(tr.children[3].firstChild.nodeValue).toBe('deutlich');
445 expect(tr.children[4].firstChild.nodeValue).toBe('leistungsfähiger');
446
447 // first row
448 tr = e.children[1].children[0];
449 expect(tr.nodeName).toBe('TR');
450 expect(tr.getAttribute('tabindex')).toEqual('0');
451 expect(tr.children[0].nodeName).toBe('TH');
452 expect(tr.children[0].firstChild.nodeValue).toEqual('cnx');
453 expect(tr.children[1].firstChild.nodeValue).toEqual('l');
454 expect(tr.children[2].firstChild.nodeValue).toEqual('meist');
455 expect(tr.children[3].firstChild.nodeValue).toEqual('deutlich');
456 expect(tr.children[4].firstChild.nodeValue).toEqual('fähig');
457 expect(tr.children[4].lastChild.nodeValue).toEqual('leistung');
458
459 // second row
460 tr = e.children[1].children[1];
461 expect(tr.nodeName).toBe('TR');
462 expect(tr.getAttribute('tabindex')).toEqual('0');
463 expect(tr.children[0].nodeName).toBe('TH');
464 expect(tr.children[0].firstChild.nodeValue).toEqual('cnx');
465 expect(tr.children[1].firstChild.nodeValue).toEqual('p');
466 expect(tr.children[2].firstChild.nodeValue).toEqual('ADV');
467 expect(tr.children[3].firstChild.nodeValue).toEqual('A');
468 expect(tr.children[4].firstChild.nodeValue).toEqual('A');
469 });
470});
471
472describe('KorAP.MatchTree', function () {
473 it('should be rendered', function () {
474 var info = KorAP.Match.create(match).info();
475
476 // Override getMatchInfo API call
477 KorAP.API.getMatchInfo = function() {
478 return { "snippet": treeSnippet };
479 };
480
481 var tree = info.getTree();
482
483 var e = tree.element();
484 expect(e.nodeName).toEqual('svg');
485 expect(e.getElementsByTagName('g').length).toEqual(48);
486 });
487});
488
489
490describe('KorAP.MatchTreeItem', function () {
491 it('should be initializable', function () {
492 var mi = KorAP.MatchTreeItem.create(['cnx/c', 'cnx', 'c'])
493 expect(mi.element().firstChild.nodeValue).toEqual('cnx/c');
494 expect(mi.lcField()).toEqual(' cnx/c');
495 expect(mi.foundry()).toEqual('cnx');
496 expect(mi.layer()).toEqual('c');
497 });
498});
499
500
501describe('KorAP.MatchTreeMenu', function () {
502 it('should be initializable', function () {
503 var menu = KorAP.MatchTreeMenu.create(undefined, [
504 ['cnx/c', 'cnx', 'c'],
505 ['xip/c', 'xip', 'c']
506 ]);
507
508 expect(menu.itemClass()).toEqual(KorAP.MatchTreeItem);
509 expect(menu.element().nodeName).toEqual('UL');
510 expect(menu.element().style.opacity).toEqual("0");
511 expect(menu.limit()).toEqual(6);
512 menu.show();
513 expect(menu.item(0).active()).toBe(true);
514 });
515});
516
517// table = view.toTable();
518// table.sortBy('');
519// table.element();
520// tree = view.toTree();
521// tree.element();
522