Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for scoping vocabularies by skos:inScheme. #1236

Open
wants to merge 2 commits into
base: skosmos-2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion model/Concept.php
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,18 @@ public function getMappingProperties(array $whitelist = null)
continue;
}
}
$ret[$prop]->addValue(new ConceptMappingPropertyValue($this->model, $this->vocab, $val, $this->resource, $prop, $this->clang));

// check if target vocabularly can be found by scheme
$targetVocab = $this->vocab;
foreach ($val->allResources("skos:inScheme") as $targetScheme) {
$schemeVocab = $this->model->getVocabularyByScheme($targetScheme->getUri());
if ($schemeVocab) {
$targetVocab = $schemeVocab;
break;
}
}

$ret[$prop]->addValue(new ConceptMappingPropertyValue($this->model, $targetVocab, $val, $this->resource, $prop, $this->clang));
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions model/GlobalConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,4 +360,12 @@ public function getCollationEnabled()
{
return $this->getBoolean('skosmos:sparqlCollationEnabled', FALSE);
}

/**
* @return boolean
*/
public function getDefaultGraphOnly()
{
return $this->getBoolean('skosmos:defaultGraphOnly', FALSE);
}
}
32 changes: 29 additions & 3 deletions model/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class Model
private $vocabsByGraph = null;
/** cache for Vocabulary objects */
private $vocabsByUriSpace = null;
/** cache for Vocabulary objects */
private $vocabsByScheme = null;
/** how long to store retrieved URI information in APC cache */
const URI_FETCH_TTL = 86400; // 1 day
private $globalConfig;
Expand Down Expand Up @@ -449,6 +451,29 @@ public function getVocabularyByGraph($graph, $endpoint = null)

}

/**
* Return the vocabulary that has the given scheme.
*
* @param $graph string graph URI
* @return Vocabulary vocabulary for this scheme, or null if not found
*/
public function getVocabularyByScheme($scheme)
{
if ($this->vocabsByScheme === null) { // initialize cache
$this->vocabsByScheme = array();
foreach ($this->getVocabularies() as $voc) {
$key = $voc->getDefaultConceptScheme();
$this->vocabsByScheme[$key] = $voc;
}
}

if (array_key_exists($scheme, $this->vocabsByScheme)) {
return $this->vocabsByScheme[$scheme];
} else {
return null;
}
}

/**
* When multiple vocabularies share same URI namespace, return the
* vocabulary in which the URI is actually defined (has a label).
Expand Down Expand Up @@ -585,19 +610,20 @@ public function getResourceFromUri($uri)
* @param string $endpoint url address of endpoint
* @param string|null $graph uri for the target graph.
*/
public function getSparqlImplementation($dialect, $endpoint, $graph)
public function getSparqlImplementation($dialect, $endpoint, $graph, $conceptSchemes=null)
{
$classname = $dialect . "Sparql";

return new $classname($endpoint, $graph, $this);
return new $classname($endpoint, $graph, $this, $conceptSchemes);
}

/**
* Returns a SPARQL endpoint object using the default implementation set in the config.ttl.
*/
public function getDefaultSparql()
{
return $this->getSparqlImplementation($this->getConfig()->getDefaultSparqlDialect(), $this->getConfig()->getDefaultEndpoint(), '?graph');
$graph = !$this->getConfig()->getDefaultGraphOnly() ? '?graph' : null;
return $this->getSparqlImplementation($this->getConfig()->getDefaultSparqlDialect(), $this->getConfig()->getDefaultEndpoint(), $graph);
}

}
3 changes: 2 additions & 1 deletion model/Vocabulary.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ public function getSparql()
$endpoint = $this->getEndpoint();
$graph = $this->getGraph();
$dialect = $this->config->getSparqlDialect() ?? $this->model->getConfig()->getDefaultSparqlDialect();
$conceptSchemes = $this->config->getConceptSchemeURIs() ?? null;

return $this->model->getSparqlImplementation($dialect, $endpoint, $graph);
return $this->model->getSparqlImplementation($dialect, $endpoint, $graph, $conceptSchemes);
}

/**
Expand Down
8 changes: 8 additions & 0 deletions model/VocabularyConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,14 @@ public function getDataURLs()
return $ret;
}

/**
* Returns an array of concept schemes to restrict to using skos:inScheme.
*/
public function getConceptSchemeURIs()
{
return $this->getResources("skosmos:conceptSchemes");
}

/**
* Returns the main Concept Scheme URI of that Vocabulary,
* or null if not set.
Expand Down
Loading