1
|
|
|
/** |
2
|
|
|
* (c) Kitodo. Key to digital objects e.V. <[email protected]> |
3
|
|
|
* |
4
|
|
|
* This file is part of the Kitodo and TYPO3 projects. |
5
|
|
|
* |
6
|
|
|
* @license GNU General Public License version 3 or later. |
7
|
|
|
* For the full copyright and license information, please read the |
8
|
|
|
* LICENSE.txt file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
describe('Test suite for the dlfAltoParser', function() { |
12
|
|
|
|
13
|
|
|
var document = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' + |
14
|
|
|
'<alto xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' + |
15
|
|
|
'xmlns="http://www.loc.gov/standards/alto/ns-v2#" xsi:schemaLocation="http://www.loc.gov/standards/alto/ns-v2# ' + |
16
|
|
|
'http://www.loc.gov/standards/alto/alto-v2.0.xsd"><Layout><Page ID="Page1" PHYSICAL_IMG_NR="1">' + |
17
|
|
|
'<PrintSpace HEIGHT="1629" WIDTH="1125" VPOS="0" HPOS="0"><TextBlock ID="BlockId-A77C2C7B-CB7F-432C-BA64-99657CEF96BE-" ' + |
18
|
|
|
'HEIGHT="24" WIDTH="18" VPOS="85" HPOS="104" STYLEREFS="StyleId-070C6916-2652-4C51-8B54-1185B1E5E973- font1">' + |
19
|
|
|
'<TextLine HEIGHT="15" WIDTH="10" VPOS="89" HPOS="108"><String CONTENT="2" HEIGHT="15" WIDTH="10" VPOS="89" ' + |
20
|
|
|
'HPOS="108"/></TextLine></TextBlock><ComposedBlock ID="BlockId-E8254DC2-E15F-4181-9CA4-6EA36940863B-" ' + |
21
|
|
|
'HEIGHT="203" WIDTH="694" VPOS="140" HPOS="103" TYPE="table"><TextBlock ' + |
22
|
|
|
'ID="BlockId-52809789-89AA-4D70-9BFF-23097229F168-" HEIGHT="29" WIDTH="51" ' + |
23
|
|
|
'VPOS="140" HPOS="103" STYLEREFS="StyleId-20CD36A1-2BCE-4E7D-AAB2-3AD839533AF2-font1">' + |
24
|
|
|
'<TextLine HEIGHT="15" WIDTH="40" VPOS="144" HPOS="107"><String STYLEREFS="font0" CONTENT="Seite" ' + |
25
|
|
|
'HEIGHT="15" WIDTH="40" VPOS="144" HPOS="107"/></TextLine></TextBlock><TextBlock ' + |
26
|
|
|
'ID="BlockId-97EA0C09-28B9-453B-AAE6-C7E5E53779F2-" HEIGHT="42" WIDTH="586" VPOS="169" HPOS="211" ' + |
27
|
|
|
'STYLEREFS="StyleId-20CD36A1-2BCE-4E7D-AAB2-3AD839533AF2- font1"><TextLine HEIGHT="29" WIDTH="559" ' + |
28
|
|
|
'VPOS="173" HPOS="233"><String CONTENT="Gespräch" HEIGHT="25" WIDTH="94" VPOS="173" HPOS="233"/><SP WIDTH="6" ' + |
29
|
|
|
'VPOS="173" HPOS="328"/></TextLine></TextBlock></ComposedBlock><TextBlock ' + |
30
|
|
|
'ID="BlockId-C9FE670C-DC48-44F9-B7EF-7980ADA80614-" HEIGHT="545" WIDTH="918" VPOS="880" HPOS="119" ' + |
31
|
|
|
'STYLEREFS="StyleId-20CD36A1-2BCE-4E7D-AAB2-3AD839533AF2- font1"><TextLine HEIGHT="32" WIDTH="214" ' + |
32
|
|
|
'VPOS="883" HPOS="127" STYLEREFS="StyleId-20D43B5F-E91D-4F10-B0E1-B68D39E7C301- font2"><String ' + |
33
|
|
|
'CONTENT="In" HEIGHT="23" WIDTH="27" VPOS="883" HPOS="127"/><SP WIDTH="9" VPOS="892" HPOS="155"/><String ' + |
34
|
|
|
'CONTENT="eigener" HEIGHT="31" WIDTH="93" VPOS="884" HPOS="165"/><SP WIDTH="8" VPOS="884" HPOS="259"/><String ' + |
35
|
|
|
'CONTENT="Sache" HEIGHT="24" WIDTH="73" VPOS="883" HPOS="268"/></TextLine><TextLine HEIGHT="25" WIDTH="878" ' + |
36
|
|
|
'VPOS="935" HPOS="126"><String CONTENT="Seit" HEIGHT="19" WIDTH="37" VPOS="935" HPOS="126"/>' + |
37
|
|
|
'<SP WIDTH="6" VPOS="942" HPOS="164"/><String CONTENT="vier" HEIGHT="19" WIDTH="38" VPOS="936" HPOS="171"/>' + |
38
|
|
|
'<SP WIDTH="3" VPOS="936" HPOS="210"/></TextLine><TextLine HEIGHT="27" WIDTH="904" VPOS="967" HPOS="126">' + |
39
|
|
|
'<String CONTENT="die" HEIGHT="19" WIDTH="30" VPOS="967" HPOS="126"/><SP WIDTH="6" VPOS="968" HPOS="157"/>' + |
40
|
|
|
'<String CONTENT="Unterstützung" HEIGHT="26" WIDTH="148" VPOS="968" HPOS="164"/><SP WIDTH="5" VPOS="976" ' + |
41
|
|
|
'HPOS="313"/></TextLine></TextBlock><ComposedBlock ID="BlockId-557B27A6-D4C2-4A5A-9F2D-BA0B8E97B692-" ' + |
42
|
|
|
'HEIGHT="599" WIDTH="964" VPOS="856" HPOS="97" TYPE="separatorsBox"><GraphicalElement ' + |
43
|
|
|
'ID="BlockId-30DBD37F-D27E-4AFB-9A01-507405CEC5A0-" HEIGHT="9" WIDTH="959" VPOS="856" HPOS="102"/>' + |
44
|
|
|
'<GraphicalElement ID="BlockId-B07F29BB-604A-4675-B005-7E445C8E9155-" HEIGHT="7" WIDTH="746" VPOS="1446" ' + |
45
|
|
|
'HPOS="97"/></ComposedBlock><GraphicalElement ID="BlockId-D2E23C8E-2A3C-4E42-AE0A-F8361AD0784E-" HEIGHT="6" ' + |
46
|
|
|
'WIDTH="704" VPOS="119" HPOS="107"/><GraphicalElement ID="BlockId-38FD417B-72B6-4AA7-AF8D-3E19ABD7D81B-" ' + |
47
|
|
|
'HEIGHT="3" WIDTH="256" VPOS="124" HPOS="811"/></PrintSpace></Page></Layout></alto>'; |
48
|
|
|
|
49
|
|
|
var textblock = '<TextBlock ID="BlockId-52809789-89AA-4D70-9BFF-23097229F168-" HEIGHT="29" WIDTH="51" VPOS="140" ' + |
50
|
|
|
'HPOS="103" STYLEREFS="StyleId-20CD36A1-2BCE-4E7D-AAB2-3AD839533AF2- font1">' + |
51
|
|
|
'<TextLine HEIGHT="15" WIDTH="40" VPOS="144" HPOS="107">' + |
52
|
|
|
'<String STYLEREFS="font0" CONTENT="Seite" HEIGHT="15" WIDTH="40" VPOS="144" HPOS="107"/>' + |
53
|
|
|
'<SP WIDTH="9" VPOS="892" HPOS="155"/><String CONTENT="eigener" HEIGHT="31" WIDTH="93" VPOS="884" HPOS="165"/>' + |
54
|
|
|
'<HYP WIDTH="8" VPOS="884" HPOS="259"/><String CONTENT="Sache" HEIGHT="24" WIDTH="73" VPOS="883" HPOS="268"/>' + |
55
|
|
|
'</TextLine></TextBlock>'; |
56
|
|
|
|
57
|
|
|
describe('Test function - parseXML_', function() { |
58
|
|
|
|
59
|
|
|
it('Input xml is of type string', function() { |
60
|
|
|
var parser = new dlfAltoParser(), |
|
|
|
|
61
|
|
|
testDoc = parser.parseXML_(document); |
62
|
|
|
expect(parser.parseXML_(testDoc) instanceof XMLDocument).toBe(true); |
|
|
|
|
63
|
|
|
}); |
64
|
|
|
|
65
|
|
|
it('Input xml is of type XMLDocument', function() { |
66
|
|
|
var parser = new dlfAltoParser(), |
|
|
|
|
67
|
|
|
testDoc = $.parseXML(document); |
68
|
|
|
expect(parser.parseXML_(testDoc) instanceof XMLDocument).toBe(true); |
|
|
|
|
69
|
|
|
}); |
70
|
|
|
|
71
|
|
|
}); |
72
|
|
|
|
73
|
|
|
describe('Test function - parseGeometry_', function() { |
74
|
|
|
|
75
|
|
|
it('Proper working for correct element', function() { |
76
|
|
|
var parser = new dlfAltoParser(), |
|
|
|
|
77
|
|
|
testDoc = parser.parseXML_('<TextLine HEIGHT="15" WIDTH="40" VPOS="144" HPOS="107"></TextLine>'), |
78
|
|
|
element = $(testDoc).find('TextLine'), |
79
|
|
|
geometry = parser.parseGeometry_(element[0]); |
80
|
|
|
expect(typeof geometry).toBe('object'); |
81
|
|
|
expect(geometry instanceof ol.geom.Polygon).toBe(true); |
|
|
|
|
82
|
|
|
}); |
83
|
|
|
|
84
|
|
|
}); |
85
|
|
|
|
86
|
|
|
describe('Test function - parseFeatureWithGeometry_', function() { |
87
|
|
|
|
88
|
|
|
it('Proper working for correct element <TextLine>', function() { |
89
|
|
|
var parser = new dlfAltoParser(), |
|
|
|
|
90
|
|
|
testDoc = parser.parseXML_('<TextLine HEIGHT="15" WIDTH="40" VPOS="144" HPOS="107"></TextLine>'), |
91
|
|
|
element = $(testDoc).find('TextLine'), |
92
|
|
|
feature = parser.parseFeatureWithGeometry_(element[0]); |
93
|
|
|
expect(typeof feature).toBe('object'); |
94
|
|
|
expect(feature instanceof ol.Feature).toBe(true); |
|
|
|
|
95
|
|
|
expect(feature.get('height')).toBe(15); |
96
|
|
|
expect(feature.get('width')).toBe(40); |
97
|
|
|
expect(feature.get('vpos')).toBe(144); |
98
|
|
|
expect(feature.get('hpos')).toBe(107); |
99
|
|
|
expect(feature.get('type')).toBe('textline'); |
100
|
|
|
}); |
101
|
|
|
|
102
|
|
|
it('Proper working for correct element <TextBlock>', function() { |
103
|
|
|
var parser = new dlfAltoParser(), |
|
|
|
|
104
|
|
|
testDoc = parser.parseXML_('<TextBlock HEIGHT="15" WIDTH="40" VPOS="144" HPOS="107"></TextBlock>'), |
105
|
|
|
element = $(testDoc).find('TextBlock'), |
106
|
|
|
feature = parser.parseFeatureWithGeometry_(element[0]); |
107
|
|
|
expect(typeof feature).toBe('object'); |
108
|
|
|
expect(feature instanceof ol.Feature).toBe(true); |
|
|
|
|
109
|
|
|
expect(feature.get('height')).toBe(15); |
110
|
|
|
expect(feature.get('width')).toBe(40); |
111
|
|
|
expect(feature.get('vpos')).toBe(144); |
112
|
|
|
expect(feature.get('hpos')).toBe(107); |
113
|
|
|
expect(feature.get('type')).toBe('textblock'); |
114
|
|
|
}); |
115
|
|
|
|
116
|
|
|
}); |
117
|
|
|
|
118
|
|
|
describe('Test function - parseAltoFeature_', function() { |
119
|
|
|
|
120
|
|
|
it('Proper working for correct element <TextLine>', function() { |
121
|
|
|
var parser = new dlfAltoParser(), |
|
|
|
|
122
|
|
|
testDoc = parser.parseXML_('<TextLine HEIGHT="15" WIDTH="40" VPOS="144" HPOS="107"></TextLine>'), |
123
|
|
|
element = $(testDoc).find('TextLine'), |
124
|
|
|
feature = parser.parseAltoFeature_(element[0]); |
125
|
|
|
expect(typeof feature).toBe('object'); |
126
|
|
|
expect(feature instanceof ol.Feature).toBe(true); |
|
|
|
|
127
|
|
|
expect(feature.get('height')).toBe(15); |
128
|
|
|
expect(feature.get('width')).toBe(40); |
129
|
|
|
expect(feature.get('vpos')).toBe(144); |
130
|
|
|
expect(feature.get('hpos')).toBe(107); |
131
|
|
|
expect(feature.get('type')).toBe('textline'); |
132
|
|
|
}); |
133
|
|
|
|
134
|
|
|
it('Proper working for correct element <Page>', function() { |
135
|
|
|
var parser = new dlfAltoParser(), |
|
|
|
|
136
|
|
|
testDoc = parser.parseXML_('<Page></Page>'), |
137
|
|
|
element = $(testDoc).find('Page'), |
138
|
|
|
feature = parser.parseAltoFeature_(element[0]); |
139
|
|
|
expect(typeof feature).toBe('object'); |
140
|
|
|
expect(feature instanceof ol.Feature).toBe(true); |
|
|
|
|
141
|
|
|
expect(feature.get('type')).toBe('page'); |
142
|
|
|
}); |
143
|
|
|
|
144
|
|
|
}); |
145
|
|
|
|
146
|
|
|
describe('Test function - parseTextBlockFeatures_', function() { |
147
|
|
|
|
148
|
|
|
it('Proper working for correct element <TextBlock>', function() { |
149
|
|
|
var parser = new dlfAltoParser(), |
|
|
|
|
150
|
|
|
testDoc = parser.parseXML_(textblock), |
151
|
|
|
features = parser.parseTextBlockFeatures_(testDoc); |
152
|
|
|
|
153
|
|
|
expect(features.length).toBe(1); |
154
|
|
|
|
155
|
|
|
var feature = features[0]; |
156
|
|
|
expect(feature instanceof ol.Feature).toBe(true); |
|
|
|
|
157
|
|
|
expect(feature.get('type')).toBe('textblock'); |
158
|
|
|
|
159
|
|
|
// get TextBlock / ComposedBlock elements |
160
|
|
|
var textline = feature.get('textlines'); |
161
|
|
|
expect(textline.length).toBe(1); |
162
|
|
|
}); |
163
|
|
|
|
164
|
|
|
}); |
165
|
|
|
|
166
|
|
|
describe('Test function - parseTextLineFeatures_', function() { |
167
|
|
|
|
168
|
|
|
it('Proper working for correct element <TextLine>', function() { |
169
|
|
|
var parser = new dlfAltoParser(), |
|
|
|
|
170
|
|
|
testDoc = parser.parseXML_(textblock), |
171
|
|
|
features = parser.parseTextLineFeatures_(testDoc); |
172
|
|
|
|
173
|
|
|
expect(features.length).toBe(1); |
174
|
|
|
|
175
|
|
|
var feature = features[0]; |
176
|
|
|
expect(feature instanceof ol.Feature).toBe(true); |
|
|
|
|
177
|
|
|
expect(feature.get('type')).toBe('textline'); |
178
|
|
|
}); |
179
|
|
|
|
180
|
|
|
}); |
181
|
|
|
|
182
|
|
|
describe('Test function - parsePrintSpaceFeature_', function() { |
183
|
|
|
|
184
|
|
|
it('Proper working for correct element <PrintSpace>', function() { |
185
|
|
|
var parser = new dlfAltoParser(), |
|
|
|
|
186
|
|
|
testDoc = parser.parseXML_(document), |
187
|
|
|
feature = parser.parsePrintSpaceFeature_(testDoc); |
188
|
|
|
|
189
|
|
|
expect(feature instanceof ol.Feature).toBe(true); |
|
|
|
|
190
|
|
|
expect(feature.get('type')).toBe('printspace'); |
191
|
|
|
|
192
|
|
|
// get TextBlock / ComposedBlock elements |
193
|
|
|
var blocks = feature.get('textblocks'); |
194
|
|
|
expect(blocks.length).toBe(4); |
195
|
|
|
}); |
196
|
|
|
|
197
|
|
|
it('Proper working for correct element <PrintSpace> with empty node', function() { |
198
|
|
|
var parser = new dlfAltoParser(), |
|
|
|
|
199
|
|
|
testDoc = parser.parseXML_('<test></test>'), |
200
|
|
|
feature = parser.parsePrintSpaceFeature_(testDoc); |
201
|
|
|
|
202
|
|
|
expect(feature).toBe(undefined); |
203
|
|
|
}); |
204
|
|
|
|
205
|
|
|
}); |
206
|
|
|
|
207
|
|
|
describe('Test function - parseFeatures', function() { |
208
|
|
|
|
209
|
|
|
it('Proper working of complete parsing', function() { |
210
|
|
|
var parser = new dlfAltoParser(), |
|
|
|
|
211
|
|
|
features = parser.parseFeatures(document); |
212
|
|
|
|
213
|
|
|
expect(features.length).toBe(1); |
214
|
|
|
|
215
|
|
|
// check if root type is page |
216
|
|
|
var feature = features[0]; |
217
|
|
|
expect(feature instanceof ol.Feature).toBe(true); |
|
|
|
|
218
|
|
|
expect(feature.get('type')).toBe('page'); |
219
|
|
|
|
220
|
|
|
// get PrintSpace |
221
|
|
|
var printspace = feature.get('printspace'); |
222
|
|
|
expect(printspace instanceof ol.Feature).toBe(true); |
223
|
|
|
expect(printspace.get('height')).toBe(1629); |
224
|
|
|
expect(printspace.get('width')).toBe(1125); |
225
|
|
|
expect(printspace.get('vpos')).toBe(0); |
226
|
|
|
expect(printspace.get('hpos')).toBe(0); |
227
|
|
|
expect(printspace.get('type')).toBe('printspace'); |
228
|
|
|
|
229
|
|
|
// get TextBlock / ComposedBlock elements |
230
|
|
|
var blocks = printspace.get('textblocks'); |
231
|
|
|
expect(blocks.length).toBe(4); |
232
|
|
|
}); |
233
|
|
|
|
234
|
|
|
it('Proper working of getStringFeatures', function() { |
235
|
|
|
var parser = new dlfAltoParser(), |
|
|
|
|
236
|
|
|
features = parser.parseFeatures(document), |
237
|
|
|
stringFeatures = features[0].getStringFeatures() |
238
|
|
|
|
239
|
|
|
// Test custom attached function to ol.Feature |
240
|
|
|
expect(stringFeatures.length).toBe(10); |
241
|
|
|
}); |
242
|
|
|
}); |
243
|
|
|
}); |
244
|
|
|
|