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

Fix for #1389 checking that skosxl properties are only shown for correct language #1425

Merged
merged 4 commits into from
Aug 22, 2023
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 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 @@ -203,4 +203,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> .