Skip to content

Commit

Permalink
adding domain in the hierarchy
Browse files Browse the repository at this point in the history
  • Loading branch information
CLARVIE committed Oct 11, 2017
1 parent a687343 commit e6a4b6d
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 13 deletions.
3 changes: 3 additions & 0 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/',
'uri' => '@id',
'type' => '@type',
'title' => 'rdfs:label',
Expand Down Expand Up @@ -254,6 +255,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/',
'id' => 'onki:vocabularyIdentifier',
'concepts' => 'void:classPartition',
'label' => 'rdfs:label',
Expand Down Expand Up @@ -549,6 +551,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/',
'type' => '@type',
'lang' => '@language',
'value' => '@value',
Expand Down
18 changes: 16 additions & 2 deletions model/sparql/GenericSparql.php
Original file line number Diff line number Diff line change
Expand Up @@ -595,9 +595,14 @@ public function queryConceptScheme($conceptscheme) {
private function generateQueryConceptSchemesQuery($lang) {
$fcl = $this->generateFromClause();
$query = <<<EOQ
SELECT ?cs ?label ?preflabel ?title $fcl
SELECT ?cs ?label ?preflabel ?title ?domaine ?domaineLabel $fcl
WHERE {
?cs a skos:ConceptScheme .
OPTIONAL{
?cs dcterms:subject ?domaine.
?domaine skos:prefLabel ?domaineLabel.
FILTER(langMatches(lang(?domaineLabel), '$lang'))
}
OPTIONAL {
?cs rdfs:label ?label .
FILTER(langMatches(lang(?label), '$lang'))
Expand All @@ -612,7 +617,8 @@ private function generateQueryConceptSchemesQuery($lang) {
{ ?cs dc:title ?title }
FILTER(langMatches(lang(?title), '$lang'))
}
} ORDER BY ?cs
}
ORDER BY ?cs
EOQ;
return $query;
}
Expand All @@ -624,7 +630,9 @@ private function generateQueryConceptSchemesQuery($lang) {
*/
private function transformQueryConceptSchemesResults($result) {
$ret = array();

foreach ($result as $row) {

$conceptscheme = array();
if (isset($row->label)) {
$conceptscheme['label'] = $row->label->getValue();
Expand All @@ -637,6 +645,11 @@ private function transformQueryConceptSchemesResults($result) {
if (isset($row->title)) {
$conceptscheme['title'] = $row->title->getValue();
}
//ajout des dcterms:subject et leurs libellés dans le retour json
if(isset($row->domaine)&&isset($row->domaineLabel)){
$conceptscheme['subject']['uri']=$row->domaine->getURI();
$conceptscheme['subject']['prefLabel']=$row->domaineLabel->getValue();
}

$ret[$row->cs->getURI()] = $conceptscheme;
}
Expand Down Expand Up @@ -1061,6 +1074,7 @@ private function transformConceptSearchResult($row, $vocabs, $fields)
$hit['prefLabel'] = $row->label->getValue();
}


if (isset($row->label)) {
$hit['lang'] = $row->label->getLang();
}
Expand Down
84 changes: 73 additions & 11 deletions resource/js/hierarchy.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ function attachTopConceptsToSchemes(schemes, currentNode, parentData) {
return schemes;
}


/*
* For building a parent hierarchy tree from the leaf concept to the ontology/vocabulary root.
* @param {String} uri
Expand All @@ -156,6 +157,7 @@ function buildParentTree(uri, parentData, schemes) {
var loopIndex = 0, // for adding the last concept as a root if no better candidates have been found.
currentNode,
rootArray = (schemes.length > 1) ? schemes : [];
var domains=[];

for(var conceptUri in parentData) {
if (parentData.hasOwnProperty(conceptUri)) {
Expand All @@ -172,6 +174,7 @@ function buildParentTree(uri, parentData, schemes) {
// if there are multiple concept schemes attach the topConcepts to the concept schemes
if (schemes.length > 1 && (parentData[conceptUri].top)) {
schemes = attachTopConceptsToSchemes(schemes, currentNode, parentData);

}
else {
rootArray.push(currentNode);
Expand Down Expand Up @@ -294,20 +297,78 @@ function pickLabelFromScheme(scheme) {

function schemeRoot(schemes) {
var topArray = [];


// Step 1 : find domain list
var domains=[];
for (var i = 0; i < schemes.length; i++) {
var scheme = schemes[i];
var label = pickLabelFromScheme(scheme);
if (label !== '') { // hiding schemes without a label/title
var schemeObject = {
text: label,
a_attr : { "href" : vocab + '/' + lang + '/page/?uri=' + scheme.uri, 'class': 'scheme'},
uri: scheme.uri,
children: true,
state: { opened: false }
};
topArray.push(schemeObject);
if(schemes[i].subject != null) {
var schemeDomain = schemes[i].subject.uri;

// test if domain was already found
var found = false;
for (var k = 0; k < domains.length; k++) {
if(domains[k].uri===schemeDomain){
found = true;
break;
}
}

// if not found, store it in domain list
if(!found) {
domains.push(schemes[i].subject);
}
}
}

// console.log(domains);

// Step 2 : create tree nodes for each domain
for (var i = 0; i < domains.length; i++) {
var theDomain = domains[i];
// Step 2.1 : create domain node without children
var domainObject = {
text: theDomain.prefLabel,
a_attr : { "href" : vocab + '/' + lang + '/page/?uri=' + theDomain.uri, 'class': 'domain'},
uri: theDomain.uri,
children: [],
state: { opened: false }
};

// Step 2.2 : find the concept schemes in this domain and add them as children
for (var k = 0; k < schemes.length; k++) {
var theScheme = schemes[k];
if((theScheme.subject) != null && (theScheme.subject.uri===theDomain.uri)) {
domainObject.children.push(
{
text:theScheme.prefLabel,
a_attr:{ "href" : vocab + '/' + lang + '/page/?uri=' + theScheme.uri, 'class': 'scheme'},
uri: theScheme.uri,
children: true,
state: { opened: false }
}
);
}
}
topArray.push(domainObject);
}

// Step 3 : add the schemes without subjects
for (var k = 0; k < schemes.length; k++) {
var theScheme = schemes[k];
if(theScheme.subject == null) {
topArray.push(
{
text:theScheme.prefLabel,
a_attr:{ "href" : vocab + '/' + lang + '/page/?uri=' + theScheme.uri, 'class': 'scheme'},
uri: theScheme.uri,
children: true,
state: { opened: false }
}
);
}
}

return topArray;
}

Expand All @@ -325,6 +386,7 @@ function addConceptsToScheme(topConcept, childObject, schemes) {
return schemes;
}


function topConceptsToSchemes(topConcepts, schemes) {
var childArray = schemes.length > 1 ? schemes : [];
for (var i in topConcepts) {
Expand Down
56 changes: 56 additions & 0 deletions test-concept-schemes.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
@prefix skos: <http://www.w3.org/2004/02/skos/core#>.
@prefix ex: <http://exemple.fr/>.
@prefix dcterms: <http://purl.org/dc/terms/>.

ex:thesaurus a skos:ConceptScheme ;
skos:prefLabel "The Thesaurus"@en .

ex:mt1 a skos:ConceptScheme ;
skos:prefLabel "Micro-Thesaurus 1"@en ;
dcterms:subject ex:d1 .

ex:mt2 a skos:ConceptScheme ;
skos:prefLabel "Micro-Thesaurus 2"@en ;
dcterms:subject ex:d1 .

ex:mt3 a skos:ConceptScheme ;
skos:prefLabel "Micro-Thesaurus 3"@en ;
dcterms:subject ex:d2 .

### Begin Domains

ex:domains a skos:ConceptScheme ;
skos:prefLabel "Special 'Domains' Concept Scheme"@en .

ex:d1 a skos:Concept ;
skos:inScheme ex:domains ;
skos:topConceptOf ex:domains ;
skos:prefLabel "Domain 1"@en .

ex:d2 a skos:Concept ;
skos:inScheme ex:domains ;
skos:topConceptOf ex:domains ;
skos:prefLabel "Domain 2"@en .

#### End Domains

ex:c1 a skos:Concept ;
skos:prefLabel "Concept 1"@en ;
skos:inScheme ex:thesaurus , ex:mt1 ;
skos:topConceptOf ex:thesaurus , ex:mt1 ;
skos:narrower ex:c1.1 .

ex:c1.1 a skos:Concept ;
skos:prefLabel "Concept 1.1"@en ;
skos:inScheme ex:thesaurus , ex:mt1 ;
skos:broader ex:c1 .

ex:c2 a skos:Concept ;
skos:prefLabel "Concept 2"@en ;
skos:inScheme ex:thesaurus , ex:mt2 ;
skos:topConceptOf ex:thesaurus , ex:mt2 .

ex:c3 a skos:Concept ;
skos:prefLabel "Concept 3"@en ;
skos:inScheme ex:thesaurus , ex:mt3 ;
skos:topConceptOf ex:thesaurus , ex:mt3 .

0 comments on commit e6a4b6d

Please sign in to comment.