weavatrix_graph/model/
provenance.rs1use super::SourceSpan;
2use crate::{EvidenceKind, GraphError, Result};
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
6#[serde(rename_all = "snake_case")]
7#[non_exhaustive]
8pub enum Confidence {
9 Exact,
10 High,
11 Medium,
12 Low,
13}
14
15#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
16pub struct Provenance {
17 pub extractor: String,
18 pub evidence: EvidenceKind,
19 pub confidence: Confidence,
20 #[serde(skip_serializing_if = "Option::is_none")]
21 pub span: Option<SourceSpan>,
22 #[serde(skip_serializing_if = "Option::is_none")]
23 pub detail: Option<String>,
24}
25
26impl Provenance {
27 pub fn new(
33 extractor: impl Into<String>,
34 evidence: EvidenceKind,
35 confidence: Confidence,
36 ) -> Result<Self> {
37 let extractor = extractor.into();
38 if extractor.is_empty() {
39 return Err(GraphError::EmptyExtractor);
40 }
41 Ok(Self {
42 extractor,
43 evidence,
44 confidence,
45 span: None,
46 detail: None,
47 })
48 }
49
50 #[must_use]
51 pub fn with_span(mut self, span: SourceSpan) -> Self {
52 self.span = Some(span);
53 self
54 }
55
56 #[must_use]
57 pub fn with_detail(mut self, detail: impl Into<String>) -> Self {
58 self.detail = Some(detail.into());
59 self
60 }
61}