Add Python 3 compatibility (#109)
* Add python3 compat * Update .gitignore * Update .gitignore again * Remove debugging return * Add unicode_literals import * Bump version * Add python3-tk note
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
VERSION = (0, 1, 2)
|
||||
VERSION = (0, 2, 0)
|
||||
|
||||
__title__ = 'camelot-py'
|
||||
__description__ = 'PDF Table Extraction for Humans.'
|
||||
|
||||
@@ -13,7 +13,7 @@ from .base import BaseParser
|
||||
from ..core import Table
|
||||
from ..utils import (scale_image, scale_pdf, segments_in_bbox, text_in_bbox,
|
||||
merge_close_lines, get_table_index, compute_accuracy,
|
||||
compute_whitespace, setup_logging, encode_)
|
||||
compute_whitespace, setup_logging)
|
||||
from ..image_processing import (adaptive_threshold, find_lines,
|
||||
find_table_contours, find_table_joints)
|
||||
|
||||
@@ -177,7 +177,7 @@ class Lattice(BaseParser):
|
||||
gs_call = [
|
||||
"-q", "-sDEVICE=png16m", "-o", self.imagename, "-r600", self.filename
|
||||
]
|
||||
if "ghostscript" in subprocess.check_output(["gs", "-version"]).lower():
|
||||
if "ghostscript" in subprocess.check_output(["gs", "-version"]).decode('utf-8').lower():
|
||||
gs_call.insert(0, "gs")
|
||||
else:
|
||||
gs_call.insert(0, "gsc")
|
||||
@@ -284,7 +284,6 @@ class Lattice(BaseParser):
|
||||
table = Lattice._copy_spanning_text(table, copy_text=self.copy_text)
|
||||
|
||||
data = table.data
|
||||
data = encode_(data)
|
||||
table.df = pd.DataFrame(data)
|
||||
table.shape = table.df.shape
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import pandas as pd
|
||||
from .base import BaseParser
|
||||
from ..core import Table
|
||||
from ..utils import (text_in_bbox, get_table_index, compute_accuracy,
|
||||
compute_whitespace, setup_logging, encode_)
|
||||
compute_whitespace, setup_logging)
|
||||
|
||||
|
||||
logger = setup_logging(__name__)
|
||||
@@ -323,7 +323,6 @@ class Stream(BaseParser):
|
||||
accuracy = compute_accuracy([[100, pos_errors]])
|
||||
|
||||
data = table.data
|
||||
data = encode_(data)
|
||||
table.df = pd.DataFrame(data)
|
||||
table.shape = table.df.shape
|
||||
|
||||
|
||||
+2
-18
@@ -560,7 +560,7 @@ def get_table_index(table, t, direction, split_text=False, flag_size=False):
|
||||
lt_col_overlap.append(abs(left - right) / abs(c[0] - c[1]))
|
||||
else:
|
||||
lt_col_overlap.append(-1)
|
||||
if len(filter(lambda x: x != -1, lt_col_overlap)) == 0:
|
||||
if len(list(filter(lambda x: x != -1, lt_col_overlap))) == 0:
|
||||
text = t.get_text().strip('\n')
|
||||
text_range = (t.x0, t.x1)
|
||||
col_range = (table.cols[0][0], table.cols[-1][1])
|
||||
@@ -669,22 +669,6 @@ def remove_empty(d):
|
||||
return d
|
||||
|
||||
|
||||
def encode_(ar):
|
||||
"""Encodes two-dimensional list into unicode.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
ar : list
|
||||
|
||||
Returns
|
||||
-------
|
||||
ar : list
|
||||
|
||||
"""
|
||||
ar = [[r.encode('utf-8') for r in row] for row in ar]
|
||||
return ar
|
||||
|
||||
|
||||
def get_page_layout(filename, char_margin=1.0, line_margin=0.5, word_margin=0.1,
|
||||
detect_vertical=True, all_texts=True):
|
||||
"""Returns a PDFMiner LTPage object and page dimension of a single
|
||||
@@ -709,7 +693,7 @@ def get_page_layout(filename, char_margin=1.0, line_margin=0.5, word_margin=0.1,
|
||||
Dimension of pdf page in the form (width, height).
|
||||
|
||||
"""
|
||||
with open(filename, 'r') as f:
|
||||
with open(filename, 'rb') as f:
|
||||
parser = PDFParser(f)
|
||||
document = PDFDocument(parser)
|
||||
if not document.is_extractable:
|
||||
|
||||
Reference in New Issue
Block a user