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