-
Notifications
You must be signed in to change notification settings - Fork 16
V3 api #128
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
Merged
Merged
V3 api #128
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
63031b3
Port to OCR-D/core API v3
kba f287386
🧹Don't pin uniseg and rapidfuzz
mikegerber 8c1b6d6
Dockerfile: build ocrd-all-tool.json
kba c0aa82d
OCR-D processor: properly handle missing or non-downloaded GT/OCR file
kba 4162836
ocrd_cli: no need to check fileGrp dir exists
kba f6a2c94
ocrd_cli: but do check for existing output files
kba 831a24f
typo: report_prefix -> file_id
kba b7bdca4
🐛 Makefile: Make phony targets .PHONY
mikegerber d974369
🐛 Docker: Fix description
mikegerber 13ab1ae
🐛 Docker: Use same vendor as license for now
mikegerber File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,5 @@ | ||
src/dinglehopper/tests | ||
dist | ||
build | ||
*.egg-info | ||
.git |
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -5,7 +5,7 @@ uniseg >= 0.9.1 | |
numpy | ||
colorama | ||
MarkupSafe | ||
ocrd >= 2.65.0 | ||
ocrd >= 3.3.0 | ||
attrs | ||
multimethod >= 1.3 | ||
tqdm | ||
|
This file contains hidden or 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 hidden or 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,83 +1,76 @@ | ||
import json | ||
from functools import cached_property | ||
import os | ||
from typing import Optional | ||
|
||
import click | ||
import importlib_resources | ||
from ocrd_models import OcrdFileType | ||
from ocrd import Processor | ||
from ocrd.decorators import ocrd_cli_options, ocrd_cli_wrap_processor | ||
from ocrd_utils import assert_file_grp_cardinality, getLogger, make_file_id | ||
from ocrd_utils import make_file_id | ||
|
||
from .cli import process as cli_process | ||
|
||
OCRD_TOOL = json.loads( | ||
importlib_resources.files(__name__) | ||
.joinpath("ocrd-tool.json") | ||
.read_text(encoding="utf-8", errors="strict") | ||
) | ||
|
||
|
||
@click.command() | ||
@ocrd_cli_options | ||
def ocrd_dinglehopper(*args, **kwargs): | ||
return ocrd_cli_wrap_processor(OcrdDinglehopperEvaluate, *args, **kwargs) | ||
|
||
|
||
class OcrdDinglehopperEvaluate(Processor): | ||
def __init__(self, *args, **kwargs): | ||
kwargs["ocrd_tool"] = OCRD_TOOL["tools"]["ocrd-dinglehopper"] | ||
kwargs["version"] = OCRD_TOOL["version"] | ||
super(OcrdDinglehopperEvaluate, self).__init__(*args, **kwargs) | ||
|
||
def process(self): | ||
assert_file_grp_cardinality(self.input_file_grp, 2, "GT and OCR") | ||
assert_file_grp_cardinality(self.output_file_grp, 1) | ||
@cached_property | ||
def executable(self): | ||
return 'ocrd-dinglehopper' | ||
|
||
log = getLogger("processor.OcrdDinglehopperEvaluate") | ||
def process_page_file(self, *input_files: Optional[OcrdFileType]) -> None: | ||
|
||
assert self.parameter | ||
metrics = self.parameter["metrics"] | ||
textequiv_level = self.parameter["textequiv_level"] | ||
gt_grp, ocr_grp = self.input_file_grp.split(",") | ||
|
||
input_file_tuples = self.zip_input_files(on_error="abort") | ||
for n, (gt_file, ocr_file) in enumerate(input_file_tuples): | ||
if not gt_file or not ocr_file: | ||
# file/page was not found in this group | ||
continue | ||
gt_file = self.workspace.download_file(gt_file) | ||
ocr_file = self.workspace.download_file(ocr_file) | ||
page_id = gt_file.pageId | ||
|
||
log.info("INPUT FILES %i / %s↔ %s", n, gt_file, ocr_file) | ||
|
||
file_id = make_file_id(ocr_file, self.output_file_grp) | ||
report_prefix = os.path.join(self.output_file_grp, file_id) | ||
|
||
# Process the files | ||
try: | ||
os.mkdir(self.output_file_grp) | ||
except FileExistsError: | ||
pass | ||
cli_process( | ||
gt_file.local_filename, | ||
ocr_file.local_filename, | ||
report_prefix, | ||
metrics=metrics, | ||
textequiv_level=textequiv_level, | ||
# wrong number of inputs: let fail | ||
gt_file, ocr_file = input_files | ||
# missing on either side: skip (zip_input_files already warned) | ||
if not gt_file or not ocr_file: | ||
return | ||
# missing download (i.e. OCRD_DOWNLOAD_INPUT=false): | ||
if not gt_file.local_filename: | ||
if config.OCRD_MISSING_INPUT == 'ABORT': | ||
raise MissingInputFile(gt_file.fileGrp, gt_file.pageId, gt_file.mimetype) | ||
return | ||
if not ocr_file.local_filename: | ||
if config.OCRD_MISSING_INPUT == 'ABORT': | ||
raise MissingInputFile(ocr_file.fileGrp, ocr_file.pageId, ocr_file.mimetype) | ||
return | ||
|
||
page_id = gt_file.pageId | ||
|
||
file_id = make_file_id(ocr_file, self.output_file_grp) | ||
cli_process( | ||
gt_file.local_filename, | ||
ocr_file.local_filename, | ||
file_id, | ||
self.output_file_grp, | ||
metrics=metrics, | ||
textequiv_level=textequiv_level, | ||
) | ||
|
||
# Add reports to the workspace | ||
for report_suffix, mimetype in [ | ||
[".html", "text/html"], | ||
[".json", "application/json"], | ||
]: | ||
output_file_id = file_id + report_suffix | ||
output_file = next(self.workspace.mets.find_files(ID=output_file_id), None) | ||
if output_file and config.OCRD_EXISTING_OUTPUT != 'OVERWRITE': | ||
raise FileExistsError(f"A file with ID=={output_file_id} already exists {output_file} and neither force nor ignore are set") | ||
self.workspace.add_file( | ||
file_id=output_file_id, | ||
file_grp=self.output_file_grp, | ||
page_id=page_id, | ||
mimetype=mimetype, | ||
local_filename=file_id + report_suffix, | ||
) | ||
|
||
# Add reports to the workspace | ||
for report_suffix, mimetype in [ | ||
[".html", "text/html"], | ||
[".json", "application/json"], | ||
]: | ||
self.workspace.add_file( | ||
file_id=file_id + report_suffix, | ||
file_grp=self.output_file_grp, | ||
page_id=page_id, | ||
mimetype=mimetype, | ||
local_filename=report_prefix + report_suffix, | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
ocrd_dinglehopper() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.