This commit is contained in:
Kovid Goyal 2015-02-16 06:29:25 +05:30
parent 36e2ab7bdf
commit dedece789e

View File

@ -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