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