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