use std::path::Path;
pub fn is_ocel_log(path: &Path) -> bool {
let ext = path
.extension()
.and_then(|e| e.to_str())
.unwrap_or_default()
.to_lowercase();
match ext.as_str() {
"ocel" | "jsonocel" => true,
"json" => {
let name = path.to_string_lossy();
name.contains(".ocel")
|| name.contains("vision_trace")
|| std::fs::read_to_string(path)
.unwrap_or_default()
.contains("ocel:")
}
_ => false,
}
}
#[cfg(test)]
mod tests {
use super::*;
use std::path::Path;
#[test]
fn detects_ocel_by_extension() {
assert!(is_ocel_log(Path::new("log.ocel")));
assert!(is_ocel_log(Path::new("log.jsonocel")));
}
#[test]
fn detects_ocel_by_json_name_hint() {
assert!(is_ocel_log(Path::new("orders.ocel.json")));
assert!(is_ocel_log(Path::new("vision_trace_42.json")));
}
#[test]
fn plain_xes_and_unrelated_json_are_not_ocel() {
assert!(!is_ocel_log(Path::new("log.xes")));
assert!(!is_ocel_log(Path::new("missing.json")));
assert!(!is_ocel_log(Path::new("README.md")));
}
}