Skip to main content

A comprehensive document splitting toolkit

Project description

omni_split: Split commonly used document (md, doc etc.) forms for RAG that support LLM.


omni_split

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

Project details


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.1rc0.tar.gz (2.0 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

omni_split-0.0.1rc0-py3-none-any.whl (2.0 MB view details)

Uploaded Python 3

File details

Details for the file omni_split-0.0.1rc0.tar.gz.

File metadata

  • Download URL: omni_split-0.0.1rc0.tar.gz
  • Upload date:
  • Size: 2.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.0

File hashes

Hashes for omni_split-0.0.1rc0.tar.gz
Algorithm Hash digest
SHA256 c6c8f6b94cbc43505db2f7e5b9ac2617a1d2b27db16cd92a3d32dcd4354e77c4
MD5 f37f7671e292ae3200119d958bc6dcbc
BLAKE2b-256 075b77d98d482a7ce27400356906b9753653ea633c6e7350443f949247a73d90

See more details on using hashes here.

File details

Details for the file omni_split-0.0.1rc0-py3-none-any.whl.

File metadata

  • Download URL: omni_split-0.0.1rc0-py3-none-any.whl
  • Upload date:
  • Size: 2.0 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.0

File hashes

Hashes for omni_split-0.0.1rc0-py3-none-any.whl
Algorithm Hash digest
SHA256 de2de7e3eede27be25e39c3b998320b0cc67fd573589c163313567655a79a889
MD5 f4e77f5e1cba6e276e9c93a525d54a4e
BLAKE2b-256 cb468dc02b17e4ff1b8900072303170920320fb4f453f7ef771204b77066d0e9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page