Skip to content

Commit

Permalink
Merge branch 'PMPY-2066' into 'integration'
Browse files Browse the repository at this point in the history
PMPY-2066 Insertion graph-based O2O relationships in the OCEL

Closes PMPY-2066

See merge request process-mining/pm4py/pm4py-core!960
  • Loading branch information
fit-alessandro-berti committed Mar 23, 2023
2 parents 30ba195 + b46d240 commit d4a5525
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
## pm4py 2.7.1 (2023.XX.YY)

### Added
* af4f00bca1ec7a3b0acc0421efe4bf895b324995
* insertion graph-based O2O relationships in the OCEL

### Changed

Expand Down
3 changes: 2 additions & 1 deletion pm4py/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
fitness_footprints, precision_footprints, check_is_fitting, conformance_temporal_profile, \
conformance_log_skeleton
from pm4py.ocel import ocel_objects_interactions_summary, ocel_temporal_summary, ocel_objects_summary, ocel_get_object_types, ocel_get_attribute_names, ocel_flattening, ocel_object_type_activities, ocel_objects_ot_count, \
discover_ocdfg, discover_oc_petri_net, discover_objects_graph, sample_ocel_objects, ocel_drop_duplicates, ocel_merge_duplicates, ocel_sort_by_additional_column, ocel_add_index_based_timedelta, sample_ocel_connected_components
discover_ocdfg, discover_oc_petri_net, discover_objects_graph, sample_ocel_objects, ocel_drop_duplicates, ocel_merge_duplicates, ocel_sort_by_additional_column, \
ocel_add_index_based_timedelta, sample_ocel_connected_components, ocel_o2o_enrichment
from pm4py.vis import view_petri_net, save_vis_petri_net, view_dfg, save_vis_dfg, view_process_tree, \
save_vis_process_tree, \
view_ocdfg, save_vis_ocdfg, view_heuristics_net, save_vis_heuristics_net, view_bpmn, save_vis_bpmn, view_sna, save_vis_sna,\
Expand Down
72 changes: 72 additions & 0 deletions pm4py/algo/transformation/ocel/graphs/ocel20_computation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
from enum import Enum
from pm4py.util import constants, exec_utils
from pm4py.algo.transformation.ocel.graphs import object_interaction_graph, object_descendants_graph, object_inheritance_graph, object_cobirth_graph, object_codeath_graph
from pm4py.objects.ocel.obj import OCEL
from typing import Optional, Dict, Any
from copy import copy
import pandas as pd


class Parameters(Enum):
INCLUDED_GRAPHS = "included_graphs"


def apply(ocel: OCEL, parameters: Optional[Dict[Any, Any]] = None) -> OCEL:
"""
Inserts the information inferred from the graph computations in the list of O2O relations of the OCEL
Parameters
----------------
ocel
Object-centric event log
parameters
Possible parameters of the algorithm:
- Parameters.INCLUDED_GRAPHS => graphs to include in the list of O2O relations
(object_interaction_graph, object_descendants_graph, object_inheritance_graph, object_cobirth_graph, object_codeath_graph)
Returns
---------------
enriched_ocel
Enriched object-centric event log
"""
if parameters is None:
parameters = {}

included_graphs = exec_utils.get_param_value(Parameters.INCLUDED_GRAPHS, parameters, None)
if included_graphs is None:
included_graphs = {"object_interaction_graph", "object_descendants_graph", "object_inheritance_graph", "object_cobirth_graph", "object_codeath_graph"}

o2o = []

if "object_interaction_graph" in included_graphs:
graph = object_interaction_graph.apply(ocel, parameters=parameters)
for el in graph:
if el[0] != el[1]:
o2o.append({ocel.object_id_column: el[0], ocel.object_id_column+"_2": el[1], ocel.qualifier: "object_interaction_graph"})
o2o.append({ocel.object_id_column: el[1], ocel.object_id_column+"_2": el[0], ocel.qualifier: "object_interaction_graph"})
if "object_descendants_graph" in included_graphs:
graph = object_descendants_graph.apply(ocel, parameters=parameters)
for el in graph:
o2o.append({ocel.object_id_column: el[0], ocel.object_id_column + "_2": el[1],
ocel.qualifier: "object_descendants_graph"})
if "object_inheritance_graph" in included_graphs:
graph = object_descendants_graph.apply(ocel, parameters=parameters)
for el in graph:
o2o.append({ocel.object_id_column: el[0], ocel.object_id_column + "_2": el[1],
ocel.qualifier: "object_inheritance_graph"})
if "object_cobirth_graph" in included_graphs:
graph = object_cobirth_graph.apply(ocel, parameters=parameters)
for el in graph:
o2o.append({ocel.object_id_column: el[0], ocel.object_id_column + "_2": el[1],
ocel.qualifier: "object_cobirth_graph"})
if "object_codeath_graph" in included_graphs:
graph = object_codeath_graph.apply(ocel, parameters=parameters)
for el in graph:
o2o.append({ocel.object_id_column: el[0], ocel.object_id_column + "_2": el[1],
ocel.qualifier: "object_codeath_graph"})

ocel = copy(ocel)
o2o = pd.DataFrame(o2o)
ocel.o2o = pd.concat([ocel.o2o, o2o])

return ocel
22 changes: 22 additions & 0 deletions pm4py/ocel.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,28 @@ def discover_objects_graph(ocel: OCEL, graph_type: str = "object_interaction") -
return object_codeath_graph.apply(ocel)


def ocel_o2o_enrichment(ocel: OCEL, included_graphs: Optional[Collection[str]] = None) -> OCEL:
"""
Inserts the information inferred from the graph computations (pm4py.discover_objects_graph)
in the list of O2O relations of the OCEL.
:param ocel: object-centric event log
:param included_graphs: types of graphs to include, provided as list/set of strings (object_interaction_graph, object_descendants_graph, object_inheritance_graph, object_cobirth_graph, object_codeath_graph)
:rtype: ``OCEL``
.. code-block:: python3
import pm4py
ocel = pm4py.read_ocel('trial.ocel')
ocel = pm4py.ocel_o2o_enrichment(ocel)
print(ocel.o2o)
"""
from pm4py.algo.transformation.ocel.graphs import ocel20_computation
return ocel20_computation.apply(ocel, parameters={"included_graphs": included_graphs})


def sample_ocel_objects(ocel: OCEL, num_objects: int) -> OCEL:
"""
Given an object-centric event log, returns a sampled event log with a subset of the objects
Expand Down

0 comments on commit d4a5525

Please sign in to comment.