Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,3 @@ params_livetext = OcrmacParams(
)
hocr = engine.process(Path("document.pdf"), params_livetext)
```

## Version

0.1.0
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ requires-python = ">=3.10"
license = { text = "MIT" }

dependencies = [
"ocrbridge-core>=0.1.0",
"ocrbridge-core>=2.0.0",
"ocrmac>=0.2.2",
"pdf2image>=1.17.0",
"Pillow>=10.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/ocrbridge/engines/ocrmac/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

__all__ = ["OcrmacEngine", "OcrmacParams", "RecognitionLevel"]

__version__ = "0.1.0"
__version__ = "1.0.0"
2 changes: 2 additions & 0 deletions src/ocrbridge/engines/ocrmac/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class OcrmacEngine(OCREngine):
Platform: macOS 10.15+ (macOS Sonoma 14.0+ for LiveText)
"""

__param_model__ = OcrmacParams

@property
def name(self) -> str:
"""Return engine name."""
Expand Down
24 changes: 12 additions & 12 deletions src/ocrbridge/engines/ocrmac/models.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
"""ocrmac OCR engine parameter models."""

import re
from enum import Enum

from pydantic import Field, field_validator

from ocrbridge.core.models import OCREngineParams # type: ignore[reportMissingTypeStubs]
from ocrbridge.core.validation import (
PATTERN_IETF_BCP47,
validate_language_code_format,
validate_list_length,
)


class RecognitionLevel(str, Enum):
Expand Down Expand Up @@ -54,18 +58,14 @@ def validate_languages(cls, v: list[str] | None) -> list[str] | None:
if v is None:
return v

if len(v) > 5:
raise ValueError("Maximum 5 languages allowed")

# IETF BCP 47 format: language[-Script][-Region]
# Examples: en, en-US, zh-Hans, zh-Hans-CN
pattern = r"^[a-z]{2,3}(-[A-Z][a-z]{3})?(-[A-Z]{2})?$"
# Use core utilities for validation
validate_list_length(v, max_length=5, field_name="languages")

# Validate each language code format using core utility
for lang in v:
if not re.match(pattern, lang, re.IGNORECASE):
raise ValueError(
f"Invalid IETF BCP 47 language code: '{lang}'. "
f"Expected format: 'en-US', 'fr-FR', 'zh-Hans'"
)
validate_language_code_format(
lang,
PATTERN_IETF_BCP47,
)

return v
1 change: 0 additions & 1 deletion tests/__init__.py

This file was deleted.

2 changes: 1 addition & 1 deletion tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def test_invalid_language_code_format(self) -> None:

# Should raise a value_error from our custom validator
error_str = str(exc_info.value)
assert "Invalid IETF BCP 47 language code" in error_str or "value_error" in error_str
assert "Invalid IETF BCP 47" in error_str or "value_error" in error_str

def test_empty_language_list(self) -> None:
"""Test that empty language list raises error."""
Expand Down
10 changes: 5 additions & 5 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.