|
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\Common\Document; |
|
14
|
|
|
|
|
15
|
|
|
use Kitodo\Dlf\Common\FulltextInterface; |
|
16
|
|
|
use Kitodo\Dlf\Common\Helper; |
|
17
|
|
|
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration; |
|
18
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Document class for the 'dlf' extension |
|
22
|
|
|
* |
|
23
|
|
|
* @author Beatrycze Volk <[email protected]> |
|
24
|
|
|
* @package TYPO3 |
|
25
|
|
|
* @subpackage dlf |
|
26
|
|
|
* @access public |
|
27
|
|
|
* @property-read bool $hasFullText Are there any full text files available? |
|
28
|
|
|
* @property array $rawTextArray array containing raw text |
|
29
|
|
|
* @abstract |
|
30
|
|
|
*/ |
|
31
|
|
|
abstract class FullTextDocument extends Document |
|
32
|
|
|
{ |
|
33
|
|
|
/** |
|
34
|
|
|
* The extension key |
|
35
|
|
|
* |
|
36
|
|
|
* @var string |
|
37
|
|
|
* @access public |
|
38
|
|
|
*/ |
|
39
|
|
|
public static $extKey = 'dlf'; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Are there any fulltext files available? This also includes IIIF text annotations |
|
43
|
|
|
* with motivation 'painting' if Kitodo.Presentation is configured to store text |
|
44
|
|
|
* annotations as fulltext. |
|
45
|
|
|
* |
|
46
|
|
|
* @var bool |
|
47
|
|
|
* @access protected |
|
48
|
|
|
*/ |
|
49
|
|
|
protected $hasFullText = false; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* This holds the documents' raw text pages with their corresponding |
|
53
|
|
|
* structMap//div's ID (METS) or Range / Manifest / Sequence ID (IIIF) as array key |
|
54
|
|
|
* |
|
55
|
|
|
* @var array |
|
56
|
|
|
* @access protected |
|
57
|
|
|
*/ |
|
58
|
|
|
protected $rawTextArray = []; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* This extracts the raw text for a physical structure node / IIIF Manifest / Canvas. Text might be |
|
62
|
|
|
* given as ALTO for METS or as annotations or ALTO for IIIF resources. If IIIF plain text annotations |
|
63
|
|
|
* with the motivation "painting" should be treated as full text representations, the extension has to be |
|
64
|
|
|
* configured accordingly. |
|
65
|
|
|
* |
|
66
|
|
|
* @access public |
|
67
|
|
|
* |
|
68
|
|
|
* @abstract |
|
69
|
|
|
* |
|
70
|
|
|
* @param string $id: The @ID attribute of the physical structure node (METS) or the @id property |
|
71
|
|
|
* of the Manifest / Range (IIIF) |
|
72
|
|
|
* |
|
73
|
|
|
* @return string The physical structure node's / IIIF resource's raw text |
|
74
|
|
|
*/ |
|
75
|
|
|
public abstract function getRawText($id); |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Analyze the document if it contains any full text that needs to be indexed. |
|
79
|
|
|
* |
|
80
|
|
|
* @access protected |
|
81
|
|
|
* |
|
82
|
|
|
* @abstract |
|
83
|
|
|
*/ |
|
84
|
|
|
protected abstract function ensureHasFullTextIsSet(); |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* This extracts the raw text for a physical structure node / IIIF Manifest / Canvas from an |
|
88
|
|
|
* XML full text representation (currently only ALTO). For IIIF manifests, ALTO documents have |
|
89
|
|
|
* to be given in the Canvas' / Manifest's "seeAlso" property. |
|
90
|
|
|
* |
|
91
|
|
|
* @param string $id: The @ID attribute of the physical structure node (METS) or the @id property |
|
92
|
|
|
* of the Manifest / Range (IIIF) |
|
93
|
|
|
* |
|
94
|
|
|
* @return string The physical structure node's / IIIF resource's raw text from XML |
|
95
|
|
|
*/ |
|
96
|
|
|
protected function getRawTextFromXml($id) |
|
97
|
|
|
{ |
|
98
|
|
|
$rawText = ''; |
|
99
|
|
|
// Load available text formats, ... |
|
100
|
|
|
$this->loadFormats(); |
|
101
|
|
|
// ... physical structure ... |
|
102
|
|
|
$this->_getPhysicalStructure(); |
|
103
|
|
|
// ... and extension configuration. |
|
104
|
|
|
$extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get(self::$extKey); |
|
105
|
|
|
$fileGrpsFulltext = GeneralUtility::trimExplode(',', $extConf['fileGrpFulltext']); |
|
106
|
|
|
if (!empty($this->physicalStructureInfo[$id])) { |
|
107
|
|
|
while ($fileGrpFulltext = array_shift($fileGrpsFulltext)) { |
|
108
|
|
|
if (!empty($this->physicalStructureInfo[$id]['files'][$fileGrpFulltext])) { |
|
109
|
|
|
// Get full text file. |
|
110
|
|
|
$file = GeneralUtility::getUrl($this->getFileLocation($this->physicalStructureInfo[$id]['files'][$fileGrpFulltext])); |
|
111
|
|
|
if ($file !== false) { |
|
112
|
|
|
$rawTextXml = Helper::getXmlFileAsString($file); |
|
|
|
|
|
|
113
|
|
|
// Get the root element's name as text format. |
|
114
|
|
|
$textFormat = strtoupper($rawTextXml->getName()); |
|
115
|
|
|
} else { |
|
116
|
|
|
$this->logger->warning('Couldn\'t load fulltext file for structure node @ID "' . $id . '"'); |
|
|
|
|
|
|
117
|
|
|
return $rawText; |
|
118
|
|
|
} |
|
119
|
|
|
break; |
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
} else { |
|
123
|
|
|
$this->logger->warning('Invalid structure node @ID "' . $id . '"'); |
|
124
|
|
|
return $rawText; |
|
125
|
|
|
} |
|
126
|
|
|
// Is this text format supported? |
|
127
|
|
|
if ( |
|
128
|
|
|
!empty($rawTextXml) |
|
129
|
|
|
&& !empty($this->formats[$textFormat]) |
|
|
|
|
|
|
130
|
|
|
) { |
|
131
|
|
|
if (!empty($this->formats[$textFormat]['class'])) { |
|
132
|
|
|
$class = $this->formats[$textFormat]['class']; |
|
133
|
|
|
// Get the raw text from class. |
|
134
|
|
|
if ( |
|
135
|
|
|
class_exists($class) |
|
136
|
|
|
&& ($obj = GeneralUtility::makeInstance($class)) instanceof FulltextInterface |
|
137
|
|
|
) { |
|
138
|
|
|
$rawText = $obj->getRawText($rawTextXml); |
|
139
|
|
|
$this->rawTextArray[$id] = $rawText; |
|
140
|
|
|
} else { |
|
141
|
|
|
$this->logger->warning('Invalid class/method "' . $class . '->getRawText()" for text format "' . $textFormat . '"'); |
|
142
|
|
|
} |
|
143
|
|
|
} |
|
144
|
|
|
} else { |
|
145
|
|
|
$this->logger->warning('Unsupported text format "' . $textFormat . '" in physical node with @ID "' . $id . '"'); |
|
146
|
|
|
} |
|
147
|
|
|
return $rawText; |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* This returns $this->hasFullText via __get() |
|
152
|
|
|
* |
|
153
|
|
|
* @access protected |
|
154
|
|
|
* |
|
155
|
|
|
* @return bool Are there any full text files available? |
|
156
|
|
|
*/ |
|
157
|
|
|
protected function _getHasFullText() |
|
158
|
|
|
{ |
|
159
|
|
|
$this->ensureHasFullTextIsSet(); |
|
160
|
|
|
return $this->hasFullText; |
|
161
|
|
|
} |
|
162
|
|
|
} |
|
163
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.