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

Issue #634 : Retrieve and display domains of ConceptScheme at the top of the tree hierarchy #660

Closed
wants to merge 19 commits into from
Closed
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
32 changes: 30 additions & 2 deletions controller/RestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ public function vocabularyInformation($request)
'skos' => 'http://www.w3.org/2004/02/skos/core#',
'onki' => 'http://schema.onki.fi/onki#',
'dct' => 'http://purl.org/dc/terms/',
'dcterms' =>'http://purl.org/dc/terms/',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need to define this prefix? dct is defined on the line above, you can just use that.

'uri' => '@id',
'type' => '@type',
'title' => 'rdfs:label',
Expand All @@ -208,6 +209,7 @@ public function vocabularyInformation($request)
'defaultLanguage' => 'onki:defaultLanguage',
'languages' => 'onki:language',
'label' => 'rdfs:label',
'subject' => 'dcterms:subject',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use dct

'prefLabel' => 'skos:prefLabel',
'title' => 'dct:title',
'@language' => $request->getLang(),
Expand Down Expand Up @@ -254,6 +256,7 @@ public function vocabularyStatistics($request)
'void' => 'http://rdfs.org/ns/void#',
'onki' => 'http://schema.onki.fi/onki#',
'uri' => '@id',
'dcterms' =>'http://purl.org/dc/terms/',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

'id' => 'onki:vocabularyIdentifier',
'concepts' => 'void:classPartition',
'label' => 'rdfs:label',
Expand Down Expand Up @@ -549,6 +552,7 @@ private function returnDataResults($results, $format) {
'dct' => 'http://purl.org/dc/terms/',
'dc11' => 'http://purl.org/dc/elements/1.1/',
'uri' => '@id',
'dcterms' =>'http://purl.org/dc/terms/',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

'type' => '@type',
'lang' => '@language',
'value' => '@value',
Expand Down Expand Up @@ -734,6 +738,29 @@ public function hierarchy($request)
if (empty($results)) {
return $this->returnError('404', 'Not Found', "Could not find concept <{$request->getUri()}>");
}

// set the "top" key from the "tops" key
foreach ($results as $value) {
$uri = $value['uri'];
if (isset($value['tops'])) {
if ($request->getVocab()->getMainConceptScheme() != null) {
foreach ($results[$uri]['tops'] as $top) {
// if a value in 'tops' matches the main concept scheme, take it
if ($top == $request->getVocab()->getMainConceptScheme()) {
$results[$uri]['top'] = $top;
break;
}
}
// if the main concept scheme was not found, set 'top' to the first 'tops' (sorted alphabetically on the URIs)
if (! isset($results[$uri]['top'])) {
$results[$uri]['top'] = $results[$uri]['tops'][0];
}
} else {
// no main concept scheme set on the vocab, take the first value of 'tops' (sorted alphabetically)
$results[$uri]['top'] = $results[$uri]['tops'][0];
}
}
}

if ($request->getVocab()->getConfig()->getShowHierarchy()) {
$schemes = $request->getVocab()->getConceptSchemes($request->getLang());
Expand All @@ -743,12 +770,13 @@ public function hierarchy($request)
}

}

/* encode the results in a JSON-LD compatible array */
$topconcepts = $request->getVocab()->getTopConcepts(array_keys($schemes), $request->getLang());

foreach ($topconcepts as $top) {
if (!isset($results[$top['uri']])) {
$results[$top['uri']] = array('uri' => $top['uri'], 'top' => $top['topConceptOf'], 'prefLabel' => $top['label'], 'hasChildren' => $top['hasChildren']);
$results[$top['uri']] = array('uri' => $top['uri'], 'top'=>$top['topConceptOf'], 'tops'=>array($top['topConceptOf']), 'prefLabel' => $top['label'], 'hasChildren' => $top['hasChildren']);
if (isset($top['notation'])) {
$results[$top['uri']]['notation'] = $top['notation'];
}
Expand Down
Loading