Python Pinyin Library Pypinyin Library detailed

Source: Internet
Author: User

#-*-coding:utf-8-*-#@Author: FELIX#@Date: 2018/6/30 9:20 fromPypinyinImportPinyin, Lazy_pinyin, Style, load_phrases_dict, Load_single_dict fromPypinyin.styleImportRegisterPrint(Pinyin ('Hello'))#[ [' nǐ '], [' Hǎo ' ]Print(Pinyin ('Center', heteronym=true))#enable Polyphone mode # [[' Zhōng ', ' Zhòng '], [' Xīn ' ]Print(Pinyin ('Center', Style=style.first_letter))#set phonetic style, first letter [[' Z '], [' X ']]Print(Pinyin ('Center', Style=style.tone2, Heteronym=true))#[ [' zho1ng ', ' zho4ng '], [' xi1n ' ]Print(Lazy_pinyin ('Center'))#do not consider the case of Polyphone # [' Zhong ', ' Xin ']######### #处理不包含拼音的字符#default behavior: Returns without any processing:Print(Lazy_pinyin ('Hello ☆'))#[' ni ', ' Hao ', ' ☆ ★ ']#Ignore: ignore this characterPrint(Lazy_pinyin ('Hello ☆', errors='Ignore'))#[' ni ', ' Hao ']#Replace : Replaced with Unicode encoding to remove \uPrint(Lazy_pinyin ('Hello ☆', errors='Replace'))#[' ni ', ' Hao ', ' 26062606 ']#Callable object: Provides a callback function that accepts no phonetic characters (strings) as arguments, supported return value types: Unicode or list ([Unicode, ...]) or None. Print(Lazy_pinyin ('Hello ☆', errors=LambdaX:'Star'))#[' ni ', ' Hao ', ' star ']########### Custom Phonetic LibrariesPrint(Lazy_pinyin ('not yet .', style=style.tone2)) Load_phrases_dict ({'Orange': [['Jú'], ['zǐ']]})#add an "orange" phrase that you can define yourselfPrint(Lazy_pinyin ('Orange', style=style.tone2)) Load_single_dict ({ord ('still'):'Hái,huán'})#Adjust the phonetic order of the "also" wordPrint(Lazy_pinyin ('not yet .', style=style.tone2))########## #自定义拼音风格@register ('Kiss')defKiss (Mypinyin, * *Kwargs):return '?? {0}'. Format (mypinyin)Print(Lazy_pinyin ('What, da ?', style='Kiss'))

Python Pinyin Library Pypinyin Library detailed

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.