Skip to main content

ontologos_rl/
lib.rs

1//! OWL RL forward-chaining rule engine.
2//!
3//! # Start here — load a file and saturate
4//!
5//! ```no_run
6//! use ontologos_parser::load_ontology;
7//! use ontologos_rl::RlEngine;
8//!
9//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
10//! let mut ontology = load_ontology(std::path::Path::new("ontology.owl"))?;
11//! let report = RlEngine::new(1).saturate(&mut ontology)?;
12//! println!("inferred {}", report.inferred_total());
13//! # Ok(())
14//! # }
15//! ```
16//!
17//! Via [`Reasoner`](ontologos_core::Reasoner): use [`classify_reasoner`] — not [`Reasoner::classify`](ontologos_core::Reasoner::classify).
18
19mod engine;
20mod reasoner;
21mod report;
22mod rules;
23mod triple_index;
24
25pub use engine::RlEngine;
26pub use reasoner::{classify_reasoner, materialize_reasoner};
27pub use report::{InferenceRecord, MaterializationReport, RlRule};
28pub use triple_index::TripleIndex;
29
30use ontologos_core::Error as CoreError;
31use thiserror::Error;
32
33pub type Result<T> = std::result::Result<T, Error>;
34
35#[derive(Debug, Error)]
36pub enum Error {
37    #[error("expected profile {expected:?}, got {actual:?}")]
38    WrongProfile {
39        expected: ontologos_core::Profile,
40        actual: ontologos_core::Profile,
41    },
42    #[error(transparent)]
43    Core(#[from] CoreError),
44}
45
46#[cfg(test)]
47mod tests {
48    use super::*;
49
50    #[test]
51    fn try_new_rejects_invalid_parallelism() {
52        assert!(RlEngine::try_new(0).is_err());
53        assert!(RlEngine::try_new(65).is_err());
54        assert!(RlEngine::try_new(1).is_ok());
55    }
56}