Skip to main content

TextProcessor

Struct TextProcessor 

Source
pub struct TextProcessor { /* private fields */ }
Expand description

Text processing utilities for chunking and preprocessing

Implementations§

Source§

impl TextProcessor

Source

pub fn new(chunk_size: usize, chunk_overlap: usize) -> Result<Self>

Create a new text processor

Source

pub fn with_parallel_processing( chunk_size: usize, chunk_overlap: usize, parallel_processor: ParallelProcessor, ) -> Result<Self>

Create a new text processor with parallel processing support

Source

pub fn chunk_text_hierarchical( &self, document: &Document, ) -> Result<Vec<TextChunk>>

Split text into chunks with overlap using hierarchical boundary preservation

Source

pub fn chunk_text(&self, document: &Document) -> Result<Vec<TextChunk>>

Split text into chunks with overlap (legacy method)

Source

pub fn chunk_text_with_enrichment( &self, document: &Document, enricher: &mut ChunkEnricher, ) -> Result<Vec<TextChunk>>

Chunk text and enrich with semantic metadata

Source

pub fn chunk_text_hierarchical_with_enrichment( &self, document: &Document, enricher: &mut ChunkEnricher, ) -> Result<Vec<TextChunk>>

Chunk text hierarchically and enrich with semantic metadata

Source

pub fn create_default_enricher(document: &Document) -> ChunkEnricher

Create a default enricher for document processing

Source

pub fn chunk_and_enrich(&self, document: &Document) -> Result<Vec<TextChunk>>

Convenience method: chunk and enrich with auto-detected format

Source

pub fn chunk_hierarchical_and_enrich( &self, document: &Document, ) -> Result<Vec<TextChunk>>

Convenience method: chunk hierarchically and enrich with auto-detected format

Source

pub fn chunk_with_strategy( &self, document: &Document, strategy: &dyn ChunkingStrategy, ) -> Result<Vec<TextChunk>>

Chunk text using any strategy that implements ChunkingStrategy trait

This method provides a flexible way to use different chunking approaches while maintaining the same interface.

§Arguments
  • document - The document to chunk
  • strategy - Any type implementing ChunkingStrategy
§Returns

A vector of TextChunk objects

§Examples
use graphrag_core::text::{TextProcessor, HierarchicalChunkingStrategy};

let processor = TextProcessor::new(1000, 100)?;
let strategy = HierarchicalChunkingStrategy::new(500, 50, document.id.clone());
let chunks = processor.chunk_with_strategy(&document, &strategy)?;
Source

pub fn clean_text(&self, text: &str) -> String

Clean and normalize text

Source

pub fn extract_sentences(&self, text: &str) -> Vec<String>

Extract sentences from text

Source

pub fn word_count(&self, text: &str) -> usize

Count words in text

Source

pub fn batch_chunk_documents( &self, documents: Vec<Document>, ) -> Result<Vec<Vec<TextChunk>>>

Process multiple documents in parallel

Source

pub fn batch_extract_keywords( &self, texts: &[&str], max_keywords: usize, ) -> Vec<Vec<String>>

Parallel extraction of keywords from multiple texts

Source

pub fn batch_extract_sentences(&self, texts: &[&str]) -> Vec<Vec<String>>

Parallel sentence extraction from multiple texts

Source

pub fn batch_clean_text(&self, texts: &[&str]) -> Vec<String>

Parallel text cleaning for multiple texts

Source

pub fn extract_keywords(&self, text: &str, max_keywords: usize) -> Vec<String>

Extract keywords using simple frequency analysis

Source

pub fn get_performance_stats(&self) -> (usize, Duration)

Get performance statistics

Source

pub fn average_processing_time(&self) -> Duration

Get average processing time per operation

Source

pub fn reset_performance_stats(&mut self)

Reset performance monitoring statistics

Source

pub fn get_parallel_stats(&self) -> Option<ParallelStatistics>

Get parallel processing statistics if available

Trait Implementations§

Source§

impl Debug for TextProcessor

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,