def test_phoneme_table_get_auxiliary_label_id():
    phoneme_table = PhonemeTable()
    phoneme_table.add_label('a')
    phoneme_table.set_auxiliary_label('#0')
    phoneme_table.set_auxiliary_label('#1')
    assert phoneme_table.get_label_id('a') == 2
    assert phoneme_table.get_auxiliary_label_id('#0') == 3
    assert phoneme_table.get_auxiliary_label_id('#1') == 4
def test_phoneme_table_get_all_auxiliary_labels():
    phoneme_table = PhonemeTable()
    phoneme_table.add_label('a')
    phoneme_table.set_auxiliary_label('#0')
    phoneme_table.set_auxiliary_label('#1')
    got = phoneme_table.get_all_auxiliary_labels()
    assert isinstance(got, dict)
    assert len(got) == 2
    assert got[3] == '#0'
    assert got[4] == '#1'
Beispiel #3
0
def test_token_create_fst_with_auxiliary_labels():
    phoneme_table = PhonemeTable()
    phoneme_table.add_labels(['a', 'i'])
    epsilon_id = phoneme_table.get_epsilon_id()
    blank_id = phoneme_table.get_blank_id()
    a = phoneme_table.get_label_id('a')
    i = phoneme_table.get_label_id('i')
    phoneme_table.set_auxiliary_label('#0')
    phoneme_table.set_auxiliary_label('#1')
    aux0 = phoneme_table.get_auxiliary_label_id('#0')
    aux1 = phoneme_table.get_auxiliary_label_id('#1')

    fst = Token().create_fst(phoneme_table)
    assert (fst.num_states() == 5)
    # start state
    state = 0
    assert (fst.num_arcs(state) == 3)
    gen_arc = fst.arcs(state)
    is_expected_arc(next(gen_arc), blank_id, epsilon_id, state)
    is_expected_arc(next(gen_arc), a, a, 3)
    is_expected_arc(next(gen_arc), i, i, 4)
    # second state
    state = 1
    assert (fst.num_arcs(state) == 2)
    gen_arc = fst.arcs(state)
    is_expected_arc(next(gen_arc), blank_id, epsilon_id, state)
    is_expected_arc(next(gen_arc), epsilon_id, epsilon_id, 2)
    # final(auxiliary) state
    state = 2
    assert (fst.num_arcs(state) == 3)
    gen_arc = fst.arcs(state)
    is_expected_arc(next(gen_arc), epsilon_id, epsilon_id, 0)
    is_expected_arc(next(gen_arc), epsilon_id, aux0, state)
    is_expected_arc(next(gen_arc), epsilon_id, aux1, state)
    # a
    state = 3
    assert (fst.num_arcs(state) == 2)
    gen_arc = fst.arcs(state)
    is_expected_arc(next(gen_arc), a, epsilon_id, state)
    is_expected_arc(next(gen_arc), epsilon_id, epsilon_id, 1)
    # b
    state = 4
    assert (fst.num_arcs(state) == 2)
    gen_arc = fst.arcs(state)
    is_expected_arc(next(gen_arc), i, epsilon_id, state)
    is_expected_arc(next(gen_arc), epsilon_id, epsilon_id, 1)