Text compression for generating keyboard expansions
Text compression for generating keyboard expansions
This is a tool for automatically creating typing shortcuts from a corpus of your own writing! I use these shortcuts mainly for email and slack:
This repo parses a corpus of text and suggest what shortcuts you should use to save the most letters while typing. It then generates config files for Autokey, a linux program that implements keyboard shortcuts!
It also contains a tool for optionally parsing a Slack Data Export of your messages to create a corpus.
The code looks through the corpus to find common n-grams that can be replaced with much shorter phrases. The suggestions are ranked by [characters saved] * [frequency of phrase].
I was surprised that very short and frequent words topped this list, such as the -> t, instead of longer phrases that I use a lot, such as what do you think -> wdytk.
Just reading through the results was amusing to see how repetitive some of my writing is :)
This is largely preferences and heuristics to try to generate memorable abbreviations for different phrases. Some of my design philosphies were:
This is currently done as a manual post-process step, but I like to make "families" of abbrevs to make them more memorable. Some example heuristics for this are:
robot -> r and robots -> rs. the -> t
robot -> r
the robot -> trsome -> s
someone -> sn
something -> st
sometime -> stiinstall.sh to install dependencies. Currently tested on python 3.10.12data/corpus/*.txtdata/slack_export. Only slack workspace admins can do this (and it only exports public channels).USERNAME_TO_EXPORT at the top of the file to your slack username.parse_slack.py. This will generate a new corpus document in data/corpus/srmfind_suggested_phrases.py. This will generate a list of the top 200 suggested shortcuts to output/suggested_shortcuts.yamlshortcuts.yaml. generate_autokeys.py to convert shortcuts.yaml into actual config files for autokey.~/.config/autokey/data/My Phrases/. If it is somewhere else, change reload.sh:8 to point to your config locationshortcuts.yaml you can re-generate and reload autokey with reload.shAutokey Uses simulated keyboard input to replace phrases with your abbreviations. I tried several chrome extensions but this worked much more reliably without conflicting with sites' own javascript.
The config files I generate are set to only apply when Chrome is in focus because that's where I do most of my english typing. I found that keeping this active in terminal and vscode caused way more problems than it was solved because my abbreviations overlapped with common short linux commands and variable names i.e. t.
No open issues yet, or sync has not completed.