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 entity;
41mod error;
42mod graph;
43mod iri;
44mod limits;
45mod ontology;
46mod parse_meta;
47mod reasoner;
48mod serialize;
49mod taxonomy;
50
51pub use axiom::{Axiom, AxiomId};
52pub use entity::{EntityId, EntityKind, EntityRecord, EntityRegistry};
53pub use error::{Error, Result};
54pub use graph::{AxiomIndex, AxiomStore};
55pub use iri::{InternPool, IriId};
56pub use limits::Limits;
57pub use ontology::{Ontology, OntologyBuilder};
58pub use parse_meta::{OwlConstruct, ParseMeta, ParseMetaSummary};
59pub use reasoner::{Profile, Reasoner, ReasonerBuilder, ReasonerConfig};
60pub use taxonomy::Taxonomy;
61
62#[cfg(test)]
63mod integration_tests {
64    use super::*;
65
66    #[test]
67    fn classify_returns_not_implemented_for_el() {
68        let ontology = Ontology::default();
69        let mut reasoner = Reasoner::builder()
70            .profile(Profile::El)
71            .build(ontology)
72            .expect("build");
73        assert_eq!(reasoner.classify().unwrap_err(), Error::NotImplemented);
74        assert_eq!(reasoner.ontology().entity_count(), 0);
75    }
76
77    #[test]
78    fn classify_rdfs_profile_returns_delegate_hint() {
79        let ontology = Ontology::default();
80        let mut reasoner = Reasoner::builder()
81            .profile(Profile::Rdfs)
82            .build(ontology)
83            .expect("build");
84        let err = reasoner.classify().expect_err("rdfs delegate hint");
85        assert!(matches!(err, Error::Message(_)));
86    }
87
88    #[test]
89    fn classify_rl_profile_returns_delegate_hint() {
90        let ontology = Ontology::default();
91        let mut reasoner = Reasoner::builder()
92            .profile(Profile::Rl)
93            .build(ontology)
94            .expect("build");
95        let err = reasoner.classify().expect_err("rl delegate hint");
96        assert!(matches!(err, Error::Message(_)));
97    }
98
99    #[test]
100    fn reasoner_rejects_invalid_parallelism() {
101        let ontology = Ontology::default();
102        let err = Reasoner::builder()
103            .config(ReasonerConfig {
104                parallelism: 0,
105                ..ReasonerConfig::default()
106            })
107            .build(ontology)
108            .expect_err("parallelism");
109        assert!(matches!(err, Error::Message(_)));
110    }
111}