Skip to content

Commit 8e32521

Browse files
author
Mark Hale
committed
Improve target vocabulary resolution by making use of skos:inScheme.
1 parent 36a7511 commit 8e32521

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

model/Concept.php

+12-1
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,18 @@ public function getMappingProperties(array $whitelist = null)
449449
continue;
450450
}
451451
}
452-
$ret[$prop]->addValue(new ConceptMappingPropertyValue($this->model, $this->vocab, $val, $this->resource, $prop, $this->clang));
452+
453+
// check if target vocabularly can be found by scheme
454+
$targetVocab = $this->vocab;
455+
foreach ($val->allResources("skos:inScheme") as $targetScheme) {
456+
$schemeVocab = $this->model->getVocabularyByScheme($targetScheme->getUri());
457+
if ($schemeVocab) {
458+
$targetVocab = $schemeVocab;
459+
break;
460+
}
461+
}
462+
463+
$ret[$prop]->addValue(new ConceptMappingPropertyValue($this->model, $targetVocab, $val, $this->resource, $prop, $this->clang));
453464
}
454465
}
455466
}

model/Model.php

+25
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ class Model
1313
private $vocabsByGraph = null;
1414
/** cache for Vocabulary objects */
1515
private $vocabsByUriSpace = null;
16+
/** cache for Vocabulary objects */
17+
private $vocabsByScheme = null;
1618
/** how long to store retrieved URI information in APC cache */
1719
const URI_FETCH_TTL = 86400; // 1 day
1820
private $globalConfig;
@@ -449,6 +451,29 @@ public function getVocabularyByGraph($graph, $endpoint = null)
449451

450452
}
451453

454+
/**
455+
* Return the vocabulary that has the given scheme.
456+
*
457+
* @param $graph string graph URI
458+
* @return Vocabulary vocabulary for this scheme, or null if not found
459+
*/
460+
public function getVocabularyByScheme($scheme)
461+
{
462+
if ($this->vocabsByScheme === null) { // initialize cache
463+
$this->vocabsByScheme = array();
464+
foreach ($this->getVocabularies() as $voc) {
465+
$key = $voc->getDefaultConceptScheme();
466+
$this->vocabsByScheme[$key] = $voc;
467+
}
468+
}
469+
470+
if (array_key_exists($scheme, $this->vocabsByScheme)) {
471+
return $this->vocabsByScheme[$scheme];
472+
} else {
473+
return null;
474+
}
475+
}
476+
452477
/**
453478
* When multiple vocabularies share same URI namespace, return the
454479
* vocabulary in which the URI is actually defined (has a label).

0 commit comments

Comments
 (0)