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)

This commit is contained in:
Kovid Goyal 2015-02-15 22:25:58 +05:30
parent 4db96c9f47
commit 82d9ce0252

View File

@ -14,6 +14,7 @@ from itertools import chain
from calibre.constants import plugins, config_dir from calibre.constants import plugins, config_dir
from calibre.spell import parse_lang_code from calibre.spell import parse_lang_code
from calibre.utils.config import JSONConfig from calibre.utils.config import JSONConfig
from calibre.utils.icu import capitalize
from calibre.utils.localization import get_lang, get_system_locale from calibre.utils.localization import get_lang, get_system_locale
Dictionary = namedtuple('Dictionary', 'primary_locale locales dicpath affpath builtin name id') Dictionary = namedtuple('Dictionary', 'primary_locale locales dicpath affpath builtin name id')
@ -159,6 +160,7 @@ class Dictionaries(object):
def __init__(self): def __init__(self):
self.remove_hyphenation = re.compile('[\u2010-]+') self.remove_hyphenation = re.compile('[\u2010-]+')
self.negative_pat = re.compile('-[.\d+]') self.negative_pat = re.compile('-[.\d+]')
self.fix_punctuation_pat = re.compile(r'''[:.]''')
self.dictionaries = {} self.dictionaries = {}
self.word_cache = {} self.word_cache = {}
self.ignored_words = set() self.ignored_words = set()
@ -347,6 +349,17 @@ class Dictionaries(object):
if len(dehyphenated_word) != len(word) and self.recognized(dehyphenated_word, locale): if len(dehyphenated_word) != len(word) and self.recognized(dehyphenated_word, locale):
# Ensure the de-hyphenated word is present and is the first suggestion # 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) 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 return ans
if __name__ == '__main__': if __name__ == '__main__':
@ -354,3 +367,4 @@ if __name__ == '__main__':
dictionaries.initialize() dictionaries.initialize()
print (dictionaries.recognized('recognized', parse_lang_code('en'))) print (dictionaries.recognized('recognized', parse_lang_code('en')))
print (dictionaries.suggestions('ade-quately', parse_lang_code('en'))) print (dictionaries.suggestions('ade-quately', parse_lang_code('en')))
print (dictionaries.suggestions('magic.wand', parse_lang_code('en')))