Skip to content

Commit

Permalink
Merge pull request #1284 from NatLibFi/issue1254-rest-search-type
Browse files Browse the repository at this point in the history
Only shorten URIs of types in the SKOS namespace in the search results
  • Loading branch information
joelit authored Mar 2, 2022
2 parents 2896c69 + c23e9e5 commit ed4ad1d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
3 changes: 2 additions & 1 deletion model/sparql/GenericSparql.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ private function shortenUri($uri) {
if (!array_key_exists($uri, $this->qnamecache)) {
$res = new EasyRdf\Resource($uri);
$qname = $res->shorten(); // returns null on failure
$this->qnamecache[$uri] = ($qname !== null) ? $qname : $uri;
// only URIs in the SKOS namespace are shortened
$this->qnamecache[$uri] = ($qname !== null && strpos($qname, "skos:") === 0) ? $qname : $uri;
}
return $this->qnamecache[$uri];
}
Expand Down
12 changes: 6 additions & 6 deletions tests/RestControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public function testSearchJsonLd() {
"uri":"http://www.skosmos.skos/test/ta117",
"type":[
"skos:Concept",
"meta:TestClass"
"http://www.skosmos.skos/test-meta/TestClass"
],
"prefLabel":"3D Bass",
"lang":"en",
Expand All @@ -200,7 +200,7 @@ public function testSearchJsonLd() {
"uri":"http://www.skosmos.skos/test/ta116",
"type":[
"skos:Concept",
"meta:TestClass"
"http://www.skosmos.skos/test-meta/TestClass"
],
"prefLabel":"Bass",
"lang":"en",
Expand All @@ -210,7 +210,7 @@ public function testSearchJsonLd() {
"uri":"http://www.skosmos.skos/test/ta122",
"type":[
"skos:Concept",
"meta:TestClass"
"http://www.skosmos.skos/test-meta/TestClass"
],
"prefLabel":"Black sea bass",
"lang":"en",
Expand Down Expand Up @@ -259,7 +259,7 @@ public function testSearchJsonLdWithAdditionalFields() {
"uri":"http://www.skosmos.skos/test/ta117",
"type":[
"skos:Concept",
"meta:TestClass"
"http://www.skosmos.skos/test-meta/TestClass"
],
"broader":[
{
Expand All @@ -279,7 +279,7 @@ public function testSearchJsonLdWithAdditionalFields() {
"uri":"http://www.skosmos.skos/test/ta116",
"type":[
"skos:Concept",
"meta:TestClass"
"http://www.skosmos.skos/test-meta/TestClass"
],
"broader":[
{
Expand All @@ -294,7 +294,7 @@ public function testSearchJsonLdWithAdditionalFields() {
"uri":"http://www.skosmos.skos/test/ta122",
"type":[
"skos:Concept",
"meta:TestClass"
"http://www.skosmos.skos/test-meta/TestClass"
],
"broader":[
{
Expand Down

0 comments on commit ed4ad1d

Please sign in to comment.