|
| 1 | +from pm4py.objects.process_tree.obj import ProcessTree, Operator as PTOperator |
| 2 | +from pm4py.objects.powl.obj import POWL, StrictPartialOrder, OperatorPOWL, Transition, SilentTransition |
| 3 | +from typing import Optional, Dict, Any |
| 4 | + |
| 5 | + |
| 6 | +def apply_recursive(tree: ProcessTree, rec_depth=0) -> POWL: |
| 7 | + """ |
| 8 | + Internal method |
| 9 | + """ |
| 10 | + nodes = [] |
| 11 | + |
| 12 | + for c in tree.children: |
| 13 | + nodes.append(apply_recursive(c, rec_depth+1)) |
| 14 | + |
| 15 | + if tree.operator is None: |
| 16 | + if tree.label is not None: |
| 17 | + powl = Transition(label=tree.label) |
| 18 | + else: |
| 19 | + powl = SilentTransition() |
| 20 | + elif tree.operator == PTOperator.OR: |
| 21 | + raise Exception("conversion of process trees containing OR nodes is not supported!") |
| 22 | + elif tree.operator == PTOperator.XOR: |
| 23 | + powl = OperatorPOWL(PTOperator.XOR, nodes) |
| 24 | + elif tree.operator == PTOperator.LOOP: |
| 25 | + powl = OperatorPOWL(PTOperator.LOOP, nodes) |
| 26 | + else: |
| 27 | + powl = StrictPartialOrder(nodes=nodes) |
| 28 | + |
| 29 | + if tree.operator == PTOperator.SEQUENCE: |
| 30 | + for i in range(len(nodes)-1): |
| 31 | + powl.order.add_edge(nodes[i], nodes[i+1]) |
| 32 | + |
| 33 | + return powl |
| 34 | + |
| 35 | + |
| 36 | +def apply(tree: ProcessTree, parameters: Optional[Dict[Any, Any]] = None) -> POWL: |
| 37 | + """ |
| 38 | + Converts a process tree model to a POWL model |
| 39 | +
|
| 40 | + Parameters |
| 41 | + --------------- |
| 42 | + tree |
| 43 | + Process tree |
| 44 | +
|
| 45 | + Returns |
| 46 | + --------------- |
| 47 | + powl_model |
| 48 | + POWL model |
| 49 | + """ |
| 50 | + if parameters is None: |
| 51 | + parameters = {} |
| 52 | + |
| 53 | + return apply_recursive(tree) |
0 commit comments