techprotrade's picture
Add src directory
734b5b4 verified
Raw
History Blame Contribute Delete
1.07 kB
from typing import Dict, List, Any
class FormatCorrectionAgent:
"""Corrects text format - spacing, alignment, fonts."""
def process(self, extracted_text: str, layout_info: Dict = None) -> Dict[str, Any]:
"""Correct text formatting."""
corrected = self._fix_spacing(extracted_text)
corrected = self._fix_alignment(corrected)
return {
"corrected_text": corrected,
"fixes_applied": ["spacing", "alignment"],
"paragraphs_fixed": self._count_paragraphs(corrected),
}
def _fix_spacing(self, text: str) -> str:
"""Fix spacing issues."""
import re
text = re.sub(r" +", " ", text)
text = re.sub(r"\n+", "\n", text)
return text
def _fix_alignment(self, text: str) -> str:
"""Fix alignment."""
lines = text.split("\n")
return "\n".join(line.strip() for line in lines)
def _count_paragraphs(self, text: str) -> int:
"""Count paragraphs."""
return len([p for p in text.split("\n\n") if p.strip()])