-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6ac15ac
commit 24f9d86
Showing
21 changed files
with
759 additions
and
321 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
# spacypdfreader.parsers | ||
|
||
::: spacypdfreader.parsers.base.BaseParser | ||
::: spacypdfreader.parsers.pdfminer | ||
|
||
::: spacypdfreader.parsers.pdfminer.PdfminerParser | ||
|
||
::: spacypdfreader.parsers.pytesseract.PytesseractParser | ||
::: spacypdfreader.parsers.pytesseract |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import shutil | ||
|
||
|
||
def copy_readme(*args, **kwargs): | ||
shutil.copy("README.md", "docs/index.md") | ||
shutil.copy("README.md", "docs/index.md") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# Multiprocessing | ||
|
||
As of version `0.3.0` spacypdfreader has built in support for multi-processing. This can dramatically improve the time it takes to convert a PDF to text. | ||
|
||
## Usage | ||
|
||
You can use multiprocessing with an parser. | ||
|
||
**pdfminder** | ||
|
||
```python | ||
import spacy | ||
|
||
from spacypdfreader.spacypdfreader import pdf_reader | ||
|
||
nlp = spacy.load("en_core_web_sm") | ||
doc = pdf_reader("tests/data/test_pdf_01.pdf", nlp, n_processes=4) | ||
``` | ||
|
||
**pytesseract** | ||
|
||
```python | ||
import spacy | ||
|
||
from spacypdfreader.parsers import pytesseract | ||
from spacypdfreader.spacypdfreader import pdf_reader | ||
|
||
nlp = spacy.load("en_core_web_sm") | ||
doc = pdf_reader("tests/data/test_pdf_01.pdf", nlp, pytesseract.parser, n_processes=4) | ||
``` | ||
|
||
## Benchmark | ||
|
||
```python | ||
import time | ||
from functools import wraps | ||
|
||
import spacy | ||
|
||
from spacypdfreader import pdf_reader | ||
from spacypdfreader.parsers import pytesseract | ||
|
||
|
||
def timeit(func): | ||
@wraps(func) | ||
def wrapper(*args, **kwargs): | ||
start = time.perf_counter() | ||
result = func(*args, **kwargs) | ||
end = time.perf_counter() | ||
print(f"Took {end - start:.6f} seconds to complete") | ||
return result | ||
|
||
return wrapper | ||
|
||
|
||
nlp = spacy.load("en_core_web_sm") | ||
file_name = "tests/data/wikipedia.pdf" | ||
|
||
|
||
@timeit | ||
def bench(n_processes): | ||
doc = pdf_reader(file_name, nlp, pytesseract.parser, n_processes=n_processes) | ||
return doc | ||
|
||
|
||
# With no multiprocessing | ||
bench(None) | ||
# Took 42.286371 seconds to complete | ||
|
||
# With multiprocessing | ||
bench(8) | ||
# Took 9.051591 seconds to complete | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
format: | ||
poetry run shed | ||
|
||
test: | ||
poetry run pytest | ||
poetry run pytest --doctest-modules spacypdfreader/ | ||
|
||
test-gha: | ||
gh workflow run pytest.yml --ref $(git branch --show-current) | ||
|
||
preview-docs: | ||
poetry run mkdocs serve | ||
|
||
publish-docs: | ||
rm -rf site | ||
mkdocs build | ||
mkdocs gh-deploy | ||
|
||
publish: | ||
poetry publish --build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.