darachhat
feat: build production-ready Khmer Document Corpus v0.2.0 with Typer CLI, PyMuPDF, Polars, and DI architecture
c4e128a
Raw
History Blame Contribute Delete
1.19 kB
"""Schema validator for DocumentMeta objects."""
from __future__ import annotations
from app.models.document import DocumentMeta, ValidationResult
class SchemaValidator:
"""Validates DocumentMeta structural integrity and mandatory attributes."""
def validate(self, meta: DocumentMeta) -> ValidationResult:
errors: list[str] = []
warnings: list[str] = []
if meta.pages < 1:
errors.append(f"Invalid page count: {meta.pages}")
if meta.file_size_bytes <= 0:
errors.append(f"Invalid file size: {meta.file_size_bytes} bytes")
if not meta.filename.endswith(".pdf"):
errors.append(f"Filename does not end with .pdf: {meta.filename}")
if meta.sha256 and len(meta.sha256) != 64:
errors.append("sha256 hash must be 64 hexadecimal characters")
if meta.language == "unknown":
warnings.append("Document language is unknown")
if meta.category == "other":
warnings.append("Document category is generic 'other'")
return ValidationResult(
is_valid=len(errors) == 0,
errors=errors,
warnings=warnings,
)