use async_trait::async_trait;
use synaptic_core::SynapticError;
use crate::evaluator::{EvalResult, Evaluator};
pub struct ExactMatchEvaluator {
ignore_case: bool,
}
impl ExactMatchEvaluator {
pub fn new() -> Self {
Self { ignore_case: false }
}
pub fn case_insensitive() -> Self {
Self { ignore_case: true }
}
}
impl Default for ExactMatchEvaluator {
fn default() -> Self {
Self::new()
}
}
#[async_trait]
impl Evaluator for ExactMatchEvaluator {
async fn evaluate(
&self,
prediction: &str,
reference: &str,
_input: &str,
) -> Result<EvalResult, SynapticError> {
let matches = if self.ignore_case {
prediction.to_lowercase() == reference.to_lowercase()
} else {
prediction == reference
};
if matches {
Ok(EvalResult::pass())
} else {
Ok(EvalResult::fail()
.with_reasoning(format!("Expected {:?}, got {:?}", reference, prediction)))
}
}
}