1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* (c) Kitodo. Key to digital objects e.V. <[email protected]> |
5
|
|
|
* |
6
|
|
|
* This file is part of the Kitodo and TYPO3 projects. |
7
|
|
|
* |
8
|
|
|
* @license GNU General Public License version 3 or later. |
9
|
|
|
* For the full copyright and license information, please read the |
10
|
|
|
* LICENSE.txt file that was distributed with this source code. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace Kitodo\Dlf\Tests\Unit\Format; |
14
|
|
|
|
15
|
|
|
use Kitodo\Dlf\Format\Alto; |
16
|
|
|
use TYPO3\TestingFramework\Core\Unit\UnitTestCase; |
17
|
|
|
|
18
|
|
|
class AltoTest extends UnitTestCase |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @test |
22
|
|
|
* @group extract data |
23
|
|
|
*/ |
24
|
|
|
public function getRawData(): void |
25
|
|
|
{ |
26
|
|
|
$xml = simplexml_load_file(__DIR__ . '/../../Fixtures/Format/alto.xml'); |
27
|
|
|
$alto = new Alto(); |
28
|
|
|
|
29
|
|
|
$rawText = $alto->getRawText($xml); |
30
|
|
|
|
31
|
|
|
self::assertEquals('Bürgertum und Bürgerlichkeit in Dresden DRESDNER HEFTE', $rawText); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @test |
36
|
|
|
* @group extract data |
37
|
|
|
*/ |
38
|
|
|
public function getTextAsMiniOcr(): void |
39
|
|
|
{ |
40
|
|
|
$xml = simplexml_load_file(__DIR__ . '/../../Fixtures/Format/alto.xml'); |
41
|
|
|
$alto = new Alto(); |
42
|
|
|
|
43
|
|
|
$rawText = $alto->getTextAsMiniOcr($xml); |
44
|
|
|
|
45
|
|
|
$miniOCR = <<<XML |
46
|
|
|
<ocr> |
47
|
|
|
<b> |
48
|
|
|
<l> |
49
|
|
|
<w x="477 2083 437 95">Bürgertum </w> |
50
|
|
|
<w x="950 2076 155 76">und </w> |
51
|
|
|
</l> |
52
|
|
|
<l> |
53
|
|
|
<w x="477 2201 574 102">Bürgerlichkeit </w> |
54
|
|
|
<w x="1084 2205 74 68">in </w> |
55
|
|
|
<w x="1194 2199 333 75">Dresden </w> |
56
|
|
|
</l> |
57
|
|
|
</b> |
58
|
|
|
<b> |
59
|
|
|
<l> |
60
|
|
|
<w x="473 315 752 98">DRESDNER </w> |
61
|
|
|
</l> |
62
|
|
|
<l> |
63
|
|
|
<w x="473 492 448 97">HEFTE </w> |
64
|
|
|
</l> |
65
|
|
|
</b> |
66
|
|
|
</ocr> |
67
|
|
|
XML; |
68
|
|
|
|
69
|
|
|
self::assertXmlStringEqualsXmlString($miniOCR, $rawText); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @test |
74
|
|
|
* @group extract data |
75
|
|
|
*/ |
76
|
|
|
public function getTextAsMiniOcrNoTextBlock(): void |
77
|
|
|
{ |
78
|
|
|
$xml = simplexml_load_file(__DIR__ . '/../../Fixtures/Format/altoNoTextBlock.xml'); |
79
|
|
|
$alto = new Alto(); |
80
|
|
|
|
81
|
|
|
$rawText = $alto->getTextAsMiniOcr($xml); |
82
|
|
|
|
83
|
|
|
self::assertEquals('', $rawText); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @test |
88
|
|
|
* @group extract data |
89
|
|
|
*/ |
90
|
|
|
public function getTextAsMiniOcrNoTextline(): void |
91
|
|
|
{ |
92
|
|
|
$xml = simplexml_load_file(__DIR__ . '/../../Fixtures/Format/altoNoTextLine.xml'); |
93
|
|
|
$alto = new Alto(); |
94
|
|
|
|
95
|
|
|
$rawText = $alto->getTextAsMiniOcr($xml); |
96
|
|
|
|
97
|
|
|
self::assertXmlStringEqualsXmlString('<?xml version="1.0"?><ocr><b/><b/></ocr>', $rawText); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @test |
102
|
|
|
* @group extract data |
103
|
|
|
*/ |
104
|
|
|
public function getTextAsMiniOcrNoString(): void |
105
|
|
|
{ |
106
|
|
|
$xml = simplexml_load_file(__DIR__ . '/../../Fixtures/Format/altoNoString.xml'); |
107
|
|
|
$alto = new Alto(); |
108
|
|
|
|
109
|
|
|
$rawText = $alto->getTextAsMiniOcr($xml); |
110
|
|
|
|
111
|
|
|
self::assertXmlStringEqualsXmlString( |
112
|
|
|
'<?xml version="1.0"?><ocr><b><l/><l/></b><b><l/><l/></b></ocr>', |
113
|
|
|
$rawText |
114
|
|
|
); |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|