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

Graceful handling of partial SKOS XL data for concept labels #1356

Merged
merged 3 commits into from
Sep 12, 2022
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: 3 additions & 5 deletions model/Concept.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,10 @@ public function getLabel()
return "";
}

public function hasXlLabel($prop = 'prefLabel')
public function hasXlLabel()
{
if ($this->resource->hasProperty('skosxl:' . $prop)) {
return true;
}
return false;
$xlLabel = $this->getXlLabel();
return ($xlLabel !== null && !empty($xlLabel->getProperties()));
}

public function getXlLabel()
Expand Down
5 changes: 2 additions & 3 deletions model/ConceptPropertyValueLiteral.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,8 @@ public function getNotation()

public function hasXlProperties()
{
$graph = $this->resource->getGraph();
$resources = $graph->resourcesMatching('skosxl:literalForm', $this->literal);
return !empty($resources);
$xlLabel = $this->getXlLabel();
return ($xlLabel !== null && !empty($xlLabel->getProperties()));
}

public function getXlLabel()
Expand Down
7 changes: 5 additions & 2 deletions model/LabelSkosXL.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ public function getProperties() {
$ret = array();
$props = $this->resource->properties();
foreach($props as $prop) {
if ($prop !== 'skosxl:prefLabel') {
$ret[$prop] = $this->resource->get($prop);
if ($prop !== 'rdf:type' && $prop !== 'skosxl:literalForm') {
// make sure to use the correct gettext keys for DC namespace
$propkey = str_starts_with($prop, 'dc11:') ?
str_replace('dc11:', 'dc:', $prop) : $prop;
$ret[$propkey] = $this->resource->get($prop);
}
}
return $ret;
Expand Down
2 changes: 1 addition & 1 deletion tests/ConceptPropertyValueLiteralTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public function testGetXlLabel() {
{
$reified_vals = $val->getXlLabel()->getProperties();
}
$this->assertArrayHasKey('skosxl:literalForm', $reified_vals);
$this->assertArrayNotHasKey('skosxl:literalForm', $reified_vals);
$this->assertArrayHasKey('skosxl:labelRelation', $reified_vals);
}
}
43 changes: 43 additions & 0 deletions tests/ConceptTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -636,4 +636,47 @@ public function testGetModifiedDateFallbackToVocabularyModified() {
$modifiedDate = $concept->getModifiedDate();
$this->assertEquals(new DateTime("2014-10-01T16:29:03+00:00"), $modifiedDate);
}

/**
* @covers Concept::hasXlLabel
*/
public function testHasXlLabelTrue() {
$vocab = $this->model->getVocabulary('xl');
$concept = $vocab->getConceptInfo('http://www.skosmos.skos/xl/c1', 'en')[0];
$this->assertTrue($concept->hasXlLabel());
}

/**
* @covers Concept::hasXlLabel
*/
public function testHasXlLabelFalse() {
$vocab = $this->model->getVocabulary('test');
$concept = $vocab->getConceptInfo('http://www.skosmos.skos/test/ta111', 'en')[0];
$this->assertFalse($concept->hasXlLabel());
}

/**
* @covers Concept::getXlLabel
* @covers LabelSkosXL::getProperties
*/
public function testGetXlLabel() {
$vocab = $this->model->getVocabulary('xl');
$concept = $vocab->getConceptInfo('http://www.skosmos.skos/xl/c1', 'en')[0];
$label = $concept->getXlLabel();
$props = $label->getProperties();
$this->assertArrayHasKey('skosxl:labelRelation', $props);
$this->assertArrayHasKey('dc:modified', $props);
$this->assertArrayNotHasKey('skosxl:literalForm', $props);
$this->assertArrayNotHasKey('rdf:type', $props);
}

/**
* @covers Concept::getXlLabel
*/
public function testGetXlLabelNull() {
$vocab = $this->model->getVocabulary('test');
$concept = $vocab->getConceptInfo('http://www.skosmos.skos/test/ta111', 'en')[0];
$this->assertNull($concept->getXlLabel());
}

}
4 changes: 0 additions & 4 deletions view/concept-shared.twig
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,9 @@
</span>
<div class="reified-tooltip">
{% for key, val in concept.xlLabel.properties %}
{% if key != 'rdf:type' and key != 'skosxl:literalForm' %}
<p>{{ key|trans }}:
<span class="versal">{{ val }}</span>
</p>
{% endif %}
{% endfor %}
</div>
<span class="prefLabel" id="pref-label">{{ concept.xlLabel }}</span>
Expand Down Expand Up @@ -150,11 +148,9 @@
<span class="reified-property-value xl-label"><img alt="{{ "Information" | trans }}" src="resource/pics/about.png"></span>
<div class="reified-tooltip">
{% for key, val in propval.xlLabel.properties %}
{% if key != 'rdf:type' and key != 'skosxl:literalForm' %}
<p>{{ key|trans }}:
<span class="versal">{{ val }}</span>
</p>
{% endif %}
{% endfor %}
</div>
{% endif %}
Expand Down