Fix computing of lossless_reconstruction and checking of redo_ocr conflicts

This commit is contained in:
James R. Barlow
2025-12-21 12:21:47 -08:00
parent 1225c0a45e
commit e4f8ba8edc
+14 -12
View File
@@ -368,8 +368,19 @@ class OCROptions(BaseModel):
return self
@model_validator(mode='after')
def set_lossless_reconstruction(self):
"""Set lossless_reconstruction based on other options."""
def validate_redo_ocr_options(self):
"""Validate options compatible with redo_ocr."""
if self.redo_ocr:
if self.deskew or self.clean_final or self.remove_background:
raise ValueError(
"--redo-ocr is not currently compatible with --deskew, "
"--clean-final, and --remove-background"
)
return self
@property
def lossless_reconstruction(self):
"""Determine lossless_reconstruction based on other options."""
lossless = not any(
[
self.deskew,
@@ -378,16 +389,7 @@ class OCROptions(BaseModel):
self.remove_background,
]
)
if not lossless and self.redo_ocr:
raise ValueError(
"--redo-ocr is not currently compatible with --deskew, "
"--clean-final, and --remove-background"
)
# Set the computed attribute
self.extra_attrs['lossless_reconstruction'] = lossless
return self
return lossless
def model_dump_json_safe(self) -> str:
"""Serialize to JSON with special handling for non-serializable types."""