forked from process-intelligence-solutions/pm4py
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
709 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from pm4py.algo.filtering.log.prefixes import prefix_filter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
from enum import Enum | ||
from pm4py.util import exec_utils, xes_constants, constants | ||
from pm4py.objects.log.obj import EventLog, EventStream, Trace | ||
from typing import Dict, Optional, Any, Union | ||
from pm4py.objects.conversion.log import converter as log_converter | ||
|
||
|
||
class Parameters(Enum): | ||
ACTIVITY_KEY = constants.PARAMETER_CONSTANT_ACTIVITY_KEY | ||
STRICT = "strict" | ||
FIRST_OR_LAST = "first_or_last" | ||
|
||
|
||
def apply(log: Union[EventLog, EventStream], activity: str, parameters: Optional[Dict[Any, Any]] = None) -> EventLog: | ||
""" | ||
Filters the prefixes of an activity in the event log | ||
Parameters | ||
---------------- | ||
log | ||
Event log | ||
activity | ||
Target activity | ||
parameters | ||
Parameters of the algorithm, including: | ||
- Parameters.ACTIVITY_KEY => the activity. | ||
- Parameters.STRICT => applies the filter strictly (cuts the occurrences of the selected activity). | ||
- Parameters.FIRST_OR_LAST => decides if the first or last occurrence of an activity should be selected. | ||
Returns | ||
---------------- | ||
filtered_log | ||
Filtered event log | ||
""" | ||
if parameters is None: | ||
parameters = {} | ||
|
||
log = log_converter.apply(log, parameters=parameters) | ||
|
||
activity_key = exec_utils.get_param_value(Parameters.ACTIVITY_KEY, parameters, xes_constants.DEFAULT_NAME_KEY) | ||
first_or_last = exec_utils.get_param_value(Parameters.FIRST_OR_LAST, parameters, "first") | ||
strict = exec_utils.get_param_value(Parameters.STRICT, parameters, True) | ||
|
||
filtered_log = EventLog(attributes=log.attributes, extensions=log.extensions, globals=log._omni, | ||
classifiers=log.classifiers, properties=log.properties) | ||
|
||
for trace in log: | ||
activities = [x[activity_key] if activity_key in x else None for x in trace] | ||
if activity in activities: | ||
if first_or_last == "first": | ||
op = min | ||
else: | ||
op = max | ||
idx_activity = op(i for i in range(len(activities)) if activities[i] == activity) | ||
if not strict: | ||
idx_activity = idx_activity + 1 | ||
filtered_trace = Trace(attributes=trace.attributes, properties=trace.properties) | ||
for i in range(0, idx_activity): | ||
filtered_trace.append(trace[i]) | ||
filtered_log.append(filtered_trace) | ||
|
||
return filtered_log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from pm4py.algo.filtering.log.suffixes import suffix_filter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
from enum import Enum | ||
from pm4py.util import exec_utils, xes_constants, constants | ||
from pm4py.objects.log.obj import EventLog, EventStream, Trace | ||
from typing import Dict, Optional, Any, Union | ||
from pm4py.objects.conversion.log import converter as log_converter | ||
|
||
|
||
class Parameters(Enum): | ||
ACTIVITY_KEY = constants.PARAMETER_CONSTANT_ACTIVITY_KEY | ||
STRICT = "strict" | ||
FIRST_OR_LAST = "first_or_last" | ||
|
||
|
||
def apply(log: Union[EventLog, EventStream], activity: str, parameters: Optional[Dict[Any, Any]] = None) -> EventLog: | ||
""" | ||
Filters the suffixes of an activity in the event log | ||
Parameters | ||
---------------- | ||
log | ||
Event log | ||
activity | ||
Target activity | ||
parameters | ||
Parameters of the algorithm, including: | ||
- Parameters.ACTIVITY_KEY => the activity. | ||
- Parameters.STRICT => applies the filter strictly (cuts the occurrences of the selected activity). | ||
- Parameters.FIRST_OR_LAST => decides if the first or last occurrence of an activity should be selected. | ||
Returns | ||
---------------- | ||
filtered_log | ||
Filtered event log | ||
""" | ||
if parameters is None: | ||
parameters = {} | ||
|
||
log = log_converter.apply(log, parameters=parameters) | ||
|
||
activity_key = exec_utils.get_param_value(Parameters.ACTIVITY_KEY, parameters, xes_constants.DEFAULT_NAME_KEY) | ||
first_or_last = exec_utils.get_param_value(Parameters.FIRST_OR_LAST, parameters, "first") | ||
strict = exec_utils.get_param_value(Parameters.STRICT, parameters, True) | ||
|
||
filtered_log = EventLog(attributes=log.attributes, extensions=log.extensions, globals=log._omni, | ||
classifiers=log.classifiers, properties=log.properties) | ||
|
||
for trace in log: | ||
activities = [x[activity_key] if activity_key in x else None for x in trace] | ||
if activity in activities: | ||
if first_or_last == "first": | ||
op = min | ||
else: | ||
op = max | ||
idx_activity = op(i for i in range(len(activities)) if activities[i] == activity) | ||
if strict: | ||
idx_activity = idx_activity + 1 | ||
filtered_trace = Trace(attributes=trace.attributes, properties=trace.properties) | ||
for i in range(idx_activity, len(trace)): | ||
filtered_trace.append(trace[i]) | ||
filtered_log.append(filtered_trace) | ||
|
||
return filtered_log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1 @@ | ||
''' | ||
This file is part of PM4Py (More Info: https://pm4py.fit.fraunhofer.de). | ||
PM4Py is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
PM4Py is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with PM4Py. If not, see <https://www.gnu.org/licenses/>. | ||
''' | ||
from pm4py.algo.transformation.ocel.features import objects, events | ||
|
||
from pm4py.algo.transformation.ocel.features import objects, events, events_objects |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1 @@ | ||
''' | ||
This file is part of PM4Py (More Info: https://pm4py.fit.fraunhofer.de). | ||
PM4Py is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
PM4Py is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with PM4Py. If not, see <https://www.gnu.org/licenses/>. | ||
''' | ||
from pm4py.algo.transformation.ocel.features.events import algorithm, event_activity, event_timestamp, event_num_rel_objs_type, event_num_rel_objs, event_str_attributes, event_num_attributes, event_start_ot, event_end_ot, related_objects_features | ||
from pm4py.algo.transformation.ocel.features.events import algorithm, event_activity, event_timestamp, event_num_rel_objs_type, event_num_rel_objs, event_str_attributes, event_num_attributes, event_start_ot, event_end_ot, related_objects_features, new_interactions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
pm4py/algo/transformation/ocel/features/events/new_interactions.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from pm4py.objects.ocel.obj import OCEL | ||
from typing import Optional, Dict, Any | ||
|
||
|
||
def apply(ocel: OCEL, parameters: Optional[Dict[Any, Any]] = None): | ||
""" | ||
Discovers the number of new interactions between the related objects which appears in a given event. | ||
Parameters | ||
--------------- | ||
ocel | ||
OCEL | ||
parameters | ||
Parameters of the method | ||
Returns | ||
---------------- | ||
data | ||
Extracted feature values | ||
feature_names | ||
Feature names | ||
""" | ||
if parameters is None: | ||
parameters = {} | ||
|
||
ordered_events = list(ocel.events[ocel.event_id_column]) | ||
rel_objs = ocel.relations.groupby(ocel.event_id_column)[ocel.object_id_column].agg(list).to_dict() | ||
|
||
interactions = set() | ||
data = [] | ||
feature_names = ["@@ev_new_interactions"] | ||
|
||
for ev in ordered_events: | ||
n = 0 | ||
if ev in rel_objs: | ||
for o1 in rel_objs[ev]: | ||
for o2 in rel_objs[ev]: | ||
if o1 < o2: | ||
if not (o1, o2) in interactions: | ||
n = n + 1 | ||
data.append([n]) | ||
|
||
return data, feature_names |
1 change: 1 addition & 0 deletions
1
pm4py/algo/transformation/ocel/features/events_objects/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from pm4py.algo.transformation.ocel.features.events_objects import algorithm, prefix_features |
74 changes: 74 additions & 0 deletions
74
pm4py/algo/transformation/ocel/features/events_objects/algorithm.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
from pm4py.objects.ocel.obj import OCEL | ||
from typing import Optional, Dict, Any | ||
from pm4py.algo.transformation.ocel.features.events import algorithm as event_feature_extraction | ||
from pm4py.algo.transformation.ocel.features.events_objects import prefix_features | ||
from pm4py.objects.ocel.util import explode | ||
from copy import copy | ||
from enum import Enum | ||
from pm4py.util import exec_utils | ||
|
||
|
||
class Parameters(Enum): | ||
ENABLE_ALL_EO_FEATURES = "enable_all_eo_features" | ||
ENABLE_EVENT_POINTWISE_FEATURES = "enable_event_pointwise_features" | ||
ENABLE_PREFIX_FEATURES = "enable_prefix_features" | ||
|
||
|
||
def apply(ocel: OCEL, parameters: Optional[Dict[Any, Any]] = None): | ||
""" | ||
Extract features that are related to the different combinations of events and objects of the OCEL. | ||
Parameters | ||
----------------- | ||
ocel | ||
Object-centric event log | ||
parameters | ||
Parameters of the algorithm, including: | ||
- Parameters.ENABLE_ALL_EO_FEATURES => enables all the belowmentioned features | ||
- Parameters.ENABLE_EVENT_POINTWISE_FEATURES => enables the calculation of pointwise features for the events | ||
- Parameters.ENABLE_PREFIX_FEATURES => enables the prefix features | ||
Returns | ||
----------------- | ||
data | ||
Values of the features | ||
feature_names | ||
Names of the features | ||
""" | ||
if parameters is None: | ||
parameters = {} | ||
|
||
enable_all = exec_utils.get_param_value(Parameters.ENABLE_ALL_EO_FEATURES, parameters, True) | ||
enable_event_pointwise_features = exec_utils.get_param_value(Parameters.ENABLE_EVENT_POINTWISE_FEATURES, parameters, enable_all) | ||
enable_prefix_features = exec_utils.get_param_value(Parameters.ENABLE_PREFIX_FEATURES, parameters, enable_all) | ||
|
||
exploded_ocel = explode.apply(ocel) | ||
ordered_events = list(exploded_ocel.events[exploded_ocel.event_id_column]) | ||
|
||
datas = [] | ||
features_namess = [] | ||
for i in range(len(ordered_events)): | ||
datas.append([]) | ||
|
||
if enable_event_pointwise_features: | ||
parameters_efe = copy(parameters) | ||
parameters_efe["enable_all"] = False | ||
parameters_efe["enable_related_objects_features"] = False | ||
parameters_efe["enable_event_activity"] = True | ||
parameters_efe["enable_event_timestamp"] = True | ||
parameters_efe["enable_event_num_rel_objs_type"] = True | ||
parameters_efe["enable_event_str_attributes"] = True | ||
parameters_efe["enable_event_num_attributes"] = True | ||
parameters_efe["enable_event_start_ot"] = True | ||
data, feature_names = event_feature_extraction.apply(exploded_ocel, parameters=parameters_efe) | ||
for i in range(len(data)): | ||
datas[i] = datas[i] + data[i] | ||
features_namess = features_namess + feature_names | ||
|
||
if enable_prefix_features: | ||
data, feature_names = prefix_features.apply(exploded_ocel, parameters=parameters) | ||
for i in range(len(data)): | ||
datas[i] = datas[i] + data[i] | ||
features_namess = features_namess + feature_names | ||
|
||
return datas, features_namess |
Oops, something went wrong.