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 ¶
- type Classifier
- func (c *Classifier) Classify(ctx context.Context, r domain.Record) (domain.Classification, error)
- func (c *Classifier) ClassifyBatch(ctx context.Context, records []domain.Record) []Result
- func (c *Classifier) ClassifyBatchConcurrent(ctx context.Context, records []domain.Record, workers int) []Result
- type Deps
- type Result
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 (*Classifier) Classify ¶
func (c *Classifier) Classify(ctx context.Context, r domain.Record) (domain.Classification, error)
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 ¶
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.