def apply(net, im, fm, parameters=None):
"""
Transforms a WF-net to a process tree
Parameters
-------------
net
Petri net
im
Initial marking
fm
Final marking
Returns
-------------
tree
Process tree
"""
if parameters is None:
parameters = {}
debug = exec_utils.get_param_value(Parameters.DEBUG, parameters, False)
fold = exec_utils.get_param_value(Parameters.FOLD, parameters, True)
grouped_net = group_blocks_in_net(net, parameters=parameters)
if len(grouped_net.transitions) == 1:
pt_str = list(grouped_net.transitions)[0].label
pt = pt_util.parse(pt_str)
ret = pt_util.fold(pt) if fold else pt
tree_sort(ret)
return ret
else:
if debug:
from pm4py.visualization.petri_net import visualizer as pn_viz
pn_viz.view(pn_viz.apply(grouped_net, parameters={"format": "svg"}))
raise ValueError('Parsing of WF-net Failed')
The problem:
The transitions in groupednet gives transition labels that are usually like ->('a', 'b')_
In our example however, it gives us test
In both cases, the string would be without any quotation marks. For the sequence it is fine, all activities are in quotation marks.
The problem is that after that in the parsing function that the function looks how the string starts (recursively).
A leaf node should be inside quotes, but this is not the case here! We need to give 'test' as a string input instead of test
# ...
if operator is not None:
parent = None if depth == 0 else depth_cache[depth - 1]
node = pt.ProcessTree(operator=operator, parent=parent)
depth_cache[depth] = node
if parent is not None:
parent.children.append(node)
depth += 1
string_rep = string_rep.strip()
assert (string_rep[0] == '(')
parse_recursive(string_rep[1:], depth_cache, depth)
else:
label = None
if string_rep.startswith('\''):
string_rep = string_rep[1:]
escape_ext = string_rep.find('\'')
label = string_rep[0:escape_ext]
string_rep = string_rep[escape_ext + 1:]
else:
assert (string_rep.startswith('tau') or string_rep.startswith('τ') or string_rep.startswith(u'\u03c4'))
if string_rep.startswith('tau'):
string_rep = string_rep[len('tau'):]
# ...
I know this is a trivial case, where we only have one transition between source and sink for the Petri Net and the Process Tree is only one normal activity, however for automation it would be nice to add a solution to this problem.
Possible solution: check if the net consists of only one transition between source and sink. Then create a ProcessTree object, with the corresponding label.
While using the conversion method, I stumbled upon the following case, that does not work for a conversion from a Petri Net to Process Tree:
The error code:
For reference, the code from pm4py.object.wf_net.variants.to_process_tree, which is called by pm4py.convert_to_process_tree:
The problem:
From https://github.com/pm4py/pm4py-core/blob/release/pm4py/objects/process_tree/utils/generic.py
I know this is a trivial case, where we only have one transition between source and sink for the Petri Net and the Process Tree is only one normal activity, however for automation it would be nice to add a solution to this problem.
Possible solution: check if the net consists of only one transition between source and sink. Then create a ProcessTree object, with the corresponding label.