From dedece789eb081b0acb66f4dc7e3690975e4cdfa Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 16 Feb 2015 06:29:25 +0530 Subject: [PATCH] ... --- src/calibre/spell/dictionary.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/calibre/spell/dictionary.py b/src/calibre/spell/dictionary.py index af61800ef7..05ffdb7d92 100644 --- a/src/calibre/spell/dictionary.py +++ b/src/calibre/spell/dictionary.py @@ -339,6 +339,10 @@ class Dictionaries(object): locale = locale or self.default_locale d = self.dictionary_for_locale(locale) ans = () + + def add_suggestion(w, ans): + return (w,) + tuple(x for x in ans if x != w) + if d is not None: try: ans = d.obj.suggest(unicode(word)) @@ -348,17 +352,17 @@ class Dictionaries(object): dehyphenated_word = self.remove_hyphenation.sub('', word) 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) + ans = add_suggestion(dehyphenated_word, ans) 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 + ans = add_suggestion(fw, ans) if capitalize(w2) != w2: fw = w1 + m.group() + ' ' + capitalize(w2) - ans = (fw,) + ans + ans = add_suggestion(fw, ans) return ans