mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
...
This commit is contained in:
parent
36e2ab7bdf
commit
dedece789e
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user