Use last known glyph for guessing bold/italic attributes of totally unknown words.
This commit is contained in:
parent
afcab12b0c
commit
4e4848e1bb
2 changed files with 9 additions and 7 deletions
|
|
@ -73,8 +73,10 @@ class Document(object):
|
|||
try:
|
||||
glyph_data = self.glyphdb[glyph]
|
||||
except KeyError:
|
||||
guessed_bold = glyph.word.guess_bold(default=self.last_style.bold)
|
||||
guessed_italic = glyph.word.guess_italic(default=self.last_style.italic)
|
||||
self.switch_layout(glyph.word.guess_language())
|
||||
text, bold, italic = self.ui.ask_for_help(glyph, glyph.word.guess_bold(), glyph.word.guess_italic())
|
||||
text, bold, italic = self.ui.ask_for_help(glyph, guessed_bold, guessed_italic)
|
||||
glyph_data = self.glyphdb.add_glyph(glyph, text, bold, italic)
|
||||
self.last_style = glyph_data.style
|
||||
return glyph_data
|
||||
|
|
|
|||
|
|
@ -280,16 +280,16 @@ class Word(PageObject):
|
|||
language, count = sorted(counts.items(), reverse=True)[0]
|
||||
return language
|
||||
|
||||
def guess_bold(self):
|
||||
return self._guess('bold')
|
||||
def guess_bold(self, *args, **kwargs):
|
||||
return self._guess('bold', *args, **kwargs)
|
||||
|
||||
def guess_italic(self):
|
||||
return self._guess('italic')
|
||||
def guess_italic(self, *args, **kwargs):
|
||||
return self._guess('italic', *args, **kwargs)
|
||||
|
||||
def _guess(self, attr):
|
||||
def _guess(self, attr, default=None):
|
||||
known_glyph_info = self._known_glyph_info()
|
||||
if not known_glyph_info:
|
||||
return None
|
||||
return default
|
||||
total = sum(getattr(glyph_info.style, attr) for glyph_info in self._known_glyph_info())
|
||||
avg = total / len(known_glyph_info)
|
||||
return avg >= 0.5
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue