Skip to content

Commit

Permalink
adding notations to the hierarchy rest query and showing those in the…
Browse files Browse the repository at this point in the history
… jstree, related to #264
  • Loading branch information
henriyli committed Sep 21, 2015
1 parent c7e4d4d commit 1772b96
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions controller/RestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,7 @@ public function hierarchy($request)
'uri' => '@id',
'type' => '@type',
'prefLabel' => 'skos:prefLabel',
'notation' => 'skos:notation',
'narrower' => array('@id'=>'skos:narrower','@type'=>'@id'),
'broader' => array('@id'=>'skos:broader','@type'=>'@id'),
'broaderTransitive' => array('@id'=>'skos:broaderTransitive','@container'=>'@index'),
Expand Down
10 changes: 9 additions & 1 deletion model/sparql/GenericSparql.php
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,7 @@ public function queryParentList($uri, $lang, $fallback)
$gc = $this->graphClause;
$query = <<<EOQ
SELECT ?broad ?parent ?member ?children ?grandchildren
(SAMPLE(?lab) as ?label) (SAMPLE(?childlab) as ?childlabel) (SAMPLE(?topcs) AS ?top)
(SAMPLE(?lab) as ?label) (SAMPLE(?childlab) as ?childlabel) (SAMPLE(?topcs) AS ?top) (SAMPLE(?nota) as ?notation) (SAMPLE(?childnota) as ?childnotation)
WHERE {
$gc {
<$uri> a skos:Concept .
Expand All @@ -1103,6 +1103,7 @@ public function queryParentList($uri, $lang, $fallback)
OPTIONAL { # fallback - other language case
?broad skos:prefLabel ?lab .
}
OPTIONAL { ?broad skos:notation ?nota . }
OPTIONAL { ?broad skos:broader ?parent . }
OPTIONAL { ?broad skos:narrower ?children .
OPTIONAL {
Expand All @@ -1116,6 +1117,9 @@ public function queryParentList($uri, $lang, $fallback)
OPTIONAL { # fallback - other language case
?children skos:prefLabel ?childlab .
}
OPTIONAL {
?children skos:notation ?childnota .
}
}
BIND ( EXISTS { ?children skos:narrower ?a . } AS ?grandchildren )
OPTIONAL { ?broad skos:topConceptOf ?topcs . }
Expand Down Expand Up @@ -1155,6 +1159,8 @@ public function queryParentList($uri, $lang, $fallback)
'label' => $label,
'hasChildren' => filter_var($row->grandchildren->getValue(), FILTER_VALIDATE_BOOLEAN),
);
if (isset($row->childnotation))
$child_arr['notation'] = $row->childnotation->getValue();
if(!in_array($child_arr, $ret[$uri]['narrower']))
$ret[$uri]['narrower'][] = $child_arr;
}
Expand All @@ -1164,6 +1170,8 @@ public function queryParentList($uri, $lang, $fallback)
$preflabel .= ' (' . $row->label->getLang() . ')';
$ret[$uri]['prefLabel'] = $preflabel;
}
if (isset($row->notation))
$ret[$uri]['notation'] = $row->notation->getValue();
if (isset($row->parent) && (isset($ret[$uri]['broader']) && !in_array($row->parent->getUri(), $ret[$uri]['broader']))) {
$ret[$uri]['broader'][] = $row->parent->getUri();
} elseif (isset($row->parent) && !isset($ret[$uri]['broader'])) {
Expand Down
1 change: 1 addition & 0 deletions resource/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -1420,6 +1420,7 @@ p.autocomplete-label {

.jstree-default a { white-space:normal !important; height: auto !important; }
.jstree-default li > ins { vertical-align:top; }
.jstree-default a > .tree-notation { color: #333 !important; };

.sidebar-grey .jstree-closed > .jstree-ocl {
background-position: -100px -8px !important;
Expand Down
4 changes: 4 additions & 0 deletions resource/js/hierarchy.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ function createConceptObject(conceptUri, conceptData) {
}
// if we are at a top concepts page we want to highlight that node and mark it as to be initially opened.
if (newNode.uri === $('.uri-input-box').html()) { newNode.li_attr = { class: 'jstree-leaf-proper' }; }
if (conceptData.notation)
newNode.text = '<span class="tree-notation">' + conceptData.notation + '</span> ' + newNode.text;
if (conceptData.narrower) { // filtering out the ones that don't have labels
var childArray = [];
for (var child in conceptData.narrower) {
Expand All @@ -99,6 +101,8 @@ function createConceptObject(conceptUri, conceptData) {
parents: conceptUri,
state: { opened: true }
};
if (conceptData.narrower[child].notation)
childObject.text = '<span class="tree-notation">' + conceptData.narrower[child].notation + '</span> ' + childObject.text;
if (child === $('.uri-input-box').html()) { /* childObject.data.attr.id = 'jstree-leaf-proper'; */ }
// if the childConcept hasn't got any children the state is not needed.
if (hasChildren) {
Expand Down
1 change: 1 addition & 0 deletions tests/GenericSparqlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ public function testQueryParentList()
'uri' => 'http://www.skosmos.skos/test/ta112',
'label' => 'Carp',
'hasChildren' => true,
'notation' => '665'
),
1 => array (
'uri' => 'http://www.skosmos.skos/test/ta117',
Expand Down

0 comments on commit 1772b96

Please sign in to comment.