blob: c25a0c90995edbedf92ed4ee36ec197462fe023b [file] [log] [blame]
Nils Diewald8bc7e412015-03-19 22:08:27 +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 'pos' : 'p121-122'
23};
24
25var snippet = "<span title=\"cnx/l:meist\">" +
26 " <span title=\"cnx/p:ADV\">" +
27 " <span title=\"cnx/syn:@PREMOD\">" +
28 " <span title=\"mate/l:meist\">" +
29 " <span title=\"mate/p:ADV\">" +
30 " <span title=\"opennlp/p:ADV\">meist</span>" +
31 " </span>" +
32 " </span>" +
33 " </span>" +
34 " </span>" +
35 "</span>" +
36 "<span title=\"cnx/l:deutlich\">" +
37 " <span title=\"cnx/p:A\">" +
38 " <span title=\"cnx/syn:@PREMOD\">" +
39 " <span title=\"mate/l:deutlich\">" +
40 " <span title=\"mate/m:degree:pos\">" +
41 " <span title=\"mate/p:ADJD\">" +
42 " <span title=\"opennlp/p:ADJD\">deutlich</span>" +
43 " </span>" +
44 " </span>" +
45 " </span>" +
46 " </span>" +
47 " </span>" +
48 "</span>" +
49 "<span title=\"cnx/l:fähig\">" +
50 " <span title=\"cnx/l:leistung\">" +
51 " <span title=\"cnx/p:A\">" +
52 " <span title=\"cnx/syn:@NH\">" +
53 " <span title=\"mate/l:leistungsfähig\">" +
54 " <span title=\"mate/m:degree:comp\">" +
55 " <span title=\"mate/p:ADJD\">" +
56 " <span title=\"opennlp/p:ADJD\">leistungsfähiger</span>" +
57 " </span>" +
58 " </span>" +
59 " </span>" +
60 " </span>" +
61 " </span>" +
62 " </span>" +
63 "</span>";
64
Nils Diewald4f6521a2015-03-20 21:30:13 +000065var treeSnippet =
66 "<span class=\"context-left\"></span>" +
67 "<span class=\"match\">" +
68 " <span title=\"xip/c:MC\">" +
69 " <span title=\"xip/c:TOP\">" +
70 " <span title=\"xip/c:PP\">" +
71 " <span title=\"xip/c:PREP\">Mit</span>" +
72 " <span title=\"xip/c:NP\">" +
73 " <span title=\"xip/c:DET\">dieser</span>" +
74 " <span title=\"xip/c:NPA\">" +
75 " <span title=\"xip/c:NOUN\">Methode</span>" +
76 " </span>" +
77 " </span>" +
78 " </span>" +
79 " <span title=\"xip/c:VERB\">ist</span>" +
80 " <span title=\"xip/c:NP\">" +
81 " <span title=\"xip/c:PRON\">es</span>" +
82 " </span>" +
83 " <span title=\"xip/c:AP\">" +
84 " <span title=\"xip/c:ADV\">nun</span>" +
85 " <span title=\"xip/c:ADJ\">möglich</span>" +
86 " </span>" +
87 " <span title=\"xip/c:ADV\">z. B.</span>" +
88 " <span title=\"xip/c:NPA\">" +
89 " <span title=\"xip/c:NP\">" +
90 " <span title=\"xip/c:NOUN\">Voice</span>" +
91 " </span>" +
92 " </span>" + "(" +
93 " <span title=\"xip/c:INS\">" +
94 " <span title=\"xip/c:NPA\">" +
95 " <span title=\"xip/c:NP\">" +
96 " <span title=\"xip/c:NOUN\">Sprache</span>" +
97 " </span>" +
98 " </span>" +
99 " </span>" + ")" +
100 " <span title=\"xip/c:VERB\">bevorzugt</span>" +
101 " <span title=\"xip/c:PP\">" +
102 " <span title=\"xip/c:PREP\">in</span>" +
103 " <span title=\"xip/c:NP\">" +
104 " <span title=\"xip/c:PRON\">der</span>" +
105 " </span>" +
106 " <span title=\"xip/c:NPA\">" +
107 " <span title=\"xip/c:NP\">" +
108 " <span title=\"xip/c:NOUN\">Bridge</span>" +
109 " </span>" +
110 " </span>" +
111 " </span>" +
112 " <span title=\"xip/c:INFC\">" +
113 " <span title=\"xip/c:INS\">" +
114 " <span title=\"xip/c:VERB\">weiterzugeben</span>" +
115 " </span>" +
116 " </span>" +
117 " </span>" +
118 " </span>" +
119 "</span>" +
120 "<span class=\"context-right\"></span>";
121
Nils Diewalde8518f82015-03-18 22:41:49 +0000122describe('KorAP.InfoLayer', function () {
123 it('should be initializable', function () {
124 expect(
125 function() { KorAP.InfoLayer.create() }
126 ).toThrow(new Error("Missing parameters"));
127
128 expect(
129 function() { KorAP.InfoLayer.create("base") }
130 ).toThrow(new Error("Missing parameters"));
131
132 var layer = KorAP.InfoLayer.create("base", "s");
133 expect(layer).toBeTruthy();
134 expect(layer.foundry).toEqual("base");
135 expect(layer.layer).toEqual("s");
136 expect(layer.type).toEqual("tokens");
137
138 layer = KorAP.InfoLayer.create("cnx", "syn", "spans");
139 expect(layer).toBeTruthy();
140 expect(layer.foundry).toEqual("cnx");
141 expect(layer.layer).toEqual("syn");
142 expect(layer.type).toEqual("spans");
143 });
144});
145
146describe('KorAP.Match', function () {
147 var match = {
148 'corpusID' : 'WPD',
149 'docID' : 'UUU',
150 'textID' : '01912',
151 'pos' : 'p121-122'
152 };
153
154 it('should be initializable', function () {
155 var mInfo = KorAP.Match.create(match);
156 expect(mInfo.corpusID).toEqual("WPD");
157 });
158});
159
160describe('KorAP.MatchInfo', function () {
Nils Diewalde8518f82015-03-18 22:41:49 +0000161 it('should be initializable', function () {
162 expect(function() {
163 KorAP.MatchInfo.create()
164 }).toThrow(new Error('Missing parameters'));
165
166 expect(function() {
167 KorAP.MatchInfo.create(available)
168 }).toThrow(new Error('Missing parameters'));
169
170 expect(KorAP.MatchInfo.create(match, available)).toBeTruthy();
171
172 // /corpus/WPD/UUU.01912/p121-122/matchInfo?spans=false&foundry=*
173 var info = KorAP.MatchInfo.create(match, available);
174
175 // Spans:
176 var spans = info.getSpans();
177 expect(spans[0].foundry).toEqual("base");
178 expect(spans[0].layer).toEqual("s");
179
180 expect(spans[1].foundry).toEqual("corenlp");
181 expect(spans[1].layer).toEqual("c");
182
183 expect(spans[2].foundry).toEqual("corenlp");
184 expect(spans[2].layer).toEqual("s");
185
186 expect(spans[spans.length-1].foundry).toEqual("tt");
187 expect(spans[spans.length-1].layer).toEqual("s");
188
189 // Tokens:
190 var tokens = info.getTokens();
191 expect(tokens[0].foundry).toEqual("corenlp");
192 expect(tokens[0].layer).toEqual("ne");
193
194 expect(tokens[1].foundry).toEqual("corenlp");
195 expect(tokens[1].layer).toEqual("p");
196
197 expect(tokens[tokens.length-1].foundry).toEqual("tt");
198 expect(tokens[tokens.length-1].layer).toEqual("p");
199 });
200
201
202 it('should parse into a table', function () {
203 var info = KorAP.MatchInfo.create(match, available);
204
205 expect(info.getTable('base/s')).not.toBeTruthy();
206
207 // Override getMatchInfo API call
Nils Diewald4f6521a2015-03-20 21:30:13 +0000208 KorAP.API.getMatchInfo = function () {
Nils Diewalde8518f82015-03-18 22:41:49 +0000209 return { "snippet": snippet };
210 };
211
212 var table = info.getTable();
213 expect(table).toBeTruthy();
214
215 expect(table.length()).toBe(3);
216
217 expect(table.getToken(0)).toBe("meist");
218 expect(table.getToken(1)).toBe("deutlich");
219 expect(table.getToken(2)).toBe("leistungsfähiger");
220
221 expect(table.getValue(0, "cnx", "p")[0]).toBe("ADV");
222 expect(table.getValue(0, "cnx", "syn")[0]).toBe("@PREMOD");
223
224 expect(table.getValue(2, "cnx", "l")[0]).toBe("fähig");
225 expect(table.getValue(2, "cnx", "l")[1]).toBe("leistung");
226 });
Nils Diewald4f6521a2015-03-20 21:30:13 +0000227
228
229 it('should parse into a tree', function () {
230 var info = KorAP.MatchInfo.create(match, available);
231
232 // Override getMatchInfo API call
233 KorAP.API.getMatchInfo = function () {
234 return { "snippet": treeSnippet };
235 };
236
237 var tree = info.getTree();
238 expect(tree).toBeTruthy();
239 expect(tree.nodes()).toEqual(49);
240
241 console.log(tree.element());
242
243 });
Nils Diewald8bc7e412015-03-19 22:08:27 +0000244});
Nils Diewalde8518f82015-03-18 22:41:49 +0000245
Nils Diewald8bc7e412015-03-19 22:08:27 +0000246describe('KorAP.MatchTable', function () {
247 it('should be rendered', function () {
248 var info = KorAP.MatchInfo.create(match, available);
249
250 // Override getMatchInfo API call
251 KorAP.API.getMatchInfo = function() {
252 return { "snippet": snippet };
253 };
254
255 var table = info.getTable();
Nils Diewald8bc7e412015-03-19 22:08:27 +0000256 var e = table.element();
257
258 expect(e.nodeName).toBe('TABLE');
259 expect(e.children[0].nodeName).toBe('THEAD');
260 var tr = e.children[0].children[0];
261 expect(tr.nodeName).toBe('TR');
262 expect(tr.children[0].nodeName).toBe('TH');
263
264 expect(tr.children[0].firstChild.nodeValue).toBe('Foundry');
265 expect(tr.children[1].firstChild.nodeValue).toBe('Layer');
266 expect(tr.children[2].firstChild.nodeValue).toBe('meist');
267 expect(tr.children[3].firstChild.nodeValue).toBe('deutlich');
268 expect(tr.children[4].firstChild.nodeValue).toBe('leistungsfähiger');
Nils Diewald4f6521a2015-03-20 21:30:13 +0000269
270 // first row
271 tr = e.children[1].children[0];
272 expect(tr.nodeName).toBe('TR');
273 expect(tr.getAttribute('tabindex')).toEqual('0');
274 expect(tr.children[0].nodeName).toBe('TH');
275 expect(tr.children[0].firstChild.nodeValue).toEqual('cnx');
276 expect(tr.children[1].firstChild.nodeValue).toEqual('l');
277 expect(tr.children[2].firstChild.nodeValue).toEqual('meist');
278 expect(tr.children[3].firstChild.nodeValue).toEqual('deutlich');
279 expect(tr.children[4].firstChild.nodeValue).toEqual('fähig');
280 expect(tr.children[4].lastChild.nodeValue).toEqual('leistung');
281
282 // second row
283 tr = e.children[1].children[1];
284 expect(tr.nodeName).toBe('TR');
285 expect(tr.getAttribute('tabindex')).toEqual('0');
286 expect(tr.children[0].nodeName).toBe('TH');
287 expect(tr.children[0].firstChild.nodeValue).toEqual('cnx');
288 expect(tr.children[1].firstChild.nodeValue).toEqual('p');
289 expect(tr.children[2].firstChild.nodeValue).toEqual('ADV');
290 expect(tr.children[3].firstChild.nodeValue).toEqual('A');
291 expect(tr.children[4].firstChild.nodeValue).toEqual('A');
292 });
293});
294
295xdescribe('KorAP.MatchTree', function () {
296 it('should be rendered', function () {
297 var info = KorAP.MatchInfo.create(match, available);
298
299 // Override getMatchInfo API call
300 KorAP.API.getMatchInfo = function() {
301 return { "snippet": treeSnippet };
302 };
303
304 var tree = info.getTree();
305 tree.element();
Nils Diewald8bc7e412015-03-19 22:08:27 +0000306 });
Nils Diewalde8518f82015-03-18 22:41:49 +0000307});
308
309// table = view.toTable();
310// table.sortBy('');
311// table.element();
312// tree = view.toTree();
313// tree.element();
Nils Diewald4f6521a2015-03-20 21:30:13 +0000314