ontologos-facade 1.0.1

Unified OWL reasoner facade routing EL/RL/RDFS/DL
Documentation
use ontologos_core::{Reasoner, Taxonomy};

use crate::engines::{classify as dispatch_classify, resolve};
use crate::error::Result;
use crate::outcome::ClassifyOutcome;

/// Classify using any supported profile (EL, RL, RDFS, ALC, DL, SWRL, Auto).
#[tracing::instrument(skip(reasoner), fields(profile = ?reasoner.profile()))]
pub fn classify(reasoner: &mut Reasoner) -> Result<ClassifyOutcome> {
    let route = resolve(reasoner)?;
    tracing::debug!(engine = ?route.kind, "resolved classify route");
    let outcome = dispatch_classify(route, reasoner)?;
    if let Some(taxonomy) = taxonomy_from_outcome(&outcome) {
        reasoner.set_cached_taxonomy(taxonomy.clone());
    } else {
        reasoner.invalidate_classify_cache();
    }
    Ok(outcome)
}

/// Extract taxonomy when the outcome is classification-shaped.
#[must_use]
pub fn taxonomy_from_outcome(outcome: &ClassifyOutcome) -> Option<&Taxonomy> {
    match outcome {
        ClassifyOutcome::Taxonomy(t) => Some(t),
        _ => None,
    }
}