use crate::core::OcrResult;
use crate::core::traits::adapter::ModelAdapter;
use crate::core::traits::task::Task;
pub struct TaskPredictorCore<T: Task> {
pub(crate) adapter: Box<dyn ModelAdapter<Task = T>>,
pub(crate) task: T,
pub(crate) config: T::Config,
}
impl<T: Task> TaskPredictorCore<T> {
pub fn new(adapter: Box<dyn ModelAdapter<Task = T>>, task: T, config: T::Config) -> Self {
Self {
adapter,
task,
config,
}
}
pub fn predict(&self, input: T::Input) -> OcrResult<T::Output> {
self.task.validate_input(&input)?;
let output = self.adapter.execute(input, Some(&self.config))?;
self.task.validate_output(&output)?;
Ok(output)
}
pub fn config(&self) -> &T::Config {
&self.config
}
pub fn config_mut(&mut self) -> &mut T::Config {
&mut self.config
}
pub fn task(&self) -> &T {
&self.task
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::domain::tasks::text_detection::{TextDetectionConfig, TextDetectionTask};
#[test]
fn test_task_predictor_core_creation() {
let _check = || -> Option<TaskPredictorCore<TextDetectionTask>> { None };
}
#[test]
fn test_config_accessors() {
let _check = || {
let mut core: Option<TaskPredictorCore<TextDetectionTask>> = None;
if let Some(c) = core.as_ref() {
let _cfg: &TextDetectionConfig = c.config();
}
if let Some(c) = core.as_mut() {
let _cfg: &mut TextDetectionConfig = c.config_mut();
}
};
}
}