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 lib;
24pub mod namespace;
25pub mod taxonomy;
26pub mod trio_loader;
27pub mod validation;
28
29pub use conjunct::ConjunctIndex;
30pub use def::{Def, DefKind};
31pub use lib::Lib;
32pub use namespace::{DefNamespace, LibSource};
33pub use taxonomy::TaxonomyTree;
34pub use trio_loader::load_trio;
35pub use validation::{FitIssue, ValidationIssue};
36
37use crate::codecs::CodecError;
38
39/// Errors that can occur during ontology loading or processing.
40#[derive(Debug, thiserror::Error)]
41pub enum OntologyError {
42 /// Error from the Trio/Zinc codec during parsing.
43 #[error("codec error: {0}")]
44 Codec(#[from] CodecError),
45 /// Invalid def record.
46 #[error("invalid def: {0}")]
47 InvalidDef(String),
48 /// General load error.
49 #[error("load error: {0}")]
50 Load(String),
51}