"""Text extraction layer for various document formats.""" from pathlib import Path from .base import ExtractionResult, TextExtractor from .docx import DocxExtractor from .ocr import OCRExtractor from .pdf import PDFExtractor from .text import PlainTextExtractor def get_extractor(file_path: Path, config=None): """Get the appropriate extractor for a file. Args: file_path: Path to the file to extract. config: Optional IngestionConfig for LLM-based extraction. Returns: An extractor instance that can handle the file, or None. """ suffix = file_path.suffix.lower() if suffix in (".md", ".txt"): return PlainTextExtractor() elif suffix == ".pdf": if config: return PDFExtractor( ocr_enabled=config.ocr_enabled, ocr_language=config.ocr_language, llm_provider=config.llm_provider, llm_model=config.llm_model, mistral_api_key=config.mistral_api_key, ) return PDFExtractor() elif suffix in (".jpg", ".jpeg", ".png"): return OCRExtractor() elif suffix == ".docx": return DocxExtractor() return None __all__ = [ "ExtractionResult", "TextExtractor", "PlainTextExtractor", "PDFExtractor", "OCRExtractor", "DocxExtractor", "get_extractor", ]