Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions utils/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,47 @@ def build_enum_data(enum_class):
from enum import IntFlag

class HtkIntFlag(IntFlag):
""" HTK IntFlag
"""HTK IntFlag

Wrapper around Python's built-in `enum.IntFlag` to provide extra
functionalities.

Requires: Python 3.6 or greater
Reference: https://docs.python.org/3.6/library/enum.html#enum.IntFlag
"""

@classmethod
def display(cls, int_value) -> list[str]:
"""Get human-readable display names for combined flag values.

Decomposes combined flag values using list_flags(), then uses
get_enum_symbolic_name() to format each flag.

Args:
int_value: Combined flag value (e.g., 3 = BICEPS_BRACHII | BRACHIALIS)

Returns:
List of human-readable flag names

Example:
class Muscle(HtkIntFlag):
UNSPECIFIED = 0
BICEPS_BRACHII = 1
BRACHIALIS = 2
BRACHIORADIALIS = 4
TRICEPS_BRACHII = 8

Muscle.display(3) # ['Biceps Brachii', 'Brachialis']
Muscle.display(1) # ['Biceps Brachii']
"""
result = [
get_enum_symbolic_name(flag)
for flag in cls.list_flags(int_value)
]
return result

@classmethod
def list_flags(cls, int_value):
def list_flags(cls, int_value) -> list[HtkIntFlag]:
"""List Flags

Returns the list of flags that value contains, running bitwise
Expand Down