go-common/vendor/github.com/go-ego/gpy
2019-04-22 18:49:16 +08:00
..
BUILD.bazel Create & Init Project... 2019-04-22 18:49:16 +08:00
CHANGELOG.md Create & Init Project... 2019-04-22 18:49:16 +08:00
circle.yml Create & Init Project... 2019-04-22 18:49:16 +08:00
CONTRIBUTING.md Create & Init Project... 2019-04-22 18:49:16 +08:00
doc.go Create & Init Project... 2019-04-22 18:49:16 +08:00
LICENSE Create & Init Project... 2019-04-22 18:49:16 +08:00
Makefile Create & Init Project... 2019-04-22 18:49:16 +08:00
phonetic_symbol.go Create & Init Project... 2019-04-22 18:49:16 +08:00
pinyin_dict.go Create & Init Project... 2019-04-22 18:49:16 +08:00
pinyin.go Create & Init Project... 2019-04-22 18:49:16 +08:00
README_zh.md Create & Init Project... 2019-04-22 18:49:16 +08:00
README.md Create & Init Project... 2019-04-22 18:49:16 +08:00

gpy

CircleCI Status Build Status codecov Go Report Card GoDoc

汉语拼音转换工具 Go 版。

简体中文

Installation

go get -u github.com/go-ego/gpy

install CLI tool:

go get -u github.com/go-ego/gpy/pinyin
$ gpy 中国人
zhōng guó rén

Documentation

API documentation can be found here: godoc

Usage

package main

import (
	"fmt"

	"github.com/go-ego/gpy"
)

func main() {
	hans := "中国人"

	// 默认
	a := gpy.NewArgs()
	fmt.Println(gpy.Pinyin(hans, a))
	// [[zhong] [guo] [ren]]

	// 包含声调
	a.Style = gpy.Tone
	fmt.Println(gpy.Pinyin(hans, a))
	// [[zhōng] [guó] [rén]]

	// 声调用数字表示
	a.Style = gpy.Tone2
	fmt.Println(gpy.Pinyin(hans, a))
	// [[zho1ng] [guo2] [re2n]]

	// 开启多音字模式
	a = gpy.NewArgs()
	a.Heteronym = true
	fmt.Println(gpy.Pinyin(hans, a))
	// [[zhong zhong] [guo] [ren]]
	a.Style = gpy.Tone2
	fmt.Println(gpy.Pinyin(hans, a))
	// [[zho1ng zho4ng] [guo2] [re2n]]

	fmt.Println(gpy.LazyPinyin(hans, gpy.NewArgs()))
	// [zhong guo ren]

	fmt.Println(gpy.Convert(hans, nil))
	// [[zhong] [guo] [ren]]

	fmt.Println(gpy.LazyConvert(hans, nil))
	// [zhong guo ren]
}

License

Under the MIT License, base on go-pinyin.