Get full and simple spelling according to Chinese name

Source: Internet
Author: User

Mainly used in Pypinyin library (to obtain pinyin according to Chinese characters)

Reference http://pypinyin.readthedocs.org/en/latest/Installing the PIP install Pypinyin

Pinyin style:

style value meaning
Pypinyin. NORMAL 0 Normal style, without tones. Such as:pin yin
Pypinyin. TONE 1 Tone style 1, pinyin tones on the first letter of the vowel (default style). Such as:pīn yīn
Pypinyin. TONE2 2 Tone style 2, that is, pinyin tone after each pinyin, with the number [0-4] to represent. Such as:pi1n yi1n
Pypinyin. Initials 3 Consonant style, returning only the initials of each phonetic part. such as: 中国 the Pinyinzh g
Pypinyin. First_letter 4 First letter style, returning only the first letter part of Pinyin. Such as:p y
Pypinyin. Finals 5 Vowel Style 1, return only the vowel portion of each pinyin, without a tone. Such as:ong uo
Pypinyin. Finals_tone 6 Vowel style 2, with tones and tones on the first letter of the vowel. Such as:ōng uó
Pypinyin. Finals_tone2 7 Vowel style 2, with tones, tones after each pinyin, expressed by the number [0-4]. Such as:o1ng uo2
Demo
#! /usr/bin/env python#-*-coding:utf-8-*-from pypinyin import pinyin,lazy_pinyinimport pypinyindef getJianPin (ORI_STR):    first_letter_list = Pinyin (ori_str, style = Pypinyin. First_letter)    return '. Join ([i[0] for I in First_letter_list]) def getquanpin (ORI_STR):    return '. Join (Lazy_ Pinyin (ori_str, style = Pypinyin. NORMAL) If __name__ = = ' __main__ ':    ori_str = U ' family most important '    print Getjianpin (ori_str)    print Getquanpin (ORI_STR)

  

Get full and simple spelling according to Chinese name

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.