owlapy.agen_kg.text_loader

Text loading module for extracting text from various file formats. Supports: TXT, PDF, DOCX, RTF, HTML, and raw text strings.

Also provides text chunking utilities for handling large documents that may not fit in an LLM’s context window.

Attributes

logger

Classes

TextLoader

Base class for text loaders.

TXTLoader

Loader for plain text files.

PDFLoader

Loader for PDF files.

DOCXLoader

Loader for DOCX files.

RTFLoader

Loader for RTF files.

HTMLLoader

Loader for HTML files.

RawTextLoader

Loader for raw text strings.

UniversalTextLoader

Universal text loader that automatically detects file type and loads content.

Module Contents

owlapy.agen_kg.text_loader.logger
class owlapy.agen_kg.text_loader.TextLoader[source]

Bases: abc.ABC

Base class for text loaders.

abstractmethod load(source: str | pathlib.Path) → str[source]

Load text from the given source.

Parameters:

source – File path or raw text string.

Returns:

Extracted text content.

Raises:

ValueError – If the source is invalid or cannot be processed.

class owlapy.agen_kg.text_loader.TXTLoader[source]

Bases: TextLoader

Loader for plain text files.

load(source: str | pathlib.Path) → str[source]

Load text from a .txt file.

class owlapy.agen_kg.text_loader.PDFLoader[source]

Bases: TextLoader

Loader for PDF files.

load(source: str | pathlib.Path) → str[source]

Load text from a PDF file.

class owlapy.agen_kg.text_loader.DOCXLoader[source]

Bases: TextLoader

Loader for DOCX files.

load(source: str | pathlib.Path) → str[source]

Load text from a DOCX file.

class owlapy.agen_kg.text_loader.RTFLoader[source]

Bases: TextLoader

Loader for RTF files.

load(source: str | pathlib.Path) → str[source]

Load text from an RTF file.

class owlapy.agen_kg.text_loader.HTMLLoader[source]

Bases: TextLoader

Loader for HTML files.

load(source: str | pathlib.Path) → str[source]

Load text from an HTML file.

class owlapy.agen_kg.text_loader.RawTextLoader[source]

Bases: TextLoader

Loader for raw text strings.

load(source: str | pathlib.Path) → str[source]

Return the source as-is if it’s not a file.

class owlapy.agen_kg.text_loader.UniversalTextLoader(enable_logging: bool = False)[source]

Universal text loader that automatically detects file type and loads content. Handles multiple formats: TXT, PDF, DOCX, RTF, HTML, and raw text strings.

logging = False
loaders
load(source: str | pathlib.Path, file_type: str | None = None) → str[source]

Load text from various sources.

Parameters:
  • source – File path (str or Path), or raw text string.

  • file_type – Optional file extension (e.g., ‘.pdf’, ‘.txt’). If not provided, will be auto-detected from the source.

Returns:

Extracted text content.

Raises:
  • ValueError – If the file type is not supported or content cannot be extracted.

  • FileNotFoundError – If the specified file does not exist.

supports_file_type(file_type: str) → bool[source]

Check if a file type is supported.

Parameters:

file_type – File extension (e.g., ‘.pdf’, ‘pdf’).

Returns:

True if the file type is supported, False otherwise.

property supported_formats: list

Get list of supported file formats.