Documentation
¶
Overview ¶
Package zhkit 提供中文处理工具包 支持汉字转拼音、拼音分词、简繁互转、数字转换、金额转换等功能
Index ¶
- func ChineseToNumber(chineseNum string) (float64, error)
- func LoadGlobalData(dataPath string) error
- func LoadGlobalEmbeddedData() error
- func SplitPinyin(pinyin string) ([]string, error)
- func SplitPinyinArray(pinyin string) ([][]string, error)
- func ToChineseNumber(number interface{}, options *NumberOptions) (string, error)
- func ToCurrencyNumber(amount interface{}, unit string) (string, error)
- func ToSimplified(text string) ([]string, error)
- func ToTraditional(text string) ([]string, error)
- type CharData
- type Chinese
- func (c *Chinese) ChineseToNumber(chineseNum string) (float64, error)
- func (c *Chinese) LoadPinyinData(dataPath string) error
- func (c *Chinese) LoadPinyinSplitData(dataPath string) error
- func (c *Chinese) LoadSimplifiedTraditionalData(dataPath string) error
- func (c *Chinese) SaveDataToJSON(dataPath string) error
- func (c *Chinese) SplitPinyin(pinyin string) ([]string, error)
- func (c *Chinese) SplitPinyinArray(pinyin string) ([][]string, error)
- func (c *Chinese) ToChineseNumber(number interface{}, options *NumberOptions) (string, error)
- func (c *Chinese) ToCurrencyNumber(amount interface{}, unit string) (string, error)
- func (c *Chinese) ToPinyin(text string, mode ConvertMode, separator string, splitNonChinese bool) (*PinyinResult, error)
- func (c *Chinese) ToSimplified(text string) ([]string, error)
- func (c *Chinese) ToTraditional(text string) ([]string, error)
- type ConvertMode
- type DataLoader
- type NumberOptions
- type PinyinResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ChineseToNumber ¶
ChineseToNumber 全局函数:中文数字转阿拉伯数字
func LoadGlobalEmbeddedData ¶
func LoadGlobalEmbeddedData() error
LoadGlobalEmbeddedData 为全局实例加载嵌入数据
func SplitPinyinArray ¶
SplitPinyinArray 全局函数:拼音分词(返回数组)
func ToChineseNumber ¶
func ToChineseNumber(number interface{}, options *NumberOptions) (string, error)
ToChineseNumber 全局函数:阿拉伯数字转中文数字
func ToCurrencyNumber ¶
ToCurrencyNumber 全局函数:数字转金额大写
Types ¶
type CharData ¶
type CharData struct {
Char string `json:"char"`
Pinyin []string `json:"pinyin,omitempty"`
Simplified []string `json:"simplified,omitempty"`
Traditional []string `json:"traditional,omitempty"`
}
CharData 字符数据结构
type Chinese ¶
type Chinese struct {
// contains filtered or unexported fields
}
Chinese 中文工具类
func NewChineseWithFullData ¶
func NewChineseWithFullData() *Chinese
NewChineseWithFullData 创建包含完整数据的Chinese实例
func (*Chinese) ChineseToNumber ¶
ChineseToNumber 中文数字转阿拉伯数字
func (*Chinese) LoadPinyinData ¶
LoadPinyinData 加载拼音数据
func (*Chinese) LoadPinyinSplitData ¶
LoadPinyinSplitData 加载拼音分词数据
func (*Chinese) LoadSimplifiedTraditionalData ¶
LoadSimplifiedTraditionalData 加载简繁转换数据
func (*Chinese) SaveDataToJSON ¶
SaveDataToJSON 保存数据到JSON文件
func (*Chinese) SplitPinyin ¶
SplitPinyin 拼音分词(返回字符串)
func (*Chinese) SplitPinyinArray ¶
SplitPinyinArray 拼音分词(返回数组)
func (*Chinese) ToChineseNumber ¶
func (c *Chinese) ToChineseNumber(number interface{}, options *NumberOptions) (string, error)
ToChineseNumber 阿拉伯数字转中文数字 number: 要转换的数字(支持整数和小数) options: 转换选项
func (*Chinese) ToCurrencyNumber ¶
ToCurrencyNumber 数字转金额大写 amount: 金额数字 unit: 货币单位(如"元"、"圆"等)
func (*Chinese) ToPinyin ¶
func (c *Chinese) ToPinyin(text string, mode ConvertMode, separator string, splitNonChinese bool) (*PinyinResult, error)
ToPinyin 汉字转拼音 text: 要转换的文本 mode: 转换模式,可以使用位运算组合多种模式 separator: 分隔符,默认为空格 splitNonChinese: 是否分割非中文字符
func (*Chinese) ToSimplified ¶
ToSimplified 繁体转简体
type ConvertMode ¶
type ConvertMode int
ConvertMode 转换模式
const ( // ModePinyin 全拼模式 ModePinyin ConvertMode = 1 << iota // ModePinyinFirst 首字母模式 ModePinyinFirst // ModePinyinSound 读音模式(带声调符号) ModePinyinSound // ModePinyinSoundNumber 读音数字模式(数字声调) ModePinyinSoundNumber )
type DataLoader ¶
type DataLoader struct {
// contains filtered or unexported fields
}
DataLoader 数据加载器
func (*DataLoader) LoadFromJSON ¶
func (dl *DataLoader) LoadFromJSON(filename string) (map[string]*CharData, error)
LoadFromJSON 从JSON文件加载数据
type NumberOptions ¶
type NumberOptions struct {
TenMin bool // "一十二" => "十二"
}
NumberOptions 数字转换选项
type PinyinResult ¶
type PinyinResult struct {
Pinyin [][]string `json:"pinyin,omitempty"`
PinyinFirst [][]string `json:"pinyinFirst,omitempty"`
PinyinSound [][]string `json:"pinyinSound,omitempty"`
PinyinSoundNumber [][]string `json:"pinyinSoundNumber,omitempty"`
}
PinyinResult 拼音转换结果
func ToPinyin ¶
func ToPinyin(text string, mode ConvertMode, separator string, splitNonChinese bool) (*PinyinResult, error)
ToPinyin 全局函数:汉字转拼音