Natural sort

Is it currently possible to apply natural sorting to Strings in KNIME, i.e. 1 < 2 < 10 and a1 < a2 < b1 < b2 etc?

There are lots of implementations of this in Java and in the past I've cobbled together meta-nodes that employ some of them. However, I was wondering if I'd missed an easier way.

If it ins't currently possible, could this be added as a feature of the Sorter node or as a new node?

Cheers,

Richard

Hi Richard,

Thank you for reporting this. At the moment you do not have something easier available to implement a natural sort. Our development team has this in the backlog for the next releases. We'll keep you posted on the progress.

Thank you again,

Best,

Vincenzo

2 Likes

Sorry to resurrect an old thread, but was there ever any progress on this?

I extend this thread with information about the current ‘Sort Node’ limitations.

Natural sorting in short, is a more human-friendly (“natural”) sorting,
it will sort a1, a2, a11
instead of a1, a11, a2 (alphabetical sorting).
(see natural sorting full definition)

Knime sorts strings alphabetically by default, and several issues arise because there is no a "Natural Sorter Node".
The usual answer is to split the string into string and and numeric parts and then sort the table in a multi-column way, such as

Yet, some issues continue unsolved

In my specific case the “split solution” is not suitable. See this example:

HoundOfTheBaskervilles_ch2.snt0part501
HoundOfTheBaskervilles_ch2.snt10part503
HoundOfTheBaskervilles_ch2.snt2part502

dog14.s1piece511
dog14.s10piece519
dog14.s2piece510

s2_500
s21_500
s3_501

wisteria1sthalf.0p501
wisteria10sthalf.0p501
wisteria2sthalf.0p501

Expected sorting for the first block:

HoundOfTheBaskervilles_ch2.snt0part501
HoundOfTheBaskervilles_ch2.snt2part502
HoundOfTheBaskervilles_ch2.snt10part503

If I want to sort all the blocks I would have to code a recursive algorithm to split strings and numbers (probably using regex) and then sort in the multicolumn way. Probably there are better alternatives, however a less obscure and proper solution from Knime may be adding the “natural sorting” option to the ‘Sorter Node’ capabilities, just as @rsherhod said.

1 Like

Hello there,

tnx for explanation and link @ajason08. Have given +1 to existing ticket (Internal reference: AP-10554)

Br,
Ivan

3 Likes