codekingpro/portable-devtools
114k
1from pathlib import Path2from typing import Any, List, Union3 4from langchain_community.document_loaders.unstructured import (5 UnstructuredFileLoader,6 validate_unstructured_version,7)8 9 10class UnstructuredOrgModeLoader(UnstructuredFileLoader):11 """Load `Org-Mode` files using `Unstructured`.12 13 You can run the loader in one of two modes: "single" and "elements".14 If you use "single" mode, the document will be returned as a single15 langchain Document object. If you use "elements" mode, the unstructured16 library will split the document into elements such as Title and NarrativeText.17 You can pass in additional unstructured kwargs after mode to apply18 different unstructured settings.19 20 Examples21 --------22 from langchain_community.document_loaders import UnstructuredOrgModeLoader23 24 loader = UnstructuredOrgModeLoader(25 "example.org", mode="elements", strategy="fast",26 )27 docs = loader.load()28 29 References30 ----------31 https://unstructured-io.github.io/unstructured/bricks.html#partition-org32 """33 34 def __init__(35 self,36 file_path: Union[str, Path],37 mode: str = "single",38 **unstructured_kwargs: Any,39 ):40 """41 42 Args:43 file_path: The path to the file to load.44 mode: The mode to load the file from. Default is "single".45 **unstructured_kwargs: Any additional keyword arguments to pass46 to the unstructured.47 """48 file_path = str(file_path)49 validate_unstructured_version(min_unstructured_version="0.7.9")50 super().__init__(file_path=file_path, mode=mode, **unstructured_kwargs)51 52 def _get_elements(self) -> List:53 from unstructured.partition.org import partition_org54 55 return partition_org(filename=self.file_path, **self.unstructured_kwargs)56 