Last active
May 11, 2022 13:52
-
-
Save m-rey/ef32de86892933ebd164363242074302 to your computer and use it in GitHub Desktop.
hacky spellcheck that uses rules from languagetool and suggests corrections
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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