Documentation ¶
Overview ¶
Package pinyin the chinese pinyin.
Index ¶
- Constants
- Variables
- func GetLinesFromByte(content []byte) []string
- func GetLinesFromFile(filename string) []string
- func IsChineseCharacters(word string) bool
- func IsHanWord(w string) bool
- func PyinAlpha(word string, isAllArgs ...bool) string
- func PyinFormat(pinyin, vFmt string) string
- func PyinNumber(word string, seqs ...string) string
- func PyinNumberList(word []string) []string
- func ReadDickFromByteKv(content []byte) map[string]string
- func ReadDickFromIni(filename string) map[string]map[string]string
- func ReadIniLines(lines []string) map[string]map[string]string
- type Element
- type List
- type Pinyin
- func (pyt *Pinyin) Dicks() map[string]Element
- func (pyt *Pinyin) FileLoadSuccess() bool
- func (pyt *Pinyin) GetPyTone(chinese string) string
- func (pyt *Pinyin) GetPyToneAlpha(chinese string) string
- func (pyt *Pinyin) GetPyToneFunc(chinese string, call func(string) string) string
- func (pyt *Pinyin) GetPyToneNumber(chinese string) string
- func (pyt *Pinyin) IsEmpty() bool
- func (pyt *Pinyin) Len() int
- func (pyt *Pinyin) LineToDick(lines []string) *Pinyin
- func (pyt *Pinyin) SearchAlpha(alpha string, limits ...int) List
- func (pyt *Pinyin) SearchByGroup(words string) List
- func (pyt *Pinyin) SearchByGroupFunc(s string, call func(el Element))
- type ZhSentences
Examples ¶
Constants ¶
const ( // PinyinTone pinyin as tone for raw PinyinTone // PinyinNumber pinyin as tone for number PinyinNumber // PinyinAlpha pinyin as tone for alpha PinyinAlpha )
const (
SearchAlphaLimit = 1000
)
const (
SepTitle = `__LIB_TITLE__`
)
Variables ¶
var ( CcReg = regexp.MustCompile("^[\u4E00-\u9FA5]$") ChineseToneMap = map[string]map[string]int{ "ue": { "üē": 1, "üé": 2, "üě": 3, "üè": 4, }, "a": { "ā": 1, "á": 2, "ǎ": 3, "à": 4, }, "e": { "ē": 1, "é": 2, "ě": 3, "è": 4, }, "i": { "ī": 1, "í": 2, "ǐ": 3, "ì": 4, }, "o": { "ō": 1, "ó": 2, "ǒ": 3, "ò": 4, }, "u": { "ū": 1, "ú": 2, "ǔ": 3, "ù": 4, }, } )
Functions ¶
func GetLinesFromByte ¶
GetLinesFromByte the line byte
func GetLinesFromFile ¶
GetLinesFromFile the line from file
func IsChineseCharacters ¶
IsChineseCharacters check if the string is chinese character
func PyinNumber ¶
PyinNumber turn pinyin with number
Since alphanumeric pinyin is loaded at the end of the word rather than replacing it in situ, new segmentation symbols are added
func PyinNumberList ¶
PyinNumberList convert the pinyin number to C and output the list
func ReadDickFromByteKv ¶
ReadDickFromByteKv read file and parse from ini files
func ReadDickFromIni ¶
ReadDickFromIni read file and parse from ini files
Types ¶
type Element ¶
type Element struct { Unicode string // it can be chinese or other char Text string // contains filtered or unexported fields }
Element the data dictionary enter
func (Element) FirstPinyin ¶
FirstPinyin if pinyin exists get the first pinyin, compatible with polyphonics
func (Element) PinyinList ¶
PinyinList get the polyphonic pinyin as list
type List ¶
type List []Element
List the list of elements
type Pinyin ¶
type Pinyin struct {
// contains filtered or unexported fields
}
Pinyin the pinyin dick creator
func NewPinyin ¶
Example ¶
var filename, pinyin string // filename is pinyin dick file or use `pinyin/material` for builtin. py := NewPinyin(filename) pinyin = py.GetPyToneAlpha(`古丞秋`) fmt.Println(pinyin) pinyin = py.GetPyTone(`中华人民共和国`) fmt.Println(pinyin)
Output: gu cheng qiu zhōng huá rén mín gòng hé guó
func (*Pinyin) FileLoadSuccess ¶
func (*Pinyin) GetPyToneAlpha ¶
GetPyToneAlpha get pinyin without tone
func (*Pinyin) GetPyToneFunc ¶
GetPyToneFunc get pinyin with tone by callback Func
func (*Pinyin) GetPyToneNumber ¶
GetPyToneNumber get pinyin with tone that replace by number (1-4)
func (*Pinyin) LineToDick ¶
LineToDick turn lines to dick data.
func (*Pinyin) SearchAlpha ¶
SearchAlpha search word by single alpha
func (*Pinyin) SearchByGroup ¶
SearchByGroup @todo implement grouped text queries
func (*Pinyin) SearchByGroupFunc ¶
SearchByGroupFunc @todo implement grouped text queries and call callback functions
type ZhSentences ¶
type ZhSentences string
ZhSentences Chinese sentences
func (ZhSentences) Len ¶
func (s ZhSentences) Len() int
Len calculate the length of Chinese sentences