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 rules;
26/// Construct scanning helpers for profile detection.
27pub mod scanner;
28
29use ontologos_core::Ontology;
30use serde::{Deserialize, Serialize};
31use thiserror::Error;
32
33pub use construct::OwlConstruct;
34pub use detect::detect_profile;
35pub use rules::{el_classification_forbidden_in, el_diagnostics, el_forbidden_in, satisfies_el};
36
37/// Result type alias for profile operations.
38pub type Result<T> = std::result::Result<T, Error>;
39
40/// Profile detection failed.
41#[derive(Debug, Error)]
42pub enum Error {
43 /// Profile detection failed with a message.
44 #[error("profile detection failed: {0}")]
45 Message(String),
46}
47
48/// Detected OWL 2 profile.
49#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
50#[serde(rename_all = "UPPERCASE")]
51pub enum OwlProfile {
52 /// OWL 2 EL.
53 El,
54 /// OWL 2 RL.
55 Rl,
56 /// OWL 2 QL.
57 Ql,
58 /// OWL 2 DL (fallback).
59 Dl,
60}
61
62/// Diagnostic emitted when unsupported constructs are encountered.
63#[derive(Debug, Clone, Serialize, Deserialize)]
64pub struct ProfileDiagnostic {
65 /// Construct name (debug representation).
66 pub construct: String,
67 /// Human-readable explanation.
68 pub message: String,
69}
70
71/// Profile detection report for an ontology.
72#[derive(Debug, Clone, Serialize, Deserialize)]
73pub struct ProfileReport {
74 /// Most specific detected profile, if any.
75 pub detected: Option<OwlProfile>,
76 /// Constructs outside the detected profile or mapping gaps.
77 pub diagnostics: Vec<ProfileDiagnostic>,
78}
79
80/// Resolve profile from ontology for reasoner configuration helpers.
81#[must_use]
82pub fn profile_from_ontology(ontology: &Ontology) -> Option<OwlProfile> {
83 detect_profile(ontology).ok().and_then(|r| r.detected)
84}