Skip to main content

zer_core/
entity.rs

1use crate::record::RecordId;
2
3pub type EntityId = u64;
4
5/// How an entity member was resolved.
6#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
7pub enum ResolutionMethod {
8    AutoMatch,
9    JudgePromoted,
10    JudgeDemoted,
11    Manual,
12}
13
14/// A record's membership in an entity, with its resolution score and method.
15///
16/// `record_key` is the natural key value (e.g. BSN, UUID) as provided by the
17/// user via `zer_adapters::DatasetConfig`.  For records created with
18/// [`crate::record::Record::new`] it falls back to the numeric ID as a string.
19/// This key is stored in the `.zes` file so that the cluster output maps
20/// directly to the user's own record identifiers.
21#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
22pub struct EntityMember {
23    pub record_id: RecordId,
24    pub record_key: String,
25    pub score: f32,
26    pub method: ResolutionMethod,
27    pub source: Option<String>,
28}
29
30/// A resolved entity grouping one or more records.
31#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
32pub struct Entity {
33    pub id: EntityId,
34    pub members: Vec<EntityMember>,
35}
36
37impl Entity {
38    pub fn new(id: EntityId) -> Self {
39        Self {
40            id,
41            members: vec![],
42        }
43    }
44
45    pub fn member_ids(&self) -> impl Iterator<Item = RecordId> + '_ {
46        self.members.iter().map(|m| m.record_id)
47    }
48}