r"""Chunks elements by titles. Args: 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.
(
elements: List["Element"], chunk_type: str, **kwargs
)
| 442 | |
| 443 | @staticmethod |
| 444 | def chunk_elements( |
| 445 | elements: List["Element"], chunk_type: str, **kwargs |
| 446 | ) -> List["Element"]: |
| 447 | r"""Chunks elements by titles. |
| 448 | |
| 449 | Args: |
| 450 | elements (List[Element]): List of Element objects to be chunked. |
| 451 | chunk_type (str): Type chunk going to apply. Supported types: |
| 452 | 'chunk_by_title'. |
| 453 | **kwargs: Additional keyword arguments for chunking. |
| 454 | |
| 455 | Returns: |
| 456 | List[Dict]: List of chunked sections. |
| 457 | |
| 458 | References: |
| 459 | https://unstructured-io.github.io/unstructured/ |
| 460 | """ |
| 461 | |
| 462 | from unstructured.chunking.title import chunk_by_title |
| 463 | |
| 464 | chunking_functions = { |
| 465 | "chunk_by_title": chunk_by_title, |
| 466 | } |
| 467 | |
| 468 | if chunk_type not in chunking_functions: |
| 469 | raise ValueError(f"Unsupported chunk type: {chunk_type}") |
| 470 | |
| 471 | # Format chunks into a list of dictionaries (or your preferred format) |
| 472 | return chunking_functions[chunk_type](elements, **kwargs) |