Skip to main content

xz_knowledge_graph/types/
confidence.rs

1use serde::{Deserialize, Serialize};
2
3/// Confidence level for entities, relations, and attributes.
4#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
5pub enum Confidence {
6    Speculative,
7    Low,
8    Medium,
9    High,
10    Confirmed,
11}
12
13impl Confidence {
14    pub fn as_f32(self) -> f32 {
15        match self {
16            Self::Speculative => 0.15,
17            Self::Low => 0.35,
18            Self::Medium => 0.60,
19            Self::High => 0.85,
20            Self::Confirmed => 1.0,
21        }
22    }
23
24    pub fn from_f32(v: f32) -> Self {
25        if v >= 1.0 {
26            Self::Confirmed
27        } else if v >= 0.85 {
28            Self::High
29        } else if v >= 0.6 {
30            Self::Medium
31        } else if v >= 0.35 {
32            Self::Low
33        } else {
34            Self::Speculative
35        }
36    }
37}