How to use the pypinyin.load_phrases_dict function in pypinyin

To help you get started, we’ve selected a few pypinyin examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mozillazg / python-pinyin / tests / test_pinyin.py View on Github external
def test_custom_pinyin_dict2():
    hans = ['同行']
    try:
        assert lazy_pinyin(hans, style=TONE2) == ['to2ng', 'ha2ng']
    except AssertionError:
        pass
    load_phrases_dict({'同行': [['tóng'], ['xíng']]})
    assert lazy_pinyin(hans, style=TONE2) == ['to2ng', 'xi2ng']
github mozillazg / python-pinyin / tests / contrib / test_mmseg.py View on Github external
def test_retrain():
    seg = mmseg.seg
    assert list(seg.cut('啊啊啊')) == ['啊', '啊', '啊']

    load_phrases_dict({'啊啊啊': [['a'], ['a'], ['a']]})
    mmseg.retrain(seg)
    assert list(seg.cut('啊啊啊')) == ['啊啊啊']
github mozillazg / python-pinyin / tests / test_pinyin.py View on Github external
def test_custom_pinyin_dict2_tone2():
    load_phrases_dict({'同行': [['to4ng'], ['ku1']]}, style='tone2')
    assert lazy_pinyin(['同行'], style=TONE2) == ['to4ng', 'ku1']
    assert pinyin('同行') == [['tòng'], ['kū']]
github awesome-archive / tacotron_cn / chinese2pinyin.py View on Github external
alpha_pronuce = {"A": "ei ", "B": "bii ", "C": "sii ", "D": "dii ", "E": "ii ", "F": "ef ", "G": "dji ", "H": "eich ",
                 "I": "ai ", "J": "jei ", "K": "kei ", "L": "el ", "M": "em ", "N": "en ",
                 "O": "eo ", "P": "pii ", "Q": "kiu ", "R": "aa ", "S": "es ", "T": "tii ", "U": "iu ", "V": "vii ",
                 "W": "dabliu ", "X ": "eiks ", "Y": "wai ", "Z": "zii "}

# PUNCTUATION2 = r'“”()×"\'()*#'  # 其它符号
# load_phrases_dict({u'360': [[u'jú'], [u'zǐ']]})

def json_load():
    with open("user_dict/fault-tolerant_word.json", "r") as rf:
        data = json.load(rf)
    return data


usr_phrase = json_load()
load_phrases_dict(usr_phrase)


def text2pinyin(syllables):
    temp = []
    for syllable in syllables:
        for p in PUNCTUATION:
            syllable = syllable.replace(p, "")
        # print(syllable)
        # if syllable.isdigit():
        try:
            syllable = atc.num2chinese(syllable)
            # print("sy:", syllable)
            new_sounds = lazy_pinyin(syllable, style=pypinyin.TONE2)
            print("pinyin:" + str(new_sounds))
            for e in new_sounds:
                temp.append(e)
github Jackiexiao / MTTS / src / txt2pinyin.py View on Github external
def _pre_pinyin_setting():
    ''' fix pinyin error'''
    load_phrases_dict({'嗯':[['ēn']]})
github Jackiexiao / MTTS / src / mtts.py View on Github external
def _pre_pinyin_setting():
    ''' fix pinyin error'''
    load_phrases_dict({'嗯': [['ēn']]})
    load_phrases_dict({'风云变幻': [['fēng'], ['yún'], ['bià'], ['huàn']]})
    load_phrases_dict({'不破不立': [['bù'], ['pò'], ['bù'], ['lì']]})
github Jackiexiao / MTTS / src / mtts.py View on Github external
def _pre_pinyin_setting():
    ''' fix pinyin error'''
    load_phrases_dict({'嗯': [['ēn']]})
    load_phrases_dict({'风云变幻': [['fēng'], ['yún'], ['bià'], ['huàn']]})
    load_phrases_dict({'不破不立': [['bù'], ['pò'], ['bù'], ['lì']]})