Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Document Chunkers

Document Chunkers is a Python library that splits raw documents into sentences or paragraphs. Use it to prepare text for natural language processing (NLP) tasks. The library reads plain text, Markdown, HTML, PDF, DOC, and DOCX input.

Install

pip install ovos-document-chunkers

Text Segmenters

img.png

A text segmenter splits plain text into sentences or paragraphs. This library wraps three segmentation models.

Usage

Example: Using SaT for Sentence Segmentation

from ovos_document_chunkers import SaTSentenceSplitter

config = {"model": "sat-3l-sm", "use_cuda": False}
splitter = SaTSentenceSplitter(config)

text = "This is a sentence. And this is another one."
sentences = splitter.chunk(text)

for sentence in sentences:
    print(sentence)

Example: Using WtP for Paragraph Segmentation

from ovos_document_chunkers import WtPParagraphSplitter

config = {"model": "wtp-bert-mini", "use_cuda": False}
splitter = WtPParagraphSplitter(config)

text = "This is a paragraph. It contains multiple sentences.\n\nThis is another paragraph."
paragraphs = splitter.chunk(text)

for paragraph in paragraphs:
    print(paragraph)

Example: Using PySBD for Sentence Segmentation

from ovos_document_chunkers import PySBDSentenceSplitter

config = {"lang": "en"}
splitter = PySBDSentenceSplitter(config)

text = "This is a sentence. This is another one!"
sentences = splitter.chunk(text)

for sentence in sentences:
    print(sentence)

File Formats

A file splitter reads a document in a given file format, then splits its text into sentences or paragraphs. Each splitter accepts a URL, a local path, or the raw file text.

Supported File Formats

Type Description Class Name Expected Input File Extension
Markdown Splits Markdown text into sentences or paragraphs MarkdownSentenceSplitter String (url, path or Markdown text) .md
MarkdownParagraphSplitter String (url, path or Markdown text) .md
HTML Splits HTML text into sentences or paragraphs HTMLSentenceSplitter String (url, path or HTML text) .html
HTMLParagraphSplitter String (url, path or HTML text) .html
PDF Splits PDF documents into sentences or paragraphs PDFSentenceSplitter String (url or path to PDF file) .pdf
PDFParagraphSplitter String (url or path to PDF file) .pdf
doc Splits Microsoft doc documents into sentences or paragraphs DOCSentenceSplitter String (url or path to doc file) .doc
DOCParagraphSplitter String (url or path to doc file) .doc
docx Splits Microsoft docx documents into sentences or paragraphs DOCxSentenceSplitter String (url or path to docx file) .docx
DOCxParagraphSplitter String (url or path to docx file) .docx

Usage

Example using MarkdownSentenceSplitter

from ovos_document_chunkers.text.markdown import MarkdownSentenceSplitter
import requests

markdown_text = requests.get("https://github.com/OpenVoiceOS/ovos-core/raw/dev/README.md").text

sentence_splitter = MarkdownSentenceSplitter()
sentences = sentence_splitter.chunk(markdown_text)

print("Sentences:")
for sentence in sentences:
    print(sentence)

Example using MarkdownParagraphSplitter

from ovos_document_chunkers.text.markdown import MarkdownParagraphSplitter
import requests

markdown_text = requests.get("https://github.com/OpenVoiceOS/ovos-core/raw/dev/README.md").text

paragraph_splitter = MarkdownParagraphSplitter()
paragraphs = paragraph_splitter.chunk(markdown_text)

print("\nParagraphs:")
for paragraph in paragraphs:
    print(paragraph)

Example using HTMLSentenceSplitter

from ovos_document_chunkers import HTMLSentenceSplitter
import requests

html_text = requests.get("https://www.gofundme.com/f/openvoiceos").text

sentence_splitter = HTMLSentenceSplitter()
sentences = sentence_splitter.chunk(html_text)

print("Sentences:")
for sentence in sentences:
    print(sentence)

Example using HTMLParagraphSplitter

from ovos_document_chunkers import HTMLParagraphSplitter
import requests

html_text = requests.get("https://www.gofundme.com/f/openvoiceos").text

paragraph_splitter = HTMLParagraphSplitter()
paragraphs = paragraph_splitter.chunk(html_text)

print("\nParagraphs:")
for paragraph in paragraphs:
    print(paragraph)

Example using PDFParagraphSplitter

from ovos_document_chunkers import PDFParagraphSplitter

pdf_path = "/path/to/your/pdf/document.pdf"

paragraph_splitter = PDFParagraphSplitter()
paragraphs = paragraph_splitter.chunk(pdf_path)

print("\nParagraphs:")
for paragraph in paragraphs:
    print(paragraph)

Credits

image

This work was sponsored by VisioLab, part of Royal Dutch Visio, is the test, education, and research center in the field of (innovative) assistive technology for blind and visually impaired people and professionals. We explore (new) technological developments such as Voice, VR and AI and make the knowledge and expertise we gain available to everyone.

Metadata

Release files for ovos-document-chunkers 0.1.3a1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ovos-document-chunkers 0.1.3a1
File Size Uploaded
ovos_document_chunkers-0.1.3a1.tar.gz 15.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ovos-document-chunkers 0.1.3a1
File Interpreter ABI Platform
ovos_document_chunkers-0.1.3a1-py3-none-any.whl Python 3 none any Details

Total release size: 34.8 kB

Release files / ovos_document_chunkers-0.1.3a1.tar.gz

Download URL ovos_document_chunkers-0.1.3a1.tar.gz
Size 15.1 kB
Tags Source
SHA-256 checksum
How to use checksums
24b520edfb419457d9c605ac7e26ae8d47e9d12c1794bdac8fd230d27030b6fe
BLAKE2b-256 checksum
How to use checksums
3a4f14edc13bdb860f49158e2d835b01b6a6eee6f3ec08b71ea72a7a288e4c14
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / ovos_document_chunkers-0.1.3a1-py3-none-any.whl

Download URL ovos_document_chunkers-0.1.3a1-py3-none-any.whl
Size 19.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9fe5e6cb0fd7335240d72028f6ba2c4a4d04c5554474a14f4228b98d90baebf9
BLAKE2b-256 checksum
How to use checksums
5ee9ac78f9a9e8bfa6b85412ae211ce0c9520dcfe9568a9f5d0133144853d4fc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page