-
Notifications
You must be signed in to change notification settings - Fork 40
pdf broken encoding reader #522
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
…takes too much time), changed imports
requirements.txt
Outdated
@@ -40,3 +39,6 @@ wget==3.2 | |||
xgbfir>=0.3.1,<1.0 | |||
xgboost>=1.6.0,<2.0 # lower versions aren't compatible with pandas>2 | |||
xlrd>=1.2.0,<2.0 | |||
nltk==3.9.1 | |||
tensorflow==2.13.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tensorflow
import should be optional similarly to torch
(https://github.com/ispras/dedoc/blob/master/pyproject.toml)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
scripts/get_text_broken_pdf.py
Outdated
|
||
from dedoc.readers.pdf_reader.pdf_txtlayer_reader.pdf_broken_encoding_reader.pdf_broken_encoding_reader import PdfBrokenEncodingReader | ||
|
||
if __name__ == "__main__": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This script can be converted into test (e.g. here https://github.com/ispras/dedoc/blob/master/tests/unit_tests/test_format_pdf_reader.py)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
dedoc/api/api_args.py
Outdated
@@ -24,7 +24,7 @@ class QueryParameters: | |||
table_type: str = Form("", description="Pipeline mode for table recognition") | |||
|
|||
# pdf handling | |||
pdf_with_text_layer: str = Form("auto_tabby", enum=["true", "false", "auto", "auto_tabby", "tabby"], | |||
pdf_with_text_layer: str = Form("auto_tabby", enum=["true", "false", "auto", "auto_tabby", "tabby","bad_encoding_reader"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
API test should be written for a new parameter: you can create file test_pdf_bad_encoding_reader.py
similarly to test_api_format_pdf_with_text.py
.gitignore
Outdated
@@ -26,6 +26,7 @@ var/ | |||
*.egg-info/ | |||
.installed.cfg | |||
*.egg | |||
dedoc/readers/pdf_reader/pdf_txtlayer_reader/pdf_broken_encoding_reader/data/pdfdata |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the directory should be placed in cache ("resources_path" of dedoc config) and downloaded if needed, as it is done for other data (datasets, models) in download_models.py - this script is used in Docker for downloading data in advance
For PyPI library, readers download their data if needed, e.g. for PdfAutoReader - pdf_auto_reader/txtlayer_classifier.py#L27
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
||
class PdfBrokenEncodingReader(PdfBaseReader): | ||
""" | ||
This class allows to extract content (text, tables, attachments) from the .pdf documents with a textual layer (copyable documents). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong docstring (it's doc for other reader)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
self.extractor_layer = PdfminerExtractor(config=self.config) | ||
self.__pdf_txtlayer_reader = PdfTxtlayerReader(config=config) | ||
|
||
def can_read(self, file_path: Optional[str] = None, mime: Optional[str] = None, extension: Optional[str] = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong docstring
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
return super().can_read(file_path=file_path, mime=mime, extension=extension) and get_param_pdf_with_txt_layer( | ||
parameters) == "bad_encoding_reader" | ||
|
||
def read(self, file_path: str, parameters: Optional[dict] = None) -> UnstructuredDocument: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docstring is needed
@@ -110,6 +110,7 @@ <h4>PDF handling</h4> | |||
<option value="auto">auto</option> | |||
<option value="auto_tabby" selected>auto_tabby</option> | |||
<option value="tabby">tabby</option> | |||
<option value="bad_encoding_reader">bad_encoding_reader</option> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New parameter should be added into docs:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
WordObj = namedtuple("Word", ["start", "end", "value"]) | ||
|
||
|
||
class PdfBrokenEncodingReader(PdfBaseReader): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New reader should be added to the docs: https://github.com/ispras/dedoc/blob/master/docs/source/modules/readers.rst
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Please look to the logs of test pipelines - they all should pass before merge |
.../pdf_reader/pdf_txtlayer_reader/pdf_broken_encoding_reader/data/models/default_models/eng.h5
Outdated
Show resolved
Hide resolved
...ders/pdf_reader/pdf_txtlayer_reader/pdf_broken_encoding_reader/pdf_broken_encoding_reader.py
Show resolved
Hide resolved
...ders/pdf_reader/pdf_txtlayer_reader/pdf_broken_encoding_reader/pdf_broken_encoding_reader.py
Outdated
Show resolved
Hide resolved
...ders/pdf_reader/pdf_txtlayer_reader/pdf_broken_encoding_reader/pdf_broken_encoding_reader.py
Outdated
Show resolved
Hide resolved
...ders/pdf_reader/pdf_txtlayer_reader/pdf_broken_encoding_reader/pdf_broken_encoding_reader.py
Outdated
Show resolved
Hide resolved
...ders/pdf_reader/pdf_txtlayer_reader/pdf_broken_encoding_reader/pdf_broken_encoding_reader.py
Outdated
Show resolved
Hide resolved
...ders/pdf_reader/pdf_txtlayer_reader/pdf_broken_encoding_reader/pdf_broken_encoding_reader.py
Outdated
Show resolved
Hide resolved
call_classifier=False)) | ||
return lines, tables, page.attachments, [] | ||
|
||
def __handle_page(self, page: PDFPage, page_number: int, path: str, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is dublicated code of dedoc/readers/pdf_reader/pdf_txtlayer_reader/pdfminer_reader/pdfminer_extractor.py
with different that you use own layout
(pass own layout ). Try to use code of dedoc/readers/pdf_reader/pdf_txtlayer_reader/pdfminer_reader/pdfminer_extractor.py
with small changes of code of pdfminer_extractor.py.
For example in file dedoc/readers/pdf_reader/pdf_txtlayer_reader/pdfminer_reader/pdfminer_extractor.py
:
- do pubic function
def __handle_page(...)
->def handle_page(...)
- added small changes into code:
def handle_page(self, page: PDFPage, page_number: int, path: str, parameters: ParametersForParseDoc, Layout: Optional[LTPage] = None) -> PageWithBBox:
...
if not layout:
layout = device.get_result()
...
So, by adding these small changes you will get rid of 300 lines of duplicate code!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Почему добавили еще одну функцию handle_page, если эта функция уже есть? Ее достаточно просто изменить как показано в примере выше. А то снова код дублируется, получается две почти одинаковые функции handle_page в одном классе
...s/pdf_reader/pdf_txtlayer_reader/pdf_broken_encoding_reader/pdf_worker/pdf_text_correcter.py
Outdated
Show resolved
Hide resolved
dedoc/readers/pdf_reader/pdf_txtlayer_reader/pdf_broken_encoding_reader/model.py
Show resolved
Hide resolved
dedoc/readers/pdf_reader/pdf_txtlayer_reader/pdf_broken_encoding_reader/model.py
Outdated
Show resolved
Hide resolved
dedoc/readers/pdf_reader/pdf_txtlayer_reader/pdf_broken_encoding_reader/functions.py
Outdated
Show resolved
Hide resolved
...ers/pdf_reader/pdf_txtlayer_reader/pdf_broken_encoding_reader/ffwrapper/fontforge_wrapper.py
Show resolved
Hide resolved
dedoc/readers/pdf_reader/pdf_txtlayer_reader/pdf_broken_encoding_reader/config.py
Outdated
Show resolved
Hide resolved
…pdfminer_extractor, added function handle_page(...) to pdfminer_extractor to use in my reader
…ction to tempfile
problems with imports (numpy) during running tests installs numpy 2.0.2 but required numpy<2.0. Runned even on dedoc without my commits on devolopment branch, but problem remains. Please check |
pyproject.toml
Outdated
@@ -37,6 +37,7 @@ include = ["dedoc*"] | |||
|
|||
[project.optional-dependencies] | |||
torch = ["torch~=1.11.0", "torchvision~=0.12.0"] | |||
tensorflow = ["tensorflow==2.13.0"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tensorflow уже не используется, надо убрать эту сточку
Reader to extract code from PDF with complex background using information from PDF
added my code from project needed to extract text:
added script to scripts dir to extract text using reader
edited index.html, api_args, manager_config, gitignore and requirements