Skip to main content

haystack_core/ontology/
mod.rs

1//! Haystack 4 ontology layer — defs, taxonomy, conjuncts, and validation.
2//!
3//! Implements the Haystack 4 def system for defining entity types, tags,
4//! relationships, and constraints:
5//!
6//! - [`DefNamespace`] — Root container holding all loaded defs and libs.
7//!   Provides lookup, taxonomy traversal, tag requirements, and validation.
8//! - [`Def`] — Individual definition (e.g., `site`, `equip`, `temp-sensor`).
9//!   Carries symbol, doc, supertypes (`is`), and tag constraints (`tagOn`).
10//! - [`DefKind`] — Discriminant for def categories (tag, conjunct, entity, lib, feature, etc.).
11//! - [`Lib`] — Named library of defs loaded from Trio source (e.g., `ph`, `phIoT`).
12//! - [`TaxonomyTree`] — Subtype hierarchy tree for `is`-based inheritance queries.
13//! - [`ConjunctIndex`] — Index of compound entity types (e.g., `hot-water-plant`).
14//!
15//! ## Loading Defs
16//!
17//! Defs are loaded from Trio-formatted source via [`DefNamespace::load_trio_str()`]
18//! or from pre-registered [`LibSource`] entries. The standard Project Haystack
19//! libraries (`ph`, `phScience`, `phIoT`, `phIct`) are available by default.
20
21pub mod conjunct;
22pub mod def;
23pub mod graph_validation;
24pub mod lib;
25pub mod namespace;
26pub mod taxonomy;
27pub mod trio_loader;
28pub mod validation;
29
30pub use conjunct::ConjunctIndex;
31pub use def::{Def, DefKind};
32pub use graph_validation::{ValidationReport, ValidationSummary, validate_graph};
33pub use lib::Lib;
34pub use namespace::{DefNamespace, LibSource};
35pub use taxonomy::TaxonomyTree;
36pub use trio_loader::load_trio;
37pub use validation::{FitIssue, ValidationIssue};
38
39use crate::codecs::CodecError;
40
41/// Errors that can occur during ontology loading or processing.
42#[derive(Debug, thiserror::Error)]
43pub enum OntologyError {
44    /// Error from the Trio/Zinc codec during parsing.
45    #[error("codec error: {0}")]
46    Codec(#[from] CodecError),
47    /// Invalid def record.
48    #[error("invalid def: {0}")]
49    InvalidDef(String),
50    /// General load error.
51    #[error("load error: {0}")]
52    Load(String),
53}