Skip to content

Commit

Permalink
Merge pull request #1198 from NatLibFi/issue1087-displaying-skos-nota…
Browse files Browse the repository at this point in the history
…tion-with-data-type-in-ui

Displaying skos notation with a data type and label in the properties on the concept page
  • Loading branch information
miguelvaara authored Sep 16, 2021
2 parents 794bd18 + aff26b4 commit 9db5409
Show file tree
Hide file tree
Showing 17 changed files with 134 additions and 11 deletions.
9 changes: 7 additions & 2 deletions model/Concept.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Concept extends VocabularyDataObject implements Modifiable
/** the EasyRdf\Graph object of the concept */
private $graph;
private $clang;
private $deleted;

/** concept properties that should not be shown to users */
private $DELETED_PROPERTIES = array(
Expand Down Expand Up @@ -78,8 +79,13 @@ class Concept extends VocabularyDataObject implements Modifiable
public function __construct($model, $vocab, $resource, $graph, $clang)
{
parent::__construct($model, $vocab, $resource);
$this->deleted = $this->DELETED_PROPERTIES;
if ($vocab !== null) {
$this->order = $vocab->getConfig()->getPropertyOrder();
// delete notations unless configured to show them
if (!$vocab->getConfig()->getShowNotationAsProperty()) {
$this->deleted[] = 'skos:notation';
}
} else {
$this->order = VocabularyConfig::DEFAULT_PROPERTY_ORDER;
}
Expand Down Expand Up @@ -508,7 +514,7 @@ public function getProperties()
$sprop = "<$prop>";
}

if (!in_array($prop, $this->DELETED_PROPERTIES) || ($this->isGroup() === false && $prop === 'skos:member')) {
if (!in_array($prop, $this->deleted) || ($this->isGroup() === false && $prop === 'skos:member')) {
// retrieve property label and super properties from the current vocabulary first
$propres = new EasyRdf\Resource($prop, $this->graph);
$proplabel = $propres->label($this->getEnvLang()) ? $propres->label($this->getEnvLang()) : $propres->label();
Expand Down Expand Up @@ -581,7 +587,6 @@ public function getProperties()
if (isset($ret[$prop]) && ($literal->getLang() === $this->clang || $literal->getLang() === null) || $this->vocab->getConfig()->hasMultiLingualProperty($prop)) {
$ret[$prop]->addValue($literal);
}

}

// Iterating through every resource and adding these to the data object.
Expand Down
22 changes: 21 additions & 1 deletion model/ConceptPropertyValueLiteral.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ class ConceptPropertyValueLiteral extends VocabularyDataObject
private $literal;
/** property type */
private $type;
/** content language */
private $clang;

public function __construct($model, $vocab, $resource, $literal, $prop)
public function __construct($model, $vocab, $resource, $literal, $prop, $clang = '')
{
parent::__construct($model, $vocab, $resource);
$this->literal = $literal;
$this->type = $prop;
$this->clang = $clang;
}

public function __toString()
Expand All @@ -31,6 +34,23 @@ public function getLang()
return $this->literal->getLang();
}

/**
* A method for fetching a datatype.
*/
public function getDatatype(): ?string
{
$datatype = $this->literal->getDatatype();
if ($datatype === null) {
return null;
}
$graph = $this->resource->getGraph();
if ($graph->resource($datatype)->label($this->clang)) {
$dtLabel = $graph->resource($datatype)->label($this->clang);
return $dtLabel->getValue();
}
return "";
}

public function getType()
{
return $this->type;
Expand Down
9 changes: 9 additions & 0 deletions model/VocabularyConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,15 @@ public function getMarcSourceCode($lang = null)
return $this->getLiteral('skosmos:marcSourceCode', false, $lang);
}

/**
* Returns the boolean value of the skosmos:showNotationAsProperty setting.
* @return boolean
*/
public function getShowNotationAsProperty()
{
return $this->getBoolean('skosmos:showNotationAsProperty', true);
}

/**
* Returns a boolean value set in the config.ttl config.
* @return array array of concept class URIs (can be empty)
Expand Down
7 changes: 7 additions & 0 deletions model/sparql/GenericSparql.php
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ private function generateConceptInfoQuery($uris, $arrayClass, $vocabs) {
?o skos:notation ?on .
?o ?oprop ?oval .
?o ?xlprop ?xlval .
?dt rdfs:label ?dtlabel .
?directgroup skos:member ?uri .
?parent skos:member ?group .
?group skos:prefLabel ?grouplabel .
Expand Down Expand Up @@ -429,6 +430,12 @@ private function generateConceptInfoQuery($uris, $arrayClass, $vocabs) {
UNION
{
?uri ?p ?o .
OPTIONAL {
FILTER(?p = skos:notation)
FILTER(isLiteral(?o))
BIND(datatype(?o) AS ?dt)
?dt rdfs:label ?dtlabel
}
OPTIONAL {
?o rdf:rest* ?b1 .
?b1 rdf:first ?item .
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.
6 changes: 6 additions & 0 deletions resource/translations/skosmos_en.po
Original file line number Diff line number Diff line change
Expand Up @@ -866,3 +866,9 @@ msgstr "Error: Loading more items failed!"

msgid "Retry"
msgstr "Retry"

msgid "skos:notation"
msgstr "Notation"

msgid "skos:notation_help"
msgstr "Code that uniquely identifies a concept within a concept scheme."
6 changes: 6 additions & 0 deletions resource/translations/skosmos_fi.po
Original file line number Diff line number Diff line change
Expand Up @@ -865,3 +865,9 @@ msgstr "Virhe: Lisätulosten haku epäonnistui!"

msgid "Retry"
msgstr "Yritä uudelleen"

msgid "skos:notation"
msgstr "Notaatio"

msgid "skos:notation_help"
msgstr "Tunniste, joka yksilöi käsitteen sanaston sisällä."
6 changes: 6 additions & 0 deletions resource/translations/skosmos_sv.po
Original file line number Diff line number Diff line change
Expand Up @@ -863,3 +863,9 @@ msgstr "Fel: Flera resultat kunde inte hämtas!"

msgid "Retry"
msgstr "Försök igen"

msgid "skos:notation"
msgstr "Notation"

msgid "skos:notation_help"
msgstr "Kod som unikt identifierar ett begrepp i en vokabulär."
Binary file modified resource/translations/sv/LC_MESSAGES/skosmos.mo
Binary file not shown.
33 changes: 33 additions & 0 deletions tests/ConceptPropertyValueLiteralTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,39 @@ public function testGetLabelThatIsABrokenDate() {
$propvals = $props['http://www.skosmos.skos/date/ownDate']->getValues();
}

/**
* @covers ConceptPropertyValueLiteral::getLabel
*/
public function testGetLabelForDatatype() {
$vocab = $this->model->getVocabulary('test');
$concepts = $vocab->getConceptInfo('http://www.skosmos.skos/test/ta112', 'en');
$props = $concepts[0]->getProperties();
$propvals = $props['skos:notation']->getValues();
$this->assertEquals('NameOfTheDatatype', $propvals['665']->getDatatype());
}

/**
* @covers ConceptPropertyValueLiteral::getLabel
*/
public function testGetNotationDatatypeWithoutLabel() {
$vocab = $this->model->getVocabulary('test');
$concepts = $vocab->getConceptInfo('http://www.skosmos.skos/test/ta128', 'en');
$props = $concepts[0]->getProperties();
$propvals = $props['skos:notation']->getValues();
$this->assertEquals('', $propvals['testnotation']->getDatatype());
}

/**
* @covers ConceptPropertyValueLiteral::getLabel
*/
public function testGetLabelForDatatypeIfNull() {
$vocab = $this->model->getVocabulary('test');
$concepts = $vocab->getConceptInfo('http://www.skosmos.skos/test/ta126', 'en');
$props = $concepts[0]->getProperties();
$propvals = $props['skos:notation']->getValues();
$this->assertNull($propvals['12.34']->getDatatype());
}

/**
* @covers ConceptPropertyValueLiteral::getLang
*/
Expand Down
6 changes: 4 additions & 2 deletions tests/ConceptTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public function testGetPropertiesCorrectNumberOfProperties()
{
$props = $this->concept->getProperties();

$this->assertEquals(8, sizeof($props));
$this->assertEquals(9, sizeof($props));
}

/**
Expand All @@ -189,7 +189,9 @@ public function testGetPropertiesCorrectNumberOfProperties()
public function testGetPropertiesCorrectOrderOfProperties()
{
$props = $this->concept->getProperties();
$expected = array (0 => 'rdf:type', 1 => 'skos:broader', 2 => 'skos:narrower', 3 => 'skos:altLabel', 4 => 'skos:scopeNote', 5 => 'http://www.skosmos.skos/multiLingOff', 6 => 'http://www.skosmos.skos/multiLingOn', 7 => 'http://www.skosmos.skos/testprop');
$expected = array (0 => 'rdf:type', 1 => 'skos:broader', 2 => 'skos:narrower', 3 => 'skos:altLabel',
4 => 'skos:scopeNote', 5 => 'http://www.skosmos.skos/multiLingOff', 6 => 'http://www.skosmos.skos/multiLingOn',
7 => 'http://www.skosmos.skos/testprop', 8 => 'skos:notation');
$this->assertEquals($expected, array_keys($props));

}
Expand Down
2 changes: 1 addition & 1 deletion tests/GenericSparqlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function testGetGraph() {
*/
public function testCountConcepts() {
$actual = $this->sparql->countConcepts();
$this->assertEquals(17, $actual['http://www.w3.org/2004/02/skos/core#Concept']['count']);
$this->assertEquals(18, $actual['http://www.w3.org/2004/02/skos/core#Concept']['count']);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/RestControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ public function testVocabularyStatistics() {
"concepts": {
"class": "http://www.w3.org/2004/02/skos/core#Concept",
"label": "Concept",
"count": 17,
"count": 18,
"deprecatedCount": 1
},
"subTypes": [
Expand Down
2 changes: 1 addition & 1 deletion tests/VocabularyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public function testGetLabelStatistics() {
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(18, $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
12 changes: 11 additions & 1 deletion tests/test-vocab-data/test.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,14 @@ test:ta111 a skos:Concept, meta:TestClass ;
owl:deprecated true ;
skos:prefLabel "Tuna"@en .

test:dt a rdfs:Datatype ;
rdfs:label "NameOfTheDatatype" .

test:dt2 a rdfs:Datatype .

test:ta112 a skos:Concept, meta:TestClass ;
skosmos:testprop "Test property value" ;
skos:notation "665" ;
skos:notation "665"^^test:dt ;
skos:broader test:ta1 ;
skos:narrower test:ta121 ;
skos:exactMatch test:ta118 ;
Expand Down Expand Up @@ -155,6 +160,11 @@ test:ta127
"Finnish before Swedish in result array"@sv,
"No language tag becomes very first in result language array" .

test:ta128
a mads:Geographic, skos:Concept ;
skos:notation "testnotation"^^test:dt2 ;
skos:prefLabel "Europa2"@nb .

test:ta1 a skos:Concept, meta:TestClass ;
skos:inScheme test:conceptscheme ;
skos:narrower test:ta111,
Expand Down
23 changes: 21 additions & 2 deletions view/concept-shared.twig
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<h3 class="versal">{% set subPrefLabelTranslation = concept.preferredSubpropertyLabelTranslation(request.lang) %}{% if subPrefLabelTranslation %}{{ subPrefLabelTranslation|upper }}{% else %}{{ 'skos:prefLabel'|trans|upper }}{% endif %}</h3>
</div>
{% if concept.foundBy %} {# hit has been found through an alternative label #}
<span class="versal">{{ concept.foundBy }} >></span>
<span class="versal">{{ concept.foundBy }} ></span>
{% if concept.ExVocab is defined %}
<span class="prefLabel conceptlabel redirected-vocab-id"> @{{ concept.ExVocab }}</span>
{% endif %}
Expand Down Expand Up @@ -85,6 +85,7 @@
<div class="col-md-12"><div class="preflabel-spacer"></div></div>
</div>
{% endspaceless %}

{% for property in concept.properties %} {# loop through ConceptProperty objects #}
{% if property.getSubPropertyOf != 'skos:hiddenLabel' %}
<div class="row{% if property.type == 'dc:isReplacedBy' %} replaced-by{% endif%} property prop-{{property.ID}}">
Expand Down Expand Up @@ -127,7 +128,25 @@
{% endif %}
{% elseif property.type == 'rdf:type' %}<p>{{ propval.label|trans }}</p>
{% else %} {# Literals (no URI), eg. alternative labels as properties #}
{% if propval.lang == request.contentLang or propval.lang == null or not request.contentLang and propval.lang == request.lang %}{% if propval.hasXlProperties %}<span class="reified-property-value xl-label"><img src="resource/pics/about.png"></span><div class="reified-tooltip">{% for key, val in propval.getXlProperties %}{% if key != 'rdf:type' and key != 'skosxl:literalForm' and val != '' %}<p>{{ key|trans }}: <span class="versal">{{ val }}</span></p>{% endif %}{% endfor %}</div>{% endif %}<span{% if property.type == 'skos:altLabel' %} class="replaced"{% endif %}>{% if propval.containsHtml %}{{ propval.label|raw }}{% else %}{{ propval.label }}{% endif %}{% if propval.lang and (request.contentLang and propval.lang != request.contentLang or explicit_langcodes) %} ({{ propval.lang }}){% endif %}</span>
{% if propval.lang == request.contentLang or propval.lang == null or not request.contentLang and propval.lang == request.lang %}
{% if propval.hasXlProperties %}
<span class="reified-property-value xl-label">
<img src="resource/pics/about.png">
</span>
<div class="reified-tooltip">
{% for key, val in propval.getXlProperties %}
{% if key != 'rdf:type' and key != 'skosxl:literalForm' and val != '' %}
<p>{{ key|trans }}:<span class="versal">{{ val }}</span></p>
{% endif %}
{% endfor %}
</div>
{% endif %}
<span>
{% if property.type == 'skos:altLabel' %} class="replaced"{% endif %}
{% if propval.containsHtml %}{{ propval.label|raw }}{% else %}{{ propval.label }}{% endif %}
{% if propval.lang and (request.contentLang and propval.lang != request.contentLang or explicit_langcodes) %}({{ propval.lang }}){% endif %}
{% if propval.datatype %} ({{ propval.datatype }}){% endif %}
</span>
{% endif %}
{% endif %}
</li>
Expand Down

0 comments on commit 9db5409

Please sign in to comment.