@@ -96,22 +96,20 @@ def get_overlapping_intervals(tier1, tier2, regex=r'[^\s]+', overlap_label=None)
96
96
return overlaps
97
97
98
98
99
- def concatenate_tiers (tier1 , tier2 , use_absolute_time ):
99
+ def concatenate_tiers (tier1 , tier2 , offset ):
100
100
"""Concatenate two tiers and return a new tier.
101
101
102
- If ``use_absolute_time`` is ``False``, start and end times of
103
- intervals in tier2 are offset by the end_time of tier1.
104
- If `use_absolute_time` is `True`, start and end times of
105
- intervals are used as is .
102
+ Offset is the time added to each interval's boundaries in order to
103
+ put them after the intervals of the preceeding tier. If intervals
104
+ have absolute timing on each tier (i.e., start times of tier > 0 for
105
+ later tiers, an offset of 0 should be used) .
106
106
107
107
Keyword argument:
108
- tier1 -- a Tier object
109
- tier2 -- a Tier object
110
- use_absolute_time -- a boolean
111
-
108
+ tier1 -- Tier object
109
+ tier2 -- Tier object
110
+ offset -- float (>= 0)
112
111
"""
113
112
result = copy .deepcopy (tier1 )
114
- offset = 0 if use_absolute_time else tier1 .end_time
115
113
for annotation in tier2 :
116
114
if hasattr (tier1 , 'intervals' ) and hasattr (tier2 , 'intervals' ):
117
115
result .add_annotation (Interval (
@@ -155,6 +153,7 @@ def concatenate_textgrids(
155
153
raise TextGridToolsException (
156
154
'Different numbers of tiers or non-matching tier names.' )
157
155
ccd_tiers = {}
156
+ offset = 0
158
157
for textgrid in textgrids :
159
158
for tier in textgrid :
160
159
if tier .name not in common_tiers and ignore_nonmatching_tiers :
@@ -165,7 +164,8 @@ def concatenate_textgrids(
165
164
ccd_tiers [tier .name ] = concatenate_tiers (
166
165
tier1 = ccd_tiers [tier .name ],
167
166
tier2 = tier ,
168
- use_absolute_time = use_absolute_time )
167
+ offset = 0 if use_absolute_time else offset )
168
+ offset = max ([tier .end_time for tier in ccd_tiers .values ()])
169
169
result_tg = TextGrid ()
170
170
result_tg .add_tiers ([ccd_tiers [x ] for x in common_tiers ]) #preserve order
171
171
return result_tg
0 commit comments