praatio.utilities.constants
Constant values and primitive definitions that can be shared throughout the code
1""" 2Constant values and primitive definitions that can be shared throughout the code 3""" 4from collections import namedtuple 5import math 6 7from typing_extensions import Final 8 9INTERVAL_TIER: Final = "IntervalTier" 10POINT_TIER: Final = "TextTier" 11 12 13# https://stackoverflow.com/questions/34570814/equality-overloading-for-namedtuple 14class Interval(namedtuple("Interval", ["start", "end", "label"])): 15 def __eq__(self, other): 16 if not isinstance(other, Interval): 17 return False 18 19 return ( 20 math.isclose(self.start, other.start) 21 and math.isclose(self.end, other.end) 22 and self.label == other.label 23 ) 24 25 def __ne__(self, other): 26 return not self == other 27 28 29class Point(namedtuple("Point", ["time", "label"])): 30 def __eq__(self, other): 31 if not isinstance(other, Point): 32 return False 33 34 return ( 35 math.isclose(self.time, other.time, abs_tol=1e-14) 36 and self.label == other.label 37 ) 38 39 def __ne__(self, other): 40 return not self == other 41 42 43MIN_INTERVAL_LENGTH: Final = 0.00000001 # Arbitrary threshold 44 45 46class TextgridFormats: 47 LONG_TEXTGRID: Final = "long_textgrid" 48 SHORT_TEXTGRID: Final = "short_textgrid" 49 JSON: Final = "json" 50 TEXTGRID_JSON: Final = "textgrid_json" 51 52 validOptions = [LONG_TEXTGRID, SHORT_TEXTGRID, JSON, TEXTGRID_JSON] 53 54 55class DataPointTypes: 56 POINT: Final = "PointProcess" 57 PITCH: Final = "PitchTier" 58 DURATION: Final = "DurationTier" 59 60 validOptions = [POINT, PITCH, DURATION] 61 62 63class CropCollision: 64 STRICT: Final = "strict" 65 LAX: Final = "lax" 66 TRUNCATED: Final = "truncated" 67 68 validOptions = [STRICT, LAX, TRUNCATED] 69 70 71class ErrorReportingMode: 72 SILENCE: Final = "silence" 73 WARNING: Final = "warning" 74 ERROR: Final = "error" 75 76 validOptions = [SILENCE, WARNING, ERROR] 77 78 79class IntervalCollision: 80 REPLACE: Final = "replace" 81 MERGE: Final = "merge" 82 ERROR: Final = "error" 83 84 validOptions = [REPLACE, MERGE, ERROR] 85 86 87class WhitespaceCollision: 88 STRETCH: Final = "stretch" 89 SPLIT: Final = "split" 90 NO_CHANGE: Final = "no_change" 91 ERROR: Final = "error" 92 93 validOptions = [STRETCH, SPLIT, NO_CHANGE, ERROR] 94 95 96class EraseCollision: 97 TRUNCATE: Final = "truncate" 98 CATEGORICAL: Final = "categorical" 99 ERROR: Final = "error" 100 101 validOptions = [TRUNCATE, CATEGORICAL, ERROR] 102 103 104class DuplicateNames: 105 ERROR: Final = "error" 106 RENAME: Final = "rename" 107 108 validOptions = [ERROR, RENAME]
INTERVAL_TIER: Final =
'IntervalTier'
POINT_TIER: Final =
'TextTier'
15class Interval(namedtuple("Interval", ["start", "end", "label"])): 16 def __eq__(self, other): 17 if not isinstance(other, Interval): 18 return False 19 20 return ( 21 math.isclose(self.start, other.start) 22 and math.isclose(self.end, other.end) 23 and self.label == other.label 24 ) 25 26 def __ne__(self, other): 27 return not self == other
Interval(start, end, label)
Inherited Members
- builtins.tuple
- index
- count
30class Point(namedtuple("Point", ["time", "label"])): 31 def __eq__(self, other): 32 if not isinstance(other, Point): 33 return False 34 35 return ( 36 math.isclose(self.time, other.time, abs_tol=1e-14) 37 and self.label == other.label 38 ) 39 40 def __ne__(self, other): 41 return not self == other
Point(time, label)
Inherited Members
- builtins.tuple
- index
- count
MIN_INTERVAL_LENGTH: Final =
1e-08
class
TextgridFormats:
class
DataPointTypes:
class
CropCollision:
class
ErrorReportingMode:
class
IntervalCollision:
class
WhitespaceCollision:
class
EraseCollision:
class
DuplicateNames: