Skip to main content

DefNamespace

Struct DefNamespace 

Source
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

Source

pub fn new() -> Self

Create an empty namespace.

Source

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.

Source

pub fn load_trio_str(&mut self, source: &str) -> Result<Vec<Lib>, OntologyError>

Load defs from Trio text and register them in this namespace.

Source

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.

Source

pub fn get_def(&self, symbol: &str) -> Option<&Def>

Look up a def by symbol.

Source

pub fn resolve(&self, name: &str) -> Option<&Def>

Resolve a name to a Def. In the future, this will also try Spec lookup.

Source

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).

Source

pub fn subtypes(&self, name: &str) -> Vec<String>

Direct subtypes of a type.

Source

pub fn supertypes(&self, name: &str) -> Vec<String>

Full supertype chain (transitive, breadth-first).

Source

pub fn mandatory_tags(&self, name: &str) -> HashSet<String>

Mandatory marker tags for a type (cached).

Walks the supertype chain and collects all mandatory markers.

Source

pub fn tags_for(&self, name: &str) -> HashSet<String>

All tags that apply to an entity type via tagOn.

Source

pub fn conjunct_parts(&self, name: &str) -> Option<&[String]>

Decompose a conjunct name into component tags.

Source

pub fn choices(&self, choice_name: &str) -> Vec<String>

Valid options for a choice def.

Source

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.

Source

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.

Source

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).

Source

pub fn len(&self) -> usize

Number of registered defs.

Source

pub fn is_empty(&self) -> bool

Returns true if no defs are registered.

Source

pub fn contains(&self, name: &str) -> bool

Check if a name is registered as a def.

Source

pub fn defs(&self) -> &HashMap<String, Def>

All registered defs.

Source

pub fn libs(&self) -> &HashMap<String, Lib>

All registered libraries.

Source

pub fn taxonomy(&self) -> &TaxonomyTree

Get a reference to the taxonomy tree.

Source

pub fn register_spec(&mut self, spec: Spec)

Register a resolved Spec in the registry.

Source

pub fn get_spec(&self, qname: &str) -> Option<&Spec>

Look up a Spec by qualified name (e.g. “ph::Ahu”).

Source

pub fn specs(&self, lib: Option<&str>) -> Vec<&Spec>

List all specs, optionally filtered by library.

Source

pub fn specs_map(&self) -> &HashMap<String, Spec>

Get the raw specs HashMap (for fitting/effective_slots).

Source

pub fn set_lib_source(&mut self, lib_name: &str, source: LibSource)

Track the source of a loaded library.

Source

pub fn lib_source(&self, lib_name: &str) -> Option<&LibSource>

Get the source tracking for a library.

Source

pub fn export_lib_xeto(&self, lib_name: &str) -> Result<String, String>

Export a library to Xeto source text.

Source

pub fn save_lib(&self, lib_name: &str, path: &Path) -> Result<(), String>

Save a library to a file on disk as Xeto text.

Source

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.

Source

pub fn load_xeto_dir( &mut self, dir: &Path, ) -> Result<(String, Vec<String>), XetoError>

Load a Xeto library from a directory of .xeto files.

Source

pub fn unload_lib(&mut self, lib_name: &str) -> Result<(), String>

Unload a library by name. Removes all defs, specs, and taxonomy entries. Returns Err if another loaded library depends on this one or if it’s bundled.

Trait Implementations§

Source§

impl Default for DefNamespace

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V