From 82d9ce02528db8da77b9024986956db3dd5fb845 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 15 Feb 2015 22:25:58 +0530 Subject: [PATCH] Edit Book spell check: For mis-spelled words of the form one:two offer one: two as a suggested correction. Fixes #1422133 [ebook editor spell check issue](https://bugs.launchpad.net/calibre/+bug/1422133) --- src/calibre/spell/dictionary.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/calibre/spell/dictionary.py b/src/calibre/spell/dictionary.py index dea0647905..e81edea996 100644 --- a/src/calibre/spell/dictionary.py +++ b/src/calibre/spell/dictionary.py @@ -14,6 +14,7 @@ from itertools import chain from calibre.constants import plugins, config_dir from calibre.spell import parse_lang_code from calibre.utils.config import JSONConfig +from calibre.utils.icu import capitalize from calibre.utils.localization import get_lang, get_system_locale Dictionary = namedtuple('Dictionary', 'primary_locale locales dicpath affpath builtin name id') @@ -159,6 +160,7 @@ class Dictionaries(object): def __init__(self): self.remove_hyphenation = re.compile('[\u2010-]+') self.negative_pat = re.compile('-[.\d+]') + self.fix_punctuation_pat = re.compile(r'''[:.]''') self.dictionaries = {} self.word_cache = {} self.ignored_words = set() @@ -347,6 +349,17 @@ class Dictionaries(object): if len(dehyphenated_word) != len(word) and self.recognized(dehyphenated_word, locale): # Ensure the de-hyphenated word is present and is the first suggestion ans = (dehyphenated_word,) + tuple(x for x in ans if x != dehyphenated_word) + else: + m = self.fix_punctuation_pat.search(word) + if m is not None: + w1, w2 = word[:m.start()], word[m.end():] + if self.recognized(w1) and self.recognized(w2): + fw = w1 + m.group() + ' ' + w2 + ans = (fw,) + ans + if m.group() == '.' and capitalize(w2) != w2: + fw = w1 + '. ' + capitalize(w2) + ans = (fw,) + ans + return ans if __name__ == '__main__': @@ -354,3 +367,4 @@ if __name__ == '__main__': dictionaries.initialize() print (dictionaries.recognized('recognized', parse_lang_code('en'))) print (dictionaries.suggestions('ade-quately', parse_lang_code('en'))) + print (dictionaries.suggestions('magic.wand', parse_lang_code('en')))