-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOaiDcterms.php
273 lines (251 loc) · 9.95 KB
/
OaiDcterms.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
<?php declare(strict_types=1);
/**
* @author John Flatness, Yu-Hsun Lin
* @copyright Copyright 2009 John Flatness, Yu-Hsun Lin
* @copyright BibLibre, 2016
* @copyright Daniel Berthereau, 2014-2018
* @license http://www.gnu.org/licenses/gpl-3.0.txt
*/
namespace OaiPmhRepository\OaiPmh\Metadata;
use DOMElement;
use Omeka\Api\Representation\ItemRepresentation;
/**
* Class implementing metadata output for the oai_dcterms metadata format.
* oai_dcterms is output of the 55 Dublin Core terms.
*
* This format is not standardized, but used by some repositories.
* Note: the namespace and the schema don’t exist. It is designed as an extended
* version of oai_dc.
*
* @link http://www.bl.uk/schemas/
* @link http://dublincore.org/documents/dc-xml-guidelines/
* @link http://dublincore.org/schemas/xmls/qdc/dcterms.xsd
*/
class OaiDcterms extends AbstractMetadata
{
/** OAI-PMH metadata prefix */
const METADATA_PREFIX = 'oai_dcterms';
/** XML namespace for output format */
const METADATA_NAMESPACE = 'http://www.openarchives.org/OAI/2.0/oai_dcterms/';
/** XML schema for output format */
// const METADATA_SCHEMA = 'http://www.openarchives.org/OAI/2.0/oai_dcterms.xsd';
const METADATA_SCHEMA = 'http://www.openarchives.org/OAI/2.0/oai_dc.xsd';
/** XML namespace for Dublin Core */
const DCTERMS_NAMESPACE_URI = 'http://purl.org/dc/terms/';
/**
* Appends Dublin Core terms metadata.
*
* {@inheritDoc}
*/
public function appendMetadata(DOMElement $metadataElement, ItemRepresentation $item): void
{
$document = $metadataElement->ownerDocument;
$oai = $document->createElementNS(self::METADATA_NAMESPACE, 'oai_dcterms:dcterms');
$metadataElement->appendChild($oai);
/* Must manually specify XML schema uri per spec, but DOM won't include
* a redundant xmlns:xsi attribute, so we just set the attribute
*/
$oai->setAttribute('xmlns:dcterms', self::DCTERMS_NAMESPACE_URI);
$oai->setAttribute('xmlns:xsi', parent::XML_SCHEMA_NAMESPACE_URI);
$oai->setAttribute('xsi:schemaLocation', self::METADATA_NAMESPACE . ' ' .
self::METADATA_SCHEMA);
// Each of the 55 Dublin Core terms, in the Omeka order.
$localNames = [
// Dublin Core Elements.
'title',
'description',
'creator',
'subject',
'publisher',
'contributor',
'date',
'type',
'format',
'identifier',
'source',
'language',
'relation',
'coverage',
'rights',
// Dublin Core terms.
'audience',
'alternative',
'tableOfContents',
'abstract',
'created',
'valid',
'available',
'issued',
'modified',
'extent',
'medium',
'isVersionOf',
'hasVersion',
'isReplacedBy',
'replaces',
'isRequiredBy',
'requires',
'isPartOf',
'hasPart',
'isReferencedBy',
'references',
'isFormatOf',
'hasFormat',
'conformsTo',
'spatial',
'temporal',
'mediator',
'dateAccepted',
'dateCopyrighted',
'dateSubmitted',
'educationLevel',
'accessRights',
'bibliographicCitation',
'license',
'rightsHolder',
'provenance',
'instructionalMethod',
'accrualMethod',
'accrualPeriodicity',
'accrualPolicy',
];
/* Must create elements using createElement to make DOM allow a
* top-level xmlns declaration instead of wasteful and non-
* compliant per-node declarations.
*/
$values = $this->filterValuesPre($item);
foreach ($localNames as $localName) {
$term = 'dcterms:' . $localName;
$termValues = $values[$term]['values'] ?? [];
$termValues = $this->filterValues($item, $term, $termValues);
foreach ($termValues as $value) {
list($text, $attributes) = $this->formatValue($value);
$attributes["comment"]=$values["$term"]["alternate_comment"] ?? "";
$this->appendNewElement($oai, $term, $text, $attributes);
}
}
$valuesAll=$item->values();
if (isset($valuesAll["bibo:uri"])) {
$wikidata_uri=$valuesAll["bibo:uri"];
foreach ($wikidata_uri["values"] as $k=>$v) {
list($text, $attributes) = $this->formatValue($v);
$attributes["type"]='wikidata';
$attributes["comment"]=$wikidata_uri["alternate_comment"];
$this->appendNewElement($oai, "dcterms:identifier", $text , $attributes);
break;
}
}
// Luettelotunniste -> dcterms:identifier
$valuesAll=$item->values();
if (isset($valuesAll["schema:catalogNumber"])) {
$wikidata_uri=$valuesAll["schema:catalogNumber"];
foreach ($wikidata_uri["values"] as $k=>$v) {
list($text, $attributes) = $this->formatValue($v);
$attributes["type"]='wikidata:P217';
$attributes["comment"]=$wikidata_uri["alternate_comment"];
$this->appendNewElement($oai, "dcterms:identifier", $text , $attributes);
break;
}
}
$appendIdentifier = $this->singleIdentifier($item);
if ($appendIdentifier) {
// $this->appendNewElement($oai, 'dcterms:identifier', $appendIdentifier);
}
// Schema:collection -> dcterms:isPartOf
if (isset($valuesAll["schema:collection"])) {
$wikidata_uri=$valuesAll["schema:collection"];
foreach ($wikidata_uri["values"] as $k=>$v) {
list($text, $attributes) = $this->formatValue($v);
$attributes["comment"]='wikidata:P195 (collection)';
$attributes["comment"]=$wikidata_uri["alternate_comment"];
$this->appendNewElement($oai, "dcterms:isPartOf", $text, $attributes );
}
}
// Also append an identifier for each file
if ($this->params['expose_media']) {
foreach ($item->media() as $media) {
$images=$media->thumbnailUrls();
foreach($images as $k=>$v) {
$this->appendNewElement($oai, 'file', $v, ['bundle'=>$k]);
}
$this->appendNewElement($oai, 'file', $media->originalUrl(), ['bundle'=>'original', 'sha256'=>$media->sha256(), 'mimetype'=>$media->mediaType()]);
}
}
// Schema:material
if (isset($valuesAll["schema:material"])) {
$wikidata_uri=$valuesAll["schema:material"];
foreach ($wikidata_uri["values"] as $k=>$v) {
list($text, $attributes) = $this->formatValue($v);
$attributes["type"]='wikidata:P186';
$attributes["comment"]=$wikidata_uri["alternate_comment"];
$this->appendNewElement($oai, "medium", $text, $attributes );
}
}
// Schema:width,height,depth
$width=array();
if (isset($valuesAll["schema:width"])) {
$wikidata_uri=$valuesAll["schema:width"];
foreach ($wikidata_uri["values"] as $k=>$v) {
list($text, $attributes) = $this->formatValue($v);
array_push($width, $text);
}
}
$height=array();
if (isset($valuesAll["schema:height"])) {
$wikidata_uri=$valuesAll["schema:height"];
foreach ($wikidata_uri["values"] as $k=>$v) {
list($text, $attributes) = $this->formatValue($v);
array_push($height, $text);
}
}
$depth=array();
if (isset($valuesAll["schema:depth"])) {
$wikidata_uri=$valuesAll["schema:depth"];
foreach ($wikidata_uri["values"] as $k=>$v) {
list($text, $attributes) = $this->formatValue($v);
array_push($depth, $text);
}
}
if (count($width)==1 && count($height)==1 && count($depth)==1) {
$text=$width[0] . " x " . $height[0] . " x " . $depth[0];
$attributes=array(
'width' => $width[0],
'height' => $height[0],
'depth' => $depth[0],
'comment' => "P2049, P2048, P5524"
);
$this->appendNewElement($oai, "dcterms:format", $text, $attributes );
}
elseif (count($width)==1 && count($height)==1) {
$text=$width[0] . " x " . $height[0] ;
$attributes=array(
'width' => $width[0],
'height' => $height[0],
'comment' => "P2049, P2048"
);
$this->appendNewElement($oai, "dcterms:format", $text, $attributes );
}
// Record id = Wikidata id in bibo:url
if (isset($valuesAll["bibo:uri"])) {
$wikidata_uri=$valuesAll["bibo:uri"];
foreach ($wikidata_uri["values"] as $k=>$v) {
list($text, $attributes) = $this->formatValue($v);
$attributes["comment"]=$wikidata_uri["alternate_comment"];
$this->appendNewElement($oai, "recordID", $text );
break;
}
}
}
public function getMetadataPrefix()
{
return self::METADATA_PREFIX;
}
public function getMetadataSchema()
{
return self::METADATA_SCHEMA;
}
public function getMetadataNamespace()
{
return self::METADATA_NAMESPACE;
}
}