Example #1
0
def double_vowel2macron(text):
    # 連続する母音(同母音, 'ou')を長音符に変換
    text = list(text)
    # 母音をひらがなに変換する辞書
    v2h = {v: h for v, h in [('a', 'あ'), ('i', 'い'), ('u', 'う'), ('e', 'え'), ('o', 'お')]}
    for i, c in enumerate(text):
        if c == 'う' and i > 0:
            # 'ou' の処理
            vs = vowels(conv_h2a.do(text[i - 1]))
            if (text[i - 1] == ' ') or (not vs):
                continue
            v = vs[0]
            try:
                if v2h[v] in 'うお':
                    text[i] = 'ー'
            except KeyError:
                pass
        elif c in 'あいえお' and i > 0:
            # 同母音の処理
            vs = vowels(conv_h2a.do(text[i - 1]))
            if (text[i - 1] == ' ') or (not vs):
                continue
            v = vs[0]
            try:
                if v2h[v] == c:
                    text[i] = 'ー'
            except KeyError:
                pass
    return ''.join(text)
Example #2
0
def syllable_match_score(syl_a, syl_b, term_syl_pos, lyrics_syl_pos, hparams):
    # 音節と音節の類似度
    roman_a, roman_b = conv.do(syl_a), conv.do(syl_b)
    c = consonant_match_score(consonants(roman_a), consonants(roman_b)) * (
        1. + float(term_syl_pos == 0) * float(lyrics_syl_pos == 0))
    v = vowel_match_score(vowels(roman_a), vowels(roman_b))
    coefs = hparams['syl_score_coefs']
    rates = hparams['syl_rates']
    if c >= 1. and v:
        syl_score = coefs[0] * (1. + c) * v
        syl_rate = rates[0]
    elif c < 1. and v:
        syl_score = coefs[1] * (1. + c) * v
        syl_rate = rates[1]
    elif 0. < c and c < 1. and (not v):
        syl_score = coefs[2] * c
        syl_rate = rates[2]
    else:
        syl_score = coefs[3]
        syl_rate = rates[3]
    return syl_score, syl_rate
Example #3
0
def macron2vowel(text):
    # 長音符を前の字の母音に変換
    text = list(text)
    # 母音をひらがなに変換する辞書
    v2h = {v: h for v, h in [('a', 'あ'), ('i', 'い'), ('u', 'う'), ('e', 'え'), ('o', 'お')]}
    for i, c in enumerate(text):
        if c in 'ー' and i > 0:
            v = vowels(conv_h2a.do(text[i - 1]))[0]
            try:
                text[i] = v2h[v]
            except KeyError:
                pass
    return ''.join(text)
Example #4
0
def syllabic_nasal2vowel(text):
    # 撥音便を前の字の母音に変換
    text = list(text)
    # 母音をひらがなに変換する辞書
    v2h = {v: h for v, h in [('a', 'あ'), ('i', 'い'), ('u', 'う'), ('e', 'え'), ('o', 'お')]}
    for i, c in enumerate(text):
        if c in 'ん' and i > 0:
            vs = vowels(conv_h2a.do(text[i - 1]))
            if (text[i - 1] == ' ') or (not vs):
                continue
            v = vs[0]
            try:
                text[i] = v2h[v]
            except KeyError:
                pass
    return ''.join(text)
Example #5
0
def initial2initials(initial, initials):
    # 歌詞のイニシャルから検索対象の単語のイニシャルを指定 (母音が共通のもの)
    return [
        i for i in initials
        if vowels(conv_h2a.do(initial)) == vowels(conv_h2a.do(i))
    ]