classifier

package
v0.0.0-...-dfadc02 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 11, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package classifier runs records through an ordered stage cascade, the library counterpart to the streaming engine. Build one with New and call Classify for a single record, ClassifyBatch or ClassifyBatchConcurrent for a slice; reach for engine when you want to drain a source into a sink instead.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Classifier

type Classifier struct {
	// contains filtered or unexported fields
}

Classifier decides a single record by walking the cascade.

func New

func New(d Deps) (*Classifier, error)

New checks deps and returns a ready Classifier.

func (*Classifier) Classify

Classify walks the cascade and returns the first decision at or above the confidence gate. It returns stage.ErrUnclassified when no stage decides, or when every decision falls below the gate. Any other stage error stops the walk and comes back wrapped.

func (*Classifier) ClassifyBatch

func (c *Classifier) ClassifyBatch(ctx context.Context, records []domain.Record) []Result

ClassifyBatch classifies records sequentially and returns one Result per input, in the same order, reusing the same cascade and gate as Classify. On a cancelled context it does not stop early: every remaining record gets a Result whose Err is the context error, so len(results) always equals len(records). For CPU-bound parallelism use ClassifyBatchConcurrent.

func (*Classifier) ClassifyBatchConcurrent

func (c *Classifier) ClassifyBatchConcurrent(ctx context.Context, records []domain.Record, workers int) []Result

ClassifyBatchConcurrent is ClassifyBatch spread across up to workers goroutines, returning Results in input order. The stages must be safe for concurrent Classify calls; the built-in stages are, since they only read state fixed at construction. Fewer than two workers, or fewer than two records, runs sequentially.

type Deps

type Deps struct {
	// Stages is the cascade, cheapest first. At least one is required.
	Stages []stage.Stage
	// MinConfidence gates a decision: anything below it escalates to the
	// next stage. Zero turns gating off.
	MinConfidence float64
}

Deps bundles what a Classifier needs.

type Result

type Result struct {
	Classification domain.Classification
	Err            error
}

Result pairs a record's Classification with the error from classifying it: nil on success, stage.ErrUnclassified when no stage decided, or a wrapped stage error.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL