1#![warn(missing_docs)]
4
5mod engine;
6mod engine_adapter;
7mod rules;
8
9use ontologos_core::{Ontology, OwlConstruct};
10use ontologos_profile::scanner::scan_constructs;
11use thiserror::Error;
12
13pub use engine::materialize_swrl_rules;
14pub use engine_adapter::SwrlEngine;
15pub use rules::{SwrlReport, apply_swrl_rules};
16
17pub type Result<T> = std::result::Result<T, Error>;
19
20#[derive(Debug, Error)]
22pub enum Error {
23 #[error(transparent)]
25 Dl(#[from] ontologos_dl::Error),
26 #[error(transparent)]
28 Core(#[from] ontologos_core::Error),
29 #[error(
31 "SWRL rule execution is not implemented (preview); ontology has no executable SWRL rules"
32 )]
33 NotImplemented,
34 #[error("SWRL preview: {0}")]
36 PreviewLimit(String),
37}
38
39pub fn classify_with_swrl(ontology: &Ontology) -> Result<(ontologos_core::Taxonomy, SwrlReport)> {
41 if !scan_constructs(ontology).contains(&OwlConstruct::SwrlRule)
42 && ontology.swrl_rules().is_empty()
43 {
44 return Err(Error::NotImplemented);
45 }
46 let mut working = ontology.clone();
47 let report = apply_swrl_rules(&mut working)?;
48 if report.rules_found == 0 {
49 return Err(Error::PreviewLimit(
50 "SWRL rules detected in profile scan but not mapped for execution".into(),
51 ));
52 }
53 let taxonomy = ontologos_dl::classify(&working)?;
54 Ok((taxonomy, report))
55}
56
57pub fn is_consistent_with_swrl(ontology: &Ontology) -> Result<bool> {
59 let mut working = ontology.clone();
60 let report = apply_swrl_rules(&mut working)?;
61 if report.rules_found == 0 && ontology.swrl_rules().is_empty() {
62 return Err(Error::NotImplemented);
63 }
64 Ok(ontologos_dl::is_consistent(&working)?)
65}