pub fn classify<'a>(
axioms: impl IntoIterator<Item = &'a Axiom>,
) -> ClassificationReportExpand description
Computes the full entailed subsumption hierarchy over axioms, via
the EL completion algorithm (spec/13-classification.md).
Examples found in repository?
examples/benchmark_synthetic_ontology.rs (line 86)
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}