Underground-Digital/Workflow-Engine
0
1import logging2 3from core.rag.extractor.extractor_base import BaseExtractor4from core.rag.models.document import Document5 6logger = logging.getLogger(__name__)7 8 9class UnstructuredMsgExtractor(BaseExtractor):10 """Load msg files.11 12 13 Args:14 file_path: Path to the file to load.15 """16 17 def __init__(self, file_path: str, api_url: str, api_key: str):18 """Initialize with file path."""19 self._file_path = file_path20 self._api_url = api_url21 self._api_key = api_key22 23 def extract(self) -> list[Document]:24 if self._api_url:25 from unstructured.partition.api import partition_via_api26 27 elements = partition_via_api(filename=self._file_path, api_url=self._api_url, api_key=self._api_key)28 else:29 from unstructured.partition.msg import partition_msg30 31 elements = partition_msg(filename=self._file_path)32 from unstructured.chunking.title import chunk_by_title33 34 chunks = chunk_by_title(elements, max_characters=2000, combine_text_under_n_chars=2000)35 documents = []36 for chunk in chunks:37 text = chunk.text.strip()38 documents.append(Document(page_content=text))39 40 return documents41 