back
▲ 2 points

Show HN: Cluster-Sort

by xk3·3y ago·4 comments·view on hn ↗

    $ pip install --upgrade xklb spacy

    $ python -m spacy download en_core_web_sm

    $ echo 'red apple
    broccoli
    yellow
    green
    orange apple
    red apple' | library cluster-sort

    orange apple
    red apple
    red apple
    broccoli
    green
    yellow
4 comments
I'm confused what xklb is doing in there. https://pypi.org/project/xklb/ describes it as being a manager for media libraries. I see from https://github.com/chapmanjacobd/library/ that it does have other features like merging SQLite databases, cluster sorting, and stuff.. but I'm intrigued why that stuff is in a media management library?
Because it's less than 4KiB to expose some functionality that I am using internally to sort media. I don't want to spend >1 hour to create a new repo and then pay the nightmare maintenance costs to maintain 30+ different repos
What sort of effect does it have on sorting media? I assume you're sorting by title. I also assume it ends up sorting by artist quite well (though alphabetical would also do that) but that there might be some interesting groupings?
Yes, there are a few different sorting options which can be used on their own or together.

Cluster-sort will bubble up unique groups first. It is sorted such that KMeans groups with fewer entries will appear first and within each KMeans group the paths / lines will be sorted alphabetically. (you can use the `--groups` flag to take a peak at the groupings)

I maintain a few line delimited files of musicians to look up, movie recommendations from different country subreddits, as well as browser tabs that I failed to read during the week. I have a simple cronjob script to automatically open some of these tabs at various points throughout the day.

Cluster-sort is really good at sorting these types of files because even if the band name is in the middle of a sentence it will be grouped with similar ones (If the lines of text were exact duplicates I would just use `sort --unique` to dedupe them). Having the lines grouped together prevents me from googling the same things every month--but maybe the downside of this approach is no spaced repetition (SRS) and less of a chance to "acquire taste".