use crate::error::{Error, Result};
use crate::ontology::Ontology;
const MAX_PARALLELISM: usize = 64;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum Profile {
#[default]
Auto,
Rdfs,
Rl,
El,
}
#[derive(Debug, Clone)]
pub struct ReasonerConfig {
pub incremental: bool,
pub explanations: bool,
pub parallelism: usize,
}
impl Default for ReasonerConfig {
fn default() -> Self {
Self {
incremental: false,
explanations: false,
parallelism: 1,
}
}
}
#[derive(Debug, Default)]
pub struct ReasonerBuilder {
profile: Profile,
config: ReasonerConfig,
}
impl ReasonerBuilder {
#[must_use]
pub fn new() -> Self {
Self::default()
}
#[must_use]
pub fn profile(mut self, profile: Profile) -> Self {
self.profile = profile;
self
}
#[must_use]
pub fn config(mut self, config: ReasonerConfig) -> Self {
self.config = config;
self
}
pub fn build(self, ontology: Ontology) -> Result<Reasoner> {
if self.config.parallelism == 0 || self.config.parallelism > MAX_PARALLELISM {
return Err(Error::Message(format!(
"parallelism must be in 1..={MAX_PARALLELISM}, got {}",
self.config.parallelism
)));
}
Ok(Reasoner {
ontology,
profile: self.profile,
config: self.config,
})
}
}
#[derive(Debug)]
pub struct Reasoner {
ontology: Ontology,
profile: Profile,
config: ReasonerConfig,
}
impl Reasoner {
#[must_use]
pub fn builder() -> ReasonerBuilder {
ReasonerBuilder::new()
}
#[must_use]
pub fn profile(&self) -> Profile {
self.profile
}
#[must_use]
pub fn config(&self) -> &ReasonerConfig {
&self.config
}
#[must_use]
pub fn ontology(&self) -> &Ontology {
&self.ontology
}
pub fn ontology_mut(&mut self) -> &mut Ontology {
&mut self.ontology
}
pub fn classify(&mut self) -> Result<()> {
if self.profile == Profile::Rdfs {
return Err(Error::Message(
"Profile::Rdfs: use ontologos_rdfs::classify_reasoner or \
ontologos_rdfs::materialize_reasoner; Reasoner::classify does not \
dispatch to profile engines"
.into(),
));
}
if self.profile == Profile::Rl {
return Err(Error::Message(
"Profile::Rl: use ontologos_rl::classify_reasoner or \
ontologos_rl::materialize_reasoner; Reasoner::classify does not \
dispatch to profile engines"
.into(),
));
}
Err(Error::NotImplemented)
}
}