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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
//! Always-on **adoption grammar** for interoperating with external process-mining
//! ecosystems (PM4Py, PMAx, and friends) — *without* cloning their internals.
//!
//! This module is the smallest, always-available vocabulary a host tool needs to
//! describe what it is *handing across the boundary* and what it is *claiming*
//! about that handoff. It is **structure only**: it carries no PM4Py objects, runs
//! no discovery, no conformance checking, no replay, and no statistics. It merely
//! lets an adopter *name* the shapes it intends to admit, and *refuse* — with a
//! specific named law — when a claim is not grounded.
//!
//! ## What this module **IS**
//!
//! - A set of small, transparent *shape descriptors* ([`crate::interop::Pm4pyShape`],
//! [`crate::interop::FilterShape`], [`crate::interop::SummaryShape`], [`crate::interop::ConformanceTriple`]) that describe the
//! *kind* of artifact being adopted, never its bytes or its computed values.
//! - An [`crate::interop::ArtifactGrounding`] that ties a claimed artifact to the evidence that
//! justifies admitting it.
//! - A first-class refusal enum, [`crate::interop::InteropRefusal`], for when a claim cannot be
//! grounded.
//!
//! ## What this module is **NOT**
//!
//! - **Not** a PM4Py / PMAx re-implementation. There are no DataFrames, no
//! PetriNet objects, no alignment matrices here.
//! - **Not** an engine. Nothing here *computes* a summary, a filter result, or a
//! conformance triple — it only describes their *shape* so the boundary can
//! reason about admission and refusal.
//!
//! ## Graduation
//!
//! These descriptors should graduate to `wasm4pm` the moment a host needs the
//! values behind them *computed or executed* (an actual filter applied, an actual
//! summary tallied, an actual conformance triple measured). At that point the
//! shape becomes a job, and a job belongs to the engine — see the `wasm4pm`
//! feature and the `graduation` module.
use PhantomData;
/// The *kind* of PM4Py-flavoured artifact an adopter is presenting at the boundary.
///
/// This describes **what category of thing** is crossing the boundary so the
/// compat layer can pick the right admission law. It does **not** hold the
/// artifact itself, and it is **structure only** — naming a `PetriNet` here does
/// not bring a Petri-net engine with it.
///
/// Graduate to `wasm4pm` when you need the artifact *materialized and executed*
/// rather than merely *named and admitted*.
/// The *shape* of a log filter an adopter intends to declare at the boundary.
///
/// This names the **dimension** a filter ranges over (activity, time, variant, …)
/// — it carries **no predicate, no threshold, and no filtered result**. It exists
/// so the compat layer can record *that a filter was claimed* without pretending
/// to *apply* one.
///
/// Graduate to `wasm4pm` when the filter must actually *select* events/traces.
/// The *shape* of a log summary an adopter intends to declare.
///
/// Names the **family of statistic** being summarized (counts, variants,
/// durations, …). It holds **no tallies**: a `SummaryShape::TraceVariants` does
/// not contain the variants, only the assertion that variant-summary is the
/// claimed shape.
///
/// Graduate to `wasm4pm` when the summary must actually be *tallied*.
/// A *shape* describing the three classic conformance quality dimensions, with
/// **no values measured**.
///
/// In full process mining a conformance result reports fitness, precision, and
/// (optionally) generalization. Here we only assert *which dimensions are being
/// claimed* — the booleans say "this dimension is part of the claim", they do
/// **not** carry the measured score. Measuring belongs to the engine.
///
/// Graduate to `wasm4pm` when the actual fitness/precision/generalization numbers
/// must be *computed by replay or alignment*.
/// Ties a claimed PM4Py-flavoured artifact to the *evidence handle* that justifies
/// admitting it across the boundary.
///
/// `ArtifactGrounding` is the unit of honesty in the interop grammar: an adopter
/// may not merely *assert* "I have a Petri net"; it must point at the evidence
/// (named by `evidence_ref`) that grounds the assertion. The generic `W` is a
/// witness family marker (see [`crate::witness`]) carried at the type level only —
/// `PhantomData`, zero runtime cost.
///
/// It is **structure only**: it never holds the artifact, and grounding it does
/// not validate it. Validation/execution is a `wasm4pm` job.
/// First-class, *specifically named* refusals for the interop grammar.
///
/// Refusal is never bare here. Each variant names the exact law violated so a
/// host (and a human) can see *why* the boundary said no. These are
/// **structure-only** verdicts: they describe a boundary judgment, they do not
/// remediate it.
/// Check that a [`FilterShape`] is meaningful for a given [`Pm4pyShape`].
///
/// Object-centric filter dimensions (`ObjectType`) are refused over flat shapes;
/// everything else is structurally admissible. This is a *shape* check only — it
/// does not validate that any matching events exist.
///
/// ```
/// use wasm4pm_compat::interop::{check_filter_shape, FilterShape, Pm4pyShape, InteropRefusal};
/// assert!(check_filter_shape(Pm4pyShape::EventLog, FilterShape::Activity).is_ok());
/// assert_eq!(
/// check_filter_shape(Pm4pyShape::EventLog, FilterShape::ObjectType),
/// Err(InteropRefusal::DimensionShapeMismatch)
/// );
/// ```
// ── OCEL → XES format grammar surfaces ──────────────────────────────────────
//
// The following types model the *named projection descriptor* for OCEL→XES
// flattening. They are the format grammar surfaces of the boundary — they name
// and parameterise the projection but do NOT implement it. The projection
// itself (instantiating crate::loss::Project) belongs in the adopter's code or
// in `wasm4pm`.
/// A descriptor for an OCEL→XES flattening projection.
///
/// Flattening OCEL to a single XES case notion is lossy: you choose one object
/// type to act as the case, and all E2O links to the other types are dropped.
/// This descriptor names the projection (via [`crate::loss::ProjectionName`])
/// and records which object type was chosen as the case notion.
///
/// It is the *grammar surface* for the OCEL→XES boundary: it names and
/// parameterises the projection so the [`crate::loss::Project`] impl an adopter
/// writes is unambiguous and auditable. It does **not** perform the flattening.
///
/// Structure-only: use this as the `Self` type of a
/// [`crate::loss::Project`] impl, with `From = OcelShape`, `To = XesShape`,
/// `Lost = Vec<String>` (dropped object type names), and
/// `Reason = crate::ocel::OcelRefusal`.
///
/// ```
/// use wasm4pm_compat::interop::OcelToXesProjection;
/// use wasm4pm_compat::loss::ProjectionName;
/// let proj = OcelToXesProjection::new("order");
/// assert_eq!(proj.case_type(), "order");
/// assert_eq!(proj.projection_name().as_str(), "ocel-flatten-to-xes:by-case-type");
/// ```
/// Shape marker for the OCEL side of an OCEL→XES projection.
///
/// Use as `From` in `LossReport<OcelShape, XesShape, …>` and in
/// [`crate::loss::Project`] impls. Zero-sized.
///
/// ```
/// use wasm4pm_compat::interop::OcelShape;
/// let _: OcelShape;
/// ```
/// Shape marker for the XES side of an OCEL→XES projection.
///
/// Use as `To` in `LossReport<OcelShape, XesShape, …>` and in
/// [`crate::loss::Project`] impls. Zero-sized.
///
/// ```
/// use wasm4pm_compat::interop::XesShape;
/// let _: XesShape;
/// ```
// ── XES → OCED format grammar surfaces ──────────────────────────────────────
//
// The OCED meta-model (Object-Centric Event Data) is a richer formalism than
// XES: where XES is case-centric and single-case-notion, OCED is object-centric
// and multi-entity. Converting XES to OCED is therefore a *named, lossy
// projection*: the XES single-case assumption is dropped, object relationships
// are inferred, and the resulting OCED log explicitly accounts for what was
// structurally implicit in XES.
//
// Law: xes-to-oced-projection-named
// Paper: "Object-Centric Analysis of XES Event Logs: Integrating OCED Modeling
// with SPARQL Queries"
//
// The reverse direction (OCEL→XES) is covered by OcelToXesProjection above.
/// Shape marker for the OCED (Object-Centric Event Data) side of a XES→OCED
/// projection.
///
/// Use as `To` in `LossReport<XesShape, OcedShape, …>` and in
/// [`crate::loss::Project`] impls for XES-to-OCED projections. Zero-sized.
///
/// This is **not** the same as [`OcelShape`]: OCED is the upstream meta-model
/// formalism (IEEE/WfMC academic standard), while OCEL is the concrete 2.0
/// serialization. They are distinct projection targets.
///
/// ## Graduation
///
/// OCED evaluation, SPARQL queries over OCED graphs, and OCED-to-OCEL
/// materialization graduate to `wasm4pm`. This marker is structure-only.
///
/// ```
/// use wasm4pm_compat::interop::OcedShape;
/// let _: OcedShape;
/// ```
/// A descriptor for a XES→OCED lifting projection.
///
/// Converting XES (case-centric, single case notion, no explicit object types)
/// into the OCED meta-model is *lossy*: the XES single-case assumption is
/// dropped, object relationships are inferred from the trace structure, and the
/// single-case-notion constraint is lost. This descriptor names that projection
/// (via [`crate::loss::ProjectionName`]) and records the object type introduced
/// as the case notion in the OCED output.
///
/// It is the *grammar surface* for the XES→OCED boundary: it names and
/// parameterises the projection so the [`crate::loss::Project`] impl an adopter
/// writes is unambiguous and auditable. It does **not** perform the lifting.
///
/// Structure-only: use this as the `Self` type of a
/// [`crate::loss::Project`] impl, with `From = XesShape`, `To = OcedShape`,
/// `Lost = Vec<String>` (structural assumptions dropped), and
/// `Reason = crate::xes::XesRefusal`.
///
/// ## Law
///
/// `xes-to-oced-projection-named` — Paper: "Object-Centric Analysis of XES
/// Event Logs: Integrating OCED Modeling with SPARQL Queries"
///
/// ```
/// use wasm4pm_compat::interop::XesToOcedProjection;
/// use wasm4pm_compat::loss::ProjectionName;
/// let proj = XesToOcedProjection::new("order");
/// assert_eq!(proj.introduced_object_type(), "order");
/// assert_eq!(proj.projection_name().as_str(), "xes-lift-to-oced:by-case-type");
/// ```
// ── Graduation candidate sealed marker ──────────────────────────────────────
//
// Always-on (base profile): the graduation boundary is part of the core
// interop grammar, not an optional feature. Structure-only in wasm4pm-compat;
// execution graduates to wasm4pm.
/// Sealed marker: a type that is a **graduation candidate** — it requires the
/// `wasm4pm` execution engine to resolve its structural claim and therefore
/// must not grow engine logic inside `wasm4pm-compat`.
///
/// This trait is *sealed* (`graduation_seal::Sealed`): only types that
/// explicitly opt in via `impl graduation_seal::Sealed for MyType {}` can
/// implement it. The seal prevents third-party crates from accidentally
/// marking arbitrary types as graduation candidates without declaring the
/// boundary seam.
///
/// ## What this trait is **NOT**
///
/// - **Not** the act of graduation. Implementing `GraduationCandidate` does
/// not graduate anything; it makes the boundary explicit at the type level.
/// - **Not** an engine. No execution, no discovery, no replay, no conformance
/// checking. Structure only.
///
/// ## Graduation
///
/// When a host needs a graduation candidate value (reason + subject +
/// evidence ref), use `wasm4pm_compat::graduation::GraduateToWasm4pm`
/// (behind the `wasm4pm` feature). This sealed marker is the always-on
/// compile-time surface that `GraduateToWasm4pm` implementors should also
/// implement at the seam.
///
/// ## Usage pattern
///
/// ```
/// use wasm4pm_compat::interop::{GraduationCandidate, graduation_seal};
///
/// struct PendingOcelDiscovery;
///
/// impl graduation_seal::Sealed for PendingOcelDiscovery {}
/// impl GraduationCandidate for PendingOcelDiscovery {}
///
/// fn only_graduation_candidates<T: GraduationCandidate>(_: &T) {}
/// only_graduation_candidates(&PendingOcelDiscovery);
/// ```
/// Sealing module for [`GraduationCandidate`].
///
/// To implement [`GraduationCandidate`], a type must first implement
/// `graduation_seal::Sealed`. This is the sealed-trait pattern in stable Rust.
// ── Compile-time filter-shape law ────────────────────────────────────────────
//
// `FilterShapeConst<IS_OC>` is the type-level surface for the pm4py shape law:
// an object-centric filter dimension (ObjectType) must only be applied to an
// object-centric artifact shape. The boolean const parameter names whether the
// artifact is object-centric. `assert_filter_oc_compatible` requires the
// sealed `RequiresObjectCentric` bound, which only `FilterShapeConst<true>`
// satisfies — so passing `FilterShapeConst<false>` (a flat artifact) is a
// compile error named `DimensionShapeMismatch`.
//
// Law: DimensionShapeMismatch — FilterShape::ObjectType over a flat Pm4pyShape.
/// A compile-time artifact-centricity tag for the filter-shape law.
///
/// `IS_OC` encodes whether the artifact is object-centric (`true`) or flat
/// (`false`). Pass `FilterShapeConst::<true>` to surfaces that require an
/// object-centric shape; `FilterShapeConst::<false>` fails those surfaces at
/// compile time with the `DimensionShapeMismatch` law.
///
/// This is **structure only** and **zero-cost**: no runtime value is stored.
///
/// ```
/// use wasm4pm_compat::interop::{FilterShapeConst, assert_filter_oc_compatible};
/// assert_filter_oc_compatible(&FilterShapeConst::<true>); // object-centric: lawful
/// ```
///
/// ```compile_fail
/// use wasm4pm_compat::interop::{FilterShapeConst, assert_filter_oc_compatible};
/// // flat artifact: DimensionShapeMismatch law — FilterShape::ObjectType is refused
/// assert_filter_oc_compatible(&FilterShapeConst::<false>);
/// ```
;
/// Sealed marker: only `FilterShapeConst<true>` (object-centric) satisfies this
/// bound. Attempting to apply an object-centric filter (`FilterShape::ObjectType`)
/// to a flat artifact shape (`FilterShapeConst<false>`) is a compile error
/// enforcing the `DimensionShapeMismatch` law.
/// Type-law gate: only object-centric artifact shapes compile through this
/// function when an `ObjectType` filter is declared.
///
/// Passing `FilterShapeConst::<false>` (a flat shape) is a compile error that
/// enforces the `DimensionShapeMismatch` pm4py shape law at the type level.
///
/// ```
/// use wasm4pm_compat::interop::{FilterShapeConst, assert_filter_oc_compatible};
/// assert_filter_oc_compatible(&FilterShapeConst::<true>);
/// ```