-
Notifications
You must be signed in to change notification settings - Fork 94
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
Add "lexical" and "natural" sort strategies for notation codes #1205
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1205 +/- ##
============================================
- Coverage 68.26% 68.24% -0.03%
- Complexity 1609 1613 +4
============================================
Files 32 32
Lines 3955 3958 +3
============================================
+ Hits 2700 2701 +1
- Misses 1255 1257 +2
Continue to review full report at Codecov.
|
@@ -33,12 +33,7 @@ public function __construct($model, $vocab, $resource, $prop, $clang = '') | |||
|
|||
public function __toString() | |||
{ | |||
$label = is_string($this->getLabel()) ? $this->getLabel() : $this->getLabel()->getValue(); | |||
if ($this->vocab->getConfig()->sortByNotation()) { | |||
$label = ltrim($this->getNotation() . ' ') . $label; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding the notation here doesn't seem to have any effect on the sort order so I just removed it.
*/ | ||
public function sortByNotation() | ||
public function getSortByNotation(): ?string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I renamed the method for better consistency with other getters, and redefined its return value.
// Natural sort from: http://stackoverflow.com/a/15479354/3894569 | ||
// adapted to return only -1 or 1 using negVsPos function above |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the documentation of the jsTree sort plugin, it expects that the return value of the sort function is either -1 or 1 (anything other than -1 will be interpreted as 1, AFAICT). To make sure that the return values meet those expectations, I added a coercing function.
Finally found the cause of the missing notation information: the However, it turns out that the natural sort order is a bit different for PHP vs JS. On the PHP side, numbers with leading zeros are always first (PHP uses Martin Pool's algorithm) The current JS implementation of naturalCompare ignores leading zeros. The differences can be seen in this screenshot, where the notation codes 33.03 and 33.04 are placed differently in the hierarchy sidebar (JS) and the concept view (PHP): Not sure if this is a big issue - the example is a bit artificial, because YKL/PLC shouldn't use natural sorting but decimal, where this doesn't happen. And for vocabularies where natural sorting is preferred (i.e. PTVL), leading zeros probably shouldn't be used anyway. |
I added unit tests that verify the sort order is correct on the PHP side in both "decimal" and "natural" cases. Ready for review. I will update the wiki documentation after merging. |
Looks great! Three remarks, one that you already pinpointed: Here (look at the image below) the natural order faces the same problem. I am not completely sure, if this vocabulary (HKLJ/HCLCS) should be using the "decimal" order. If that is the case (which may very well be), there is no problem as you mentioned and explained. (URL for your convenience: https://finto.fi/hklj/fi/page/001) Here, a "real" problem where irregardless of the setting, this always shows up like this: (URL for your convenience: https://finto.fi/hklj/fi/page/691.1) It seems like the sorting is done by the label only. For mapping properties one should probably also sort by its (if vocabulary known to Skosmos) sortByNotation setting. I am not sure if this complicates the issue a bit too much - maybe (I think) it is OK to use the same value. Here it seems like the search is done using always the "decimal" order, even though one changes the value to "natural". This would mean that no vocabulary may use true "natural" sort strategy in search queries, am I right? The same naturally applies to the typeahead component, too (they use the same implementation under the hood). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I already commented in the PR where I had three remarks (of which at least two require some action or explanation).
Thanks for the review @kouralex . You're right, I didn't consider ordering of search results at all in this PR. I will take a closer look at that and the other things you mentioned. |
Renamed the "decimal" strategy to "lexical". It's not really appropriate for decimal numbers (e.g. "110" sorts before "13") but is just based on lexical string sorting. Amended the PR title and OP accordingly. |
Regarding the four comments: 1. Different natural sort orders in PHP and JSAlready discussed above, not a big issue IMHO. 2. Search result orderI looked at the ordering of search results by notation in more detail and opened an issue #1209. But I don't think there's anything worth changing in this area so I set that issue to the Blue Sky milestone. 3. Mapping property order
I opened a separate issue #1208 about ordering mapping property values. I think that's out of scope for this PR and issue. 4. Setting "false" has no effect on hierarchy
You are right, I'm currently investigating this. I think this happens because when sorting by notation is disabled (set to false), the sorting of jsTree nodes (representing concepts) falls back to comparison of node text. But that text includes the notation code, so notation codes will affect the sorting anyway. |
…d to sort by notation.
I fixed the JS side sorting in the hierarchy when the setting is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to be working now and the issues I pinpointed have been addressed. Great job @osma !
I noticed that the default value is "false" if the property is not set at all, which kind of makes sense, however, the comments in the code imply it could be "lexical" (which is true if the value is "true"!).
Apart from that, ready for merging! 🙂
I fixed a minor JS issue and clarified the comments about default values. Will merge after tests have passed. |
SonarCloud Quality Gate failed. 0 Bugs No Coverage information |
This PR makes it possible to select either "lexical" or "natural" sort strategy for sorting notation codes (see #937 for more background). The sorting is implemented both on the PHP and JS sides. The
skosmos:sortByNotation
configuration setting, which previously was just a boolean value, can now given a literal value to select the appropriate sort strategy:TODO:
it seems that sorting by notation is not always working on the JS side because notations are missing for the jsTree concept objects(fixed, the problem was in Finto layout footer.inc)Fixes #937