nirdizati_light.encoding.constants
1from enum import Enum 2 3from pm4py.objects.log.obj import EventLog, Trace 4 5 6class EncodingType(Enum): 7 SIMPLE = 'simple' 8 FREQUENCY = 'frequency' 9 COMPLEX = 'complex' 10 DECLARE = 'declare' 11 LORELEY = 'loreley' 12 LORELEY_COMPLEX = 'loreley_complex' 13 14 15class EncodingTypeAttribute(Enum): 16 LABEL = 'label' 17 ONEHOT = 'onehot' 18 19 20class TaskGenerationType(Enum): 21 ONLY_THIS = 'only_this' 22 ALL_IN_ONE = 'all_in_one' 23 24 25class PrefixLengthStrategy(Enum): 26 FIXED = 'fixed' 27 PERCENTAGE = 'percentage' 28 TARGET_EVENT = 'target_event' 29 30 31def get_prefix_length(trace: Trace, prefix_length: float, prefix_length_strategy, target_event=None) -> int: 32 if prefix_length_strategy == PrefixLengthStrategy.FIXED.value: 33 return int(prefix_length) 34 elif prefix_length_strategy == PrefixLengthStrategy.PERCENTAGE.value: 35 return int(prefix_length * len(trace)) 36 elif prefix_length_strategy == PrefixLengthStrategy.TARGET_EVENT.value: 37 if target_event is not None: 38 try: 39 index = [e['concept:name'] for e in trace].index(target_event) + 1 40 except ValueError: 41 return 0 42 return index 43 else: 44 return 0 45 else: 46 raise Exception('Wrong prefix_length strategy') 47 48 49def get_max_prefix_length(log: EventLog, prefix_length: float, prefix_length_strategy, target_event) -> int: 50 prefix_lengths = [get_prefix_length(trace, prefix_length, prefix_length_strategy, target_event) for trace in log] 51 return max(prefix_lengths)
7class EncodingType(Enum): 8 SIMPLE = 'simple' 9 FREQUENCY = 'frequency' 10 COMPLEX = 'complex' 11 DECLARE = 'declare' 12 LORELEY = 'loreley' 13 LORELEY_COMPLEX = 'loreley_complex'
Create a collection of name/value pairs.
Example enumeration:
>>> class Color(Enum):
... RED = 1
... BLUE = 2
... GREEN = 3
Access them by:
- attribute access::
>>> Color.RED
<Color.RED: 1>
- value lookup:
>>> Color(1)
<Color.RED: 1>
- name lookup:
>>> Color['RED']
<Color.RED: 1>
Enumerations can be iterated over, and know how many members they have:
>>> len(Color)
3
>>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]
Methods can be added to enumerations, and members can have their own attributes -- see the documentation for details.
Inherited Members
- enum.Enum
- name
- value
Create a collection of name/value pairs.
Example enumeration:
>>> class Color(Enum):
... RED = 1
... BLUE = 2
... GREEN = 3
Access them by:
- attribute access::
>>> Color.RED
<Color.RED: 1>
- value lookup:
>>> Color(1)
<Color.RED: 1>
- name lookup:
>>> Color['RED']
<Color.RED: 1>
Enumerations can be iterated over, and know how many members they have:
>>> len(Color)
3
>>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]
Methods can be added to enumerations, and members can have their own attributes -- see the documentation for details.
Inherited Members
- enum.Enum
- name
- value
Create a collection of name/value pairs.
Example enumeration:
>>> class Color(Enum):
... RED = 1
... BLUE = 2
... GREEN = 3
Access them by:
- attribute access::
>>> Color.RED
<Color.RED: 1>
- value lookup:
>>> Color(1)
<Color.RED: 1>
- name lookup:
>>> Color['RED']
<Color.RED: 1>
Enumerations can be iterated over, and know how many members they have:
>>> len(Color)
3
>>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]
Methods can be added to enumerations, and members can have their own attributes -- see the documentation for details.
Inherited Members
- enum.Enum
- name
- value
26class PrefixLengthStrategy(Enum): 27 FIXED = 'fixed' 28 PERCENTAGE = 'percentage' 29 TARGET_EVENT = 'target_event'
Create a collection of name/value pairs.
Example enumeration:
>>> class Color(Enum):
... RED = 1
... BLUE = 2
... GREEN = 3
Access them by:
- attribute access::
>>> Color.RED
<Color.RED: 1>
- value lookup:
>>> Color(1)
<Color.RED: 1>
- name lookup:
>>> Color['RED']
<Color.RED: 1>
Enumerations can be iterated over, and know how many members they have:
>>> len(Color)
3
>>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]
Methods can be added to enumerations, and members can have their own attributes -- see the documentation for details.
Inherited Members
- enum.Enum
- name
- value
32def get_prefix_length(trace: Trace, prefix_length: float, prefix_length_strategy, target_event=None) -> int: 33 if prefix_length_strategy == PrefixLengthStrategy.FIXED.value: 34 return int(prefix_length) 35 elif prefix_length_strategy == PrefixLengthStrategy.PERCENTAGE.value: 36 return int(prefix_length * len(trace)) 37 elif prefix_length_strategy == PrefixLengthStrategy.TARGET_EVENT.value: 38 if target_event is not None: 39 try: 40 index = [e['concept:name'] for e in trace].index(target_event) + 1 41 except ValueError: 42 return 0 43 return index 44 else: 45 return 0 46 else: 47 raise Exception('Wrong prefix_length strategy')