Skip to content

Commit

Permalink
Merge pull request #201 from Forced-Alignment-and-Vowel-Extraction/co…
Browse files Browse the repository at this point in the history
…ncat-methods

patch for piecemeal appending
  • Loading branch information
JoFrhwld authored Jun 25, 2024
2 parents f60e352 + b018a8b commit d301d60
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/aligned_textgrid/mixins/tiermixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,12 @@ def append(self:TierGroupType, new:TierType):
f"Only a tier of {self._seq_type.__name__} "
f"can be appended to a {self.__class__.__name__}"
))


if self.within:
self.within._reclone_classes([new.entry_class])
new_class, = self.within._swap_classes([new.entry_class], self.within._cloned_classes)
new.__init__(new, entry_class=new_class)

possible_set = {SequenceBaseClass}
existing_set = set()
if len(self) > 0:
Expand Down
22 changes: 22 additions & 0 deletions tests/test_add_append.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,28 @@ def test_clone_reuse(self):

assert tgr1.entry_classes[0] is tgr2.entry_classes[0]

def test_piecemeal_append(self):
MyWord, MyPhone = custom_classes(["MyWord", "MyPhone"])

word_tier = SequenceTier([
MyWord((0, 10, "a")),
MyWord((10,15,"b"))
])

phone_tier = SequenceTier([
MyPhone((0, 10, "AA")),
MyPhone((10, 15,"BB"))
])

tier_group = TierGroup([word_tier])

atg = AlignedTextGrid([tier_group])

atg[0].append(phone_tier)

assert phone_tier in tier_group
assert tier_group in atg

class TestCleanups:
def test_sequence_cleanup(self):
MyWord, MyPhone = custom_classes(["MyWord", "MyPhone"])
Expand Down

0 comments on commit d301d60

Please sign in to comment.