| 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) | |