Skip to main content

ontologos_core/
lib.rs

1//! Core data model and reasoner API for OntoLogos.
2//!
3//! v0.4 provides an in-memory ontology representation with interned IRIs,
4//! typed entities, structured axioms, secondary indexes, and JSON v2 serialization.
5//!
6//! # Start here — load and reason
7//!
8//! **Do not use [`Ontology::from_file`] or [`Reasoner::classify`] for file loading / reasoning.**
9//!
10//! ```ignore
11//! use ontologos_parser::load_ontology;
12//! use ontologos_rdfs::RdfsEngine;
13//!
14//! let mut ontology = load_ontology(std::path::Path::new("ontology.owl"))?;
15//! let report = RdfsEngine::new().materialize(&mut ontology)?;
16//! println!("inferred {}", report.inferred_total());
17//! ```
18//!
19//! OWL RL saturation: `ontologos_rl::RlEngine::new(1)?.saturate(&mut ontology)?`
20//!
21//! # Builder-only (no parser)
22//!
23//! ```
24//! use ontologos_core::{Error, Ontology};
25//!
26//! fn main() -> Result<(), Error> {
27//!     let ontology = Ontology::builder()
28//!         .class("http://example.org/Pizza")?
29//!         .class("http://example.org/Food")?
30//!         .subclass_of("http://example.org/Pizza", "http://example.org/Food")?
31//!         .build()?;
32//!     assert_eq!(ontology.axiom_count(), 1);
33//!     Ok(())
34//! }
35//! ```
36
37#![warn(missing_docs)]
38
39mod axiom;
40mod dirty;
41mod entity;
42mod error;
43mod graph;
44mod iri;
45mod limits;
46mod ontology;
47mod parse_meta;
48mod reasoner;
49mod serialize;
50mod session;
51mod taxonomy;
52mod trace;
53
54pub use axiom::{Axiom, AxiomId};
55pub use dirty::{axiom_signature, DirtySet, OntologyRevision};
56pub use entity::{EntityId, EntityKind, EntityRecord, EntityRegistry};
57pub use error::{Error, Result};
58pub use graph::{AxiomIndex, AxiomStore};
59pub use iri::{InternPool, IriId};
60pub use limits::Limits;
61pub use ontology::{Ontology, OntologyBuilder};
62pub use parse_meta::{OwlConstruct, ParseMeta, ParseMetaSummary};
63pub use reasoner::{Profile, Reasoner, ReasonerBuilder, ReasonerConfig};
64pub use session::ReasonerSession;
65pub use taxonomy::Taxonomy;
66pub use trace::{InferenceTrace, TraceConclusion, TracePremise, TraceStep};
67
68#[cfg(test)]
69mod integration_tests {
70    use super::*;
71
72    #[test]
73    fn classify_returns_not_implemented_for_el() {
74        let ontology = Ontology::default();
75        let mut reasoner = Reasoner::builder()
76            .profile(Profile::El)
77            .build(ontology)
78            .expect("build");
79        assert_eq!(reasoner.classify().unwrap_err(), Error::NotImplemented);
80        assert_eq!(reasoner.ontology().entity_count(), 0);
81    }
82
83    #[test]
84    fn classify_rdfs_profile_returns_delegate_hint() {
85        let ontology = Ontology::default();
86        let mut reasoner = Reasoner::builder()
87            .profile(Profile::Rdfs)
88            .build(ontology)
89            .expect("build");
90        let err = reasoner.classify().expect_err("rdfs delegate hint");
91        assert!(matches!(err, Error::Message(_)));
92    }
93
94    #[test]
95    fn classify_rl_profile_returns_delegate_hint() {
96        let ontology = Ontology::default();
97        let mut reasoner = Reasoner::builder()
98            .profile(Profile::Rl)
99            .build(ontology)
100            .expect("build");
101        let err = reasoner.classify().expect_err("rl delegate hint");
102        assert!(matches!(err, Error::Message(_)));
103    }
104
105    #[test]
106    fn reasoner_rejects_invalid_parallelism() {
107        let ontology = Ontology::default();
108        let err = Reasoner::builder()
109            .config(ReasonerConfig {
110                parallelism: 0,
111                ..ReasonerConfig::default()
112            })
113            .build(ontology)
114            .expect_err("parallelism");
115        assert!(matches!(err, Error::Message(_)));
116    }
117}