Skip to main content

DedupTransformer

Struct DedupTransformer 

Source
pub struct DedupTransformer {
    pub streaming: bool,
    /* private fields */
}
Expand description

A transform that deduplicates samples using MinHash + LSH.

This transform buffers samples to compute signatures and find duplicates. It can operate in two modes:

  • Streaming: Process samples as they arrive, outputting non-duplicates immediately
  • Batch: Buffer all samples, then output deduplicated set

§Example

use dedup::{Config, DedupTransformer};
use tenshift_core::sample::Sample;
use tenshift_core::transform::Transform;

let config = Config::default()
    .with_similarity_threshold(0.9);

let mut dedup = DedupTransformer::new(config).unwrap();

Fields§

§streaming: bool

Whether we’re in streaming mode.

Implementations§

Source§

impl DedupTransformer

Source

pub fn new(config: Config) -> Result<Self>

Create a new deduplication transformer.

§Errors

Returns an error if the configuration is invalid.

Source

pub fn with_text_field(self, field: impl Into<String>) -> Self

Set the field name containing text to deduplicate on.

Source

pub fn with_streaming(self, enabled: bool) -> Self

Enable streaming mode (output non-duplicates immediately).

Source

pub fn with_mark_duplicates(self, enabled: bool) -> Self

Enable marking duplicates instead of filtering them.

When enabled, duplicates are tagged with a is_duplicate field instead of being removed from the output.

Source

pub fn process_sample(&mut self, sample: &Sample) -> Result<bool>

Process a single sample.

Computes the MinHash signature and adds to the LSH index. Returns true if the sample is unique, false if it’s a duplicate.

§Errors

Returns an error if signature computation fails.

Source

pub fn push(&mut self, sample: Sample)

Add a sample to the buffer for batch processing, or process immediately if streaming mode is enabled.

Source

pub fn drain_streaming(&mut self) -> Vec<Sample>

Drain any pending output samples produced in streaming mode.

Source

pub fn finish_batch(&mut self) -> Vec<Sample>

Process all buffered samples and return deduplicated results.

This computes signatures for all samples, builds the LSH index, finds clusters, and returns only unique samples.

Source

pub fn clusters(&mut self) -> &[DuplicateCluster]

Get duplicate clusters.

Returns all detected duplicate clusters. Call after finish_batch() for complete results.

Source

pub fn stats(&self) -> LshStats

Get statistics about the deduplication process.

Source

pub fn unique_count(&self) -> usize

Get the number of unique documents found.

Source

pub fn duplicate_count(&self) -> usize

Get the number of duplicate documents found.

Source

pub fn reset(&mut self)

Reset the transformer state.

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, 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<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