Skip to content

Commit

Permalink
Merge branch 'PM4PY-1566-NEW' into 'integration'
Browse files Browse the repository at this point in the history
Resolve PMPY-1566 "New"

See merge request process-mining/pm4py/pm4py-core!601
  • Loading branch information
fit-sebastiaan-van-zelst committed Jan 25, 2022
2 parents 84742ce + fbc6af1 commit d07a908
Show file tree
Hide file tree
Showing 11 changed files with 199 additions and 122 deletions.
41 changes: 27 additions & 14 deletions pm4py/conformance.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@

import deprecation

from pm4py.objects.log.obj import EventLog, Trace, Event
from pm4py.objects.log.obj import EventLog, Trace, Event, EventStream
from pm4py.objects.petri_net.obj import PetriNet, Marking
from collections import Counter
from pm4py.objects.process_tree.obj import ProcessTree
from pm4py.util import xes_constants
from pm4py.utils import get_properties, general_checks_classical_event_log
from pm4py.utils import get_properties
import pandas as pd


@deprecation.deprecated(deprecated_in='2.2.2', removed_in='2.4.0',
Expand Down Expand Up @@ -36,7 +37,8 @@ def conformance_tbr(log: EventLog, petri_net: PetriNet, initial_marking: Marking
replay_results
A list of replay results for each trace of the log
"""
general_checks_classical_event_log(log)
if type(log) not in [pd.DataFrame, EventLog, EventStream]: raise Exception("the method can be applied only to a traditional event log!")

from pm4py.algo.conformance.tokenreplay import algorithm as token_replay
return token_replay.apply(log, petri_net, initial_marking, final_marking, parameters=get_properties(log))

Expand All @@ -63,7 +65,8 @@ def conformance_diagnostics_token_based_replay(log: EventLog, petri_net: PetriNe
replay_results
A list of replay results for each trace of the log (in the same order as the traces in the event log)
"""
general_checks_classical_event_log(log)
if type(log) not in [pd.DataFrame, EventLog, EventStream]: raise Exception("the method can be applied only to a traditional event log!")

from pm4py.algo.conformance.tokenreplay import algorithm as token_replay
return token_replay.apply(log, petri_net, initial_marking, final_marking, parameters=get_properties(log))

Expand All @@ -87,7 +90,8 @@ def conformance_diagnostics_alignments(log: EventLog, *args, multi_processing: b
aligned_traces
A list of alignments for each trace of the log (in the same order as the traces in the event log)
"""
general_checks_classical_event_log(log)
if type(log) not in [pd.DataFrame, EventLog, EventStream]: raise Exception("the method can be applied only to a traditional event log!")

if len(args) == 3:
if type(args[0]) is PetriNet:
# Petri net alignments
Expand Down Expand Up @@ -143,7 +147,8 @@ def conformance_alignments(log: EventLog, petri_net: PetriNet, initial_marking:
aligned_traces
A list of alignments for each trace of the log
"""
general_checks_classical_event_log(log)
if type(log) not in [pd.DataFrame, EventLog, EventStream]: raise Exception("the method can be applied only to a traditional event log!")

from pm4py.algo.conformance.alignments.petri_net import algorithm as alignments
return alignments.apply(log, petri_net, initial_marking, final_marking, parameters=get_properties(log))

Expand Down Expand Up @@ -172,7 +177,8 @@ def fitness_token_based_replay(log: EventLog, petri_net: PetriNet, initial_marki
fitness_dictionary
dictionary describing average fitness (key: average_trace_fitness) and the percentage of fitting traces (key: percentage_of_fitting_traces)
"""
general_checks_classical_event_log(log)
if type(log) not in [pd.DataFrame, EventLog, EventStream]: raise Exception("the method can be applied only to a traditional event log!")

from pm4py.algo.evaluation.replay_fitness import algorithm as replay_fitness
return replay_fitness.apply(log, petri_net, initial_marking, final_marking,
variant=replay_fitness.Variants.TOKEN_BASED, parameters=get_properties(log))
Expand Down Expand Up @@ -203,7 +209,8 @@ def evaluate_fitness_tbr(log: EventLog, petri_net: PetriNet, initial_marking: Ma
fitness_dictionary
Fitness dictionary (from TBR)
"""
general_checks_classical_event_log(log)
if type(log) not in [pd.DataFrame, EventLog, EventStream]: raise Exception("the method can be applied only to a traditional event log!")

from pm4py.algo.evaluation.replay_fitness import algorithm as replay_fitness
return replay_fitness.apply(log, petri_net, initial_marking, final_marking,
variant=replay_fitness.Variants.TOKEN_BASED, parameters=get_properties(log))
Expand Down Expand Up @@ -232,7 +239,8 @@ def fitness_alignments(log: EventLog, petri_net: PetriNet, initial_marking: Mark
fitness_dictionary
dictionary describing average fitness (key: average_trace_fitness) and the percentage of fitting traces (key: percentage_of_fitting_traces)
"""
general_checks_classical_event_log(log)
if type(log) not in [pd.DataFrame, EventLog, EventStream]: raise Exception("the method can be applied only to a traditional event log!")

from pm4py.algo.evaluation.replay_fitness import algorithm as replay_fitness
parameters = get_properties(log)
parameters["multiprocessing"] = multi_processing
Expand Down Expand Up @@ -264,7 +272,8 @@ def evaluate_fitness_alignments(log: EventLog, petri_net: PetriNet, initial_mark
fitness_dictionary
Fitness dictionary (from alignments)
"""
general_checks_classical_event_log(log)
if type(log) not in [pd.DataFrame, EventLog, EventStream]: raise Exception("the method can be applied only to a traditional event log!")

from pm4py.algo.evaluation.replay_fitness import algorithm as replay_fitness
return replay_fitness.apply(log, petri_net, initial_marking, final_marking,
variant=replay_fitness.Variants.ALIGNMENT_BASED, parameters=get_properties(log))
Expand All @@ -291,7 +300,8 @@ def precision_token_based_replay(log: EventLog, petri_net: PetriNet, initial_mar
precision
float representing the precision value
"""
general_checks_classical_event_log(log)
if type(log) not in [pd.DataFrame, EventLog, EventStream]: raise Exception("the method can be applied only to a traditional event log!")

from pm4py.algo.evaluation.precision import algorithm as precision_evaluator
return precision_evaluator.apply(log, petri_net, initial_marking, final_marking,
variant=precision_evaluator.Variants.ETCONFORMANCE_TOKEN, parameters=get_properties(log))
Expand Down Expand Up @@ -321,7 +331,8 @@ def evaluate_precision_tbr(log: EventLog, petri_net: PetriNet, initial_marking:
precision
float representing the precision value
"""
general_checks_classical_event_log(log)
if type(log) not in [pd.DataFrame, EventLog, EventStream]: raise Exception("the method can be applied only to a traditional event log!")

from pm4py.algo.evaluation.precision import algorithm as precision_evaluator
return precision_evaluator.apply(log, petri_net, initial_marking, final_marking,
variant=precision_evaluator.Variants.ETCONFORMANCE_TOKEN, parameters=get_properties(log))
Expand Down Expand Up @@ -350,7 +361,8 @@ def precision_alignments(log: EventLog, petri_net: PetriNet, initial_marking: Ma
precision
float representing the precision value
"""
general_checks_classical_event_log(log)
if type(log) not in [pd.DataFrame, EventLog, EventStream]: raise Exception("the method can be applied only to a traditional event log!")

from pm4py.algo.evaluation.precision import algorithm as precision_evaluator
parameters = get_properties(log)
parameters["multiprocessing"] = multi_processing
Expand Down Expand Up @@ -383,7 +395,8 @@ def evaluate_precision_alignments(log: EventLog, petri_net: PetriNet, initial_ma
precision
float representing the precision value
"""
general_checks_classical_event_log(log)
if type(log) not in [pd.DataFrame, EventLog, EventStream]: raise Exception("the method can be applied only to a traditional event log!")

from pm4py.algo.evaluation.precision import algorithm as precision_evaluator
return precision_evaluator.apply(log, petri_net, initial_marking, final_marking,
variant=precision_evaluator.Variants.ALIGN_ETCONFORMANCE, parameters=get_properties(log))
Expand Down
11 changes: 7 additions & 4 deletions pm4py/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from pm4py.objects.log.obj import EventLog, EventStream
from pm4py.objects.petri_net.obj import PetriNet, Marking
from pm4py.objects.process_tree.obj import ProcessTree
from pm4py.utils import get_properties, general_checks_classical_event_log
from pm4py.utils import get_properties


def convert_to_event_log(obj: Union[pd.DataFrame, EventStream]) -> EventLog:
Expand All @@ -24,7 +24,8 @@ def convert_to_event_log(obj: Union[pd.DataFrame, EventStream]) -> EventLog:
log
Event log object
"""
general_checks_classical_event_log(obj)
if type(obj) not in [pd.DataFrame, EventLog, EventStream]: raise Exception("the method can be applied only to a traditional event log!")

from pm4py.objects.conversion.log import converter
log = converter.apply(obj, variant=converter.Variants.TO_EVENT_LOG, parameters=get_properties(obj))
return log
Expand All @@ -44,7 +45,8 @@ def convert_to_event_stream(obj: Union[EventLog, pd.DataFrame]) -> EventStream:
stream
Event stream object
"""
general_checks_classical_event_log(obj)
if type(obj) not in [pd.DataFrame, EventLog, EventStream]: raise Exception("the method can be applied only to a traditional event log!")

from pm4py.objects.conversion.log import converter
stream = converter.apply(obj, variant=converter.Variants.TO_EVENT_STREAM, parameters=get_properties(obj))
return stream
Expand All @@ -64,7 +66,8 @@ def convert_to_dataframe(obj: Union[EventStream, EventLog]) -> pd.DataFrame:
df
Dataframe
"""
general_checks_classical_event_log(obj)
if type(obj) not in [pd.DataFrame, EventLog, EventStream]: raise Exception("the method can be applied only to a traditional event log!")

from pm4py.objects.conversion.log import converter
df = converter.apply(obj, variant=converter.Variants.TO_DATA_FRAME, parameters=get_properties(obj))
return df
Expand Down
41 changes: 27 additions & 14 deletions pm4py/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from pm4py.objects.petri_net.obj import PetriNet, Marking
from pm4py.objects.process_tree.obj import ProcessTree
from pm4py.util.pandas_utils import check_is_pandas_dataframe, check_pandas_dataframe_columns
from pm4py.utils import get_properties, xes_constants, general_checks_classical_event_log
from pm4py.utils import get_properties, xes_constants
from pm4py.objects.ocel.obj import OCEL
from pm4py.util import constants

Expand All @@ -35,7 +35,8 @@ def discover_dfg(log: Union[EventLog, pd.DataFrame]) -> Tuple[dict, dict, dict]:
end_activities
End activities
"""
general_checks_classical_event_log(log)
if type(log) not in [pd.DataFrame, EventLog, EventStream]: raise Exception("the method can be applied only to a traditional event log!")

if check_is_pandas_dataframe(log):
check_pandas_dataframe_columns(log)
from pm4py.util import constants
Expand All @@ -62,7 +63,8 @@ def discover_dfg(log: Union[EventLog, pd.DataFrame]) -> Tuple[dict, dict, dict]:


def discover_directly_follows_graph(log: Union[EventLog, pd.DataFrame]) -> Tuple[dict, dict, dict]:
general_checks_classical_event_log(log)
if type(log) not in [pd.DataFrame, EventLog, EventStream]: raise Exception("the method can be applied only to a traditional event log!")

return discover_dfg(log)


Expand Down Expand Up @@ -90,7 +92,8 @@ def discover_performance_dfg(log: Union[EventLog, pd.DataFrame], business_hours:
end_activities
End activities
"""
general_checks_classical_event_log(log)
if type(log) not in [pd.DataFrame, EventLog, EventStream]: raise Exception("the method can be applied only to a traditional event log!")

if check_is_pandas_dataframe(log):
check_pandas_dataframe_columns(log)
from pm4py.util import constants
Expand Down Expand Up @@ -138,7 +141,8 @@ def discover_petri_net_alpha(log: Union[EventLog, pd.DataFrame]) -> Tuple[PetriN
final_marking
Final marking
"""
general_checks_classical_event_log(log)
if type(log) not in [pd.DataFrame, EventLog, EventStream]: raise Exception("the method can be applied only to a traditional event log!")

from pm4py.algo.discovery.alpha import algorithm as alpha_miner
return alpha_miner.apply(log, variant=alpha_miner.Variants.ALPHA_VERSION_CLASSIC, parameters=get_properties(log))

Expand All @@ -161,7 +165,8 @@ def discover_petri_net_alpha_plus(log: Union[EventLog, pd.DataFrame]) -> Tuple[P
final_marking
Final marking
"""
general_checks_classical_event_log(log)
if type(log) not in [pd.DataFrame, EventLog, EventStream]: raise Exception("the method can be applied only to a traditional event log!")

from pm4py.algo.discovery.alpha import algorithm as alpha_miner
return alpha_miner.apply(log, variant=alpha_miner.Variants.ALPHA_VERSION_PLUS, parameters=get_properties(log))

Expand All @@ -187,7 +192,8 @@ def discover_petri_net_inductive(log: Union[EventLog, pd.DataFrame], noise_thres
final_marking
Final marking
"""
general_checks_classical_event_log(log)
if type(log) not in [pd.DataFrame, EventLog, EventStream]: raise Exception("the method can be applied only to a traditional event log!")

pt = discover_process_tree_inductive(log, noise_threshold)
from pm4py.convert import convert_to_petri_net
return convert_to_petri_net(pt)
Expand Down Expand Up @@ -219,7 +225,8 @@ def discover_petri_net_heuristics(log: Union[EventLog, pd.DataFrame], dependency
final_marking
Final marking
"""
general_checks_classical_event_log(log)
if type(log) not in [pd.DataFrame, EventLog, EventStream]: raise Exception("the method can be applied only to a traditional event log!")

from pm4py.algo.discovery.heuristics import algorithm as heuristics_miner
heu_parameters = heuristics_miner.Variants.CLASSIC.value.Parameters
parameters = get_properties(log)
Expand All @@ -246,7 +253,8 @@ def discover_process_tree_inductive(log: Union[EventLog, pd.DataFrame], noise_th
process_tree
Process tree object
"""
general_checks_classical_event_log(log)
if type(log) not in [pd.DataFrame, EventLog, EventStream]: raise Exception("the method can be applied only to a traditional event log!")

from pm4py.algo.discovery.inductive import algorithm as inductive_miner
parameters = get_properties(log)
parameters[inductive_miner.Variants.IM_CLEAN.value.Parameters.NOISE_THRESHOLD] = noise_threshold
Expand All @@ -272,7 +280,8 @@ def discover_tree_inductive(log: Union[EventLog, pd.DataFrame], noise_threshold:
process_tree
Process tree object
"""
general_checks_classical_event_log(log)
if type(log) not in [pd.DataFrame, EventLog, EventStream]: raise Exception("the method can be applied only to a traditional event log!")

return discover_process_tree_inductive(log, noise_threshold)


Expand All @@ -298,7 +307,8 @@ def discover_heuristics_net(log: Union[EventLog, pd.DataFrame], dependency_thres
heu_net
Heuristics net
"""
general_checks_classical_event_log(log)
if type(log) not in [pd.DataFrame, EventLog, EventStream]: raise Exception("the method can be applied only to a traditional event log!")

from pm4py.algo.discovery.heuristics import algorithm as heuristics_miner
heu_parameters = heuristics_miner.Variants.CLASSIC.value.Parameters
parameters = get_properties(log)
Expand All @@ -324,7 +334,8 @@ def derive_minimum_self_distance(log: Union[DataFrame, EventLog, EventStream]) -
-------
dict mapping an activity to its self-distance, if it exists, otherwise it is not part of the dict.
'''
general_checks_classical_event_log(log)
if type(log) not in [pd.DataFrame, EventLog, EventStream]: raise Exception("the method can be applied only to a traditional event log!")

from pm4py.algo.discovery.minimum_self_distance import algorithm as msd
return msd.apply(log, parameters=get_properties(log))

Expand Down Expand Up @@ -357,7 +368,8 @@ def discover_eventually_follows_graph(log: Union[EventLog, pd.DataFrame]) -> Dic
eventually_follows_graph
Dictionary of tuples of activities that eventually follows each other; along with the number of occurrences
"""
general_checks_classical_event_log(log)
if type(log) not in [pd.DataFrame, EventLog, EventStream]: raise Exception("the method can be applied only to a traditional event log!")

if check_is_pandas_dataframe(log):
check_pandas_dataframe_columns(log)
from pm4py.statistics.eventually_follows.pandas import get
Expand All @@ -383,7 +395,8 @@ def discover_bpmn_inductive(log: Union[EventLog, pd.DataFrame], noise_threshold:
bpmn_diagram
BPMN diagram
"""
general_checks_classical_event_log(log)
if type(log) not in [pd.DataFrame, EventLog, EventStream]: raise Exception("the method can be applied only to a traditional event log!")

pt = discover_process_tree_inductive(log, noise_threshold)
from pm4py.convert import convert_to_bpmn
return convert_to_bpmn(pt)
Expand Down
Loading

0 comments on commit d07a908

Please sign in to comment.