Skip to main content

Classification

Struct Classification 

Source
pub struct Classification { /* private fields */ }
Expand description

The result of classify: every named concept’s entailed named superclasses (transitively closed).

Implementations§

Source§

impl Classification

Source

pub fn subsumers(&self, concept: SctId) -> impl Iterator<Item = SctId> + '_

Every concept concept is (transitively) subsumed by, per the input axioms — strict: never includes concept itself, mirroring SnapshotStore::ancestors’s convention. Empty for a concept the axioms said nothing about.

Examples found in repository?
examples/benchmark_synthetic_ontology.rs (line 96)
48fn main() {
49    let n: u64 = std::env::var("N")
50        .ok()
51        .and_then(|s| s.parse().ok())
52        .unwrap_or(370_000);
53    let mut rng = Rng(42);
54    let role = id(999_998);
55    let mut axioms = Vec::new();
56    for i in 2..=n {
57        let parent = 1 + rng.below(i - 1);
58        axioms.push(Axiom::SubClassOf {
59            sub: ClassExpression::Concept(id(1000 + i)),
60            sup: ClassExpression::Concept(id(1000 + parent)),
61        });
62    }
63    // 1 in 20 concepts also asserts an existential to a random earlier
64    // concept, exercising CR2/CR3 at scale.
65    for i in 2..=n {
66        if i % 20 == 0 {
67            let filler = 1 + rng.below(i - 1);
68            axioms.push(Axiom::SubClassOf {
69                sub: ClassExpression::Concept(id(1000 + i)),
70                sup: ClassExpression::ObjectSomeValuesFrom {
71                    attribute: role,
72                    filler: Box::new(ClassExpression::Concept(id(1000 + filler))),
73                },
74            });
75        }
76    }
77    axioms.push(Axiom::SubClassOf {
78        sub: ClassExpression::ObjectSomeValuesFrom {
79            attribute: role,
80            filler: Box::new(ClassExpression::Concept(id(1001))),
81        },
82        sup: ClassExpression::Concept(id(999_999)),
83    });
84
85    let start = Instant::now();
86    let report = classify(&axioms);
87    let elapsed = start.elapsed();
88    println!(
89        "N={n} axioms={} elapsed={elapsed:?} skipped={}",
90        axioms.len(),
91        report.skipped.len()
92    );
93    let mut total_subsumers = 0usize;
94    let mut max_subsumers = 0usize;
95    for i in 1..=n {
96        let count = report.classification.subsumers(id(1000 + i)).count();
97        total_subsumers += count;
98        max_subsumers = max_subsumers.max(count);
99    }
100    println!(
101        "avg subsumers/concept = {:.1}, max = {max_subsumers}",
102        total_subsumers as f64 / n as f64
103    );
104}
Source

pub fn is_subsumed_by(&self, sub: SctId, sup: SctId) -> bool

Reflexive subsumption test: true when sub == sup or sup is among sub’s entailed superclasses.

Source

pub fn equivalent_to(&self, concept: SctId) -> impl Iterator<Item = SctId> + '_

Concepts mutually subsuming concept (i.e. logically equivalent under the input axioms) — excludes concept itself.

Source

pub fn concepts(&self) -> impl Iterator<Item = SctId> + '_

Every concept the input axioms said anything about — i.e. every concept subsumers/is_subsumed_by/equivalent_to have a real (possibly empty) answer for, not just concepts that happen to appear somewhere as a filler. Order is unspecified.

Trait Implementations§

Source§

impl Clone for Classification

Source§

fn clone(&self) -> Classification

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 Classification

Source§

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

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

impl Default for Classification

Source§

fn default() -> Classification

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