Skip to main content

ontologos_profile/
lib.rs

1//! OWL profile detection and diagnostics for OntoLogos.
2//!
3//! v0.2 classifies ontologies into OWL 2 EL, RL, QL, or DL profiles using
4//! mapped TBox constructs. Diagnostics also report constructs observed in the
5//! full parse that fall outside the detected profile.
6//!
7//! # Example
8//!
9//! ```
10//! use ontologos_core::Ontology;
11//! use ontologos_profile::{detect_profile, OwlProfile};
12//!
13//! let ontology = Ontology::default();
14//! let report = detect_profile(&ontology)?;
15//! assert_eq!(report.detected, Some(OwlProfile::Ql));
16//! # Ok::<(), Box<dyn std::error::Error>>(())
17//! ```
18//!
19//! See [profile detection guide](https://github.com/eddiethedean/ontologos/blob/main/docs/guides/profile-detection.md).
20
21#![warn(missing_docs)]
22
23mod construct;
24mod detect;
25mod hybrid;
26mod routing;
27mod rules;
28/// Construct scanning helpers for profile detection.
29pub mod scanner;
30
31use ontologos_core::Ontology;
32use serde::{Deserialize, Serialize};
33use thiserror::Error;
34
35pub use construct::OwlConstruct;
36pub use detect::detect_profile;
37pub use hybrid::{
38    ClassifiedModule, HybridReport, bottom_module_class_seeds, classify_hybrid, engine_for_profile,
39    extract_signature, merge_taxonomies, partition_axioms, signature_for_axioms,
40    subontology_with_axioms,
41};
42pub use routing::{detected_profile_kind, resolve_route};
43pub use rules::{el_classification_forbidden_in, el_diagnostics, el_forbidden_in, satisfies_el};
44
45/// Result type alias for profile operations.
46pub type Result<T> = std::result::Result<T, Error>;
47
48/// Profile detection failed.
49#[derive(Debug, Error)]
50pub enum Error {
51    /// Profile detection failed with a message.
52    #[error("profile detection failed: {0}")]
53    Message(String),
54}
55
56/// Detected OWL 2 profile.
57#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
58#[serde(rename_all = "UPPERCASE")]
59pub enum OwlProfile {
60    /// OWL 2 EL.
61    El,
62    /// OWL 2 RL.
63    Rl,
64    /// OWL 2 QL.
65    Ql,
66    /// OWL 2 DL (fallback).
67    Dl,
68}
69
70/// Diagnostic emitted when unsupported constructs are encountered.
71#[derive(Debug, Clone, Serialize, Deserialize)]
72pub struct ProfileDiagnostic {
73    /// Construct name (debug representation).
74    pub construct: String,
75    /// Human-readable explanation.
76    pub message: String,
77}
78
79/// Profile detection report for an ontology.
80#[derive(Debug, Clone, Serialize, Deserialize)]
81pub struct ProfileReport {
82    /// Most specific detected profile, if any.
83    pub detected: Option<OwlProfile>,
84    /// Constructs outside the detected profile or mapping gaps.
85    pub diagnostics: Vec<ProfileDiagnostic>,
86}
87
88/// Resolve profile from ontology for reasoner configuration helpers.
89#[must_use]
90pub fn profile_from_ontology(ontology: &Ontology) -> Option<OwlProfile> {
91    detect_profile(ontology).ok().and_then(|r| r.detected)
92}