Skip to main content
Rust4PM

Convert between formats

Read a log in one format and write it in another. The file extensions do all the work.

import r4pm

# Event logs: XES, gzipped XES and JSON.
log = r4pm.import_item("EventLog", "data/road-traffic-fines.xes.gz")
r4pm.export_item(log, "fines.xes")
r4pm.export_item(log, "fines.json")

# OCEL 2.0: XML, JSON and SQLite, each also gzipped (except SQLite).
ocel = r4pm.import_item("OCEL", "data/order-management.xml.gz")
r4pm.export_item(ocel, "orders.json")
r4pm.export_item(ocel, "orders.sqlite")

# Read a converted file back to check it.
again = r4pm.import_item("OCEL", "orders.sqlite")
print(r4pm.item_to_df(again)["events"].height, "events after the round trip")
21008 events after the round trip

How it works

Import and export pick the format from the file extension, so converting is an import followed by an export. The same item can be exported several times in different formats. The file formats page lists every format each data type supports.

  • Event logs: .xes, .xes.gz and .json.
  • OCEL 2.0: .xml, .json and .sqlite, plus gzipped XML and JSON, the CSV table layout .ocel.csv, and with optional Rust features DuckDB and the .ocel.zip bundle.
  • Petri nets: .pnml.

The Python snippet writes SQLite because the Python package includes it. In Rust, SQLite needs the ocel-sqlite feature, so the Rust snippet sticks to formats of the default build.

Command line

With the CLI, a function that returns a log writes it in the format of the output path's extension. To turn an OCEL into an XES event log for one object type, for example:

r4pm flatten_ocel_on --ocel order-management.xml.gz --object_type 'orders' orders.xes