Package: betterletter
betterletterIn a given text, replaces alternative spellings of native characters with their proper spellings[^1]:InstallationpipinstallbetterletterUsageThe packagewill install a Python script of the same name, so instead of the usualpython -m betterletter, you can simply invoke that directly, if the Python script directory is on your$PATH:$betterletter-h
usage:betterletter[-h][-c][-f][-r][-g][-d][--debug]{de}Tooltoreplacealternativespellingsofnativecharacters(e.g.German
umlauts[ä,ö,ü]etc.[ß])withthepropernativecharacters.Forexample,
thisproblemoccurswhennoproperkeyboardlayoutwasavailable.Thisprogram
isdictionary-basedtocheckifreplacementsarevalidwords.Bydefault,
readsfromSTDINandwritestoSTDOUT.

positionalarguments:{de}Textlanguagetoworkwith,inISO639-1format.

options:-h,--helpshowthishelpmessageandexit-c,--clipboardReadfromandwritebacktoclipboardinsteadofSTDIN/STDOUT.-f,--forceForcesubstitutionsandreturnthetextversionwiththemaximumnumberofsubstitutions,eveniftheyareillegalwords(usefulfornames).-r,--reverseReversemode,whereallnativecharactersaresimplyreplacedbytheiralternativespellings.-g,--guiStopandopenaGUIpromptforconfirmationbeforefinishing.-d,--diffPrintadiffviewofthesubstitutionstostderr.--debugOutputdetailedlogginginformation.Usage ExamplesNormal usage:$echo'Hoeflich fragen waere angebracht!'|betterletterde
Höflichfragenwäreangebracht!Reverse it:$echo'Höflich fragen wäre angebracht!'|betterletter--reversede
Hoeflichfragenwaereangebracht!A diff view, useful for longer text and to confirm correctness.
Thediffis written to STDERR so won't interfere with further redirection.$echo'Hoeflich fragen waere angebracht!'|betterletter--diffde2>diff.txt
Höflichfragenwäreangebracht!
$catdiff.txt
-Hoeflichfragenwaereangebracht!
?^^^^
+Höflichfragenwäreangebracht!
?^^The tool may be coerced into working with names:$# A name won't be in the dictionary:$echo'Sehr geehrte Frau Huebenstetter, ...'|betterletterde
SehrgeehrteFrauHuebenstetter,...
$# But we can force it to work:$echo'Sehr geehrte Frau Huebenstetter, ...'|betterletter--forcede
SehrgeehrteFrauHübenstetter,...Clipboard-basedworkflows are also possible:# Nothing happens: clipboard is read and written to silently.# Paste the processed version from your clipboard.$betterletter--clipboarddeBackgroundFor example, German native characters and their corresponding alternative spellings (e.g. when no proper keyboard layout is at hand, or ASCII is used) are:Native CharacterAlternative SpellingÄ/äAe/aeÖ/öOe/oeÜ/üUe/ueẞ/ßSS/ssThese pairings are recordedhere.Going from left to right is simple: replace all native characters with their alternative spellings, minding case.
That use case is also supported by this tool (reverseflag).The other direction is much less straightforward: there exist countless words for which alternative spellings occur somewhere as a pattern, yet replacing them with the corresponding native character would be wrong:CharacterCorrect SpellingWrong SpellingÄAerodynamikÄrodynamikÄIsraelIsrälÄSchufaeintragSchufäintragÖKoeffizientKöffizientÖDominoeffektDominöffektÖPoetPötÜAbenteuerAbenteürÜMauerMaürÜSteuerungSteürungßMessgerätMeßgerätßMesseMeßeßAbschlussAbschlußjust to name a few, pretty common examples.As such, this tool is based on a dictionary lookup, see also thecontaining directory.Long-form samplesSee also thetests.deThe input:Ueberhaupt braeuchte es mal einen Teststring.
Saetze ohne Bedeutung, aber mit vielen Umlauten.
DRPFA-Angehoerige gehoeren haeufig nicht dazu.
Bindestrich-Woerter spraechen Baende ueber Fehler.
Doppelgaenger-Doppelgaenger sind doppelt droelfzig.
Oder Uemlaeuten? Auslaeuten? Leute gaebe es, wuerde man meinen.
Ueble Nachrede ist naechtens nicht erlaubt.
Erlaube man dieses, waere es schoen uebertrieben.
Busse muesste geloest werden, bevor Gruesse zum Gruss kommen.
Busse sind Geraete, die womoeglich schnell fuehren.
Voegel sind aehnlich zu Oel.
Hierfuer ist fuer den droegen Poebel zu beachten, dass Anmassungen zu Gehoerverlust fuehren koennen.
Stroemelschnoesseldaemel!is turned into:Überhaupt bräuchte es mal einen Teststring.
Sätze ohne Bedeutung, aber mit vielen Umlauten.
DRPFA-Angehörige gehören häufig nicht dazu.
Bindestrich-Wörter sprächen Bände über Fehler.
Doppelgänger-Doppelgänger sind doppelt droelfzig.
Oder Uemlaeuten? Auslaeuten? Leute gäbe es, würde man meinen.
Üble Nachrede ist nächtens nicht erlaubt.
Erlaube man dieses, wäre es schön übertrieben.
Buße müsste gelöst werden, bevor Grüße zum Gruß kommen.
Buße sind Geräte, die womöglich schnell führen.
Vögel sind ähnlich zu Öl.
Hierfür ist für den drögen Pöbel zu beachten, dass Anmaßungen zu Gehörverlust führen können.
Stroemelschnoesseldaemel!Note that some corrections are out of scope for this little script, e.g.:BusseIn German,BusseandBußeare two words of vastly different meaning (bussesandpenance, respectively).
Unfortunately, they map to the same alternative spelling ofBusse.
The tool seesBusse(meaningjust that, with no intent of changing it), noticesBußeis a legal substitution, and therefore makes it.
The tool has no awareness of context.Turning substitutions like these off would mean the tool would no longer emitBuße, ever.
This could be as undesirable as the current behaviour.
There seems to be no easy resolve.DevelopmentThis project usespoetryfor dependency management.
Refer to thepoetry config filefor more info (e.g. the required Python modules to install if you don't want to deal withpoetry).Using poetry, from the project root, run:# Installs virtual environment according to lock file (if available in repo),# otherwise pyproject.toml:poetryinstall# Run command within that environment:poetryrunpython-mbetterletter-hDevelopment tasks are all run throughpoetry, within the context of the virtual environment.Runjust(without arguments) for more available commands related to development.AutoHotKeyThis tool can be integrated withAutoHotKey, allowing you to use it at the touch of a button.
This can be used to setup a keyboard shortcut to run this tool in-place, quickly replacing what you need without leaving your text editing environment.The AutoHotKey file ishereandrequiresAutoHotKey v2(check out commits 7dd68f9 and earlier for the AHK v1.1 script).Followthis guideto have the script launch on boot automatically.AHK try icongenerated usinghttps://favicon.io/favicon-generator/.[^1]: In this demo,Ctrl + CandCtrl + Vare inserted automatically using theAutoHotKey script.
The user only selects the desired text and presses the hotkey, amounting to two keystrokes.
The delay between theCtrl + CandCtrl + Vkeystrokes in the above demo is the script actually doing its work.
First, the script reads in a dictionary from disk, taking constant time (O(1)), aka it doesn't scale with input size, just dictionary size.
Sadly, this takes comparatively long for short texts.
However, the script scales acceptably with longer inputs (regularO(n)).Very long inputs are required for the actual processing to take longer than the initial dictionary I/O.Hence, this script could run very fast if it were (re-)designed as a daemon, with the dictionary preloaded in memory.