Skip to content

Commit

Permalink
Sort import statements with isort
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Weil <sw@weilnetz.de>
  • Loading branch information
stweil committed Mar 13, 2024
1 parent ed73d96 commit d0e2428
Show file tree
Hide file tree
Showing 14 changed files with 85 additions and 156 deletions.
10 changes: 5 additions & 5 deletions ocrd_tesserocr/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from .binarize import TesserocrBinarize
from .crop import TesserocrCrop
from .deskew import TesserocrDeskew
from .fontshape import TesserocrFontShape
from .recognize import TesserocrRecognize
from .segment import TesserocrSegment
from .segment_word import TesserocrSegmentWord
from .segment_line import TesserocrSegmentLine
from .segment_table import TesserocrSegmentTable
from .segment_region import TesserocrSegmentRegion
from .crop import TesserocrCrop
from .deskew import TesserocrDeskew
from .binarize import TesserocrBinarize
from .segment_table import TesserocrSegmentTable
from .segment_word import TesserocrSegmentWord
19 changes: 4 additions & 15 deletions ocrd_tesserocr/binarize.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
from __future__ import absolute_import

import os.path
from tesserocr import (
PyTessBaseAPI,
PSM, RIL
)

from ocrd_utils import (
getLogger,
assert_file_grp_cardinality,
make_file_id,
MIMETYPE_PAGE
)
from ocrd_modelfactory import page_from_file
from ocrd_models.ocrd_page import (
AlternativeImageType,
TextRegionType,
to_xml
)
from ocrd_models.ocrd_page import AlternativeImageType, TextRegionType, to_xml
from ocrd_utils import (MIMETYPE_PAGE, assert_file_grp_cardinality, getLogger,
make_file_id)
from tesserocr import PSM, RIL, PyTessBaseAPI

from .config import OCRD_TOOL
from .recognize import TesserocrRecognize
Expand Down
11 changes: 6 additions & 5 deletions ocrd_tesserocr/cli.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import click

from ocrd.decorators import ocrd_cli_options, ocrd_cli_wrap_processor

from ocrd_tesserocr.binarize import TesserocrBinarize
from ocrd_tesserocr.crop import TesserocrCrop
from ocrd_tesserocr.deskew import TesserocrDeskew
from ocrd_tesserocr.fontshape import TesserocrFontShape
from ocrd_tesserocr.recognize import TesserocrRecognize
from ocrd_tesserocr.segment import TesserocrSegment
from ocrd_tesserocr.segment_line import TesserocrSegmentLine
from ocrd_tesserocr.segment_region import TesserocrSegmentRegion
from ocrd_tesserocr.segment_table import TesserocrSegmentTable
from ocrd_tesserocr.segment_line import TesserocrSegmentLine
from ocrd_tesserocr.segment_word import TesserocrSegmentWord
from ocrd_tesserocr.crop import TesserocrCrop
from ocrd_tesserocr.deskew import TesserocrDeskew
from ocrd_tesserocr.binarize import TesserocrBinarize


@click.command()
@ocrd_cli_options
Expand Down
1 change: 1 addition & 0 deletions ocrd_tesserocr/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json

from pkg_resources import resource_string

OCRD_TOOL = json.loads(resource_string(__name__, 'ocrd-tool.json').decode('utf8'))
28 changes: 8 additions & 20 deletions ocrd_tesserocr/crop.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,16 @@
from __future__ import absolute_import

import os.path

import tesserocr
from ocrd_utils import (
getLogger,
crop_image,
coordinates_for_segment,
coordinates_of_segment,
bbox_from_polygon,
bbox_from_points,
polygon_from_bbox,
points_from_polygon,
bbox_from_xywh,
make_file_id,
assert_file_grp_cardinality,
MIMETYPE_PAGE
)
from ocrd_modelfactory import page_from_file
from ocrd_models.ocrd_page import (
CoordsType,
AlternativeImageType,
BorderType,
to_xml
)
from ocrd_models.ocrd_page import (AlternativeImageType, BorderType,
CoordsType, to_xml)
from ocrd_utils import (MIMETYPE_PAGE, assert_file_grp_cardinality,
bbox_from_points, bbox_from_polygon, bbox_from_xywh,
coordinates_for_segment, coordinates_of_segment,
crop_image, getLogger, make_file_id,
points_from_polygon, polygon_from_bbox)

from .config import OCRD_TOOL
from .recognize import TesserocrRecognize, polygon_for_parent
Expand Down
27 changes: 7 additions & 20 deletions ocrd_tesserocr/deskew.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,15 @@
from __future__ import absolute_import

import os.path
import math
from tesserocr import (
PyTessBaseAPI,
PSM, OEM,
Orientation,
WritingDirection,
TextlineOrder
)
import os.path

from ocrd_utils import (
getLogger,
make_file_id,
assert_file_grp_cardinality,
membername,
MIMETYPE_PAGE
)
from ocrd_modelfactory import page_from_file
from ocrd_models.ocrd_page import (
AlternativeImageType,
TextLineType, TextRegionType, PageType,
to_xml
)
from ocrd_models.ocrd_page import (AlternativeImageType, PageType,
TextLineType, TextRegionType, to_xml)
from ocrd_utils import (MIMETYPE_PAGE, assert_file_grp_cardinality, getLogger,
make_file_id, membername)
from tesserocr import (OEM, PSM, Orientation, PyTessBaseAPI, TextlineOrder,
WritingDirection)

from .config import OCRD_TOOL
from .recognize import TesserocrRecognize
Expand Down
22 changes: 6 additions & 16 deletions ocrd_tesserocr/fontshape.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
from __future__ import absolute_import
import os.path
from PIL import Image, ImageStat

from tesserocr import (
RIL, PSM, OEM,
PyTessBaseAPI,
get_languages
)
import os.path

from ocrd_utils import (
getLogger,
make_file_id,
assert_file_grp_cardinality,
MIMETYPE_PAGE
)
from ocrd_models.ocrd_page import (
TextStyleType,
to_xml)
from ocrd_modelfactory import page_from_file
from ocrd_models.ocrd_page import TextStyleType, to_xml
from ocrd_utils import (MIMETYPE_PAGE, assert_file_grp_cardinality, getLogger,
make_file_id)
from PIL import Image, ImageStat
from tesserocr import OEM, PSM, RIL, PyTessBaseAPI, get_languages

from .config import OCRD_TOOL
from .recognize import TesserocrRecognize
Expand Down
87 changes: 30 additions & 57 deletions ocrd_tesserocr/recognize.py
Original file line number Diff line number Diff line change
@@ -1,65 +1,38 @@
from __future__ import absolute_import

import itertools
import math
from os.path import join
from pathlib import Path
import math
import itertools
from PIL import Image, ImageStat
import numpy as np
from scipy.sparse.csgraph import minimum_spanning_tree
from shapely.geometry import Polygon, LineString
from shapely.ops import unary_union, nearest_points

from tesserocr import (
RIL, PSM, PT, OEM,
Orientation,
WritingDirection,
TextlineOrder,
tesseract_version,
PyTessBaseAPI,
get_languages)

from ocrd_utils import (
getLogger,
make_file_id,
assert_file_grp_cardinality,
shift_coordinates,
coordinates_for_segment,
polygon_from_x0y0x1y1,
polygon_from_points,
points_from_polygon,
xywh_from_polygon,
MIMETYPE_PAGE,
membername
)
from ocrd_models.ocrd_page import (
ReadingOrderType,
RegionRefType,
RegionRefIndexedType,
OrderedGroupType,
OrderedGroupIndexedType,
UnorderedGroupType,
UnorderedGroupIndexedType,
PageType,
CoordsType,
ImageRegionType,
MathsRegionType,
SeparatorRegionType,
NoiseRegionType,
TableRegionType,
TextRegionType,
TextLineType,
WordType,
GlyphType,
TextEquivType,
AlternativeImageType,
to_xml)
from ocrd_models.ocrd_page_generateds import (
ReadingDirectionSimpleType,
TextLineOrderSimpleType,
TextTypeSimpleType
)
from ocrd_modelfactory import page_from_file
import numpy as np
from ocrd import Processor
from ocrd_modelfactory import page_from_file
from ocrd_models.ocrd_page import (AlternativeImageType, CoordsType, GlyphType,
ImageRegionType, MathsRegionType,
NoiseRegionType, OrderedGroupIndexedType,
OrderedGroupType, PageType,
ReadingOrderType, RegionRefIndexedType,
RegionRefType, SeparatorRegionType,
TableRegionType, TextEquivType,
TextLineType, TextRegionType,
UnorderedGroupIndexedType,
UnorderedGroupType, WordType, to_xml)
from ocrd_models.ocrd_page_generateds import (ReadingDirectionSimpleType,
TextLineOrderSimpleType,
TextTypeSimpleType)
from ocrd_utils import (MIMETYPE_PAGE, assert_file_grp_cardinality,
coordinates_for_segment, getLogger, make_file_id,
membername, points_from_polygon, polygon_from_points,
polygon_from_x0y0x1y1, shift_coordinates,
xywh_from_polygon)
from PIL import Image, ImageStat
from scipy.sparse.csgraph import minimum_spanning_tree
from shapely.geometry import LineString, Polygon
from shapely.ops import nearest_points, unary_union
from tesserocr import (OEM, PSM, PT, RIL, Orientation, PyTessBaseAPI,
TextlineOrder, WritingDirection, get_languages,
tesseract_version)

from .config import OCRD_TOOL

Expand Down
6 changes: 3 additions & 3 deletions test/conftest.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from test.assets import assets as assets

from ocrd.resolver import Resolver
from ocrd_utils import pushd_popd, initLogging
from ocrd_utils import initLogging, pushd_popd
from pytest import fixture

from test.assets import assets as assets

METS_KANT_BINARIZED = assets.url_of('kant_aufklaerung_1784-binarized/data/mets.xml')
METS_HEROLD_SMALL = assets.url_of('SBB0000F29300010000/data/mets_one_file.xml')

Expand Down
4 changes: 2 additions & 2 deletions test/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from click.testing import CliRunner

from pathlib import Path

from click.testing import CliRunner

runner = CliRunner()

def test_show_resource(tmpdir, monkeypatch):
Expand Down
13 changes: 6 additions & 7 deletions test/test_recognize.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import os

from ocrd_models.constants import NAMESPACES
from ocrd_modelfactory import page_from_file
from ocrd_models.constants import NAMESPACES
from ocrd_utils import MIMETYPE_PAGE
from ocrd_tesserocr import TesserocrDeskew
from ocrd_tesserocr import TesserocrSegmentWord
from ocrd_tesserocr import TesserocrSegmentLine
from ocrd_tesserocr import TesserocrSegmentRegion
from ocrd_tesserocr import TesserocrRecognize
from ocrd_tesserocr import TesserocrFontShape

from ocrd_tesserocr import (TesserocrDeskew, TesserocrFontShape,
TesserocrRecognize, TesserocrSegmentLine,
TesserocrSegmentRegion, TesserocrSegmentWord)


def test_run_modular(workspace_kant_binarized):
TesserocrSegmentRegion(
Expand Down
6 changes: 3 additions & 3 deletions test/test_segment_line.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from ocrd_tesserocr import TesserocrSegmentRegion
from ocrd_tesserocr import TesserocrSegmentLine
from ocrd_tesserocr import TesserocrSegment
from ocrd_tesserocr import (TesserocrSegment, TesserocrSegmentLine,
TesserocrSegmentRegion)


def test_run_modular(workspace_herold_small):
TesserocrSegmentRegion(
Expand Down
1 change: 1 addition & 0 deletions test/test_segment_region.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from ocrd_tesserocr import TesserocrSegmentRegion


def test_run(workspace_herold_small):
TesserocrSegmentRegion(
workspace_herold_small,
Expand Down
6 changes: 3 additions & 3 deletions test/test_segment_word.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from ocrd_tesserocr import TesserocrSegmentRegion
from ocrd_tesserocr import TesserocrSegmentLine
from ocrd_tesserocr import TesserocrSegmentWord
from ocrd_tesserocr import (TesserocrSegmentLine, TesserocrSegmentRegion,
TesserocrSegmentWord)


def test_run_modular(workspace_kant_binarized):
TesserocrSegmentRegion(
Expand Down

0 comments on commit d0e2428

Please sign in to comment.