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'
class Interval(Interval):
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)

Interval(start, end, label)

Create new instance of Interval(start, end, label)

start

Alias for field number 0

end

Alias for field number 1

label

Alias for field number 2

Inherited Members
builtins.tuple
index
count
class Point(Point):
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)

Point(time, label)

Create new instance of Point(time, label)

time

Alias for field number 0

label

Alias for field number 1

Inherited Members
builtins.tuple
index
count
MIN_INTERVAL_LENGTH: Final = 1e-08
class TextgridFormats:
47class TextgridFormats:
48    LONG_TEXTGRID: Final = "long_textgrid"
49    SHORT_TEXTGRID: Final = "short_textgrid"
50    JSON: Final = "json"
51    TEXTGRID_JSON: Final = "textgrid_json"
52
53    validOptions = [LONG_TEXTGRID, SHORT_TEXTGRID, JSON, TEXTGRID_JSON]
LONG_TEXTGRID: Final = 'long_textgrid'
SHORT_TEXTGRID: Final = 'short_textgrid'
JSON: Final = 'json'
TEXTGRID_JSON: Final = 'textgrid_json'
validOptions = ['long_textgrid', 'short_textgrid', 'json', 'textgrid_json']
class DataPointTypes:
56class DataPointTypes:
57    POINT: Final = "PointProcess"
58    PITCH: Final = "PitchTier"
59    DURATION: Final = "DurationTier"
60
61    validOptions = [POINT, PITCH, DURATION]
POINT: Final = 'PointProcess'
PITCH: Final = 'PitchTier'
DURATION: Final = 'DurationTier'
validOptions = ['PointProcess', 'PitchTier', 'DurationTier']
class CropCollision:
64class CropCollision:
65    STRICT: Final = "strict"
66    LAX: Final = "lax"
67    TRUNCATED: Final = "truncated"
68
69    validOptions = [STRICT, LAX, TRUNCATED]
STRICT: Final = 'strict'
LAX: Final = 'lax'
TRUNCATED: Final = 'truncated'
validOptions = ['strict', 'lax', 'truncated']
class ErrorReportingMode:
72class ErrorReportingMode:
73    SILENCE: Final = "silence"
74    WARNING: Final = "warning"
75    ERROR: Final = "error"
76
77    validOptions = [SILENCE, WARNING, ERROR]
SILENCE: Final = 'silence'
WARNING: Final = 'warning'
ERROR: Final = 'error'
validOptions = ['silence', 'warning', 'error']
class IntervalCollision:
80class IntervalCollision:
81    REPLACE: Final = "replace"
82    MERGE: Final = "merge"
83    ERROR: Final = "error"
84
85    validOptions = [REPLACE, MERGE, ERROR]
REPLACE: Final = 'replace'
MERGE: Final = 'merge'
ERROR: Final = 'error'
validOptions = ['replace', 'merge', 'error']
class WhitespaceCollision:
88class WhitespaceCollision:
89    STRETCH: Final = "stretch"
90    SPLIT: Final = "split"
91    NO_CHANGE: Final = "no_change"
92    ERROR: Final = "error"
93
94    validOptions = [STRETCH, SPLIT, NO_CHANGE, ERROR]
STRETCH: Final = 'stretch'
SPLIT: Final = 'split'
NO_CHANGE: Final = 'no_change'
ERROR: Final = 'error'
validOptions = ['stretch', 'split', 'no_change', 'error']
class EraseCollision:
 97class EraseCollision:
 98    TRUNCATE: Final = "truncate"
 99    CATEGORICAL: Final = "categorical"
100    ERROR: Final = "error"
101
102    validOptions = [TRUNCATE, CATEGORICAL, ERROR]
TRUNCATE: Final = 'truncate'
CATEGORICAL: Final = 'categorical'
ERROR: Final = 'error'
validOptions = ['truncate', 'categorical', 'error']
class DuplicateNames:
105class DuplicateNames:
106    ERROR: Final = "error"
107    RENAME: Final = "rename"
108
109    validOptions = [ERROR, RENAME]
ERROR: Final = 'error'
RENAME: Final = 'rename'
validOptions = ['error', 'rename']