A comprehensive document splitting toolkit
Project description
omni_split: Split commonly used document (md, doc etc.) forms for RAG that support LLM.
note: All other text formats are highly recommended to be converted to Markdown, and we focus on optimizing documents for Markdown.
usage
install
pip install omni_split
use case
import json
from omni_split import OmniSplit
from omni_split import word_preprocessing_and_return_bytesIO
from omni_split import download_files_to_test_doc
### == step 2: download test_doc file ==
doc_dict = download_files_to_test_doc()
text_doc_file_path = doc_dict["text_test.txt"]
json_list_doc_file_path = doc_dict["json_list_test.json"]
markdown_doc_file_path = doc_dict["markdown_test.md"]
word_doc_file_path = doc_dict["docx_test.docx"]
### == step 3: split to chunk ==
omni_spliter = OmniSplit()
## note: test text split
test_text = True
if test_text:
with open(text_doc_file_path, "r") as f:
text_content = "".join(f.readlines())
res = omni_spliter.text_chunk_func(text_content,txt_chunk_size=1000)
for item in res:
print(item)
print("------------")
print("=" * 10)
## note: test markdown json split
test_markdown = True
if test_markdown:
with open(json_list_doc_file_path, "r") as f:
md_content_json = json.load(f)
res = omni_spliter.markdown_json_chunk_func(md_content_json)
for item in res:
print(item)
print("------------")
print("=" * 10)
res = omni_spliter.markdown_json_chunk_func(md_content_json, clear_model=True)
for item in res:
print(item)
print("------------")
print("=" * 10)
## note: test markdown split
test_markdown = True
if test_markdown:
with open(markdown_doc_file_path, "r") as f:
md_content = f.read()
res = omni_spliter.markdown_chunk_func(md_content)
for item in res:
print(item)
print("------------")
print("=" * 10)
res = omni_spliter.markdown_chunk_func(md_content, clear_model=True)
for item in res:
print(item)
print("------------")
print("=" * 10)
## note: test word split
test_document = True
if test_document:
new_doc_io = word_preprocessing_and_return_bytesIO(word_doc_file_path)
res = omni_spliter.document_chunk_func(new_doc_io, txt_chunk_size=1000, clear_model=False)
for item in res:
print(item)
print("------------")
print("=" * 10)
res = omni_spliter.document_chunk_func(new_doc_io, txt_chunk_size=1000, clear_model=False, save_local_images_dir="./images")
for item in res:
print(item)
print("------------")
print("=" * 10)
res = omni_spliter.document_chunk_func(new_doc_io, txt_chunk_size=1000, clear_model=True)
for item in res:
print(item)
print("------------")
print("=" * 10)
Reminder of dependency:
To automatically convert binary metafiles(e.g. x-wmf.) in Word to PNG, you need to install ImageMagick on Linux. Try to install: https://docs.wand-py.org/en/latest/guide/install.html
This project is inspired by:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
omni_split-0.0.3.tar.gz
(2.0 MB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file omni_split-0.0.3.tar.gz.
File metadata
- Download URL: omni_split-0.0.3.tar.gz
- Upload date:
- Size: 2.0 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
245370fc5bd10523e8a27f2fc5be2b0ee5767f7e30c3686528ec488f02e82544
|
|
| MD5 |
6c6d5aa236eacd7aacb6b92a9b30e1b1
|
|
| BLAKE2b-256 |
950e967d1e7f422694ec0817b6925f6c7cec347c0eb2b7e0e1f4ac2015846a44
|
File details
Details for the file omni_split-0.0.3-py3-none-any.whl.
File metadata
- Download URL: omni_split-0.0.3-py3-none-any.whl
- Upload date:
- Size: 2.0 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d44acd8caf3be502ce107198d08f0625180e25587d709042abe358720656d92e
|
|
| MD5 |
5f5178831d868af1ce02faed60816b41
|
|
| BLAKE2b-256 |
d13cc714b1a44e2deb329024df165d9d681c1abd06b28bceed6adb80da59139d
|