Skip to content

Instantly share code, notes, and snippets.

@m-rey
Last active May 11, 2022 13:52
Show Gist options
  • Save m-rey/ef32de86892933ebd164363242074302 to your computer and use it in GitHub Desktop.
Save m-rey/ef32de86892933ebd164363242074302 to your computer and use it in GitHub Desktop.
hacky spellcheck that uses rules from languagetool and suggests corrections
#!/bin/env python3
# this needs https://github.com/bminixhofer/nlprule to work:
# pip install nlprule
from nlprule import Tokenizer, Rules
from sys import argv
LANG = "en"
input_string = []
args = argv[1:]
if args:
input_string.extend(args) # first read in all args to parse them as string later
text = list(filter(None, map(str.strip, input_string))) # split & strip & whitespace
rules = Rules.load(LANG, Tokenizer.load(LANG))
for line in text:
print(line)
for s in rules.suggest(line):
print(f"{s.start * ' '}{(s.end - s.start) * '^'} {s.replacements}: {s.message}")
print("")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment