Skip to content

Commit

Permalink
Merge pull request #1123 from NatLibFi/issue1115-MultiLingual-Propert…
Browse files Browse the repository at this point in the history
…y-Setting-Doesnt-Work-As-Intended

Add support for multilingual properties in case no hit in content lan…
  • Loading branch information
Vainonen authored Feb 25, 2021
2 parents dc9c72a + 1acb473 commit a4cb4dc
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 8 deletions.
4 changes: 2 additions & 2 deletions model/Concept.php
Original file line number Diff line number Diff line change
Expand Up @@ -577,8 +577,8 @@ public function getProperties()
// Iterating through every literal and adding these to the data object.
foreach ($this->resource->allLiterals($sprop) as $val) {
$literal = new ConceptPropertyValueLiteral($this->model, $this->vocab, $this->resource, $val, $prop);
// only add literals when they match the content/hit language or have no language defined
if (isset($ret[$prop]) && ($literal->getLang() === $this->clang || $literal->getLang() === null)) {
// only add literals when they match the content/hit language or have no language defined OR when they are literals of a multilingual property
if (isset($ret[$prop]) && ($literal->getLang() === $this->clang || $literal->getLang() === null) || $this->vocab->getConfig()->hasMultiLingualProperty($prop)) {
$ret[$prop]->addValue($literal);
}

Expand Down
72 changes: 70 additions & 2 deletions tests/ConceptTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public function testGetPropertiesCorrectNumberOfProperties()
{
$props = $this->concept->getProperties();

$this->assertEquals(6, sizeof($props));
$this->assertEquals(8, sizeof($props));
}

/**
Expand All @@ -188,7 +188,7 @@ public function testGetPropertiesCorrectNumberOfProperties()
public function testGetPropertiesCorrectOrderOfProperties()
{
$props = $this->concept->getProperties();
$expected = array (0 => 'rdf:type', 1=> 'skos:broader',2 => 'skos:narrower',3 => 'skos:altLabel',4 => 'skos:scopeNote',5 => 'http://www.skosmos.skos/testprop');
$expected = array (0 => 'rdf:type', 1 => 'skos:broader', 2 => 'skos:narrower', 3 => 'skos:altLabel', 4 => 'skos:scopeNote', 5 => 'http://www.skosmos.skos/multiLingOff', 6 => 'http://www.skosmos.skos/multiLingOn', 7 => 'http://www.skosmos.skos/testprop');
$this->assertEquals($expected, array_keys($props));

}
Expand Down Expand Up @@ -461,6 +461,74 @@ public function testGetPropertiesWithNarrowersPartOfACollection()
}
}

/**
* @covers Concept::getProperties
*/
public function testMultilingualPropertiesOnWithLangHit() {
$vocab = $this->model->getVocabulary('test');
$concepts = $vocab->getConceptInfo('http://www.skosmos.skos/test/ta112', 'en');
$concept = $concepts[0];
$props = $concept->getProperties();
$propvals = $props['http://www.skosmos.skos/multiLingOn']->getValues();
$runner = array();
foreach ($propvals as $propval) {
array_push($runner, $propval->getLabel());
}
$compareableArray = ['English', 'Finnish', 'Without lang tag'];
$this->assertSame($runner, $compareableArray);
}

/**
* @covers Concept::getProperties
*/
public function testMultilingualPropertiesOnWithoutLangHit() {
$vocab = $this->model->getVocabulary('test');
$concepts = $vocab->getConceptInfo('http://www.skosmos.skos/test/ta112', 'ru');
$concept = $concepts[0];
$props = $concept->getProperties();
$propvals = $props['http://www.skosmos.skos/multiLingOn']->getValues();
$runner = array();
foreach ($propvals as $propval) {
array_push($runner, $propval->getLabel());
}
$compareableArray = ['English', 'Finnish', 'Without lang tag'];
$this->assertSame($runner, $compareableArray);
}

/**
* @covers Concept::getProperties
*/
public function testMultilingualPropertiesOffWithLangHit() {
$vocab = $this->model->getVocabulary('test');
$concepts = $vocab->getConceptInfo('http://www.skosmos.skos/test/ta112', 'en');
$concept = $concepts[0];
$props = $concept->getProperties();
$propvals = $props['http://www.skosmos.skos/multiLingOff']->getValues();
$runner = array();
foreach ($propvals as $propval) {
array_push($runner, $propval->getLabel());
}
$compareableArray = ['English', 'Without lang tag'];
$this->assertSame($runner, $compareableArray);
}

/**
* @covers Concept::getProperties
*/
public function testMultilingualPropertiesOffWithoutLangHit() {
$vocab = $this->model->getVocabulary('test');
$concepts = $vocab->getConceptInfo('http://www.skosmos.skos/test/ta112', 'ru');
$concept = $concepts[0];
$props = $concept->getProperties();
$propvals = $props['http://www.skosmos.skos/multiLingOff']->getValues();
$runner = array();
foreach ($propvals as $propval) {
array_push($runner, $propval->getLabel());
}
$compareableArray = ['Without lang tag'];
$this->assertSame($runner, $compareableArray);
}

/**
* @covers Concept::getProperties
*/
Expand Down
16 changes: 15 additions & 1 deletion tests/test-vocab-data/test.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ skosmos:testprop a rdf:Property ;
rdfs:label "Skosmos test property"@en ;
rdfs:comment "description for Skosmos test property"@en .

skosmos:multiLingOn a rdf:Property ;
rdfs:label "Skosmos test property"@en ;
rdfs:comment "description for Skosmos test property"@en .

skosmos:multiLingOff a rdf:Property ;
rdfs:label "Skosmos test property"@en ;
rdfs:comment "description for Skosmos test property"@en .

skos:prefLabel a rdf:Property ;
rdfs:label "preferred label"@en .

Expand Down Expand Up @@ -52,7 +60,13 @@ test:ta112 a skos:Concept, meta:TestClass ;
"Karppi"@fi ;
skos:altLabel "Golden crucian"@en;
skos:hiddenLabel "Karpit"@fi;
skos:scopeNote "Carp are oily freshwater fish"@en .
skos:scopeNote "Carp are oily freshwater fish"@en;
skosmos:multiLingOn "English"@en,
"Finnish"@fi,
"Without lang tag";
skosmos:multiLingOff "English"@en,
"Finnish"@fi,
"Without lang tag" .

test:ta114 a skos:Concept, meta:TestClass ;
skos:broader test:ta1 ;
Expand Down
1 change: 1 addition & 0 deletions tests/testconfig.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
skosmos:showTopConcepts "true";
skosmos:shortName "Test short",
"Testi lyhyt"@fi;
skosmos:hasMultiLingualProperty <http://www.skosmos.skos/multiLingOn>;
skosmos:sparqlGraph <http://www.skosmos.skos/test/> .

:test-notation-sort a skosmos:Vocabulary, void:Dataset ;
Expand Down
5 changes: 2 additions & 3 deletions view/concept-shared.twig
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,10 @@
</div>
<div class="property-value-column"><div class="property-value-wrapper">
{% if request.vocab.config.hasMultiLingualProperty(property.type) %}
{% set prevlang = '' %}{# Only displaying the language when it appears for the very first time #}
{% for language,labels in concept.allLabels(property.type) %}
{% for value in labels %}
<div class="row other-languages{% if prevlang != language %} first-of-language{% endif %}"><span class="versal col-xs-6{% if value.type == "skos:altLabel" %} replaced{% endif %}">{{ value.label }}</span><span class="versal col-xs-6">{% if prevlang != language %} {{ language }}{% endif %}</span></div>
{% set prevlang = language %}
<div class="row other-languages{% if loop.first %} first-of-language{% endif %}">
<div class="versal col-xs-6{% if value.type == "skos:altLabel" %} replaced{% endif %}">{% if value.containsHtml %}{{ value.label|raw }}{% else %}{{ value.label }}{% endif %}</div><div class="versal col-xs-6">{% if loop.first %} {{ language }}{% endif %}</div></div>
{% endfor %}
{% endfor %}
{% else %}
Expand Down

0 comments on commit a4cb4dc

Please sign in to comment.