コード例 #1
0
def test_cspanish_bad(onsets, vowels):
    separator = Separator(phone=';', syllable='_', word=' ')

    text = [
        # here kk and hh are out of onsets
        'nkko sehh kae',
        'si aj aj al aj',
        'esta aj la tata e9u',
        'mira esta xugan9o']

    s = Syllabifier(onsets, vowels, separator=separator)
    with pytest.raises(ValueError):
        s.syllabify(text)
コード例 #2
0
def test_no_vowel(onsets, vowels):
    text = 's;i; a;j; l;j; a;l; a;j; '

    s = Syllabifier(onsets, vowels, separator=Separator(';', '_', ' '))
    with pytest.raises(ValueError) as err:
        s.syllabify([text])
    assert 'no vowel in word' in str(err.value)

    s = Syllabifier(onsets, vowels, separator=Separator(';', '_', ' '))
    assert [] == s.syllabify([text], tolerant=True)

    s = Syllabifier(
        onsets, vowels, separator=Separator(';', '_', ' '), filling_vowel=True)
    assert ['s;i;_ a;j;_ l;j;_ a;l;_ a;j;_ '] == s.syllabify([text])
コード例 #3
0
def test_bad_input():
    separator = Separator(phone=';', syllable='_', word=' ')

    with pytest.raises(ValueError) as err:
        s = Syllabifier(['a', 'd'], ['b', 'dd'], separator=separator)
        s.syllabify(['ab c_ dd'])  # syllable separator in input
        assert 'line 1' in err

    with pytest.raises(ValueError) as err:
        Syllabifier(['a'], [])
        assert 'empty vowels' in err

    with pytest.raises(ValueError) as err:
        Syllabifier([], ['a'])
        assert 'empty onsets' in err
コード例 #4
0
def test_cspanish_phones(onsets, vowels, strip):
    separator = Separator(phone=';', syllable='_', word=' ')

    text = [
        'n;o; s;e; k;a;e; ',
        's;i; a;j; a;j; a;l; a;j; ',
        'es;t;a; a;j; l;a; t;a;t;a; e;9u; ',
        'm;i;r;a; es;t;a; x;u;g;a;n;9o; '
    ]

    if strip:
        expected = [
            'n;o s;e k;a_e',
            's;i a;j a;j a;l a;j',
            'es_t;a a;j l;a t;a_t;a e_9u',
            'm;i_r;a es_t;a x;u_g;a;n_9o'
        ]
    else:
        expected = [
            'n;o;_ s;e;_ k;a;_e;_ ',
            's;i;_ a;j;_ a;j;_ a;l;_ a;j;_ ',
            'es;_t;a;_ a;j;_ l;a;_ t;a;_t;a;_ e;_9u;_ ',
            'm;i;_r;a;_ es;_t;a;_ x;u;_g;a;n;_9o;_ ']

    s = Syllabifier(onsets, vowels, separator=separator)
    sylls = s.syllabify(text, strip=strip)
    assert sylls == expected
コード例 #5
0
def test_cspanish_default_separator(onsets, vowels, strip):
    text = ['m i r a ;eword']
    expected = (
        ['m i ;esyllr a ;esyll;eword'] if not strip else ['m i;esyllr a'])

    s = Syllabifier(onsets, vowels, separator=Separator())
    sylls = s.syllabify(text, strip=strip)
    assert sylls == expected
コード例 #6
0
def test_cspanish_good(onsets, vowels, syllable):
    separator = Separator(phone=';', syllable=syllable, word=' ')

    text = [
        'no se kae', 'si aj aj al aj', 'esta aj la tata e9u',
        'mira esta xugan9o'
    ]

    expected = [
        'no_ se_ ka_e_ ', 'si_ aj_ aj_ al_ aj_ ',
        'es_ta_ aj_ la_ ta_ta_ e_9u_ ', 'mi_ra_ es_ta_ xu_gan_9o_ '
    ]

    s = Syllabifier(onsets, vowels, separator=separator)
    sylls = s.syllabify(text)
    assert sylls == [e.replace('_', syllable) for e in expected]
コード例 #7
0
def test_cspanish_strip(onsets, vowels):
    separator = Separator(phone=';', syllable='_', word=' ')

    text = [
        'no se kae', 'si aj aj al aj', 'esta aj la tata e9u',
        'mira esta xugan9o'
    ]

    expected = [
        'no se ka_e', 'si aj aj al aj', 'es_ta aj la ta_ta e_9u',
        'mi_ra es_ta xu_gan_9o'
    ]

    s = Syllabifier(onsets, vowels, separator=separator)
    sylls = s.syllabify(text, strip=True, tolerant=True)
    assert sylls == expected
コード例 #8
0
def test_errors(onsets, vowels, text, error):
    s = Syllabifier(onsets, vowels, separator=Separator(';', '_', ' '))
    with pytest.raises(ValueError) as err:
        s.syllabify([text])
    assert error in str(err.value)