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 sorting of concepts in hierarchy that broke in PR 1133 #1140

Merged
merged 1 commit into from
Mar 22, 2021

Conversation

osma
Copy link
Member

@osma osma commented Mar 18, 2021

In PR #1133, the sorting of concepts in the hierarchy view was modified to take into account the domain (if any) of concept schemes. However, as a side effect, it broke the sorting in a frequently occurring situation: when sortByNotation is enabled (which is the default) but no notation codes are actually defined in the vocabulary. This happens e.g. in YSO.

Original situation (good), concepts are alphabetically ordered:

image

Situation after PR #1133 when sortByNotation is enabled (bad), not ordered:

image

The problem was that PR #1133 introduced an if...else structure but it didn't take into account the possibility of having sortByNotation enabled but not having any notations in the vocabulary data.

The solution is simply to remove the else block, so that the code that used to be in the else block is also executed if execution falls through the other if clauses. I've also added comments to highlight this somewhat unusual execution flow.

Thanks to @kouralex for originally reporting this!

@osma osma added the bug label Mar 18, 2021
@osma osma added this to the 2.10 milestone Mar 18, 2021
@osma osma requested a review from kouralex March 18, 2021 12:26
@sonarcloud
Copy link

sonarcloud bot commented Mar 18, 2021

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@codecov
Copy link

codecov bot commented Mar 18, 2021

Codecov Report

Merging #1140 (110bac8) into master (e213096) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #1140   +/-   ##
=========================================
  Coverage     67.96%   67.96%           
  Complexity     1584     1584           
=========================================
  Files            32       32           
  Lines          3890     3890           
=========================================
  Hits           2644     2644           
  Misses         1246     1246           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e213096...110bac8. Read the comment docs.

Copy link
Contributor

@kouralex kouralex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to do the trick! Good work, @osma !

For fun, one can check how this is done (except for domains) in PHP code here:

private function sortValues()
{
# TODO: sort by URI as last resort
# Note that getLabel() returns URIs in case of no label and may return a prefixed value which affects sorting
if (!empty($this->values)) {
if ($this->sort_by_notation) {
uasort($this->values, function($a, $b) {
$anot = $a->getNotation();
$bnot = $b->getNotation();
if ($anot == null) {
if ($bnot == null) {
// assume that labels are unique
return strcoll(strtolower($a->getLabel()), strtolower($b->getLabel()));
}
return 1;
}
else if ($bnot == null) {
return -1;
}
else {
// assume that notations are unique
return strnatcasecmp($anot, $bnot);
}
});
}
else {
uasort($this->values, function($a, $b) {
// assume that labels are unique
return strcoll(strtolower($a->getLabel()), strtolower($b->getLabel()));
});
}
}
$this->is_sorted = true;
}

As it is standing, there is no handling of similar labels but with different URIs but that is the case for above PHP code as well (see TODO comment above). This may result in different order in cases that are common in e.g., special ontologies that extend the more general one as in the original image. This can be seen below where the order of black-blue pairs are in inconsistent state. But this is how it already was so no harm done. Also, it seems to be happening in quite rare conditions now that I just tested (usually the black one is first, black meaning the more general ontology).
image
That said, this is an improvement and very well meets Skosmos quality measures and can be merged as-is.

Edit: it seems like the above case only happens when the more specific ontology concept has children but the other one does not and even then not always (= 50/50 chance). Another requirement is that it only happens on the initially opened hierarchical view of the defined concept - further openings via hierarchy (clicking triangle icons or concept labels) seem to be behave in a consistent manner.

@osma
Copy link
Member Author

osma commented Mar 22, 2021

Thanks for the review @kouralex ! I'm merging this as is. If you want you can open a separate issue for the "similar labels but with different URIs" case.

@osma osma merged commit c84dc97 into master Mar 22, 2021
@osma osma deleted the fix-hierarchy-sort-after-pr-1113 branch March 22, 2021 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants