Linting
parent
55fd459634
commit
4b3eee4b05
|
|
@ -171,16 +171,16 @@ class TextAlignments():
|
||||||
idx_insert = None
|
idx_insert = None
|
||||||
if idx_closest is None:
|
if idx_closest is None:
|
||||||
idx_insert = 0
|
idx_insert = 0
|
||||||
|
else:
|
||||||
|
coord_closest = alignment_array[idx_closest].coord
|
||||||
# Note: np.isclose is slow!
|
# Note: np.isclose is slow!
|
||||||
elif coord - 0.5 < \
|
if coord - 0.5 < coord_closest < coord + 0.5:
|
||||||
alignment_array[idx_closest].coord < \
|
|
||||||
coord + 0.5:
|
|
||||||
self._update_alignment(
|
self._update_alignment(
|
||||||
alignment_array[idx_closest],
|
alignment_array[idx_closest],
|
||||||
coord,
|
coord,
|
||||||
textline
|
textline
|
||||||
)
|
)
|
||||||
elif alignment_array[idx_closest].coord < coord:
|
elif coord_closest < coord:
|
||||||
idx_insert = idx_closest + 1
|
idx_insert = idx_closest + 1
|
||||||
else:
|
else:
|
||||||
idx_insert = idx_closest
|
idx_insert = idx_closest
|
||||||
|
|
@ -212,8 +212,8 @@ class TextEdges(TextAlignments):
|
||||||
te = self._create_new_text_alignment(coord, textline, align)
|
te = self._create_new_text_alignment(coord, textline, align)
|
||||||
self._text_alignments[align].append(te)
|
self._text_alignments[align].append(te)
|
||||||
|
|
||||||
def _update_alignment(self, edge, coord, textline):
|
def _update_alignment(self, alignment, coord, textline):
|
||||||
edge.update_coords(coord, textline, self.edge_tol)
|
alignment.update_coords(coord, textline, self.edge_tol)
|
||||||
|
|
||||||
def generate(self, textlines):
|
def generate(self, textlines):
|
||||||
"""Generates the text edges dict based on horizontal text
|
"""Generates the text edges dict based on horizontal text
|
||||||
|
|
@ -469,8 +469,7 @@ class Table():
|
||||||
if self.page == other.page:
|
if self.page == other.page:
|
||||||
if self.order < other.order:
|
if self.order < other.order:
|
||||||
return True
|
return True
|
||||||
if self.page < other.page:
|
return self.page < other.page
|
||||||
return True
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def data(self):
|
def data(self):
|
||||||
|
|
@ -674,7 +673,7 @@ class Table():
|
||||||
bottom = cell.bottom
|
bottom = cell.bottom
|
||||||
if cell.bound == 4:
|
if cell.bound == 4:
|
||||||
continue
|
continue
|
||||||
elif cell.bound == 3:
|
if cell.bound == 3:
|
||||||
if not left and (right and top and bottom):
|
if not left and (right and top and bottom):
|
||||||
cell.hspan = True
|
cell.hspan = True
|
||||||
elif not right and (left and top and bottom):
|
elif not right and (left and top and bottom):
|
||||||
|
|
|
||||||
|
|
@ -44,9 +44,9 @@ def draw_labeled_bbox(
|
||||||
)
|
)
|
||||||
|
|
||||||
vlabel, hlabel = label_pos.split(",")
|
vlabel, hlabel = label_pos.split(",")
|
||||||
if (vlabel == "top"):
|
if vlabel == "top":
|
||||||
y = max(bbox[1], bbox[3])
|
y = max(bbox[1], bbox[3])
|
||||||
elif (vlabel == "bottom"):
|
elif vlabel == "bottom":
|
||||||
y = min(bbox[1], bbox[3])
|
y = min(bbox[1], bbox[3])
|
||||||
else:
|
else:
|
||||||
y = 0.5 * (bbox[1] + bbox[3])
|
y = 0.5 * (bbox[1] + bbox[3])
|
||||||
|
|
@ -58,9 +58,9 @@ def draw_labeled_bbox(
|
||||||
"center": "center"
|
"center": "center"
|
||||||
}
|
}
|
||||||
vlabel_out_of_box = label_align_swap[vlabel]
|
vlabel_out_of_box = label_align_swap[vlabel]
|
||||||
if (hlabel == "right"):
|
if hlabel == "right":
|
||||||
x = max(bbox[0], bbox[2])
|
x = max(bbox[0], bbox[2])
|
||||||
elif (hlabel == "left"):
|
elif hlabel == "left":
|
||||||
x = min(bbox[0], bbox[2])
|
x = min(bbox[0], bbox[2])
|
||||||
else:
|
else:
|
||||||
x = 0.5 * (bbox[0] + bbox[2])
|
x = 0.5 * (bbox[0] + bbox[2])
|
||||||
|
|
@ -203,7 +203,7 @@ class PlotMethods():
|
||||||
raise NotImplementedError(
|
raise NotImplementedError(
|
||||||
"Lattice flavor does not support kind='{}'".format(kind)
|
"Lattice flavor does not support kind='{}'".format(kind)
|
||||||
)
|
)
|
||||||
elif table.flavor in ["stream", "hybrid"] and kind in ["line"]:
|
if table.flavor in ["stream", "hybrid"] and kind in ["line"]:
|
||||||
raise NotImplementedError(
|
raise NotImplementedError(
|
||||||
"Stream flavor does not support kind='{}'".format(kind)
|
"Stream flavor does not support kind='{}'".format(kind)
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -157,12 +157,15 @@ def remove_extra(kwargs, flavor="lattice"):
|
||||||
# https://stackoverflow.com/a/22726782
|
# https://stackoverflow.com/a/22726782
|
||||||
# and https://stackoverflow.com/questions/10965479
|
# and https://stackoverflow.com/questions/10965479
|
||||||
class TemporaryDirectory():
|
class TemporaryDirectory():
|
||||||
|
def __init__(self):
|
||||||
|
self.dir_path = None
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
self.name = tempfile.mkdtemp()
|
self.dir_path = tempfile.mkdtemp()
|
||||||
# Only delete the temporary directory upon
|
# Only delete the temporary directory upon
|
||||||
# program exit.
|
# program exit.
|
||||||
atexit.register(shutil.rmtree, self.name)
|
atexit.register(shutil.rmtree, self.dir_path)
|
||||||
return self.name
|
return self.dir_path
|
||||||
|
|
||||||
def __exit__(self, exc_type, exc_value, traceback):
|
def __exit__(self, exc_type, exc_value, traceback):
|
||||||
pass
|
pass
|
||||||
|
|
@ -343,8 +346,8 @@ def get_rotation(chars, horizontal_text, vertical_text):
|
||||||
hlen = len([t for t in horizontal_text if t.get_text().strip()])
|
hlen = len([t for t in horizontal_text if t.get_text().strip()])
|
||||||
vlen = len([t for t in vertical_text if t.get_text().strip()])
|
vlen = len([t for t in vertical_text if t.get_text().strip()])
|
||||||
if hlen < vlen:
|
if hlen < vlen:
|
||||||
clockwise = sum(t.matrix[1] < 0 and t.matrix[2] > 0 for t in chars)
|
clockwise = sum(t.matrix[1] < 0 < t.matrix[2] for t in chars)
|
||||||
anticlockwise = sum(t.matrix[1] > 0 and t.matrix[2] < 0 for t in chars)
|
anticlockwise = sum(t.matrix[1] > 0 > t.matrix[2] for t in chars)
|
||||||
rotation = "anticlockwise" if clockwise < anticlockwise \
|
rotation = "anticlockwise" if clockwise < anticlockwise \
|
||||||
else "clockwise"
|
else "clockwise"
|
||||||
return rotation
|
return rotation
|
||||||
|
|
@ -753,7 +756,7 @@ def flag_font_size(textline, direction, strip_text=""):
|
||||||
flist.append("".join(fchars))
|
flist.append("".join(fchars))
|
||||||
fstring = "".join(flist)
|
fstring = "".join(flist)
|
||||||
else:
|
else:
|
||||||
fstring = "".join([t.get_text() for t in textline])
|
fstring = "".join(t.get_text() for t in textline)
|
||||||
return text_strip(fstring, strip_text)
|
return text_strip(fstring, strip_text)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -815,7 +818,6 @@ def split_textline(table, textline, direction, flag_size=False, strip_text=""):
|
||||||
):
|
):
|
||||||
cut_text.append((r, cut[0], obj))
|
cut_text.append((r, cut[0], obj))
|
||||||
break
|
break
|
||||||
else:
|
|
||||||
# TODO: add test
|
# TODO: add test
|
||||||
if cut == x_cuts[-1]:
|
if cut == x_cuts[-1]:
|
||||||
cut_text.append((r, cut[0] + 1, obj))
|
cut_text.append((r, cut[0] + 1, obj))
|
||||||
|
|
@ -848,7 +850,6 @@ def split_textline(table, textline, direction, flag_size=False, strip_text=""):
|
||||||
and (obj.y0 + obj.y1) / 2 >= cut[1]:
|
and (obj.y0 + obj.y1) / 2 >= cut[1]:
|
||||||
cut_text.append((cut[0], c, obj))
|
cut_text.append((cut[0], c, obj))
|
||||||
break
|
break
|
||||||
else:
|
|
||||||
# TODO: add test
|
# TODO: add test
|
||||||
if cut == y_cuts[-1]:
|
if cut == y_cuts[-1]:
|
||||||
cut_text.append((cut[0] - 1, c, obj))
|
cut_text.append((cut[0] - 1, c, obj))
|
||||||
|
|
@ -964,7 +965,6 @@ def get_table_index(
|
||||||
),
|
),
|
||||||
error,
|
error,
|
||||||
)
|
)
|
||||||
else:
|
|
||||||
if flag_size:
|
if flag_size:
|
||||||
return (
|
return (
|
||||||
[
|
[
|
||||||
|
|
@ -978,7 +978,6 @@ def get_table_index(
|
||||||
],
|
],
|
||||||
error,
|
error,
|
||||||
)
|
)
|
||||||
else:
|
|
||||||
return [(r_idx, c_idx, text_strip(t.get_text(), strip_text))], \
|
return [(r_idx, c_idx, text_strip(t.get_text(), strip_text))], \
|
||||||
error
|
error
|
||||||
|
|
||||||
|
|
@ -1002,7 +1001,7 @@ def compute_accuracy(error_weights):
|
||||||
SCORE_VAL = 100
|
SCORE_VAL = 100
|
||||||
try:
|
try:
|
||||||
score = 0
|
score = 0
|
||||||
if sum([ew[0] for ew in error_weights]) != SCORE_VAL:
|
if sum(ew[0] for ew in error_weights) != SCORE_VAL:
|
||||||
raise ValueError("Sum of weights should be equal to 100.")
|
raise ValueError("Sum of weights should be equal to 100.")
|
||||||
for ew in error_weights:
|
for ew in error_weights:
|
||||||
weight = ew[0] / len(ew[1])
|
weight = ew[0] / len(ew[1])
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,9 @@ from pandas.testing import assert_frame_equal
|
||||||
|
|
||||||
import camelot
|
import camelot
|
||||||
from camelot.core import Table, TableList
|
from camelot.core import Table, TableList
|
||||||
from camelot.utils import compare_tables
|
|
||||||
from camelot.__version__ import generate_version
|
from camelot.__version__ import generate_version
|
||||||
|
# compare_tables used in console mode while debugging
|
||||||
|
from camelot.utils import compare_tables # noqa
|
||||||
|
|
||||||
from .data import *
|
from .data import *
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue