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

Custom labels and tooltips for properties in concept view #1244

Merged
merged 6 commits into from
Nov 11, 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
5 changes: 4 additions & 1 deletion controller/WebController.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ public function invokeVocabularyConcept(Request $request)
if ($this->notModified($results[0])) {
return;
}
$customLabels = $vocab->getConfig()->getPropertyLabelOverrides();

$pluginParameters = json_encode($vocab->getConfig()->getPluginParameters());
$template = (in_array('skos:Concept', $results[0]->getType()) || in_array('skos:ConceptScheme', $results[0]->getType())) ? $this->twig->loadTemplate('concept-info.twig') : $this->twig->loadTemplate('group-contents.twig');

Expand All @@ -191,7 +193,8 @@ public function invokeVocabularyConcept(Request $request)
'bread_crumbs' => $crumbs['breadcrumbs'],
'combined' => $crumbs['combined'],
'request' => $request,
'plugin_params' => $pluginParameters)
'plugin_params' => $pluginParameters,
'custom_labels' => $customLabels)
);
}

Expand Down
51 changes: 50 additions & 1 deletion model/VocabularyConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class VocabularyConfig extends BaseConfig
private $pluginRegister;
private $pluginParameters = array();
private $languageOrderCache = array();
private $labelOverrides = array();

const DEFAULT_PROPERTY_ORDER = array("rdf:type", "dc:isReplacedBy",
"skos:definition", "skos:broader", "isothes:broaderGeneric",
Expand All @@ -33,6 +34,7 @@ public function __construct($resource, $globalPlugins=array())
$this->resource = $resource;
$this->globalPlugins = $globalPlugins;
$this->setParameterizedPlugins();
$this->setPropertyLabelOverrides();
$pluginArray = $this->getPluginArray();
$this->pluginRegister = new PluginRegister($pluginArray);
}
Expand Down Expand Up @@ -71,7 +73,6 @@ public function getPluginArray() : array

/**
* Sets array of parameterized plugins
* @param Easyrdf\Resource $pluginResource
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't relevant to the PR, but OK, it's a valid docstring fix.

* @return void
*/
private function setParameterizedPlugins() : void
Expand Down Expand Up @@ -123,6 +124,46 @@ private function setPluginParameters(Easyrdf\Resource $pluginResource) : void
}
}

/**
* Sets array of configured property label overrides
* @return void
*/
private function setPropertyLabelOverrides() : void
{
$this->labelOverrides = array();
$overrides = $this->resource->allResources('skosmos:propertyLabelOverride');
if (!empty($overrides)) {
foreach ($overrides as $override) {
$this->setLabelOverride($override);
}
}
}

/**
* Updates array of label overrides by adding a new override from the configuration file
* @param Easyrdf\Resource $labelOverride
* @return void
*/
private function setLabelOverride(Easyrdf\Resource $override) : void
{
$labelProperty = $override->getResource('skosmos:property');
$labelPropUri = $labelProperty->shorten();
if (empty($this->labelOverrides[$labelPropUri])) {
$this->labelOverrides[$labelPropUri] = array();
}
$newOverrides = array();

$labels = $override->allLiterals('rdfs:label'); //property label overrides
foreach ($labels as $label) {
$newOverrides['label'][$label->getLang()] = $label->getValue();
}
$descriptions = $override->allLiterals('rdfs:comment'); //optionally override property label tooltips
foreach ($descriptions as $description) {
$newOverrides['description'][$description->getLang()] = $description->getValue();
}
$this->labelOverrides[$labelPropUri] = array_merge($newOverrides, $this->labelOverrides[$labelPropUri]);
}

/**
* Get the SPARQL endpoint URL for this vocabulary
*
Expand Down Expand Up @@ -505,6 +546,14 @@ public function getPluginParameters() {
return $this->pluginParameters;
}

/**
* Get the list of property label overrides
* @return array of custom property labels
*/
public function getPropertyLabelOverrides() {
return $this->labelOverrides;
}

/**
* Returns the vocabulary default sidebar view.
* @return string name of the view
Expand Down
18 changes: 18 additions & 0 deletions tests/VocabularyConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -618,4 +618,22 @@ public function testGetPropertyOrderCustom() {
$this->assertEquals($order, $params);
}

/**
* @covers VocabularyConfig::getPropertyLabelOverrides
* @covers VocabularyConfig::setPropertyLabelOverrides
* @covers VocabularyConfig::setLabelOverride
*/
public function testGetPropertyLabelOverrides() {
$vocab = $this->model->getVocabulary('conceptPropertyLabels');

$overrides = $vocab->getConfig()->getPropertyLabelOverrides();

$expected = array(
'skos:prefLabel' => array( 'label' => array ( 'en' => 'Caption', 'fi' => 'Luokka' ) ),
'skos:notation' => array( 'label' => array ( 'en' => 'UDC number', 'fi' => 'UDC-numero', 'sv' => 'UDC-nummer' ),
'description' => array( 'en' => 'Class Number') ),
);
$this->assertEquals($expected, $overrides);
}

}
16 changes: 16 additions & 0 deletions tests/testconfig.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,22 @@
skosmos:language "fi";
skosmos:sparqlGraph <http://www.skosmos.skos/collation/> .

:conceptPropertyLabels a skosmos:Vocabulary, void:Dataset ;
dc:title "Test custom property labels"@en ;
dc:subject :cat_science ;
dc:type mdrtype:ONTOLOGY ;
void:dataDump <http://skosmos.skos/dump/test/> ;
void:uriSpace "http://www.skosmos.skos/test/";
skosmos:defaultLanguage "en";
skosmos:language "en";
skosmos:propertyLabelOverride
[ skosmos:property skos:prefLabel ;
rdfs:label "Caption"@en, "Luokka"@fi ],
[ skosmos:property skos:notation ;
rdfs:label "UDC number"@en, "UDC-numero"@fi, "UDC-nummer"@sv ;
rdfs:comment "Class Number"@en ] ;
skosmos:sparqlGraph <http://www.skosmos.skos/conceptPropertyLabels/> .

:cbd a skosmos:Vocabulary, void:Dataset ;
dc11:title "A vocabulary for testing blank node processing and reification"@en ;
dc:subject :cat_general ;
Expand Down
22 changes: 20 additions & 2 deletions view/concept-shared.twig
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,16 @@
{% spaceless %}
<div class="row{% if concept.type == 'skosext:DeprecatedConcept' %} deprecated{% endif %} property prop-preflabel">
<div class="property-label property-label-pref">
<h3 class="versal">{% set subPrefLabelTranslation = concept.preferredSubpropertyLabelTranslation(request.lang) %}{% if subPrefLabelTranslation %}{{ subPrefLabelTranslation }}{% else %}{{ 'skos:prefLabel'|trans }}{% endif %}</h3>
<h3 class="versal">
{% set subPrefLabelTranslation = concept.preferredSubpropertyLabelTranslation(request.lang) %}
{% if subPrefLabelTranslation %}
{{ subPrefLabelTranslation }}
{% elseif custom_labels['skos:prefLabel']['label'][request.lang] %}
{{ custom_labels['skos:prefLabel']['label'][request.lang] }}
{% else %}
{{ 'skos:prefLabel'|trans }}
{% endif %}
</h3>
</div>
{% if concept.foundBy %} {# hit has been found through an alternative label #}
<span class="versal">{{ concept.foundBy }} ></span>
Expand Down Expand Up @@ -90,7 +99,16 @@
{% if property.getSubPropertyOf != 'skos:hiddenLabel' %}
<div class="row{% if property.type == 'dc:isReplacedBy' %} replaced-by{% endif%} property prop-{{property.ID}}">
<div class="property-label">
<h3 class="versal{% if property.type == 'rdf:type' %}-bold{% endif %}{% if property.description %} property-click" title="{{ property.description }}{% endif %}">{{ property.label }}</h3>
<h3 class="versal{% if property.type == 'rdf:type' %}-bold{% endif %}
{% if custom_labels[property.type]['description'][request.lang] %}property-click" title="{{ custom_labels[property.type]['description'][request.lang] }}
{% elseif property.description %} property-click" title="{{ property.description }}
{% endif %}">
{% if custom_labels[property.type]['label'][request.lang] %}
{{ custom_labels[property.type]['label'][request.lang] }}
{% else %}
{{ property.label }}
{% endif %}
</h3>
</div>
<div class="property-value-column"><div class="property-value-wrapper">
{% if request.vocab.config.hasMultiLingualProperty(property.type) %}
Expand Down