pub struct Ontology { /* private fields */ }Expand description
Validated domain ontology with deterministic semantic traversal.
The default ontology contains standard relation definitions but no domain concepts or axioms. Callers explicitly register their product vocabulary.
§Examples
use termivar_core::{ConceptId, Ontology, OntologyAxiom, OntologyConcept};
let mut ontology = Ontology::new();
let framework = ConceptId::new("framework")?;
let technology = ConceptId::new("technology")?;
let laravel = ConceptId::new("laravel")?;
ontology.add_concept(OntologyConcept::new(framework.clone(), "Framework")?)?;
ontology.add_concept(OntologyConcept::new(technology.clone(), "Technology")?)?;
ontology.add_concept(OntologyConcept::new(laravel.clone(), "Laravel")?)?;
ontology.add_axiom(OntologyAxiom::new(
laravel.clone(),
Ontology::relation_id(Ontology::IS_A)?,
framework.clone(),
))?;
ontology.add_axiom(OntologyAxiom::new(
framework,
Ontology::relation_id(Ontology::IS_A)?,
technology.clone(),
))?;
assert!(ontology.is_a(&laravel, &technology)?);Implementations§
Source§impl Ontology
impl Ontology
Sourcepub const HAS_PART: &'static str = "has_part"
pub const HAS_PART: &'static str = "has_part"
Inverse of Self::PART_OF.
Sourcepub const DEPENDS_ON: &'static str = "depends_on"
pub const DEPENDS_ON: &'static str = "depends_on"
Directional dependency relation.
Sourcepub const REQUIRED_BY: &'static str = "required_by"
pub const REQUIRED_BY: &'static str = "required_by"
Inverse of Self::DEPENDS_ON.
Sourcepub const ASSOCIATED_WITH: &'static str = "associated_with"
pub const ASSOCIATED_WITH: &'static str = "associated_with"
Symmetric non-hierarchical association.
Sourcepub const IMPLEMENTED_IN: &'static str = "implemented_in"
pub const IMPLEMENTED_IN: &'static str = "implemented_in"
Implementation-language relation.
Sourcepub fn relation_id(
value: impl Into<String>,
) -> Result<RelationTypeId, OntologyError>
pub fn relation_id( value: impl Into<String>, ) -> Result<RelationTypeId, OntologyError>
Builds a validated relation-type ID for a canonical or custom name.
Sourcepub fn add_concept(
&mut self,
concept: OntologyConcept,
) -> Result<OntologyWrite, OntologyError>
pub fn add_concept( &mut self, concept: OntologyConcept, ) -> Result<OntologyWrite, OntologyError>
Registers a concept idempotently.
Sourcepub fn add_relation_type(
&mut self,
relation_type: OntologyRelationType,
) -> Result<OntologyWrite, OntologyError>
pub fn add_relation_type( &mut self, relation_type: OntologyRelationType, ) -> Result<OntologyWrite, OntologyError>
Registers a semantic relation type idempotently.
Sourcepub fn add_axiom(
&mut self,
axiom: OntologyAxiom,
) -> Result<OntologyWrite, OntologyError>
pub fn add_axiom( &mut self, axiom: OntologyAxiom, ) -> Result<OntologyWrite, OntologyError>
Registers a validated semantic axiom idempotently.
Sourcepub fn concept(&self, id: &ConceptId) -> Option<&OntologyConcept>
pub fn concept(&self, id: &ConceptId) -> Option<&OntologyConcept>
Returns a concept definition by ID.
Sourcepub fn relation_type(
&self,
id: &RelationTypeId,
) -> Option<&OntologyRelationType>
pub fn relation_type( &self, id: &RelationTypeId, ) -> Option<&OntologyRelationType>
Returns a semantic relation definition by ID.
Sourcepub fn concepts(&self) -> Vec<OntologyConcept>
pub fn concepts(&self) -> Vec<OntologyConcept>
Returns all concepts in stable ID order.
Sourcepub fn relation_types(&self) -> Vec<OntologyRelationType>
pub fn relation_types(&self) -> Vec<OntologyRelationType>
Returns all relation types in stable ID order.
Sourcepub fn axioms(&self) -> Vec<OntologyAxiom>
pub fn axioms(&self) -> Vec<OntologyAxiom>
Returns all axioms in stable tuple order.
Evaluates a relationship using its declared semantic behavior.
Sourcepub fn is_a(
&self,
child: &ConceptId,
ancestor: &ConceptId,
) -> Result<bool, OntologyError>
pub fn is_a( &self, child: &ConceptId, ancestor: &ConceptId, ) -> Result<bool, OntologyError>
Evaluates the canonical transitive is_a hierarchy.
Sourcepub fn axioms_from(
&self,
subject: &ConceptId,
) -> Result<Vec<OntologyAxiom>, OntologyError>
pub fn axioms_from( &self, subject: &ConceptId, ) -> Result<Vec<OntologyAxiom>, OntologyError>
Returns axioms whose subject matches a concept, in stable order.
Sourcepub fn stats(&self) -> OntologyStats
pub fn stats(&self) -> OntologyStats
Returns a count snapshot.