Use last the language of the last known glyph for totally unknown words.
This commit is contained in:
parent
4e4848e1bb
commit
807ab6291c
2 changed files with 5 additions and 3 deletions
|
|
@ -39,6 +39,7 @@ class Document(object):
|
||||||
self.config = Configuration.load_file(path.join(self.dirname, 'config.yaml'))
|
self.config = Configuration.load_file(path.join(self.dirname, 'config.yaml'))
|
||||||
self.output_format = output_format
|
self.output_format = output_format
|
||||||
self.last_style = Style(bold=False, italic=False, color=(255, 255, 255)) # FIXME get rid of hardcoded value
|
self.last_style = Style(bold=False, italic=False, color=(255, 255, 255)) # FIXME get rid of hardcoded value
|
||||||
|
self.last_language = None
|
||||||
|
|
||||||
def save_glyphdb(self):
|
def save_glyphdb(self):
|
||||||
self.glyphdb.save()
|
self.glyphdb.save()
|
||||||
|
|
@ -75,10 +76,11 @@ class Document(object):
|
||||||
except KeyError:
|
except KeyError:
|
||||||
guessed_bold = glyph.word.guess_bold(default=self.last_style.bold)
|
guessed_bold = glyph.word.guess_bold(default=self.last_style.bold)
|
||||||
guessed_italic = glyph.word.guess_italic(default=self.last_style.italic)
|
guessed_italic = glyph.word.guess_italic(default=self.last_style.italic)
|
||||||
self.switch_layout(glyph.word.guess_language())
|
self.switch_layout(glyph.word.guess_language(self.last_language))
|
||||||
text, bold, italic = self.ui.ask_for_help(glyph, guessed_bold, guessed_italic)
|
text, bold, italic = self.ui.ask_for_help(glyph, guessed_bold, guessed_italic)
|
||||||
glyph_data = self.glyphdb.add_glyph(glyph, text, bold, italic)
|
glyph_data = self.glyphdb.add_glyph(glyph, text, bold, italic)
|
||||||
self.last_style = glyph_data.style
|
self.last_style = glyph_data.style
|
||||||
|
self.last_language = self.language_map.get(glyph_data.text)
|
||||||
return glyph_data
|
return glyph_data
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
|
|
|
||||||
|
|
@ -269,12 +269,12 @@ class Word(PageObject):
|
||||||
image = line.image[:, beginning.left:end.right]
|
image = line.image[:, beginning.left:end.right]
|
||||||
super().__init__(line.document, image)
|
super().__init__(line.document, image)
|
||||||
|
|
||||||
def guess_language(self):
|
def guess_language(self, default=None):
|
||||||
counts = defaultdict(int)
|
counts = defaultdict(int)
|
||||||
language_map = self.document.language_map
|
language_map = self.document.language_map
|
||||||
known_glyph_info = self._known_glyph_info()
|
known_glyph_info = self._known_glyph_info()
|
||||||
if not known_glyph_info:
|
if not known_glyph_info:
|
||||||
return None
|
return default
|
||||||
for glyph_info in known_glyph_info:
|
for glyph_info in known_glyph_info:
|
||||||
counts[language_map.get(glyph_info.text)] += 1
|
counts[language_map.get(glyph_info.text)] += 1
|
||||||
language, count = sorted(counts.items(), reverse=True)[0]
|
language, count = sorted(counts.items(), reverse=True)[0]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue