blob: dc0d4a1a04c354fa0fd0cd833e4f912335b34f79 [file] [log] [blame]
Nils Diewalde8518f82015-03-18 22:41:49 +00001describe('KorAP.InfoLayer', function () {
2 it('should be initializable', function () {
3 expect(
4 function() { KorAP.InfoLayer.create() }
5 ).toThrow(new Error("Missing parameters"));
6
7 expect(
8 function() { KorAP.InfoLayer.create("base") }
9 ).toThrow(new Error("Missing parameters"));
10
11 var layer = KorAP.InfoLayer.create("base", "s");
12 expect(layer).toBeTruthy();
13 expect(layer.foundry).toEqual("base");
14 expect(layer.layer).toEqual("s");
15 expect(layer.type).toEqual("tokens");
16
17 layer = KorAP.InfoLayer.create("cnx", "syn", "spans");
18 expect(layer).toBeTruthy();
19 expect(layer.foundry).toEqual("cnx");
20 expect(layer.layer).toEqual("syn");
21 expect(layer.type).toEqual("spans");
22 });
23});
24
25describe('KorAP.Match', function () {
26 var match = {
27 'corpusID' : 'WPD',
28 'docID' : 'UUU',
29 'textID' : '01912',
30 'pos' : 'p121-122'
31 };
32
33 it('should be initializable', function () {
34 var mInfo = KorAP.Match.create(match);
35 expect(mInfo.corpusID).toEqual("WPD");
36 });
37});
38
39describe('KorAP.MatchInfo', function () {
40 var available = [
41 'base/s=spans',
42 'corenlp/c=spans',
43 'corenlp/ne=tokens',
44 'corenlp/p=tokens',
45 'corenlp/s=spans',
46 'glemm/l=tokens',
47 'mate/l=tokens',
48 'mate/m=tokens',
49 'mate/p=tokens',
50 'opennlp/p=tokens',
51 'opennlp/s=spans',
52 'tt/l=tokens',
53 'tt/p=tokens',
54 'tt/s=spans'
55 ];
56
57 var match = {
58 'corpusID' : 'WPD',
59 'docID' : 'UUU',
60 'textID' : '01912',
61 'pos' : 'p121-122'
62 };
63
64 var snippet = "<span title=\"cnx/l:meist\">" +
65 " <span title=\"cnx/p:ADV\">" +
66 " <span title=\"cnx/syn:@PREMOD\">" +
67 " <span title=\"mate/l:meist\">" +
68 " <span title=\"mate/p:ADV\">" +
69 " <span title=\"opennlp/p:ADV\">meist</span>" +
70 " </span>" +
71 " </span>" +
72 " </span>" +
73 " </span>" +
74 "</span>" +
75 "<span title=\"cnx/l:deutlich\">" +
76 " <span title=\"cnx/p:A\">" +
77 " <span title=\"cnx/syn:@PREMOD\">" +
78 " <span title=\"mate/l:deutlich\">" +
79 " <span title=\"mate/m:degree:pos\">" +
80 " <span title=\"mate/p:ADJD\">" +
81 " <span title=\"opennlp/p:ADJD\">deutlich</span>" +
82 " </span>" +
83 " </span>" +
84 " </span>" +
85 " </span>" +
86 " </span>" +
87 "</span>" +
88 "<span title=\"cnx/l:fähig\">" +
89 " <span title=\"cnx/l:leistung\">" +
90 " <span title=\"cnx/p:A\">" +
91 " <span title=\"cnx/syn:@NH\">" +
92 " <span title=\"mate/l:leistungsfähig\">" +
93 " <span title=\"mate/m:degree:comp\">" +
94 " <span title=\"mate/p:ADJD\">" +
95 " <span title=\"opennlp/p:ADJD\">leistungsfähiger</span>" +
96 " </span>" +
97 " </span>" +
98 " </span>" +
99 " </span>" +
100 " </span>" +
101 " </span>" +
102 "</span>";
103
104
105 it('should be initializable', function () {
106 expect(function() {
107 KorAP.MatchInfo.create()
108 }).toThrow(new Error('Missing parameters'));
109
110 expect(function() {
111 KorAP.MatchInfo.create(available)
112 }).toThrow(new Error('Missing parameters'));
113
114 expect(KorAP.MatchInfo.create(match, available)).toBeTruthy();
115
116 // /corpus/WPD/UUU.01912/p121-122/matchInfo?spans=false&foundry=*
117 var info = KorAP.MatchInfo.create(match, available);
118
119 // Spans:
120 var spans = info.getSpans();
121 expect(spans[0].foundry).toEqual("base");
122 expect(spans[0].layer).toEqual("s");
123
124 expect(spans[1].foundry).toEqual("corenlp");
125 expect(spans[1].layer).toEqual("c");
126
127 expect(spans[2].foundry).toEqual("corenlp");
128 expect(spans[2].layer).toEqual("s");
129
130 expect(spans[spans.length-1].foundry).toEqual("tt");
131 expect(spans[spans.length-1].layer).toEqual("s");
132
133 // Tokens:
134 var tokens = info.getTokens();
135 expect(tokens[0].foundry).toEqual("corenlp");
136 expect(tokens[0].layer).toEqual("ne");
137
138 expect(tokens[1].foundry).toEqual("corenlp");
139 expect(tokens[1].layer).toEqual("p");
140
141 expect(tokens[tokens.length-1].foundry).toEqual("tt");
142 expect(tokens[tokens.length-1].layer).toEqual("p");
143 });
144
145
146 it('should parse into a table', function () {
147 var info = KorAP.MatchInfo.create(match, available);
148
149 expect(info.getTable('base/s')).not.toBeTruthy();
150
151 // Override getMatchInfo API call
152 KorAP.API.getMatchInfo = function() {
153 return { "snippet": snippet };
154 };
155
156 var table = info.getTable();
157 expect(table).toBeTruthy();
158
159 expect(table.length()).toBe(3);
160
161 expect(table.getToken(0)).toBe("meist");
162 expect(table.getToken(1)).toBe("deutlich");
163 expect(table.getToken(2)).toBe("leistungsfähiger");
164
165 expect(table.getValue(0, "cnx", "p")[0]).toBe("ADV");
166 expect(table.getValue(0, "cnx", "syn")[0]).toBe("@PREMOD");
167
168 expect(table.getValue(2, "cnx", "l")[0]).toBe("fähig");
169 expect(table.getValue(2, "cnx", "l")[1]).toBe("leistung");
170 });
171
172});
173
174// table = view.toTable();
175// table.sortBy('');
176// table.element();
177// tree = view.toTree();
178// tree.element();