Skip to content

Commit

Permalink
making it possible to classify vocabularies by type, fixes #458
Browse files Browse the repository at this point in the history
  • Loading branch information
henriyli committed Jun 6, 2016
1 parent baf2931 commit 15c8067
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 2 deletions.
4 changes: 4 additions & 0 deletions controller/RestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ public function vocabularyInformation($request)
'languages' => array_values($vocab->getConfig()->getLanguages()),
'conceptschemes' => $conceptschemes,
);

if ($vocab->getConfig()->getTypes($request->getLang())) {
$ret['type'] = $vocab->getConfig()->getTypes($request->getLang());
}

return $this->returnJson($ret);
}
Expand Down
16 changes: 16 additions & 0 deletions model/VocabularyConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -405,4 +405,20 @@ public function showAlphabeticalIndex()
{
return $this->getBoolean('skosmos:showAlphabeticalIndex', true);
}

/**
* Returns the vocabulary dc:type value(s) with their labels and uris, if set in the vocabulary configuration.
* @return array of objects or an empty array
*/
public function getTypes($lang = null)
{
$resources = $this->resource->allResources("dc:type");
$ret = array();
foreach ($resources as $res) {
$prop = $res->getURI();
$label = $res->label($lang) ? $res->label($lang) : $res->label($this->getDefaultLanguage());
$ret[] = array('uri' => $prop, 'prefLabel' => $label->getValue());
}
return $ret;
}
}
16 changes: 16 additions & 0 deletions tests/VocabularyConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,20 @@ public function testGetHierarchyProperty() {
$vocab = $this->model->getVocabulary('testdiff');
$this->assertEquals(array('isothes:broaderGeneric'), $vocab->getConfig()->getHierarchyProperty());
}

/**
* @covers VocabularyConfig::getTypes
*/
public function testGetTypes() {
$vocab = $this->model->getVocabulary('test');
$this->assertEquals(array(0 => array('uri' => 'http://publications.europa.eu/resource/authority/dataset-type/ONTOLOGY', 'prefLabel' => 'Ontology')), $vocab->getConfig()->getTypes('en'));
}

/**
* @covers VocabularyConfig::getTypes
*/
public function testGetTypesWhenNotSet() {
$vocab = $this->model->getVocabulary('testdiff');
$this->assertEquals(array(), $vocab->getConfig()->getTypes('en'));
}
}
8 changes: 8 additions & 0 deletions tests/testvocabularies.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
@prefix isothes: <http://purl.org/iso25964/skos-thes#>.
@prefix meta: <http://www.skosmos.skos/test-meta/> .
@prefix my: <http://example.com/myns#> .
@prefix mdrtype: <http://publications.europa.eu/resource/authority/dataset-type/> .
@prefix : <#> .


:test a skosmos:Vocabulary, void:Dataset ;
dc:title "Test ontology"@en ;
dc:subject :cat_science ;
dc:type mdrtype:ONTOLOGY ;
void:dataDump <http://skosmos.skos/dump/test/> ;
void:sparqlEndpoint <http://localhost:3030/ds/sparql> ;
void:uriSpace "http://www.skosmos.skos/test/";
Expand Down Expand Up @@ -141,3 +143,9 @@
"Naturvetenskap och medicin"@sv,
"Science and medicine"@en .

mdrtype:THESAURUS a skos:Concept ;
skos:prefLabel "Тезаурус"@bg, "Tezaurus"@cs, "Tesaurus"@da, "Thesaurus"@de, "Θησαυρός"@el, "Thesaurus"@en, "Tesaurus"@et, "Tesaurus"@fi, "Thésaurus"@fr, "Pojmovnik"@hr, "Tezaurusz"@hu, "Tesauro"@it, "Tēzaurs"@lv, "Tezauras"@lt, "Teżawru"@mt, "Thesaurus"@nl, "Tesaurus"@no, "Tezaurus"@pl, "Tesauro"@pt, "Tezaur"@ro, "Synonymický slovník"@sk, "Tezaver"@sl, "Tesauro"@es, "Tesaurus"@sv .

mdrtype:ONTOLOGY a skos:Concept ;
skos:prefLabel "Онтология"@bg, "Ontologie"@cs, "Ontologi"@da, "Ontologie"@de, "Οντολογία"@el, "Ontology"@en, "Ontoloogia"@et, "Ontologia"@fi, "Ontologie"@fr, "Ontologija"@hr, "Ontológia"@hu, "Ontologia"@it, "Ontoloģija"@lv, "Ontologija"@lt, "Ontoloġija"@mt, "Ontologie"@nl, "Ontologi"@no, "Struktura pojęciowa"@pl, "Ontologia"@pt, "Ontologie"@ro, "Ontológia"@sk, "Ontologija"@sl, "Ontología"@es, "Ontologi"@sv .

12 changes: 10 additions & 2 deletions vocabularies.ttl.dist
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
@prefix skosmos: <http://purl.org/net/skosmos#> .
@prefix isothes: <http://purl.org/iso25964/skos-thes#> .
@prefix mdrtype: <http://publications.europa.eu/resource/authority/dataset-type/> .
@prefix : <#> .


:ysa a skosmos:Vocabulary, void:Dataset ;
dc:title "YSA - Yleinen suomalainen asiasanasto"@fi,
"YSA - Allmän tesaurus på finska"@sv,
"YSA - General Finnish thesaurus"@en ;
dc:subject :cat_general ;
dc:type mdrtype:THESAURUS ;
void:uriSpace "http://www.yso.fi/onto/ysa/";
skosmos:groupClass skos:Collection;
skosmos:language "fi";
Expand All @@ -33,6 +34,7 @@
"ALLFO - Allmän finländsk ontologi"@sv,
"YSO - General Finnish ontology"@en ;
dc:subject :cat_general ;
dc:type mdrtype:ONTOLOGY ;
void:uriSpace "http://www.yso.fi/onto/yso/";
skosmos:language "fi", "sv", "en";
skosmos:defaultLanguage "fi";
Expand All @@ -48,7 +50,6 @@
skosmos:sparqlGraph <http://www.yso.fi/onto/yso/> ;
skosmos:mainConceptScheme <http://www.yso.fi/onto/yso/> .


:categories a skos:ConceptScheme;
skos:prefLabel "Skosmos Vocabulary Categories"@en .

Expand All @@ -58,3 +59,10 @@
skos:prefLabel "Yleiskäsitteet"@fi,
"Allmänna begrepp"@sv,
"General concepts"@en .

mdrtype:THESAURUS a skos:Concept ;
skos:prefLabel "Тезаурус"@bg, "Tezaurus"@cs, "Tesaurus"@da, "Thesaurus"@de, "Θησαυρός"@el, "Thesaurus"@en, "Tesaurus"@et, "Tesaurus"@fi, "Thésaurus"@fr, "Pojmovnik"@hr, "Tezaurusz"@hu, "Tesauro"@it, "Tēzaurs"@lv, "Tezauras"@lt, "Teżawru"@mt, "Thesaurus"@nl, "Tesaurus"@no, "Tezaurus"@pl, "Tesauro"@pt, "Tezaur"@ro, "Synonymický slovník"@sk, "Tezaver"@sl, "Tesauro"@es, "Tesaurus"@sv .

mdrtype:ONTOLOGY a skos:Concept ;
skos:prefLabel "Онтология"@bg, "Ontologie"@cs, "Ontologi"@da, "Ontologie"@de, "Οντολογία"@el, "Ontology"@en, "Ontoloogia"@et, "Ontologia"@fi, "Ontologie"@fr, "Ontologija"@hr, "Ontológia"@hu, "Ontologia"@it, "Ontoloģija"@lv, "Ontologija"@lt, "Ontoloġija"@mt, "Ontologie"@nl, "Ontologi"@no, "Struktura pojęciowa"@pl, "Ontologia"@pt, "Ontologie"@ro, "Ontológia"@sk, "Ontologija"@sl, "Ontología"@es, "Ontologi"@sv .

0 comments on commit 15c8067

Please sign in to comment.