From d001004c12a836064c2f27464f3f42721ce6713c Mon Sep 17 00:00:00 2001 From: Henri Ylikotila Date: Thu, 23 Mar 2023 13:59:52 +0200 Subject: [PATCH 1/4] checking that the skosxl properties are only shown for the correct skosxl label language --- model/ConceptPropertyValueLiteral.php | 2 +- model/LabelSkosXL.php | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/model/ConceptPropertyValueLiteral.php b/model/ConceptPropertyValueLiteral.php index 56367089b..acbb369ac 100644 --- a/model/ConceptPropertyValueLiteral.php +++ b/model/ConceptPropertyValueLiteral.php @@ -88,7 +88,7 @@ public function getNotation() public function hasXlProperties() { $xlLabel = $this->getXlLabel(); - return ($xlLabel !== null && !empty($xlLabel->getProperties())); + return ($xlLabel !== null && !empty($xlLabel->getProperties()) && $this->getLang() == $xlLabel->getLang()); } public function getXlLabel() diff --git a/model/LabelSkosXL.php b/model/LabelSkosXL.php index 71fc471af..e1394ad11 100644 --- a/model/LabelSkosXL.php +++ b/model/LabelSkosXL.php @@ -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(); } From 3f821ca638b6473b7c860833cc5971fd04175916 Mon Sep 17 00:00:00 2001 From: Henri Ylikotila Date: Thu, 23 Mar 2023 15:45:47 +0200 Subject: [PATCH 2/4] moving the label lang check to the getXlLabel function --- model/ConceptPropertyValueLiteral.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/model/ConceptPropertyValueLiteral.php b/model/ConceptPropertyValueLiteral.php index acbb369ac..32b0251c9 100644 --- a/model/ConceptPropertyValueLiteral.php +++ b/model/ConceptPropertyValueLiteral.php @@ -88,7 +88,7 @@ public function getNotation() public function hasXlProperties() { $xlLabel = $this->getXlLabel(); - return ($xlLabel !== null && !empty($xlLabel->getProperties()) && $this->getLang() == $xlLabel->getLang()); + return ($xlLabel !== null && !empty($xlLabel->getProperties())); } public function getXlLabel() @@ -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; } From a5a938e6e040c0651be7a4c49f545963c24a5c35 Mon Sep 17 00:00:00 2001 From: Henri Ylikotila Date: Mon, 27 Mar 2023 12:49:49 +0300 Subject: [PATCH 3/4] adding a unit test case --- tests/ConceptPropertyValueLiteralTest.php | 34 +++++++++++++++++++++++ tests/test-vocab-data/xl.ttl | 10 +++++++ 2 files changed, 44 insertions(+) diff --git a/tests/ConceptPropertyValueLiteralTest.php b/tests/ConceptPropertyValueLiteralTest.php index 0b445ef94..f5d775c3d 100644 --- a/tests/ConceptPropertyValueLiteralTest.php +++ b/tests/ConceptPropertyValueLiteralTest.php @@ -203,4 +203,38 @@ public function testGetXlLabel() { $this->assertArrayNotHasKey('skosxl:literalForm', $reified_vals); $this->assertArrayHasKey('skosxl:labelRelation', $reified_vals); } + + /** + * @covers ConceptPropertyValueLiteral::getXlLabel + * @covers ConceptPropertyValueLiteral::hasXlProperties + */ + 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); + } } diff --git a/tests/test-vocab-data/xl.ttl b/tests/test-vocab-data/xl.ttl index 962fd7387..90db36b9c 100644 --- a/tests/test-vocab-data/xl.ttl +++ b/tests/test-vocab-data/xl.ttl @@ -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 . + +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 . From 101a2d9cd71bc469387263dcc3ac8f202bb1afa0 Mon Sep 17 00:00:00 2001 From: Osma Suominen Date: Tue, 22 Aug 2023 15:48:49 +0300 Subject: [PATCH 4/4] add missing covers annotation to testGetXlPropertiesByLang unit test --- tests/ConceptPropertyValueLiteralTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/ConceptPropertyValueLiteralTest.php b/tests/ConceptPropertyValueLiteralTest.php index f5d775c3d..417d15c06 100644 --- a/tests/ConceptPropertyValueLiteralTest.php +++ b/tests/ConceptPropertyValueLiteralTest.php @@ -207,6 +207,7 @@ public function testGetXlLabel() { /** * @covers ConceptPropertyValueLiteral::getXlLabel * @covers ConceptPropertyValueLiteral::hasXlProperties + * @covers LabelSkosXL::getLang */ public function testGetXlPropertiesByLang() { $voc = $this->model->getVocabulary('xl');