Skip to content

Commit

Permalink
Rewrite concept group handling to take into account multiple hierarch…
Browse files Browse the repository at this point in the history
…ical groups. Fixes #811
  • Loading branch information
osma committed Dec 11, 2018
1 parent 7e009ed commit f1c1df9
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 19 deletions.
27 changes: 14 additions & 13 deletions model/Concept.php
Original file line number Diff line number Diff line change
Expand Up @@ -732,37 +732,38 @@ public function getGroupProperties()
*/
private function getCollections($includeArrays) {
$groups = array();
$reverseResources = $this->graph->resourcesMatching('skos:member', $this->resource);
if (isset($reverseResources)) {
$collections = $this->graph->resourcesMatching('skos:member', $this->resource);
if (isset($collections)) {
$arrayClassURI = $this->vocab !== null ? $this->vocab->getConfig()->getArrayClassURI() : null;
$arrayClass = $arrayClassURI !== null ? EasyRdf\RdfNamespace::shorten($arrayClassURI) : null;
$superGroups = $this->resource->all('isothes:superGroup');
$superGroupUris = array_map(function($obj) { return $obj->getUri(); }, $superGroups);
foreach ($reverseResources as $reverseResource) {
if (in_array($arrayClass, $reverseResource->types()) === $includeArrays) {
foreach ($collections as $collection) {
if (in_array($arrayClass, $collection->types()) === $includeArrays) {
// not adding the memberOf if the reverse resource is already covered by isothes:superGroup see issue #433
if (in_array($reverseResource->getUri(), $superGroupUris)) {
if (in_array($collection->getUri(), $superGroupUris)) {
continue;
}
$property = in_array($arrayClass, $reverseResource->types()) ? "skosmos:memberOfArray" : "skosmos:memberOf";
$collLabel = $reverseResource->label($this->clang) ? $reverseResource->label($this->clang) : $reverseResource->label();
$property = in_array($arrayClass, $collection->types()) ? "skosmos:memberOfArray" : "skosmos:memberOf";
$collLabel = $collection->label($this->clang) ? $collection->label($this->clang) : $collection->label();
if ($collLabel) {
$collLabel = $collLabel->getValue();
}

$groups[$collLabel] = new ConceptPropertyValue($this->model, $this->vocab, $reverseResource, $property, $this->clang);
ksort($groups);
$super = $this->graph->resourcesMatching('skos:member', $reverseResource);
while (isset($super) && !empty($super)) {
$group = new ConceptPropertyValue($this->model, $this->vocab, $collection, $property, $this->clang);
$groups[$collLabel] = array($group);

$res = $collection;
while($super = $this->graph->resourcesMatching('skos:member', $res)) {
foreach ($super as $res) {
$superprop = new ConceptPropertyValue($this->model, $this->vocab, $res, 'skosmos:memberOfSuper', $this->clang);
array_unshift($groups, $superprop);
$super = $this->graph->resourcesMatching('skos:member', $res);
array_unshift($groups[$collLabel], $superprop);
}
}
}
}
}
uksort($groups, 'strcoll');
return $groups;
}

Expand Down
4 changes: 3 additions & 1 deletion tests/ConceptTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,9 @@ public function testGetGroupPropertiesWithHierarchy()
$vocab = $model->getVocabulary('dupgroup');
$concept = $vocab->getConceptInfo("http://www.skosmos.skos/dupgroup/ta111", "en");
$groups = $concept[0]->getGroupProperties();
$this->assertEquals(0, sizeof($groups));
$this->assertEquals(2, sizeof($groups));
$this->assertArrayHasKey("Animalia", $groups);
$this->assertArrayHasKey("Biology", $groups);
}

/**
Expand Down
21 changes: 21 additions & 0 deletions tests/test-vocab-data/dupgroup.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,24 @@ dupgroup:c2 a isothes:ConceptGroup ;
skos:prefLabel "Is the superGroup"@en ;
skos:member dupgroup:c1 .

dupgroup:species a isothes:ConceptGroup, skos:Collection ;
skos:member dupgroup:animalia ;
skos:prefLabel "Species"@en .

dupgroup:animalia a isothes:ConceptGroup, skos:Collection ;
isothes:superGroup dupgroup:species ;
skos:member dupgroup:ta111 ;
skos:prefLabel "Animalia"@en .

dupgroup:lifesciences a isothes:ConceptGroup, skos:Collection ;
skos:member dupgroup:biology ;
skos:prefLabel "Life sciences"@en .

dupgroup:biology a isothes:ConceptGroup, skos:Collection ;
isothes:superGroup dupgroup:lifesciences ;
skos:member dupgroup:ta111 ;
skos:prefLabel "Biology"@en .

dupgroup:ta111 a skos:Concept ;
skos:broader dupgroup:ta1 ;
skos:prefLabel "Tuna"@en .
11 changes: 6 additions & 5 deletions view/concept-shared.twig
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,13 @@
<div class="property-label"><span class="versal property-click" title="{% trans "skosmos:memberOf_help" %}" >{{ 'skosmos:memberOf'|trans|upper }}</span></div>
<div class="property-value-column"><div class="property-value-wrapper">
<ul>
{% for group in concept.groupProperties %}
{% if (group.type == 'skosmos:memberOfSuper' and not superFound) or (group.type == 'skosmos:memberOf' and not superFound) %}<li>{% endif %}
{% for grouppath in concept.groupProperties %}
<li>
{% for group in grouppath %}
<a class="versal" href="{{ group.uri | link_url(group.vocab,request.lang,'page',request.contentLang) }}">{% if group.notation %}<span class="versal">{{ group.notation }}</span>{% endif %}{{ group.label(request.contentLang) }}</a>
{% if group.type == 'skosmos:memberOfSuper' %}<span class="versal"> &#62; </span>{% endif %}
{% if group.type == 'skosmos:memberOf' or loop.last %}</li>{% endif %}
{% if group.type == 'skosmos:memberOfSuper' %}{% set superFound = true %}{% elseif group.type == 'skosmos:memberOf' and superFound %}{% set superFound = false %}{% endif %}
{% if not loop.last %}<span class="versal"> &#62; </span>{% endif %}
{% endfor %}
</li>
{% endfor %}
</ul>
</div></div>
Expand Down

0 comments on commit f1c1df9

Please sign in to comment.