dataprof_core/pattern.rs
1use crate::classification::PatternCategory;
2
3/// A detected value pattern within a column (e.g. email, phone, UUID).
4#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
5pub struct Pattern {
6 /// Pattern name (e.g. "Email", "Phone (US)", "UUID")
7 pub name: String,
8 /// Regex used for detection
9 pub regex: String,
10 /// Number of analyzed non-null values passing the regex and semantic validator.
11 pub match_count: usize,
12 /// Percentage of analyzed non-null values passing validation (0.0--100.0).
13 pub match_percentage: f64,
14 /// Semantic category (e.g. contact, network, financial)
15 pub category: PatternCategory,
16 /// Detection confidence score (0.0--1.0), derived from pattern specificity and match rate
17 pub confidence: f64,
18}
19
20/// What a pattern's `match_count` counts, as recorded in a report's metric
21/// semantics.
22///
23/// Only the current definition has a value. Through 0.12 the count was every
24/// value the regular expression matched, whether or not the pattern's validator
25/// accepted it, and those releases recorded no definition.
26#[derive(
27 Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema,
28)]
29#[serde(rename_all = "snake_case")]
30pub enum PatternMatchCount {
31 /// Values that pass the regular expression and, where the pattern has
32 /// one, its semantic validator.
33 Validated,
34}