Get chunked elements
Task
You want to get, and print or save, the contents of elements that have been chunked.
Approach
Chunked elements are typically represented in this format:
To get the element’s chunked content, extract the contents of the element’s text
field.
The chunked content might not contain all of its associated content. To get all of the elements that were used to derive this chunked content, extract the contents of the element’s orig_elements
field, which is nested inside of its parent metadata
field.
The contents of the orig_elements
field is in compressed Base64 gzipped format. To get the content, Base64-decode the bytes, decompress them, and then decode them using UTF-8.
To run this example
You will need to chunk a document during processing. This example uses a PDF file chunked into 200- to 300-character elements.
Code
For the Unstructured Python SDK, you’ll need:
These environment variables:
UNSTRUCTURED_API_KEY
- Your Unstructured API key value.UNSTRUCTURED_API_URL
- Your Unstructured API URL.