pub struct DefNamespace { /* private fields */ }Expand description
Unified container for Haystack 4 defs.
Provides resolution, taxonomy queries, structural typing (fits),
and validation. Loads defs from Trio format.
Implementations§
Source§impl DefNamespace
impl DefNamespace
Sourcepub fn load_standard() -> Result<Self, OntologyError>
pub fn load_standard() -> Result<Self, OntologyError>
Load the bundled standard Haystack 4 defs.
Loads ph, phScience, phIoT, and phIct libraries from the bundled
defs.trio file.
Sourcepub fn load_trio_str(&mut self, source: &str) -> Result<Vec<Lib>, OntologyError>
pub fn load_trio_str(&mut self, source: &str) -> Result<Vec<Lib>, OntologyError>
Load defs from Trio text and register them in this namespace.
Sourcepub fn register_lib(&mut self, lib: Lib)
pub fn register_lib(&mut self, lib: Lib)
Register a library and all its defs.
Uses a two-pass approach: first registers all defs (taxonomy, mandatory, conjuncts, tagOn), then builds the choice index so that parent defs are guaranteed to exist when checking.
Sourcepub fn resolve(&self, name: &str) -> Option<&Def>
pub fn resolve(&self, name: &str) -> Option<&Def>
Resolve a name to a Def. In the future, this will also try Spec lookup.
Sourcepub fn is_a(&self, name: &str, supertype: &str) -> bool
pub fn is_a(&self, name: &str, supertype: &str) -> bool
Check nominal subtype relationship.
Returns true if name is a subtype of supertype (or equal).
Sourcepub fn supertypes(&self, name: &str) -> Vec<String>
pub fn supertypes(&self, name: &str) -> Vec<String>
Full supertype chain (transitive, breadth-first).
Mandatory marker tags for a type (cached).
Walks the supertype chain and collects all mandatory markers.
All tags that apply to an entity type via tagOn.
Sourcepub fn conjunct_parts(&self, name: &str) -> Option<&[String]>
pub fn conjunct_parts(&self, name: &str) -> Option<&[String]>
Decompose a conjunct name into component tags.
Sourcepub fn fits(&self, entity: &HDict, type_name: &str) -> bool
pub fn fits(&self, entity: &HDict, type_name: &str) -> bool
Check if an entity structurally fits a type.
Checks whether entity has all mandatory markers defined by
type_name and its supertypes.
Sourcepub fn fits_explain(&self, entity: &HDict, type_name: &str) -> Vec<FitIssue>
pub fn fits_explain(&self, entity: &HDict, type_name: &str) -> Vec<FitIssue>
Explain why an entity does or does not fit a type.
Returns a list of FitIssue items; empty if entity fits.
Sourcepub fn validate_entity(&self, entity: &HDict) -> Vec<ValidationIssue>
pub fn validate_entity(&self, entity: &HDict) -> Vec<ValidationIssue>
Validate a single entity against the namespace.
Checks that all mandatory markers are present for each type the entity claims to be (marker tags that are also defs).
Sourcepub fn taxonomy(&self) -> &TaxonomyTree
pub fn taxonomy(&self) -> &TaxonomyTree
Get a reference to the taxonomy tree.
Sourcepub fn register_spec(&mut self, spec: Spec)
pub fn register_spec(&mut self, spec: Spec)
Register a resolved Spec in the registry.
Sourcepub fn get_spec(&self, qname: &str) -> Option<&Spec>
pub fn get_spec(&self, qname: &str) -> Option<&Spec>
Look up a Spec by qualified name (e.g. “ph::Ahu”).
Sourcepub fn specs(&self, lib: Option<&str>) -> Vec<&Spec>
pub fn specs(&self, lib: Option<&str>) -> Vec<&Spec>
List all specs, optionally filtered by library.
Sourcepub fn specs_map(&self) -> &HashMap<String, Spec>
pub fn specs_map(&self) -> &HashMap<String, Spec>
Get the raw specs HashMap (for fitting/effective_slots).
Sourcepub fn set_lib_source(&mut self, lib_name: &str, source: LibSource)
pub fn set_lib_source(&mut self, lib_name: &str, source: LibSource)
Track the source of a loaded library.
Sourcepub fn lib_source(&self, lib_name: &str) -> Option<&LibSource>
pub fn lib_source(&self, lib_name: &str) -> Option<&LibSource>
Get the source tracking for a library.
Sourcepub fn export_lib_xeto(&self, lib_name: &str) -> Result<String, String>
pub fn export_lib_xeto(&self, lib_name: &str) -> Result<String, String>
Export a library to Xeto source text.
Sourcepub fn save_lib(&self, lib_name: &str, path: &Path) -> Result<(), String>
pub fn save_lib(&self, lib_name: &str, path: &Path) -> Result<(), String>
Save a library to a file on disk as Xeto text.
Sourcepub fn load_xeto_str(
&mut self,
source: &str,
lib_name: &str,
) -> Result<Vec<String>, XetoError>
pub fn load_xeto_str( &mut self, source: &str, lib_name: &str, ) -> Result<Vec<String>, XetoError>
Load a Xeto library from source text and register all specs.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for DefNamespace
impl !RefUnwindSafe for DefNamespace
impl Send for DefNamespace
impl Sync for DefNamespace
impl Unpin for DefNamespace
impl UnsafeUnpin for DefNamespace
impl UnwindSafe for DefNamespace
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more