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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
//! A "rough" concrete XES interchange validator.
//!
//! This example demonstrates concrete enforcement of the `XesRefusal` laws,
//! specifically checking if all namespaced attributes in `XesEvent` are backed
//! by a declared extension in the `XesLog`.
use wasm4pm_compat::xes::{XesEvent, XesExtension, XesLog, XesRefusal, XesTrace};
/// A rough validator that performs a structural check on a XES log.
///
/// While `XesLog::validate` already performs these checks, this implementation
/// demonstrates how to manually inspect and enforce the XES interchange laws.
struct RoughXesValidator<'a> {
log: &'a XesLog,
}
impl<'a> RoughXesValidator<'a> {
fn new(log: &'a XesLog) -> Self {
Self { log }
}
/// Validate the log and return a detailed report of any violations.
fn validate(&self) -> Result<(), Vec<String>> {
let mut errors = Vec::new();
// 1. Check Log Name (MissingLogName law)
if self.log.name().is_empty() {
errors.push(format!("Violation: {}", XesRefusal::MissingLogName));
}
// 2. Check Extensions (InvalidExtension law)
let mut declared_prefixes = Vec::new();
for ext in self.log.extensions() {
if ext.prefix().is_empty() {
errors.push(format!(
"Violation: {} (extension '{}' has empty prefix)",
XesRefusal::InvalidExtension,
ext.name()
));
} else {
declared_prefixes.push(ext.prefix());
}
}
// 3. Check Traces (NoTraces, MissingTraceName, EmptyTrace laws)
if self.log.traces().is_empty() {
errors.push(format!("Violation: {}", XesRefusal::NoTraces));
}
for (t_idx, trace) in self.log.traces().iter().enumerate() {
if trace.name().is_empty() {
errors.push(format!(
"Violation: {} at trace index {}",
XesRefusal::MissingTraceName,
t_idx
));
}
if trace.is_empty() {
errors.push(format!(
"Violation: {} for trace '{}'",
XesRefusal::EmptyTrace,
trace.name()
));
}
// 4. Check Events (MissingConceptName, UndeclaredExtensionPrefix laws)
for (e_idx, event) in trace.events().iter().enumerate() {
if event.concept_name().is_none() {
errors.push(format!(
"Violation: {} in trace '{}', event index {}",
XesRefusal::MissingConceptName,
trace.name(),
e_idx
));
}
for (key, _) in event.attributes() {
if key.contains(':') {
let prefix = key.split(':').next().unwrap_or("");
if !prefix.is_empty() && !declared_prefixes.contains(&prefix) {
errors.push(format!(
"Violation: {} (attribute '{}' in trace '{}', event index {} uses undeclared prefix '{}')",
XesRefusal::UndeclaredExtensionPrefix,
key,
trace.name(),
e_idx,
prefix
));
}
}
}
}
}
if errors.is_empty() {
Ok(())
} else {
Err(errors)
}
}
}
fn main() {
println!("--- Rough XES Validator ---");
// Case 1: A valid log
println!("\nValidating Case 1: Standard Concept/Time/Lifecycle/Org log...");
let valid_log = XesLog::new(
"StandardLog",
[
XesExtension::new(
"Concept",
"concept",
"http://www.xes-standard.org/concept.xesext",
),
XesExtension::new("Time", "time", "http://www.xes-standard.org/time.xesext"),
],
[XesTrace::new(
"case-001",
[XesEvent::new()
.with("concept:name", "Register")
.with("time:timestamp", "2026-05-30T10:00:00Z")],
)],
);
let validator = RoughXesValidator::new(&valid_log);
match validator.validate() {
Ok(_) => println!("✅ Log is structurally valid."),
Err(e) => {
println!("❌ Log validation failed:");
for err in e {
println!(" - {}", err);
}
}
}
// Case 2: An invalid log with undeclared extensions and missing names
println!("\nValidating Case 2: Log with law violations...");
let invalid_log = XesLog::new(
"", // MissingLogName
[XesExtension::new("Concept", "concept", "uri")],
[
XesTrace::new(
"case-777",
[
XesEvent::new()
.with("concept:name", "Action")
.with("custom:extra", "data"), // UndeclaredExtensionPrefix
XesEvent::new(), // MissingConceptName
],
),
XesTrace::new("", []), // MissingTraceName and EmptyTrace
],
);
let validator = RoughXesValidator::new(&invalid_log);
match validator.validate() {
Ok(_) => println!("✅ Log is structurally valid."),
Err(e) => {
println!("❌ Log validation failed (Expected):");
for err in e {
println!(" - {}", err);
}
}
}
}