Add export to TableList and Table

This commit is contained in:
Vinayak Mehta
2018-09-07 05:13:34 +05:30
parent 557189da24
commit 0c329634e7
6 changed files with 169 additions and 246 deletions
+1 -1
View File
@@ -18,5 +18,5 @@ class BaseParser(object):
self.horizontal_text = get_text_objects(self.layout, ltype="lh")
self.vertical_text = get_text_objects(self.layout, ltype="lv")
self.pdf_width, self.pdf_height = self.dimensions
self.basename, __ = os.path.splitext(self.filename)
self.rootname, __ = os.path.splitext(self.filename)
self.g = Geometry()
+4 -4
View File
@@ -85,7 +85,7 @@ class Lattice(BaseParser):
return t
def _generate_image(self):
self.imagename = ''.join([self.basename, '.png'])
self.imagename = ''.join([self.rootname, '.png'])
gs_call = [
"-q", "-sDEVICE=png16m", "-o", self.imagename, "-r600", self.filename
]
@@ -164,7 +164,7 @@ class Lattice(BaseParser):
v_s = kwargs.get('v_s')
h_s = kwargs.get('h_s')
if v_s is None or h_s is None:
raise ValueError('No segments found on {}'.format(self.basename))
raise ValueError('No segments found on {}'.format(self.rootname))
table = Table(cols, rows)
# set table edges to True using ver+hor lines
@@ -199,7 +199,7 @@ class Lattice(BaseParser):
table.accuracy = accuracy
table.whitespace = whitespace
table.order = table_idx + 1
table.page = int(os.path.basename(self.basename).replace('page-', ''))
table.page = int(os.path.basename(self.rootname).replace('page-', ''))
return table
@@ -219,7 +219,7 @@ class Lattice(BaseParser):
if not self.horizontal_text:
warnings.warn("No tables found on {}".format(
os.path.basename(self.basename)))
os.path.basename(self.rootname)))
return [], self.g
self._generate_image()
+9 -9
View File
@@ -32,12 +32,6 @@ class Stream(BaseParser):
self.flag_size = flag_size
self.debug = debug
def _validate_columns(self):
if self.table_area is not None and self.columns is not None:
if len(self.table_area) != len(self.columns):
raise ValueError("Length of table_area and columns"
" should be equal")
@staticmethod
def _text_bbox(t_bbox):
xmin = min([t.x0 for direction in t_bbox for t in t_bbox[direction]])
@@ -125,6 +119,12 @@ class Stream(BaseParser):
for i in range(0, len(cols) - 1)]
return cols
def _validate_columns(self):
if self.table_area is not None and self.columns is not None:
if len(self.table_area) != len(self.columns):
raise ValueError("Length of table_area and columns"
" should be equal")
def _generate_table_bbox(self):
if self.table_area is not None:
table_bbox = {}
@@ -169,7 +169,7 @@ class Stream(BaseParser):
if ncols == 1:
# no tables condition
warnings.warn("No tables found on {}".format(
os.path.basename(self.basename)))
os.path.basename(self.rootname)))
cols = [(t.x0, t.x1)
for r in rows_grouped if len(r) == ncols for t in r]
cols = self._merge_columns(sorted(cols), mtol=self.mtol)
@@ -213,7 +213,7 @@ class Stream(BaseParser):
table.accuracy = accuracy
table.whitespace = whitespace
table.order = table_idx + 1
table.page = int(os.path.basename(self.basename).replace('page-', ''))
table.page = int(os.path.basename(self.rootname).replace('page-', ''))
return table
@@ -233,7 +233,7 @@ class Stream(BaseParser):
if not self.horizontal_text:
warnings.warn("No tables found on {}".format(
os.path.basename(self.basename)))
os.path.basename(self.rootname)))
return [], self.g
self._generate_table_bbox()