Fix Line._combine_diacritics(): the first 5 glyphs were not examined.
This commit is contained in:
parent
34f58f0471
commit
a7f2c332ca
2 changed files with 10 additions and 2 deletions
|
|
@ -21,7 +21,7 @@ import numpy as np
|
|||
from scipy import ndimage
|
||||
from scipy.ndimage import filters
|
||||
|
||||
from .utils import cached_property, collect_iterable, pairwise
|
||||
from .utils import cached_property, collect_iterable, pairwise, neighbourhood
|
||||
from .image import Image, combine
|
||||
|
||||
|
||||
|
|
@ -145,7 +145,7 @@ class Line(PageObject):
|
|||
for i, glyph in enumerate(glyphs):
|
||||
if glyph.is_body():
|
||||
continue
|
||||
neighbours = glyphs[i - 5: i] + glyphs[i + 1: i + 6]
|
||||
neighbours = neighbourhood(glyphs, i, 5)
|
||||
body = max(neighbours, key=lambda neighbour: neighbour.detect_diacritic(glyph))
|
||||
if body.detect_diacritic(glyph):
|
||||
diacritics[body].append(glyph)
|
||||
|
|
|
|||
|
|
@ -44,3 +44,11 @@ def pairwise(iterable):
|
|||
a, b = itertools.tee(iterable)
|
||||
next(b, None)
|
||||
return itertools.zip_longest(a, b)
|
||||
|
||||
|
||||
def neighbourhood(lst, index, window=5):
|
||||
"""Return adjacent list items."""
|
||||
|
||||
before = lst[:index]
|
||||
after = lst[index + 1:]
|
||||
return before[-window:] + after[:window]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue