fabula_discovery/score.rs
1use fabula::pattern::Pattern;
2use std::collections::HashMap;
3
4/// Per-evaluator scores for a candidate pattern.
5#[derive(Debug, Clone, Default)]
6pub struct PatternScore {
7 /// Named scores from each evaluator that ran.
8 pub scores: HashMap<String, f64>,
9 /// Which round of the session produced this.
10 pub round: usize,
11 /// Which generator produced the candidate.
12 pub generator: String,
13}
14
15impl PatternScore {
16 /// Weighted composite score across all evaluators.
17 ///
18 /// Evaluators not present in `weights` default to weight 1.0.
19 pub fn composite(&self, weights: &HashMap<String, f64>) -> f64 {
20 self.scores
21 .iter()
22 .map(|(name, &value)| {
23 let w = weights.get(name).copied().unwrap_or(1.0);
24 w * value
25 })
26 .sum()
27 }
28}
29
30/// A candidate pattern paired with its evaluation scores.
31#[derive(Debug, Clone)]
32pub struct ScoredPattern<L, V> {
33 /// The candidate pattern.
34 pub pattern: Pattern<L, V>,
35 /// Evaluation scores from all evaluators.
36 pub score: PatternScore,
37}