1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//! Engine-agnostic inference trace types for explanation generation.
use serde::{Deserialize, Serialize};
use crate::axiom::AxiomId;
use crate::entity::EntityId;
/// What an inference step concludes.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case", tag = "kind")]
pub enum TraceConclusion {
/// A new or existing ontology axiom.
Axiom {
/// Concluded axiom id.
id: AxiomId,
},
/// EL completion: `sub ⊑ sup`.
SubClassOf {
/// Subclass entity.
sub: EntityId,
/// Superclass entity.
sup: EntityId,
},
/// EL completion: `class ⊑ ∃property.filler`.
Existential {
/// Subject class.
class: EntityId,
/// Object property.
property: EntityId,
/// Filler class.
filler: EntityId,
},
/// EL completion: `subProperty ⊑ superProperty`.
SubObjectPropertyOf {
/// Sub property.
sub: EntityId,
/// Super property.
sup: EntityId,
},
}
/// A premise referenced by an inference step.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case", tag = "kind")]
pub enum TracePremise {
/// An ontology axiom used as a premise.
Axiom {
/// Premise axiom id.
id: AxiomId,
},
/// EL graph edge `sub ⊑ sup` used as a premise.
SubClassOf {
/// Subclass entity.
sub: EntityId,
/// Superclass entity.
sup: EntityId,
},
/// EL graph edge `sub ⊑ ∃property.filler` used as a premise.
Existential {
/// Subject class.
class: EntityId,
/// Object property.
property: EntityId,
/// Filler class.
filler: EntityId,
},
/// EL graph edge `subProperty ⊑ superProperty` used as a premise.
SubObjectPropertyOf {
/// Sub property.
sub: EntityId,
/// Super property.
sup: EntityId,
},
}
/// A single recorded inference step.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct TraceStep {
/// Rule name (engine-specific snake_case identifier).
pub rule: String,
/// Premises for this step.
pub premises: Vec<TracePremise>,
/// What this step concludes.
pub conclusion: TraceConclusion,
}
/// Ordered list of inference steps from a reasoning run.
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct InferenceTrace {
/// Steps in derivation order.
pub steps: Vec<TraceStep>,
}
impl InferenceTrace {
/// Create an empty trace.
#[must_use]
pub fn new() -> Self {
Self::default()
}
/// Append a step.
pub fn push(&mut self, step: TraceStep) {
self.steps.push(step);
}
}