File size: 1,317 Bytes
734b5b4 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | from typing import Dict, List, Any
class ContentValidationAgent:
"""Validates extracted content for errors and completeness."""
def process(self, extracted_data: Dict) -> Dict[str, Any]:
"""Validate content."""
text = extracted_data.get("text", "")
return {
"is_valid": self._check_validity(text),
"errors": self._find_errors(text),
"completeness": self._check_completeness(text),
"word_count": len(text.split()) if text else 0,
}
def _check_validity(self, text: str) -> bool:
"""Check if text is valid."""
if not text:
return False
if len(text.strip()) < 10:
return False
return True
def _find_errors(self, text: str) -> List[str]:
"""Find potential errors."""
errors = []
import re
if re.search(r"\?\?", text):
errors.append("Potential OCR errors (??)")
if re.search(r"[\x00-\x08]", text):
errors.append("Contains control characters")
return errors
def _check_completeness(self, text: str) -> float:
"""Check completeness."""
if not text:
return 0.0
lines = [l for l in text.split("\n") if l.strip()]
return min(1.0, len(lines) / 10)
|