def test_overlapping_words(self): words = [ Word('the', 0, 0.10, ['dh', 'iy'], ['dh'], 'DT'), Word('cat', 0.05, 0.39, ['k', 'ae', 't'], ['k', 'ae', 't'], 'NN') ] utt = Utterance(words)
def test_misaligned(self): misaligned_word = Word('', 0.50, 0.25) assert_true(misaligned_word.misaligned) phone_dh = Phone('dh') misaligned_word._phones = [phone_dh] assert_true(misaligned_word.misaligned)
def test_append_none(self): word = Word('the', 0.05, 0.25, ['dh', 'iy'], ['dh'], 'DT') utt_append_none = Utterance([word]) none_word = Word('uh', None, None, ['ah'], ['ah'], 'UH') assert_raises(TypeError, utt_append_none.append, none_word) none_beg_word = Word('uh', None, 0.5, ['ah'], ['ah'], 'UH') assert_raises(TypeError, utt_append_none.append, none_beg_word) none_end_word = Word('uh', 0.65, None, ['ah'], ['ah'], 'UH') assert_raises(TypeError, utt_append_none.append, none_end_word)
def test_multiple_medial_pauses(self): words = self.words[:] words[5:] = [ Pause('<SIL>', 0.91, 1.0), Pause('<SIL>', 1.0, 1.42), Word('mat', 1.42, 1.7, ['m', 'ae', 't'], ['m', 'ae', 't']) ] utterances = list(words_to_utterances(words)) assert_equal(len(utterances), 2) for i, word in enumerate(utterances[0]): assert_equal(words[i].beg, word.beg) assert_equal(words[i].end, word.end) assert_equal(words[i].orthography, word.orthography) assert_equal(words[i].phonemic, word.phonemic) assert_equal(words[i].phonetic, word.phonetic) for i, word in enumerate(utterances[1], 7): assert_equal(words[i].beg, word.beg) assert_equal(words[i].end, word.end) assert_equal(words[i].orthography, word.orthography) assert_equal(words[i].phonemic, word.phonemic) assert_equal(words[i].phonetic, word.phonetic)
def test_sep_arg(self): words = self.words[:] words[5:] = [ Pause('<SIL>', 0.91, 1.0), Word('mat', 1.0, 1.28, ['m', 'ae', 't'], ['m', 'ae', 't']) ] utterances = list(words_to_utterances(words, sep=0.08)) assert_equal(len(utterances), 2) assert_equal(len(utterances[0]), 5) assert_equal(len(utterances[1]), 1) for i, word in enumerate(utterances[0]): assert_equal(words[i].beg, word.beg) assert_equal(words[i].end, word.end) assert_equal(words[i].orthography, word.orthography) assert_equal(words[i].phonemic, word.phonemic) assert_equal(words[i].phonetic, word.phonetic) assert_equal(words[6].beg, utterances[1][0].beg) assert_equal(words[6].end, utterances[1][0].end) assert_equal(words[6].orthography, utterances[1][0].orthography) assert_equal(words[6].phonemic, utterances[1][0].phonemic) assert_equal(words[6].phonetic, utterances[1][0].phonetic)
def test_strip_end_zero(self): zero = Word('', 1.25, 1.25) utt_strip = Utterance(self.words + [zero]) utt_strip.strip() assert_not_in(zero, utt_strip) assert_equal(utt_strip.words(), self.words)
def test_strip_beg_zero(self): zero = Word('', 0.0, 0.0) utt_strip = Utterance([zero] + self.words) utt_strip.strip() assert_not_in(zero, utt_strip) assert_equal(utt_strip.words(), self.words)
def test_multiple_short_medial_pauses(self): words = self.words[:] words[3:] = [ Pause('<VOCNOISE>', 0.59, 0.65), Word('on', 0.65, 0.77, ['aa', 'n'], ['aa', 'n']), self.words[4], Pause('<SIL>', 0.91, 1.35), Word('mat', 1.35, 1.63, ['m', 'ae', 't'], ['m', 'ae', 't']) ] utterances = list(words_to_utterances(words)) assert_equal(len(utterances), 1) assert_equal(words[3].entry, utterances[0][3].entry) assert_equal(words[6].entry, utterances[0][6].entry) for i, word in enumerate(utterances[0]): assert_equal(words[i].beg, word.beg) assert_equal(words[i].end, word.end)
def test_append(self): utt_a = Utterance() word = Word('the', 0.05, 0.25, ['dh', 'iy'], ['dh'], 'DT') utt_a.append(word) assert_equal(utt_a.words(), [word]) assert_equal(utt_a.beg(), 0.05) assert_equal(utt_a.end(), 0.25) assert_equal(utt_a.dur(), 0.25 - 0.05) uh = Word('uh', 0.25, 0.45, ['ah'], ['ah'], 'UH') utt_a.append(uh) assert_equal(utt_a.words(), [word, uh]) assert_equal(utt_a.beg(), 0.05) assert_equal(utt_a.end(), 0.45) assert_equal(utt_a.dur(), 0.45 - 0.05)
def test_speech_rate_none_at_edge(self): utt = Utterance(self.words[:]) word = Word('the', None, 0.10, ['dh', 'iy'], ['dh'], 'DT') # normally there couldn't be a None-duration word in the utterance # anyway utt._words[0] = word assert_raises(TypeError, utt.speech_rate) assert_raises(TypeError, utt.speech_rate, False, 'zero') assert_raises(TypeError, utt.speech_rate, False, 'squeeze')
def test_strip_end_multiple(self): pause = Pause(beg=1.25, end=1.95) zero = Word('', 1.95, 1.95) utt_strip = Utterance() utt_strip._words = self.words + [pause, zero] utt_strip.strip() for entry in {pause, zero}: assert_not_in(entry, utt_strip) assert_equal(utt_strip.words(), self.words)
def test_strip_beg_multiple(self): pause = Pause(beg=0, end=0.39) zero = Word('', 0.39, 0.39) utt_strip = Utterance() utt_strip._words = [pause, zero] + self.words[2:] utt_strip.strip() for entry in {pause, zero}: assert_not_in(entry, utt_strip) assert_equal(utt_strip.words(), self.words[2:])
def test_syllables_phones(self): word = Word('the', 0.05, 0.25, ['dh', 'iy'], ['dh'], 'DT') word._phones = [Phone('dh')] assert_equal(word.syllables(), 1) assert_equal(word.syllables(phonetic=False), 1) assert_equal(word.syllables(phonetic=True), 0)
def setup_class(cls): cls.words = [ Word('the', 0.05, 0.15, ['dh', 'iy'], ['dh', 'ah']), Word('cat', 0.15, 0.44, ['k', 'ae', 't'], ['k', 'ae', 't']), Word('is', 0.44, 0.59, ['ih', 'z'], ['ih', 'z']), Word('on', 0.59, 0.77, ['aa', 'n'], ['aa', 'n']), Word('the', 0.77, 0.91, ['dh', 'iy'], ['dh', 'ah']), Word('mat', 0.91, 1.19, ['m', 'ae', 't'], ['m', 'ae', 't']) ]
def test_short_medial_pause(self): words = self.words[:] words[5:] = [ Pause('<SIL>', 0.91, 1.0), Word('mat', 1.0, 1.28, ['m', 'ae', 't'], ['m', 'ae', 't']) ] utterances = list(words_to_utterances(words)) assert_equal(len(utterances), 1) assert_equal(words[5].entry, utterances[0][5].entry) for i, word in enumerate(utterances[0]): assert_equal(words[i].beg, word.beg) assert_equal(words[i].end, word.end)
def test_medial_pause_no_strip(self): # insert a pause into a copy of the word list words = self.words[:] words[5:] = [ Pause('<SIL>', 0.91, 1.42), Word('mat', 1.42, 1.7, ['m', 'ae', 't'], ['m', 'ae', 't']) ] utterances = list(words_to_utterances(words, strip_pauses=False)) assert_equal(len(utterances), 2) assert_equal(len(utterances[0]), 6) assert_equal(len(utterances[1]), 1) for i, word in enumerate(utterances[0]): assert_equal(words[i].beg, word.beg) assert_equal(words[i].end, word.end)
def setup(self): self.words = [ Word('the', 0, 0.10, ['dh', 'iy'], ['dh'], 'DT'), Word('cat', 0.10, 0.39, ['k', 'ae', 't'], ['k', 'ae', 't'], 'NN'), Word('is', 0.39, 0.55, ['ih', 'z'], ['ih', 'z'], 'VB'), Word('on', 0.55, 0.73, ['aa', 'n'], ['aan'], 'IN'), Word('the', 0.73, 0.80, ['dh', 'iy'], ['dh', 'uh'], 'DT'), Word('mat', 0.80, 1.25, ['m', 'ae', 't'], ['m', 'ae', 't'], 'NN') ] self.utt = Utterance(self.words) self.empty_utt = Utterance()
def test_multiple_medial_pauses_no_strip(self): words = self.words[:] words[5:] = [ Pause('<SIL>', 0.91, 1.0), Pause('<SIL>', 1.0, 1.42), Word('mat', 1.42, 1.7, ['m', 'ae', 't'], ['m', 'ae', 't']) ] utterances = list(words_to_utterances(words, strip_pauses=False)) assert_equal(len(utterances), 2) assert_equal(len(utterances[0]), 7) assert_equal(len(utterances[1]), 1) for i, word in enumerate(utterances[0]): assert_equal(words[i].beg, word.beg) assert_equal(words[i].end, word.end) for i, word in enumerate(utterances[1], 7): assert_equal(words[i].beg, word.beg) assert_equal(words[i].end, word.end)
def test_medial_pause(self): # insert a pause into a copy of the word list words = self.words[:] words[5:] = [ Pause('<SIL>', 0.91, 1.42), Word('mat', 1.42, 1.7, ['m', 'ae', 't'], ['m', 'ae', 't']) ] utterances = list(words_to_utterances(words)) assert_equal(len(utterances), 2) assert_equal(len(utterances[0]), 5) assert_equal(len(utterances[1]), 1) for i, word in enumerate(utterances[0]): assert_equal(words[i].beg, word.beg) assert_equal(words[i].end, word.end) assert_equal(words[6].beg, utterances[1][0].beg) assert_equal(words[6].end, utterances[1][0].end) assert_equal(words[6].orthography, utterances[1][0].orthography) assert_equal(words[6].phonemic, utterances[1][0].phonemic) assert_equal(words[6].phonetic, utterances[1][0].phonetic)
def test_misaligned_different_length_phonetic_and_phones(self): misaligned_word = Word('', 0.25, 0.50, phonetic=['dh', 'ah']) misaligned_word._phones = [Phone('dh')] assert_true(misaligned_word.misaligned)
class TestWord(object): def setup(self): self.word = Word('the', 0.05, 0.25, ['dh', 'iy'], ['dh'], 'DT') self.empty_word = Word('uh', 0.25, 0.40) def test_word(self): assert_equal(self.word.orthography, 'the') assert_equal(self.word.beg, 0.05) assert_equal(self.word.end, 0.25) assert_equal(self.word.phonemic, ['dh', 'iy']) assert_equal(self.word.phonetic, ['dh']) assert_equal(self.word.pos, 'DT') assert_equal(self.word.dur, 0.25 - 0.05) assert_is_none(self.word.phones) def test_empty_word(self): assert_equal(self.empty_word.orthography, 'uh') assert_equal(self.empty_word.beg, 0.25) assert_equal(self.empty_word.end, 0.40) assert_is_none(self.empty_word.phonemic) assert_is_none(self.empty_word.phonetic) assert_is_none(self.empty_word.pos) assert_is_none(self.empty_word.phones) assert_equal(self.empty_word.dur, 0.40 - 0.25) @raises(TypeError) def test_missing_word(self): word = Word() def test_syllables(self): assert_equal(self.word.syllables(), 1) assert_equal(self.word.syllables(phonetic=False), 1) assert_equal(self.word.syllables(phonetic=True), 0) assert_is_none(self.empty_word.syllables()) assert_is_none(self.empty_word.syllables(False)) assert_is_none(self.empty_word.syllables(True)) @raises(AttributeError) def test_readonly_orthography(self): self.word.orthography = 'an' @raises(AttributeError) def test_readonly_beg(self): self.word.beg = 0.0 @raises(AttributeError) def test_readonly_end(self): self.word.end = 1.0 @raises(AttributeError) def test_readonly_dur(self): self.word.dur = 1.0 @raises(AttributeError) def test_readonly_phonemic(self): self.word.phonemic = ['uh', 'n'] @raises(AttributeError) def test_readonly_phonetic(self): self.word.phonetic = ['en'] @raises(AttributeError) def test_readonly_pos(self): self.word.pos = 'DT' def test_phones_setter(self): assert_false(self.word.misaligned) phone_th = Phone('th') phone_dh = Phone('dh') self.word._phones = [phone_th] assert_in(phone_th, self.word.phones) assert_true(self.word.misaligned) self.word._phones = [phone_dh] assert_in(phone_dh, self.word.phones) assert_false(self.word.misaligned) self.word._phones = [] assert_true(self.word.misaligned) def test_misaligned(self): misaligned_word = Word('', 0.50, 0.25) assert_true(misaligned_word.misaligned) phone_dh = Phone('dh') misaligned_word._phones = [phone_dh] assert_true(misaligned_word.misaligned) def test_misaligned_zero(self): zero_word = Word('', 0.40, 0.40) assert_false(zero_word.misaligned) def test_repr(self): assert_equal(repr(self.word), "Word('the', 0.05, 0.25, ['dh', 'iy'], ['dh'], 'DT')") def test_str(self): assert_equal(str(self.word), '<Word "the" at 0.05>')
def test_missing_word(self): word = Word()
def test_misaligned_zero(self): zero_word = Word('', 0.40, 0.40) assert_false(zero_word.misaligned)
def setup(self): self.word = Word('the', 0.05, 0.25, ['dh', 'iy'], ['dh'], 'DT') self.empty_word = Word('uh', 0.25, 0.40)
def test_append_backwards(self): word = Word('uh', 1.95, 1.65, ['ah'], ['ah'], 'UH') self.empty_utt.append(word)
def test_append_end_none(self): word = Word('uh', 0.25, None, ['ah'], ['ah'], 'UH') self.utt.append(word)
def test_append_beg_none(self): word = Word('uh', None, 0.45, ['ah'], ['ah'], 'UH') self.utt.append(word)
def test_append_overlap(self): word = Word('uh', 0.25, 0.45, ['ah'], ['ah'], 'UH') self.utt.append(word)
def test_word_nonnumeric_times(self): word = Word('the', 'beg', 'end', ['dh', 'iy'], ['dh'], 'DT') word.dur
def test_flipped_word(self): word = Word('the', 0.10, 0, ['dh', 'iy'], ['dh'], 'DT') utt = Utterance([word])