pinyin

package
v1.4.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 20, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package pinyin the chinese pinyin.

Index

Examples

Constants

View Source
const (

	// PinyinTone pinyin as tone for raw
	PinyinTone
	// PinyinNumber pinyin as tone for number
	PinyinNumber
	// PinyinAlpha pinyin as tone for alpha
	PinyinAlpha
)
View Source
const (
	SearchAlphaLimit = 1000
)
View Source
const (
	SepTitle = `__LIB_TITLE__`
)

Variables

View Source
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

func GetLinesFromByte(content []byte) []string

GetLinesFromByte the line byte

func GetLinesFromFile

func GetLinesFromFile(filename string) []string

GetLinesFromFile the line from file

func IsChineseCharacters

func IsChineseCharacters(word string) bool

IsChineseCharacters check if the string is chinese character

func IsHanWord added in v1.4.1

func IsHanWord(w string) bool

IsHanWord detect if it is chinese word.

func PyinAlpha added in v1.4.1

func PyinAlpha(word string, isAllArgs ...bool) string

PyinAlpha turn pinyin with alpha

func PyinFormat added in v1.4.1

func PyinFormat(pinyin, vFmt string) string

PyinFormat set format date

support `title` like 'latest name' to 'Latest Name'

func PyinNumber added in v1.4.1

func PyinNumber(word string, seqs ...string) string

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 added in v1.4.2

func PyinNumberList(word []string) []string

PyinNumberList convert the pinyin number to C and output the list

func ReadDickFromByteKv

func ReadDickFromByteKv(content []byte) map[string]string

ReadDickFromByteKv read file and parse from ini files

func ReadDickFromIni

func ReadDickFromIni(filename string) map[string]map[string]string

ReadDickFromIni read file and parse from ini files

func ReadIniLines

func ReadIniLines(lines []string) map[string]map[string]string

ReadIniLines read ini file as line array, support [key], and repeat parse line.

Types

type Element added in v1.4.0

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 added in v1.4.1

func (e Element) FirstPinyin() string

FirstPinyin if pinyin exists get the first pinyin, compatible with polyphonics

func (Element) IsEmpty added in v1.4.1

func (e Element) IsEmpty() bool

IsEmpty test if is empty that support all unicode

func (Element) PinyinList added in v1.4.1

func (e Element) PinyinList() []string

PinyinList get the polyphonic pinyin as list

func (Element) Polyphony added in v1.4.1

func (e Element) Polyphony() bool

Polyphony test if the pinyin is polyphonic

type List added in v1.4.1

type List []Element

List the list of elements

func (List) Alpha added in v1.4.1

func (e List) Alpha(seps ...string) string

Alpha Alpha(seps, fmt string)

func (List) Number added in v1.4.1

func (e List) Number(seps ...string) string

Number Number(seps, fmt string)

func (List) Polyphony added in v1.4.2

func (e List) Polyphony(vType int32, args ...string) []string

Polyphony gets all columns composed of polyphonics

Polyphony(vType int32, join string)

func (List) String added in v1.4.1

func (e List) String() string

func (List) Text added in v1.4.1

func (e List) Text() []string

Text get pinyin text as the list of element

func (List) Tone added in v1.4.1

func (e List) Tone(seps ...string) string

Tone Tone(seps, fmt string)

type Pinyin

type Pinyin struct {
	// contains filtered or unexported fields
}

Pinyin the pinyin dick creator

func NewPinyin

func NewPinyin(filename string) *Pinyin
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) Dicks

func (pyt *Pinyin) Dicks() map[string]Element

func (*Pinyin) FileLoadSuccess added in v1.4.0

func (pyt *Pinyin) FileLoadSuccess() bool

func (*Pinyin) GetPyTone

func (pyt *Pinyin) GetPyTone(chinese string) string

GetPyTone get pinyin with tone

func (*Pinyin) GetPyToneAlpha

func (pyt *Pinyin) GetPyToneAlpha(chinese string) string

GetPyToneAlpha get pinyin without tone

func (*Pinyin) GetPyToneFunc

func (pyt *Pinyin) GetPyToneFunc(chinese string, call func(string) string) string

GetPyToneFunc get pinyin with tone by callback Func

func (*Pinyin) GetPyToneNumber

func (pyt *Pinyin) GetPyToneNumber(chinese string) string

GetPyToneNumber get pinyin with tone that replace by number (1-4)

func (*Pinyin) IsEmpty added in v1.4.2

func (pyt *Pinyin) IsEmpty() bool

func (*Pinyin) Len added in v1.4.1

func (pyt *Pinyin) Len() int

Len get the length of dicks

func (*Pinyin) LineToDick

func (pyt *Pinyin) LineToDick(lines []string) *Pinyin

LineToDick turn lines to dick data.

func (*Pinyin) SearchAlpha added in v1.4.1

func (pyt *Pinyin) SearchAlpha(alpha string, limits ...int) List

SearchAlpha search word by single alpha

func (*Pinyin) SearchByGroup added in v1.4.1

func (pyt *Pinyin) SearchByGroup(words string) List

SearchByGroup @todo implement grouped text queries

func (*Pinyin) SearchByGroupFunc added in v1.4.1

func (pyt *Pinyin) SearchByGroupFunc(s string, call func(el Element))

SearchByGroupFunc @todo implement grouped text queries and call callback functions

type ZhSentences added in v1.4.1

type ZhSentences string

ZhSentences Chinese sentences

func (ZhSentences) Len added in v1.4.1

func (s ZhSentences) Len() int

Len calculate the length of Chinese sentences

func (ZhSentences) Words added in v1.4.1

func (s ZhSentences) Words() []string

Words split sentences into words

Directories

Path Synopsis
Package material the Material of pinyin dick, it's `embed`.
Package material the Material of pinyin dick, it's `embed`.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL