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

Issue913 deprecated concepts number #1174

Merged
merged 5 commits into from
Jun 2, 2021
Merged
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
8 changes: 7 additions & 1 deletion controller/RestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ public function vocabularyStatistics($request)
$this->setLanguageProperties($request->getLang());
$arrayClass = $request->getVocab()->getConfig()->getArrayClassURI();
$groupClass = $request->getVocab()->getConfig()->getGroupClassURI();
$vocabStats = $request->getVocab()->getStatistics($request->getQueryParam('lang'), $arrayClass, $groupClass);
$queryLang = $request->getQueryParam('lang') ?? $request->getLang();
$vocabStats = $request->getVocab()->getStatistics($queryLang, $arrayClass, $groupClass);
$types = array('http://www.w3.org/2004/02/skos/core#Concept', 'http://www.w3.org/2004/02/skos/core#Collection', $arrayClass, $groupClass);
$subTypes = array();
foreach ($vocabStats as $subtype) {
Expand Down Expand Up @@ -292,6 +293,7 @@ public function vocabularyStatistics($request)
'class' => 'http://www.w3.org/2004/02/skos/core#Concept',
'label' => gettext('skos:Concept'),
'count' => isset($vocabStats['http://www.w3.org/2004/02/skos/core#Concept']) ? $vocabStats['http://www.w3.org/2004/02/skos/core#Concept']['count'] : 0,
'deprecatedCount' => isset($vocabStats['http://www.w3.org/2004/02/skos/core#Concept']) ? $vocabStats['http://www.w3.org/2004/02/skos/core#Concept']['deprecatedCount'] : 0,
),
'subTypes' => $subTypes,
);
Expand All @@ -301,18 +303,22 @@ public function vocabularyStatistics($request)
'class' => 'http://www.w3.org/2004/02/skos/core#Collection',
'label' => gettext('skos:Collection'),
'count' => $vocabStats['http://www.w3.org/2004/02/skos/core#Collection']['count'],
'deprecatedCount' => $vocabStats['http://www.w3.org/2004/02/skos/core#Collection']['deprecatedCount'],
);

} else if (isset($vocabStats[$groupClass])) {
$ret['conceptGroups'] = array(
'class' => $groupClass,
'label' => isset($vocabStats[$groupClass]['label']) ? $vocabStats[$groupClass]['label'] : gettext(EasyRdf\RdfNamespace::shorten($groupClass)),
'count' => $vocabStats[$groupClass]['count'],
'deprecatedCount' => $vocabStats[$groupClass]['deprecatedCount'],
);
} else if (isset($vocabStats[$arrayClass])) {
$ret['arrays'] = array(
'class' => $arrayClass,
'label' => isset($vocabStats[$arrayClass]['label']) ? $vocabStats[$arrayClass]['label'] : gettext(EasyRdf\RdfNamespace::shorten($arrayClass)),
'count' => $vocabStats[$arrayClass]['count'],
'deprecatedCount' => $vocabStats[$arrayClass]['deprecatedCount'],
);
}

Expand Down
2 changes: 2 additions & 0 deletions model/Vocabulary.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ private function parseVersionInfo($version)
/**
* Counts the statistics of the vocabulary.
* @return Array containing the label counts
* @param string $array the uri of the concept array class, eg. isothes:ThesaurusArray
* @param string $group the uri of the concept group class, eg. isothes:ConceptGroup
*/
public function getStatistics($lang = '', $array=null, $group=null)
{
Expand Down
36 changes: 25 additions & 11 deletions model/sparql/GenericSparql.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,21 @@ private function shortenUri($uri) {
*/
private function generateCountConceptsQuery($array, $group) {
$fcl = $this->generateFromClause();
$optional = $array ? "UNION { ?type rdfs:subClassOf* <$array> }" : '';
$optional .= $group ? "UNION { ?type rdfs:subClassOf* <$group> }" : '';
$optional = $array ? "(<$array>) " : '';
$optional .= $group ? "(<$group>)" : '';
$query = <<<EOQ
SELECT (COUNT(?conc) as ?c) ?type ?typelabel $fcl WHERE {
{ ?conc a ?type .
{ ?type rdfs:subClassOf* skos:Concept . } UNION { ?type rdfs:subClassOf* skos:Collection . } $optional }
OPTIONAL { ?type rdfs:label ?typelabel . }
}
GROUP BY ?type ?typelabel
SELECT (COUNT(DISTINCT(?conc)) as ?c) ?type ?typelabel (COUNT(?depr) as ?deprcount) $fcl WHERE {
VALUES (?value) { (skos:Concept) (skos:Collection) $optional }
?type rdfs:subClassOf* ?value
{ ?type ^a ?conc .
OPTIONAL { ?conc owl:deprecated ?depr .
FILTER (?depr = True)
}
} UNION {SELECT * WHERE {
?type rdfs:label ?typelabel
}
}
} GROUP BY ?type ?typelabel
EOQ;
return $query;
}
Expand All @@ -203,10 +209,16 @@ private function transformCountConceptsResults($result, $lang) {
if (!isset($row->type)) {
continue;
}
$ret[$row->type->getUri()]['type'] = $row->type->getUri();
$ret[$row->type->getUri()]['count'] = $row->c->getValue();
$typeURI = $row->type->getUri();
$ret[$typeURI]['type'] = $typeURI;

if (!isset($row->typelabel)) {
$ret[$typeURI]['count'] = $row->c->getValue();
$ret[$typeURI]['deprecatedCount'] = $row->deprcount->getValue();
}

if (isset($row->typelabel) && $row->typelabel->getLang() === $lang) {
$ret[$row->type->getUri()]['label'] = $row->typelabel->getValue();
$ret[$typeURI]['label'] = $row->typelabel->getValue();
}

}
Expand All @@ -216,6 +228,8 @@ private function transformCountConceptsResults($result, $lang) {
/**
* Used for counting number of concepts and collections in a vocabulary.
* @param string $lang language of labels
* @param string $array the uri of the concept array class, eg. isothes:ThesaurusArray
* @param string $group the uri of the concept group class, eg. isothes:ConceptGroup
* @return array with number of concepts in this vocabulary per label
*/
public function countConcepts($lang = null, $array = null, $group = null) {
Expand Down
3 changes: 2 additions & 1 deletion resource/js/docready.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ $(function() { // DOCUMENT READY
$.ajax({
url : rest_base_url + vocab + '/vocabularyStatistics',
req_kind: $.ajaxQ.requestKind.GLOBAL,
data: $.param({'lang' : content_lang}),
data: $.param({'lang' : lang}),
success : function(data) {
var $spinner = $('#counts tr:nth-of-type(2)');
var typeStats = '<tr><td class="count-type versal">' + data.concepts.label + '</td><td class="versal">' + data.concepts.count +'</td></tr>';
Expand All @@ -212,6 +212,7 @@ $(function() { // DOCUMENT READY
var label = sub.label ? sub.label : sub.type;
typeStats += '<tr><td class="count-type versal">&nbsp;&bull;&nbsp;' + label + '</td><td class="versal">' + sub.count + '</td></tr>';
}
typeStats += '<tr><td class="count-type versal">&nbsp;&bull;&nbsp;' + depr_trans + '</td><td class="versal">' + data.concepts.deprecatedCount + '</td></tr>';
if (data.conceptGroups) {
typeStats += '<tr><td class="count-type versal">' + data.conceptGroups.label + '</td><td class="versal">' + data.conceptGroups.count +'</td></tr>';
}
Expand Down
Binary file modified resource/translations/en/LC_MESSAGES/skosmos.mo
Binary file not shown.
Binary file modified resource/translations/fi/LC_MESSAGES/skosmos.mo
Binary file not shown.
3 changes: 3 additions & 0 deletions resource/translations/skosmos_en.po
Original file line number Diff line number Diff line change
Expand Up @@ -851,3 +851,6 @@ msgstr "You can select a vocabulary"

msgid "We're sorry but Skosmos doesn't work properly without JavaScript enabled. Please enable it to continue."
msgstr "We're sorry but Skosmos doesn't work properly without JavaScript enabled. Please enable it to continue."

msgid "Deprecated concept"
msgstr "Deprecated concept"
3 changes: 3 additions & 0 deletions resource/translations/skosmos_fi.po
Original file line number Diff line number Diff line change
Expand Up @@ -850,3 +850,6 @@ msgstr "Voit valita halutessasi sanaston"

msgid "We're sorry but Skosmos doesn't work properly without JavaScript enabled. Please enable it to continue."
msgstr "Pahoittelut, mutta Skosmos ei toimi kunnolla ilman JavaScript-tukea. Ole hyvä ja ota se käyttöön."

msgid "Deprecated concept"
msgstr "Käytöstä poistettu käsite"
3 changes: 3 additions & 0 deletions resource/translations/skosmos_sv.po
Original file line number Diff line number Diff line change
Expand Up @@ -848,3 +848,6 @@ msgstr "Du kan välja en vokabulär"

msgid "We're sorry but Skosmos doesn't work properly without JavaScript enabled. Please enable it to continue."
msgstr "Vi beklagar, men Skosmos fungerar inte ordentligt utan JavaScript-stöd. Var god och aktivera JavaScript för att fortsätta."

msgid "Deprecated concept"
msgstr "Raderat begrepp"
Binary file modified resource/translations/sv/LC_MESSAGES/skosmos.mo
Binary file not shown.
16 changes: 14 additions & 2 deletions swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1742,11 +1742,17 @@
"description": "Label of the class"
},
"count": {
"type": "integer"
"type": "integer",
"description": "Total number of concepts"
},
"deprecatedCount": {
"type": "integer",
"description": "Number of deprecated concepts"
}
},
"required": [
"count",
"deprecatedCount",
"class"
]
},
Expand All @@ -1762,11 +1768,17 @@
"description": "Label of the type"
},
"count": {
"type": "integer"
"type": "integer",
"description": "Total number of concepts by type"
},
"deprecatedCount": {
"type": "integer",
"description": "Number of deprecated concepts by type"
}
},
"required": [
"count",
"deprecatedCount",
"type"
]
},
Expand Down
13 changes: 13 additions & 0 deletions tests/GenericSparqlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@ public function testCountConcepts() {
$this->assertEquals(17, $actual['http://www.w3.org/2004/02/skos/core#Concept']['count']);
}

/**
* @covers GenericSparql::countConcepts
* @covers GenericSparql::generateCountConceptsQuery
* @covers GenericSparql::transformCountConceptsResults
*/
public function testTransformCountConceptsResults() {
$result = $this->sparql->countConcepts();

$this->assertEquals(13, $result['http://www.skosmos.skos/test-meta/TestClass']['count']);
$this->assertEquals(1, $result['http://www.skosmos.skos/test-meta/TestClass']['deprecatedCount']);
$this->assertEquals('http://www.skosmos.skos/test-meta/TestClass', $result['http://www.skosmos.skos/test-meta/TestClass']['type']);
}

/**
* @covers GenericSparql::countLangConcepts
* @covers GenericSparql::generateCountLangConceptsQuery
Expand Down
55 changes: 55 additions & 0 deletions tests/RestControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -422,4 +422,59 @@ public function testModifiedConcepts() {
$this->assertJsonStringEqualsJsonString($changeList, $expected);

}

/**
* @covers RestController::vocabularyStatistics
*/
public function testVocabularyStatistics() {
$request = new Request($this->model);
$request->setVocab('test');
$request->setLang('en');

$this->controller->vocabularyStatistics($request);
$statistics = $this->getActualOutput();
$expected = <<<EOD
{
"@context": {
"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
"skos": "http://www.w3.org/2004/02/skos/core#",
"void": "http://rdfs.org/ns/void#",
"onki": "http://schema.onki.fi/onki#",
"uri": "@id",
"id": "onki:vocabularyIdentifier",
"concepts": "void:classPartition",
"label": "rdfs:label",
"class": {
"@id": "void:class",
"@type": "@id"
},
"subTypes": {
"@id": "void:class",
"@type": "@id"
},
"count": "void:entities",
"@language": "en",
"@base": "http://tests.localhost/Skosmos/rest/v1/test/"
},
"uri": "",
"id": "test",
"title": "Test ontology",
"concepts": {
"class": "http://www.w3.org/2004/02/skos/core#Concept",
"label": "Concept",
"count": 17,
"deprecatedCount": 1
},
"subTypes": [
{
"type": "http://www.skosmos.skos/test-meta/TestClass",
"count": 13,
"deprecatedCount": 1,
"label": "Test class"
}
]
}
EOD;
$this->assertJsonStringEqualsJsonString($statistics, $expected);
}
}
3 changes: 3 additions & 0 deletions tests/VocabularyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ public function testGetStatistics() {
$vocab = $this->model->getVocabulary('test');
$stats = $vocab->getStatistics();
$this->assertEquals(17, $stats['http://www.w3.org/2004/02/skos/core#Concept']['count']);
$this->assertEquals(1, $stats['http://www.w3.org/2004/02/skos/core#Concept']['deprecatedCount']);
$this->assertEquals(13, $stats['http://www.skosmos.skos/test-meta/TestClass']['count']);
$this->assertEquals(1, $stats['http://www.skosmos.skos/test-meta/TestClass']['deprecatedCount']);
}

/**
Expand Down
1 change: 1 addition & 0 deletions view/scripts.twig
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var missing_value = "{% trans %}Value is required and can not be empty{% endtran
var expand_paths = "{% trans %}show all # paths{% endtrans %}";
var expand_propvals = "{% trans %}show all # values{% endtrans %}";
var hiertrans = "{% trans "Hier-nav" %}";
var depr_trans = "{% trans %}Deprecated concept{% endtrans %}";
var sr_only_translations = {
hierarchy_listing: "{% trans "Hierarchical listing of vocabulary concepts" %}",
groups_listing: "{% trans "Hierarchical listing of vocabulary concepts and groupings" %}",
Expand Down