> ## Documentation Index
> Fetch the complete documentation index at: https://docs.camel-ai.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Camel.loaders.unstructured io

<a id="camel.loaders.unstructured_io" />

<a id="camel.loaders.unstructured_io.UnstructuredIO" />

## UnstructuredIO

```python theme={"system"}
class UnstructuredIO:
```

A class to handle various functionalities provided by the
Unstructured library, including version checking, parsing, cleaning,
extracting, staging, chunking data, and integrating with cloud
services like S3 and Azure for data connection.

References:
[https://docs.unstructured.io/](https://docs.unstructured.io/)

<a id="camel.loaders.unstructured_io.UnstructuredIO.create_element_from_text" />

### create\_element\_from\_text

```python theme={"system"}
def create_element_from_text(
    text: str,
    element_id: Optional[str] = None,
    embeddings: Optional[List[float]] = None,
    filename: Optional[str] = None,
    file_directory: Optional[str] = None,
    last_modified: Optional[str] = None,
    filetype: Optional[str] = None,
    parent_id: Optional[str] = None
):
```

Creates a Text element from a given text input, with optional
metadata and embeddings.

**Parameters:**

* **text** (str): The text content for the element.
* **element\_id** (Optional\[str], optional): Unique identifier for the element. (default: :obj:`None`)
* **embeddings** (List\[float], optional): A list of float numbers representing the text embeddings. (default: :obj:`None`)
* **filename** (Optional\[str], optional): The name of the file the element is associated with. (default: :obj:`None`)
* **file\_directory** (Optional\[str], optional): The directory path where the file is located. (default: :obj:`None`)
* **last\_modified** (Optional\[str], optional): The last modified date of the file. (default: :obj:`None`)
* **filetype** (Optional\[str], optional): The type of the file. (default: :obj:`None`)
* **parent\_id** (Optional\[str], optional): The identifier of the parent element. (default: :obj:`None`)

**Returns:**

Element: An instance of Text with the provided content and
metadata.

<a id="camel.loaders.unstructured_io.UnstructuredIO.parse_file_or_url" />

### parse\_file\_or\_url

```python theme={"system"}
def parse_file_or_url(input_path: str, **kwargs: Any):
```

Loads a file or a URL and parses its contents into elements.

**Parameters:**

* **input\_path** (str): Path to the file or URL to be parsed. \*\*kwargs: Extra kwargs passed to the partition function.

**Returns:**

Union\[List\[Element],None]: List of elements after parsing the file
or URL if success.

**Note:**

Supported file types:
"csv", "doc", "docx", "epub", "image", "md", "msg", "odt",
"org", "pdf", "ppt", "pptx", "rtf", "rst", "tsv", "xlsx".

References:
[https://unstructured-io.github.io/unstructured/](https://unstructured-io.github.io/unstructured/)

<a id="camel.loaders.unstructured_io.UnstructuredIO.parse_bytes" />

### parse\_bytes

```python theme={"system"}
def parse_bytes(file: IO[bytes], **kwargs: Any):
```

Parses a bytes stream and converts its contents into elements.

**Parameters:**

* **file** (IO\[bytes]): The file in bytes format to be parsed. \*\*kwargs: Extra kwargs passed to the partition function.

**Returns:**

Union\[List\[Element], None]: List of elements after parsing the file
if successful, otherwise `None`.

**Note:**

Supported file types:
"csv", "doc", "docx", "epub", "image", "md", "msg", "odt",
"org", "pdf", "ppt", "pptx", "rtf", "rst", "tsv", "xlsx".

References:
[https://docs.unstructured.io/open-source/core-functionality/partitioning](https://docs.unstructured.io/open-source/core-functionality/partitioning)

<a id="camel.loaders.unstructured_io.UnstructuredIO.clean_text_data" />

### clean\_text\_data

```python theme={"system"}
def clean_text_data(
    text: str,
    clean_options: Optional[List[Tuple[str, Dict[str, Any]]]] = None
):
```

Cleans text data using a variety of cleaning functions provided by
the `unstructured` library.

This function applies multiple text cleaning utilities by calling the
`unstructured` library's cleaning bricks for operations like
replacing Unicode quotes, removing extra whitespace, dashes, non-ascii
characters, and more.

If no cleaning options are provided, a default set of cleaning
operations is applied. These defaults including operations
"replace\_unicode\_quotes", "clean\_non\_ascii\_chars",
"group\_broken\_paragraphs", and "clean\_extra\_whitespace".

**Parameters:**

* **text** (str): The text to be cleaned.
* **clean\_options** (dict): A dictionary specifying which cleaning options to apply. The keys should match the names of the cleaning functions, and the values should be dictionaries containing the parameters for each function. Supported types: 'clean\_extra\_whitespace', 'clean\_bullets', 'clean\_ordered\_bullets', 'clean\_postfix', 'clean\_prefix', 'clean\_dashes', 'clean\_trailing\_punctuation', 'clean\_non\_ascii\_chars', 'group\_broken\_paragraphs', 'remove\_punctuation', 'replace\_unicode\_quotes', 'bytes\_string\_to\_string', 'translate\_text'.

**Returns:**

str: The cleaned text.

**Note:**

The 'options' dictionary keys must correspond to valid cleaning
brick names from the `unstructured` library.
Each brick's parameters must be provided in a nested dictionary
as the value for the key.

References:
[https://unstructured-io.github.io/unstructured/](https://unstructured-io.github.io/unstructured/)

<a id="camel.loaders.unstructured_io.UnstructuredIO.extract_data_from_text" />

### extract\_data\_from\_text

```python theme={"system"}
def extract_data_from_text(
    text: str,
    extract_type: Literal['extract_datetimetz', 'extract_email_address', 'extract_ip_address', 'extract_ip_address_name', 'extract_mapi_id', 'extract_ordered_bullets', 'extract_text_after', 'extract_text_before', 'extract_us_phone_number'],
    **kwargs
):
```

Extracts various types of data from text using functions from
unstructured.cleaners.extract.

**Parameters:**

* **text** (str): Text to extract data from. extract\_type (Literal\['extract\_datetimetz', 'extract\_email\_address', 'extract\_ip\_address', 'extract\_ip\_address\_name', 'extract\_mapi\_id', 'extract\_ordered\_bullets', 'extract\_text\_after', 'extract\_text\_before', 'extract\_us\_phone\_number']): Type of data to extract. \*\*kwargs: Additional keyword arguments for specific extraction functions.

**Returns:**

Any: The extracted data, type depends on extract\_type.

References:
[https://unstructured-io.github.io/unstructured/](https://unstructured-io.github.io/unstructured/)

<a id="camel.loaders.unstructured_io.UnstructuredIO.stage_elements" />

### stage\_elements

```python theme={"system"}
def stage_elements(
    elements: List[Any],
    stage_type: Literal['convert_to_csv', 'convert_to_dataframe', 'convert_to_dict', 'dict_to_elements', 'stage_csv_for_prodigy', 'stage_for_prodigy', 'stage_for_baseplate', 'stage_for_datasaur', 'stage_for_label_box', 'stage_for_label_studio', 'stage_for_weaviate'],
    **kwargs
):
```

Stages elements for various platforms based on the
specified staging type.

This function applies multiple staging utilities to format data
for different NLP annotation and machine learning tools. It uses
the 'unstructured.staging' module's functions for operations like
converting to CSV, DataFrame, dictionary, or formatting for
specific platforms like Prodigy, etc.

**Parameters:**

* **elements** (List\[Any]): List of Element objects to be staged. stage\_type (Literal\['convert\_to\_csv', 'convert\_to\_dataframe', 'convert\_to\_dict', 'dict\_to\_elements', 'stage\_csv\_for\_prodigy', 'stage\_for\_prodigy', 'stage\_for\_baseplate', 'stage\_for\_datasaur', 'stage\_for\_label\_box', 'stage\_for\_label\_studio', 'stage\_for\_weaviate']): Type of staging to perform. \*\*kwargs: Additional keyword arguments specific to the staging type.

**Returns:**

Union\[str, List\[Dict], Any]: Staged data in the
format appropriate for the specified staging type.

<a id="camel.loaders.unstructured_io.UnstructuredIO.chunk_elements" />

### chunk\_elements

```python theme={"system"}
def chunk_elements(elements: List['Element'], chunk_type: str, **kwargs):
```

Chunks elements by titles.

**Parameters:**

* **elements** (List\[Element]): List of Element objects to be chunked.
* **chunk\_type** (str): Type chunk going to apply. Supported types: 'chunk\_by\_title'. \*\*kwargs: Additional keyword arguments for chunking.

**Returns:**

List\[Dict]: List of chunked sections.

References:
[https://unstructured-io.github.io/unstructured/](https://unstructured-io.github.io/unstructured/)
