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
Classes
Base class for text loaders. |
|
Loader for plain text files. |
|
Loader for PDF files. |
|
Loader for DOCX files. |
|
Loader for RTF files. |
|
Loader for HTML files. |
|
Loader for raw text strings. |
|
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.TXTLoader[source]
Bases:
TextLoaderLoader for plain text files.
- class owlapy.agen_kg.text_loader.PDFLoader[source]
Bases:
TextLoaderLoader for PDF files.
- class owlapy.agen_kg.text_loader.DOCXLoader[source]
Bases:
TextLoaderLoader for DOCX files.
- class owlapy.agen_kg.text_loader.RTFLoader[source]
Bases:
TextLoaderLoader for RTF files.
- class owlapy.agen_kg.text_loader.HTMLLoader[source]
Bases:
TextLoaderLoader for HTML files.
- class owlapy.agen_kg.text_loader.RawTextLoader[source]
Bases:
TextLoaderLoader for raw text strings.
- 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.