Fix param flow

* Fix param flow

* Add check for None
pull/2/head
Vinayak Mehta 2016-09-09 14:52:38 +05:30 committed by GitHub
parent 766260d5d9
commit a94c350a7b
2 changed files with 18 additions and 16 deletions

View File

@ -117,14 +117,10 @@ class Lattice:
hmask, h_segments = find_lines(threshold, direction='horizontal', hmask, h_segments = find_lines(threshold, direction='horizontal',
scale=self.scale) scale=self.scale)
if self.table_area: if self.table_area is not None:
if self.fill: if self.fill is not None:
if len(self.table_area) != len(self.fill): if len(self.table_area) != len(self.fill):
raise ValueError("message") raise ValueError("message")
if len(self.jtol) == 1 and self.jtol[0] == 2:
self.jtol = self.jtol * len(self.table_area)
if len(self.mtol) == 1 and self.mtol[0] == 2:
self.mtol = self.mtol * len(self.table_area)
areas = [] areas = []
for area in self.table_area: for area in self.table_area:
x1, y1, x2, y2 = area.split(",") x1, y1, x2, y2 = area.split(",")
@ -139,6 +135,11 @@ class Lattice:
contours = find_table_contours(vmask, hmask) contours = find_table_contours(vmask, hmask)
table_bbox = find_table_joints(contours, vmask, hmask) table_bbox = find_table_joints(contours, vmask, hmask)
if len(self.jtol) == 1 and self.jtol[0] == 2:
self.jtol = self.jtol * len(table_bbox)
if len(self.mtol) == 1 and self.mtol[0] == 2:
self.mtol = self.mtol * len(table_bbox)
if self.debug: if self.debug:
self.debug_images = (img, table_bbox) self.debug_images = (img, table_bbox)
@ -225,7 +226,7 @@ class Lattice:
score = get_score([[50, rerror], [50, cerror]]) score = get_score([[50, rerror], [50, cerror]])
table_data['score'] = score table_data['score'] = score
if self.fill: if self.fill is not None:
table = fill_spanning(table, fill=self.fill[table_no]) table = fill_spanning(table, fill=self.fill[table_no])
ar = table.get_list() ar = table.get_list()
if table_rotation == 'left': if table_rotation == 'left':

View File

@ -231,17 +231,13 @@ class Stream:
self.debug_text = [(t.x0, t.y0, t.x1, t.y1) for t in text] self.debug_text = [(t.x0, t.y0, t.x1, t.y1) for t in text]
return None return None
if self.table_area: if self.table_area is not None:
if self.columns: if self.columns is not None:
if len(self.table_area) != len(self.columns): if len(self.table_area) != len(self.columns):
raise ValueError("message") raise ValueError("message")
if self.ncolumns: if self.ncolumns is not None:
if len(self.table_area) != len(self.ncolumns): if len(self.table_area) != len(self.ncolumns):
raise ValueError("message") raise ValueError("message")
if len(self.ytol) == 1 and self.ytol[0] == 2:
self.ytol = self.ytol * len(self.table_area)
if len(self.mtol) == 1 and self.mtol[0] == 2:
self.mtol = self.mtol * len(self.table_area)
table_bbox = {} table_bbox = {}
for area in self.table_area: for area in self.table_area:
x1, y1, x2, y2 = area.split(",") x1, y1, x2, y2 = area.split(",")
@ -253,6 +249,11 @@ class Stream:
else: else:
table_bbox = {(0, 0, width, height): None} table_bbox = {(0, 0, width, height): None}
if len(self.ytol) == 1 and self.ytol[0] == 2:
self.ytol = self.ytol * len(table_bbox)
if len(self.mtol) == 1 and self.mtol[0] == 2:
self.mtol = self.mtol * len(table_bbox)
page = {} page = {}
tables = {} tables = {}
table_no = 0 table_no = 0
@ -268,7 +269,7 @@ class Stream:
elements = [len(r) for r in rows_grouped] elements = [len(r) for r in rows_grouped]
guess = False guess = False
if self.columns and self.columns[table_no] != "": if self.columns is not None and self.columns[table_no] != "":
# user has to input boundary columns too # user has to input boundary columns too
# take (0, width) by default # take (0, width) by default
# similar to else condition # similar to else condition
@ -277,7 +278,7 @@ class Stream:
cols = [(float(cols[i]), float(cols[i + 1])) cols = [(float(cols[i]), float(cols[i + 1]))
for i in range(0, len(cols) - 1)] for i in range(0, len(cols) - 1)]
else: else:
if self.ncolumns and self.ncolumns[table_no] != -1: if self.ncolumns is not None and self.ncolumns[table_no] != -1:
ncols = self.ncolumns[table_no] ncols = self.ncolumns[table_no]
cols = [(t.x0, t.x1) cols = [(t.x0, t.x1)
for r in rows_grouped if len(r) == ncols for t in r] for r in rows_grouped if len(r) == ncols for t in r]