Skip to main content

Ontology

Struct Ontology 

Source
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

Source

pub const IS_A: &'static str = "is_a"

Canonical transitive type hierarchy relation.

Source

pub const PART_OF: &'static str = "part_of"

Canonical transitive containment relation.

Source

pub const HAS_PART: &'static str = "has_part"

Inverse of Self::PART_OF.

Source

pub const DEPENDS_ON: &'static str = "depends_on"

Directional dependency relation.

Source

pub const REQUIRED_BY: &'static str = "required_by"

Inverse of Self::DEPENDS_ON.

Source

pub const IMPLIES: &'static str = "implies"

Logical implication relation.

Source

pub const ASSOCIATED_WITH: &'static str = "associated_with"

Symmetric non-hierarchical association.

Source

pub const IMPLEMENTED_IN: &'static str = "implemented_in"

Implementation-language relation.

Source

pub const PROVIDES: &'static str = "provides"

Capability or category provision relation.

Source

pub fn new() -> Self

Creates an empty domain vocabulary with standard relation definitions.

Source

pub fn relation_id( value: impl Into<String>, ) -> Result<RelationTypeId, OntologyError>

Builds a validated relation-type ID for a canonical or custom name.

Source

pub fn add_concept( &mut self, concept: OntologyConcept, ) -> Result<OntologyWrite, OntologyError>

Registers a concept idempotently.

Source

pub fn add_relation_type( &mut self, relation_type: OntologyRelationType, ) -> Result<OntologyWrite, OntologyError>

Registers a semantic relation type idempotently.

Source

pub fn add_axiom( &mut self, axiom: OntologyAxiom, ) -> Result<OntologyWrite, OntologyError>

Registers a validated semantic axiom idempotently.

Source

pub fn concept(&self, id: &ConceptId) -> Option<&OntologyConcept>

Returns a concept definition by ID.

Source

pub fn relation_type( &self, id: &RelationTypeId, ) -> Option<&OntologyRelationType>

Returns a semantic relation definition by ID.

Source

pub fn concepts(&self) -> Vec<OntologyConcept>

Returns all concepts in stable ID order.

Source

pub fn relation_types(&self) -> Vec<OntologyRelationType>

Returns all relation types in stable ID order.

Source

pub fn axioms(&self) -> Vec<OntologyAxiom>

Returns all axioms in stable tuple order.

Evaluates a relationship using its declared semantic behavior.

Source

pub fn is_a( &self, child: &ConceptId, ancestor: &ConceptId, ) -> Result<bool, OntologyError>

Evaluates the canonical transitive is_a hierarchy.

Source

pub fn axioms_from( &self, subject: &ConceptId, ) -> Result<Vec<OntologyAxiom>, OntologyError>

Returns axioms whose subject matches a concept, in stable order.

Source

pub fn stats(&self) -> OntologyStats

Returns a count snapshot.

Trait Implementations§

Source§

impl Clone for Ontology

Source§

fn clone(&self) -> Ontology

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Ontology

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Ontology

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.