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