1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* VocabularyConfig provides access to the vocabulary configuration defined in config.ttl. |
5
|
|
|
*/ |
6
|
|
|
class VocabularyConfig extends BaseConfig |
7
|
|
|
{ |
8
|
|
|
private $pluginRegister; |
9
|
|
|
private $pluginParameters = array(); |
10
|
|
|
private $languageOrderCache = array(); |
11
|
|
|
|
12
|
|
|
const DEFAULT_PROPERTY_ORDER = array("rdf:type", "dc:isReplacedBy", |
13
|
|
|
"skos:definition", "skos:broader", "isothes:broaderGeneric", |
14
|
|
|
"isothes:broaderPartitive", "isothes:broaderInstantial", |
15
|
|
|
"skos:narrower", "isothes:narrowerGeneric", "isothes:narrowerPartitive", |
16
|
|
|
"isothes:narrowerInstantial", "skos:related", "skos:altLabel", |
17
|
|
|
"skos:note", "skos:scopeNote", "skos:historyNote", "rdfs:comment", |
18
|
|
|
"dc11:source", "dc:source", "skosmos:memberOf", "skosmos:memberOfArray"); |
19
|
|
|
|
20
|
|
|
const ISO25964_PROPERTY_ORDER = array("rdf:type", "dc:isReplacedBy", |
21
|
|
|
// ISO 25964 allows placing all text fields (inc. SN and DEF) together |
22
|
|
|
// so we will do that, except for HN, which is clearly administrative |
23
|
|
|
"skos:note", "skos:scopeNote", "skos:definition", "rdfs:comment", |
24
|
|
|
"dc11:source", "dc:source", "skos:altLabel", "skos:broader", |
25
|
|
|
"isothes:broaderGeneric", "isothes:broaderPartitive", |
26
|
|
|
"isothes:broaderInstantial", "skos:narrower", "isothes:narrowerGeneric", |
27
|
|
|
"isothes:narrowerPartitive", "isothes:narrowerInstantial", |
28
|
|
|
"skos:related", "skos:historyNote", "skosmos:memberOf", |
29
|
|
|
"skosmos:memberOfArray"); |
30
|
|
|
|
31
|
|
|
public function __construct($resource, $globalPlugins=array()) |
32
|
|
|
{ |
33
|
|
|
$this->resource = $resource; |
34
|
|
|
$this->globalPlugins = $globalPlugins; |
|
|
|
|
35
|
|
|
$this->setParameterizedPlugins(); |
36
|
|
|
$pluginArray = $this->getPluginArray(); |
37
|
|
|
$this->pluginRegister = new PluginRegister($pluginArray); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Get an ordered array of plugin names with order configured in skosmos:vocabularyPlugins |
42
|
|
|
* @return array of plugin names |
43
|
|
|
*/ |
44
|
|
|
public function getPluginArray() : array |
45
|
|
|
{ |
46
|
|
|
$pluginArray = array(); |
47
|
|
|
|
48
|
|
|
$vocabularyPlugins = $this->resource->getResource('skosmos:vocabularyPlugins'); |
49
|
|
|
if (!is_array($vocabularyPlugins)) { |
|
|
|
|
50
|
|
|
$vocabularyPlugins = $this->resource->all('skosmos:vocabularyPlugins'); |
51
|
|
|
} |
52
|
|
|
if ($vocabularyPlugins) { |
|
|
|
|
53
|
|
|
foreach ($vocabularyPlugins as $plugin) { |
54
|
|
|
if ($plugin instanceof EasyRdf\Literal) { |
55
|
|
|
$pluginArray[] = $plugin->getValue(); |
56
|
|
|
} |
57
|
|
|
else if ($plugin instanceof EasyRdf\Resource) { |
58
|
|
|
$pluginArray[] = $plugin->getLiteral('skosmos:usePlugin')->getValue(); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
$pluginArray = array_merge($pluginArray, $this->globalPlugins); |
63
|
|
|
|
64
|
|
|
$plugins = $this->resource->allLiterals('skosmos:usePlugin'); |
65
|
|
|
if ($plugins) { |
|
|
|
|
66
|
|
|
foreach ($plugins as $pluginlit) { |
67
|
|
|
$pluginArray[] = $pluginlit->getValue(); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
return array_values(array_unique($pluginArray)); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Sets array of parameterized plugins |
75
|
|
|
* @param Easyrdf\Resource $pluginResource |
76
|
|
|
* @return void |
77
|
|
|
*/ |
78
|
|
|
private function setParameterizedPlugins() : void |
79
|
|
|
{ |
80
|
|
|
$this->pluginParameters = array(); |
81
|
|
|
|
82
|
|
|
$vocabularyPlugins = $this->resource->getResource('skosmos:vocabularyPlugins'); |
83
|
|
|
if ($vocabularyPlugins) { |
|
|
|
|
84
|
|
|
foreach ($vocabularyPlugins as $plugin) { |
85
|
|
|
if ($plugin instanceof EasyRdf\Resource) { |
86
|
|
|
$this->setPluginParameters($plugin); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
$pluginResources = $this->resource->allResources('skosmos:useParamPlugin'); |
91
|
|
|
if ($pluginResources) { |
|
|
|
|
92
|
|
|
foreach ($pluginResources as $pluginResource) { |
93
|
|
|
$this->setPluginParameters($pluginResource); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Updates array of parameterized plugins adding parameter values |
100
|
|
|
* @param Easyrdf\Resource $pluginResource |
101
|
|
|
* @return void |
102
|
|
|
*/ |
103
|
|
|
private function setPluginParameters(Easyrdf\Resource $pluginResource) : void |
104
|
|
|
{ |
105
|
|
|
$pluginName = $pluginResource->getLiteral('skosmos:usePlugin')->getValue(); |
106
|
|
|
$this->pluginParameters[$pluginName] = array(); |
107
|
|
|
|
108
|
|
|
$pluginParams = $pluginResource->allResources('skosmos:parameters'); |
109
|
|
|
foreach ($pluginParams as $parameter) { |
110
|
|
|
|
111
|
|
|
$paramLiterals = $parameter->allLiterals('schema:value'); |
112
|
|
|
foreach ($paramLiterals as $paramLiteral) { |
113
|
|
|
$paramName = $parameter->getLiteral('schema:propertyID')->getValue(); |
114
|
|
|
$paramValue = $paramLiteral->getValue(); |
115
|
|
|
$paramLang = $paramLiteral->getLang(); |
116
|
|
|
if ($paramLang) { |
117
|
|
|
$paramName .= '_' . $paramLang; |
118
|
|
|
} |
119
|
|
|
$this->pluginParameters[$pluginName][$paramName] = $paramValue; |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Get the SPARQL endpoint URL for this vocabulary |
126
|
|
|
* |
127
|
|
|
* @return string|null endpoint URL, or null if not set |
128
|
|
|
*/ |
129
|
|
|
public function getSparqlEndpoint() |
130
|
|
|
{ |
131
|
|
|
$endpoint = $this->resource->get('void:sparqlEndpoint'); |
132
|
|
|
if ($endpoint) { |
133
|
|
|
return $endpoint->getUri(); |
134
|
|
|
} |
135
|
|
|
return null; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* Get the SPARQL graph URI for this vocabulary |
140
|
|
|
* |
141
|
|
|
* @return string|null graph URI, or null if not set |
142
|
|
|
*/ |
143
|
|
|
public function getSparqlGraph() |
144
|
|
|
{ |
145
|
|
|
$graph = $this->resource->get('skosmos:sparqlGraph'); |
146
|
|
|
if ($graph) { |
147
|
|
|
$graph = $graph->getUri(); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
return $graph; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* Get the SPARQL dialect for this vocabulary |
155
|
|
|
* |
156
|
|
|
* @return string|null dialect name |
157
|
|
|
*/ |
158
|
|
|
public function getSparqlDialect() |
159
|
|
|
{ |
160
|
|
|
$dialect = $this->resource->get('skosmos:sparqlDialect'); |
161
|
|
|
if ($dialect) { |
162
|
|
|
$dialect = $dialect->getValue(); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
return $dialect; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* Get the default language of this vocabulary |
170
|
|
|
* @return string default language, e.g. 'en' |
171
|
|
|
*/ |
172
|
|
|
|
173
|
|
|
public function getDefaultLanguage() |
174
|
|
|
{ |
175
|
|
|
$deflang = $this->resource->getLiteral('skosmos:defaultLanguage'); |
176
|
|
|
if ($deflang) { |
|
|
|
|
177
|
|
|
return $deflang->getValue(); |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
$langs = $this->getLanguages(); |
181
|
|
|
$deflang = reset($langs); // picking the first one from the list with reset since the keys are not numeric |
182
|
|
|
if (sizeof($langs) > 1) { |
183
|
|
|
trigger_error("Default language for vocabulary '" . $this->getShortName() . "' unknown, choosing '$deflang'.", E_USER_WARNING); |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
return $deflang; |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* Whether the alphabetical index is small enough to be shown all at once. |
191
|
|
|
* @return boolean true if all concepts can be shown at once. |
192
|
|
|
*/ |
193
|
|
|
public function getAlphabeticalFull() |
194
|
|
|
{ |
195
|
|
|
return $this->getBoolean('skosmos:fullAlphabeticalIndex'); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* Returns a short name for a vocabulary if configured. If that has not been set |
200
|
|
|
* using vocabId as a fallback. |
201
|
|
|
* @return string |
202
|
|
|
*/ |
203
|
|
|
public function getShortName() |
204
|
|
|
{ |
205
|
|
|
$shortname = $this->getLiteral('skosmos:shortName'); |
206
|
|
|
if ($shortname) |
207
|
|
|
return $shortname; |
208
|
|
|
|
209
|
|
|
// if no shortname exists fall back to the id |
210
|
|
|
return $this->getId(); |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* Get the vocabulary feedback e-mail address and return it. |
215
|
|
|
* |
216
|
|
|
* @return string e-mail address or null if not defined. |
217
|
|
|
*/ |
218
|
|
|
public function getFeedbackRecipient() |
219
|
|
|
{ |
220
|
|
|
$email = $this->resource->get('skosmos:feedbackRecipient'); |
221
|
|
|
return isset($email) ? $email->getValue() : null; |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* Returns the human readable vocabulary title. |
226
|
|
|
* @return string the title of the vocabulary |
227
|
|
|
*/ |
228
|
|
|
public function getTitle($lang = null) |
229
|
|
|
{ |
230
|
|
|
return $this->getLiteral('dc:title', false, $lang); |
|
|
|
|
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* Returns a boolean value set in the config.ttl config. |
235
|
|
|
* @return boolean |
236
|
|
|
*/ |
237
|
|
|
public function sortByNotation() |
238
|
|
|
{ |
239
|
|
|
return $this->getBoolean('skosmos:sortByNotation'); |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* Returns a boolean value set in the config.ttl config. |
244
|
|
|
* @return boolean |
245
|
|
|
*/ |
246
|
|
|
public function showChangeList() |
247
|
|
|
{ |
248
|
|
|
return $this->getBoolean('skosmos:showChangeList'); |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
/** |
252
|
|
|
* get the URLs from which the vocabulary data can be downloaded |
253
|
|
|
* @return array Array with MIME type as key, URL as value |
254
|
|
|
*/ |
255
|
|
|
public function getDataURLs() |
256
|
|
|
{ |
257
|
|
|
$ret = array(); |
258
|
|
|
$urls = $this->resource->allResources("void:dataDump"); |
259
|
|
|
foreach ($urls as $url) { |
260
|
|
|
// first try dc:format and dc11:format |
261
|
|
|
$mimetypelit = $url->getLiteral('dc:format'); |
262
|
|
|
if ($mimetypelit === null) { |
263
|
|
|
$mimetypelit = $url->getLiteral('dc11:format'); |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
if ($mimetypelit !== null) { |
267
|
|
|
$mimetype = $mimetypelit->getValue(); |
268
|
|
|
} else { |
269
|
|
|
$format = EasyRdf\Format::guessFormat(null, $url->getURI()); |
270
|
|
|
if ($format === null) { |
271
|
|
|
trigger_error("Could not guess format for <$url>.", E_USER_WARNING); |
272
|
|
|
continue; |
273
|
|
|
} |
274
|
|
|
$mimetypes = array_keys($format->getMimeTypes()); |
275
|
|
|
$mimetype = $mimetypes[0]; |
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
$langLit = $url->getLiteral('dc:language'); |
279
|
|
|
|
280
|
|
|
if ($langLit != null) { |
281
|
|
|
//when the mimetype has language variants |
282
|
|
|
$dataUrlLang = $langLit->getValue(); |
283
|
|
|
|
284
|
|
|
if (!isset($ret[$mimetype])) { |
285
|
|
|
$arr = array(); |
286
|
|
|
} else { |
287
|
|
|
$arr = $ret[$mimetype]; |
288
|
|
|
} |
289
|
|
|
$arr[$dataUrlLang] = $url->getURI(); |
290
|
|
|
$ret[$mimetype] = $arr; |
291
|
|
|
} else { |
292
|
|
|
$ret[$mimetype] = $url->getURI(); |
293
|
|
|
} |
294
|
|
|
} |
295
|
|
|
return $ret; |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
/** |
299
|
|
|
* Returns the main Concept Scheme URI of that Vocabulary, |
300
|
|
|
* or null if not set. |
301
|
|
|
* @return string concept scheme URI or null |
302
|
|
|
*/ |
303
|
|
|
|
304
|
|
|
public function getMainConceptSchemeURI() |
305
|
|
|
{ |
306
|
|
|
$val = $this->resource->getResource("skosmos:mainConceptScheme"); |
307
|
|
|
if ($val) { |
|
|
|
|
308
|
|
|
return $val->getURI(); |
309
|
|
|
} |
310
|
|
|
|
311
|
|
|
return null; |
312
|
|
|
} |
313
|
|
|
|
314
|
|
|
/** |
315
|
|
|
* Returns the class URI used for concept groups in this vocabulary, |
316
|
|
|
* or null if not set. |
317
|
|
|
* @return string group class URI or null |
318
|
|
|
*/ |
319
|
|
|
|
320
|
|
|
public function getGroupClassURI() |
321
|
|
|
{ |
322
|
|
|
$val = $this->resource->getResource("skosmos:groupClass"); |
323
|
|
|
if ($val) { |
|
|
|
|
324
|
|
|
return $val->getURI(); |
325
|
|
|
} |
326
|
|
|
|
327
|
|
|
return null; |
328
|
|
|
} |
329
|
|
|
|
330
|
|
|
/** |
331
|
|
|
* Returns the class URI used for thesaurus arrays in this vocabulary, |
332
|
|
|
* or null if not set. |
333
|
|
|
* @return string array class URI or null |
334
|
|
|
*/ |
335
|
|
|
|
336
|
|
|
public function getArrayClassURI() |
337
|
|
|
{ |
338
|
|
|
$val = $this->resource->getResource("skosmos:arrayClass"); |
339
|
|
|
if ($val) { |
|
|
|
|
340
|
|
|
return $val->getURI(); |
341
|
|
|
} |
342
|
|
|
|
343
|
|
|
return null; |
344
|
|
|
} |
345
|
|
|
|
346
|
|
|
/** |
347
|
|
|
* Returns custom properties displayed on the search page if configured. |
348
|
|
|
* @return array array class URI or null |
349
|
|
|
*/ |
350
|
|
|
|
351
|
|
|
public function getAdditionalSearchProperties() |
352
|
|
|
{ |
353
|
|
|
$resources = $this->resource->allResources("skosmos:showPropertyInSearch"); |
354
|
|
|
$ret = array(); |
355
|
|
|
foreach ($resources as $res) { |
356
|
|
|
$prop = $res->getURI(); |
357
|
|
|
if (EasyRdf\RdfNamespace::shorten($prop) !== null) // shortening property labels if possible |
358
|
|
|
{ |
359
|
|
|
$prop = EasyRdf\RdfNamespace::shorten($prop); |
360
|
|
|
} |
361
|
|
|
|
362
|
|
|
$ret[] = $prop; |
363
|
|
|
} |
364
|
|
|
return $ret; |
365
|
|
|
} |
366
|
|
|
|
367
|
|
|
/** |
368
|
|
|
* Queries whether the property should be shown with all the label language variations. |
369
|
|
|
* @param string $property |
370
|
|
|
* @return boolean |
371
|
|
|
*/ |
372
|
|
|
public function hasMultiLingualProperty($property) |
373
|
|
|
{ |
374
|
|
|
$resources = $this->resource->allResources("skosmos:hasMultiLingualProperty"); |
375
|
|
|
foreach ($resources as $res) { |
376
|
|
|
$prop = $res->getURI(); |
377
|
|
|
if (EasyRdf\RdfNamespace::shorten($prop) !== null) // shortening property labels if possible |
378
|
|
|
{ |
379
|
|
|
$prop = EasyRdf\RdfNamespace::shorten($prop); |
380
|
|
|
} |
381
|
|
|
|
382
|
|
|
if ($prop === $property) { |
383
|
|
|
return true; |
384
|
|
|
} |
385
|
|
|
|
386
|
|
|
} |
387
|
|
|
return false; |
388
|
|
|
} |
389
|
|
|
|
390
|
|
|
/** |
391
|
|
|
* Returns a boolean value set in the config.ttl config. |
392
|
|
|
* @return boolean |
393
|
|
|
*/ |
394
|
|
|
public function getShowHierarchy() |
395
|
|
|
{ |
396
|
|
|
return $this->getBoolean('skosmos:showTopConcepts'); |
397
|
|
|
} |
398
|
|
|
|
399
|
|
|
/** |
400
|
|
|
* Returns a boolean value set in the config.ttl config. |
401
|
|
|
* @return boolean |
402
|
|
|
*/ |
403
|
|
|
public function showConceptSchemesInHierarchy() |
404
|
|
|
{ |
405
|
|
|
return $this->getBoolean('skosmos:conceptSchemesInHierarchy'); |
406
|
|
|
} |
407
|
|
|
|
408
|
|
|
/** |
409
|
|
|
* Returns a boolean value set in the config.ttl config. |
410
|
|
|
* @return boolean defaults to true if fetching hasn't been explicitly denied. |
411
|
|
|
*/ |
412
|
|
|
public function getExternalResourcesLoading() |
413
|
|
|
{ |
414
|
|
|
return $this->getBoolean('skosmos:loadExternalResources', true); |
415
|
|
|
} |
416
|
|
|
|
417
|
|
|
/** |
418
|
|
|
* Returns a boolean value set in the config.ttl config. |
419
|
|
|
* @return boolean |
420
|
|
|
*/ |
421
|
|
|
public function getShowLangCodes() |
422
|
|
|
{ |
423
|
|
|
return $this->getBoolean('skosmos:explicitLanguageTags'); |
424
|
|
|
} |
425
|
|
|
|
426
|
|
|
/** |
427
|
|
|
* Returns a boolean value set in the config.ttl config. |
428
|
|
|
* @return boolean |
429
|
|
|
*/ |
430
|
|
|
public function searchByNotation() |
431
|
|
|
{ |
432
|
|
|
return $this->getBoolean('skosmos:searchByNotation'); |
433
|
|
|
} |
434
|
|
|
|
435
|
|
|
/** |
436
|
|
|
* Returns skosmos:marcSourcecode value set in config.ttl. |
437
|
|
|
* @return string marcsource name |
438
|
|
|
*/ |
439
|
|
|
public function getMarcSourceCode($lang = null) |
440
|
|
|
{ |
441
|
|
|
return $this->getLiteral('skosmos:marcSourceCode', false, $lang); |
|
|
|
|
442
|
|
|
} |
443
|
|
|
|
444
|
|
|
/** |
445
|
|
|
* Returns a boolean value set in the config.ttl config. |
446
|
|
|
* @return array array of concept class URIs (can be empty) |
447
|
|
|
*/ |
448
|
|
|
public function getIndexClasses() |
449
|
|
|
{ |
450
|
|
|
return $this->getResources("skosmos:indexShowClass"); |
451
|
|
|
} |
452
|
|
|
|
453
|
|
|
/** |
454
|
|
|
* Returns skosmos:externalProperty values set in the config.ttl config. |
455
|
|
|
* @return array array of external property URIs (can be empty) |
456
|
|
|
*/ |
457
|
|
|
public function getExtProperties() |
458
|
|
|
{ |
459
|
|
|
return $this->getResources("skosmos:externalProperty"); |
460
|
|
|
} |
461
|
|
|
|
462
|
|
|
/** |
463
|
|
|
* Get the languages supported by this vocabulary |
464
|
|
|
* @return array languages supported by this vocabulary (as language tag strings) |
465
|
|
|
*/ |
466
|
|
|
public function getLanguages() |
467
|
|
|
{ |
468
|
|
|
$langs = $this->resource->allLiterals('skosmos:language'); |
469
|
|
|
$ret = array(); |
470
|
|
|
foreach ($langs as $lang) { |
471
|
|
|
$langlit = Punic\Language::getName($lang->getValue(), $this->getEnvLang()); |
472
|
|
|
$ret[$langlit] = $lang->getValue(); |
473
|
|
|
} |
474
|
|
|
ksort($ret); |
475
|
|
|
|
476
|
|
|
return $ret; |
477
|
|
|
} |
478
|
|
|
|
479
|
|
|
/** |
480
|
|
|
* Returns the parameters of parameterized plugins |
481
|
|
|
* @return array of plugin parameters |
482
|
|
|
*/ |
483
|
|
|
public function getPluginParameters() { |
484
|
|
|
return $this->pluginParameters; |
485
|
|
|
} |
486
|
|
|
|
487
|
|
|
/** |
488
|
|
|
* Returns the vocabulary default sidebar view. |
489
|
|
|
* @return string name of the view |
490
|
|
|
*/ |
491
|
|
|
public function getDefaultSidebarView() |
492
|
|
|
{ |
493
|
|
|
$defview = $this->resource->getLiteral('skosmos:defaultSidebarView'); |
494
|
|
|
if ($defview) { |
|
|
|
|
495
|
|
|
$value = $defview->getValue(); |
496
|
|
|
if ($value === 'groups' || $value === 'hierarchy') { |
497
|
|
|
return $value; |
498
|
|
|
} |
499
|
|
|
|
500
|
|
|
} |
501
|
|
|
if ($this->showAlphabeticalIndex() === false) { |
502
|
|
|
if ($this->getShowHierarchy()) { |
503
|
|
|
return 'hierarchy'; |
504
|
|
|
} else if ($this->getGroupClassURI()) { |
505
|
|
|
return 'groups'; |
506
|
|
|
} |
507
|
|
|
} |
508
|
|
|
return 'alphabetical'; // if not defined displaying the alphabetical index |
509
|
|
|
} |
510
|
|
|
|
511
|
|
|
/** |
512
|
|
|
* Extracts the vocabulary id string from the baseuri of the vocabulary. |
513
|
|
|
* @return string identifier eg. 'mesh'. |
514
|
|
|
*/ |
515
|
|
|
public function getId() |
516
|
|
|
{ |
517
|
|
|
$uriparts = explode("#", $this->resource->getURI()); |
518
|
|
|
if (count($uriparts) != 1) |
519
|
|
|
// hash namespace |
520
|
|
|
{ |
521
|
|
|
return $uriparts[1]; |
522
|
|
|
} |
523
|
|
|
|
524
|
|
|
// slash namespace |
525
|
|
|
$uriparts = explode("/", $this->resource->getURI()); |
526
|
|
|
|
527
|
|
|
return $uriparts[count($uriparts) - 1]; |
528
|
|
|
} |
529
|
|
|
|
530
|
|
|
public function getShowStatistics() { |
531
|
|
|
return $this->getBoolean('skosmos:showStatistics', true); |
532
|
|
|
} |
533
|
|
|
|
534
|
|
|
public function getPluginRegister() |
535
|
|
|
{ |
536
|
|
|
return $this->pluginRegister; |
537
|
|
|
} |
538
|
|
|
|
539
|
|
|
/** |
540
|
|
|
* Returns the property/properties used for visualizing concept hierarchies. |
541
|
|
|
* @return array array class URI or null |
542
|
|
|
*/ |
543
|
|
|
|
544
|
|
|
public function getHierarchyProperty() |
545
|
|
|
{ |
546
|
|
|
$resources = $this->resource->allResources("skosmos:hierarchyProperty"); |
547
|
|
|
$ret = array(); |
548
|
|
|
foreach ($resources as $res) { |
549
|
|
|
$prop = $res->getURI(); |
550
|
|
|
if (EasyRdf\RdfNamespace::shorten($prop) !== null) // prefixing if possible |
551
|
|
|
{ |
552
|
|
|
$prop = EasyRdf\RdfNamespace::shorten($prop); |
553
|
|
|
} |
554
|
|
|
|
555
|
|
|
$ret[] = $prop; |
556
|
|
|
} |
557
|
|
|
return empty($ret) ? array('skos:broader') : $ret; |
558
|
|
|
} |
559
|
|
|
|
560
|
|
|
/** |
561
|
|
|
* Returns a boolean value set in the config.ttl config. |
562
|
|
|
* @return boolean |
563
|
|
|
*/ |
564
|
|
|
public function showNotation() |
565
|
|
|
{ |
566
|
|
|
return $this->getBoolean('skosmos:showNotation', true); |
567
|
|
|
} |
568
|
|
|
|
569
|
|
|
/** |
570
|
|
|
* Returns a boolean value set in the config.ttl config. |
571
|
|
|
* @return boolean |
572
|
|
|
*/ |
573
|
|
|
public function showAlphabeticalIndex() |
574
|
|
|
{ |
575
|
|
|
return $this->getBoolean('skosmos:showAlphabeticalIndex', true); |
576
|
|
|
} |
577
|
|
|
|
578
|
|
|
/** |
579
|
|
|
* Returns the alphabetical list qualifier in this vocabulary, |
580
|
|
|
* or null if not set. |
581
|
|
|
* @return EasyRdf\Resource|null alphabetical list qualifier resource or null |
582
|
|
|
*/ |
583
|
|
|
public function getAlphabeticalListQualifier() |
584
|
|
|
{ |
585
|
|
|
return $this->resource->getResource('skosmos:alphabeticalListQualifier'); |
586
|
|
|
} |
587
|
|
|
|
588
|
|
|
/** |
589
|
|
|
* Returns a boolean value set in the config.ttl config. |
590
|
|
|
* @return boolean |
591
|
|
|
*/ |
592
|
|
|
public function getShowDeprecated() |
593
|
|
|
{ |
594
|
|
|
return $this->getBoolean('skosmos:showDeprecated', false); |
595
|
|
|
} |
596
|
|
|
|
597
|
|
|
/** |
598
|
|
|
* Returns the vocabulary dc:type value(s) with their labels and uris, if set in the vocabulary configuration. |
599
|
|
|
* @return array of objects or an empty array |
600
|
|
|
*/ |
601
|
|
|
public function getTypes($lang = null) |
602
|
|
|
{ |
603
|
|
|
$resources = $this->resource->allResources("dc:type"); |
604
|
|
|
$ret = array(); |
605
|
|
|
foreach ($resources as $res) { |
606
|
|
|
$prop = $res->getURI(); |
607
|
|
|
$label = $res->label($lang) ? $res->label($lang) : $res->label($this->getDefaultLanguage()); |
608
|
|
|
$ret[] = array('uri' => $prop, 'prefLabel' => $label->getValue()); |
609
|
|
|
} |
610
|
|
|
return $ret; |
611
|
|
|
} |
612
|
|
|
|
613
|
|
|
/** |
614
|
|
|
* Returns an array of fallback languages that is ordered by priority and |
615
|
|
|
* defined in the vocabulary configuration as a collection. |
616
|
|
|
* Additionally, the chosen content language is inserted with the highest priority |
617
|
|
|
* and the vocab default language is inserted with the lowest priority. |
618
|
|
|
* @param string $clang |
619
|
|
|
* @return array of language code strings |
620
|
|
|
*/ |
621
|
|
|
public function getLanguageOrder($clang) |
622
|
|
|
{ |
623
|
|
|
if (array_key_exists($clang, $this->languageOrderCache)) { |
624
|
|
|
return $this->languageOrderCache[$clang]; |
625
|
|
|
} |
626
|
|
|
$ret = array($clang); |
627
|
|
|
$fallbacks = !empty($this->resource->get('skosmos:fallbackLanguages')) ? $this->resource->get('skosmos:fallbackLanguages') : array(); |
628
|
|
|
foreach ($fallbacks as $lang) { |
629
|
|
|
if (!in_array($lang, $ret)) { |
630
|
|
|
$ret[] = (string)$lang; // Literal to string conversion |
631
|
|
|
} |
632
|
|
|
} |
633
|
|
|
if (!in_array($this->getDefaultLanguage(), $ret)) { |
634
|
|
|
$ret[] = (string)$this->getDefaultLanguage(); |
635
|
|
|
} |
636
|
|
|
foreach ($this->getLanguages() as $lang) { |
637
|
|
|
if (!in_array($lang, $ret)) { |
638
|
|
|
$ret[] = $lang; |
639
|
|
|
} |
640
|
|
|
} |
641
|
|
|
// store in cache so this doesn't have to be computed again |
642
|
|
|
$this->languageOrderCache[$clang] = $ret; |
643
|
|
|
return $ret; |
644
|
|
|
} |
645
|
|
|
|
646
|
|
|
/** |
647
|
|
|
* @return boolean |
648
|
|
|
*/ |
649
|
|
|
public function isUseModifiedDate() |
650
|
|
|
{ |
651
|
|
|
return $this->getBoolean('skosmos:useModifiedDate', false); |
652
|
|
|
} |
653
|
|
|
|
654
|
|
|
/** |
655
|
|
|
* @return array |
656
|
|
|
*/ |
657
|
|
|
public function getPropertyOrder() |
658
|
|
|
{ |
659
|
|
|
$order = $this->getResource()->getResource('skosmos:propertyOrder'); |
660
|
|
|
if ($order === null) { |
661
|
|
|
return self::DEFAULT_PROPERTY_ORDER; |
662
|
|
|
} |
663
|
|
|
|
664
|
|
|
$short = EasyRdf\RdfNamespace::shorten($order); |
665
|
|
|
if ($short == 'skosmos:iso25964PropertyOrder') { |
666
|
|
|
return self::ISO25964_PROPERTY_ORDER; |
667
|
|
|
} elseif ($short == 'skosmos:defaultPropertyOrder') { |
668
|
|
|
return self::DEFAULT_PROPERTY_ORDER; |
669
|
|
|
} |
670
|
|
|
|
671
|
|
|
// check for custom order definition |
672
|
|
|
$orderList = $order->getResource('rdf:value'); |
673
|
|
|
if ($orderList !== null && $orderList instanceof EasyRdf\Collection) { |
674
|
|
|
$ret = array(); |
675
|
|
|
foreach ($orderList as $prop) { |
676
|
|
|
$short = $prop->shorten(); |
|
|
|
|
677
|
|
|
$ret[] = ($short !== null) ? $short : $prop->getURI(); |
678
|
|
|
} |
679
|
|
|
return $ret; |
680
|
|
|
} |
681
|
|
|
|
682
|
|
|
trigger_error("Property order for vocabulary '{$this->getShortName()}' unknown, using default order", E_USER_WARNING); |
683
|
|
|
return self::DEFAULT_PROPERTY_ORDER; |
684
|
|
|
} |
685
|
|
|
} |
686
|
|
|
|