Skip to content

Commit

Permalink
Merge pull request #1425 from henriyli/issue-1389
Browse files Browse the repository at this point in the history
Fix for #1389 checking that skosxl properties are only shown for correct language
  • Loading branch information
osma authored Aug 22, 2023
2 parents f74bc3c + 101a2d9 commit 58eee0b
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
5 changes: 4 additions & 1 deletion model/ConceptPropertyValueLiteral.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ public function getXlLabel()
$graph = $this->resource->getGraph();
$labelResources = $graph->resourcesMatching('skosxl:literalForm', $this->literal);
foreach($labelResources as $labres) {
return new LabelSkosXL($this->model, $labres);
$xlLabel = new LabelSkosXL($this->model, $labres);
if ($xlLabel->getLang() == $this->getLang()) {
return $xlLabel;
}
}
return null;
}
Expand Down
4 changes: 4 additions & 0 deletions model/LabelSkosXL.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ public function getProperties() {
return $ret;
}

public function getLang() {
return $this->resource->getLiteral('skosxl:literalForm')->getLang();
}

public function getLiteral() {
return $this->resource->getLiteral('skosxl:literalForm')->getValue();
}
Expand Down
35 changes: 35 additions & 0 deletions tests/ConceptPropertyValueLiteralTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,39 @@ public function testGetXlLabel() {
$this->assertArrayNotHasKey('skosxl:literalForm', $reified_vals);
$this->assertArrayHasKey('skosxl:labelRelation', $reified_vals);
}

/**
* @covers ConceptPropertyValueLiteral::getXlLabel
* @covers ConceptPropertyValueLiteral::hasXlProperties
* @covers LabelSkosXL::getLang
*/
public function testGetXlPropertiesByLang() {
$voc = $this->model->getVocabulary('xl');
$conc = $voc->getConceptInfo('http://www.skosmos.skos/xl/c2', 'en')[0];
$props = $conc->getProperties();
$vals = $props['skos:altLabel']->getValues();
$val = reset($vals);

$reified_vals = array();
if ($val->hasXlProperties())
{
$reified_vals = $val->getXlLabel()->getProperties();
}
$this->assertArrayHasKey('dc:source', $reified_vals);
$this->assertArrayHasKey('dc:modified', $reified_vals);
$this->assertCount(2, $reified_vals);

// testing that XlProperties are only shown for matching language
$conc = $voc->getConceptInfo('http://www.skosmos.skos/xl/c2', 'fi')[0];
$props = $conc->getProperties();
$vals = $props['skos:altLabel']->getValues();
$val = reset($vals);

$reified_vals = array();
if ($val->hasXlProperties())
{
$reified_vals = $val->getXlLabel()->getProperties();
}
$this->assertEmpty($reified_vals);
}
}
10 changes: 10 additions & 0 deletions tests/test-vocab-data/xl.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,13 @@ xl:d1
rdf:value "Unit of thought"@en ;
dct:modified "2018-04-13T10:29:03+00:00"^^xsd:dateTime ;
dc:source <https://en.wikipedia.org/wiki/Concept> .

xl:c2 a skos:Concept ;
skos:prefLabel "Ontology"@en, "Ontologia"@fi ;
skos:altLabel "Onto"@en, "Onto"@fi ;
skosxl:altLabel xl:l3 .

xl:l3 a skosxl:Label ;
skosxl:literalForm "Onto"@en ;
dct:modified "2018-04-13T10:29:03+00:00"^^xsd:dateTime ;
dc:source <https://en.wikipedia.org/wiki/Ontology> .

0 comments on commit 58eee0b

Please sign in to comment.