Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/go-ego/gpy
Go 语言汉字转拼音工具
https://github.com/go-ego/gpy
chinese go golang pinyin
Last synced: 3 months ago
JSON representation
Go 语言汉字转拼音工具
- Host: GitHub
- URL: https://github.com/go-ego/gpy
- Owner: go-ego
- License: mit
- Created: 2017-06-24T14:56:50.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2024-05-13T08:17:14.000Z (6 months ago)
- Last Synced: 2024-06-20T00:40:24.587Z (5 months ago)
- Topics: chinese, go, golang, pinyin
- Language: Go
- Homepage:
- Size: 1.1 MB
- Stars: 187
- Watchers: 14
- Forks: 37
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
- go-awesome - gpy - Pinyin tool to convert Chinese characters to Go language (Open source library / Word Processing)
README
# gpy
[![Build Status](https://github.com/go-ego/gpy/workflows/Go/badge.svg)](https://github.com/go-ego/gpy/commits/master)
[![CircleCI Status](https://circleci.com/gh/go-ego/gpy.svg?style=shield)](https://circleci.com/gh/go-ego/gpy)
[![Build Status](https://travis-ci.org/go-ego/gpy.svg?branch=master)](https://travis-ci.org/go-ego/gpy)
[![codecov](https://codecov.io/gh/go-ego/gpy/branch/master/graph/badge.svg)](https://codecov.io/gh/go-ego/gpy)
[![Go Report Card](https://goreportcard.com/badge/github.com/go-ego/gpy)](https://goreportcard.com/report/github.com/go-ego/gpy)
[![GoDoc](https://godoc.org/github.com/go-ego/gpy?status.svg)](https://godoc.org/github.com/go-ego/gpy)汉语拼音转换工具 Go 版。
[简体中文](https://github.com/go-ego/gpy/blob/master/README_zh.md)
## Installation
```
go get -u github.com/go-ego/gpy
```### Install CLI tool:
```
go get -u github.com/go-ego/gpy/tools/pinyin
$ pinyin 中国话
zhōng guó huà$ pinyin -s zhao 中国话
zhong guo hua
```## Usage
```go
package mainimport (
"fmt""github.com/go-ego/gse"
"github.com/go-ego/gpy"
"github.com/go-ego/gpy/phrase"
)var test = `西雅图都会区; 长夜漫漫, winter is coming!`
func main() {
args := gpy.Args{
Style: gpy.Tone,
Heteronym: true}py := gpy.Pinyin(test, args)
fmt.Println("gpy:", py)s := gpy.ToString(py)
fmt.Println("gpy string:", s)phrase.LoadGseDict()
go func() {
fmt.Println("gpy phrase1:", phrase.Paragraph(test))
}()
fmt.Println("gpy phrase2:", phrase.Paragraph(test))seg := gse.New("zh, dict.txt")
// phrase.DictAdd["都会区"] = "dū huì qū"
phrase.AddDict("都会区", "dū huì qū")fmt.Println("gpy phrase:", phrase.Paragraph(test, seg))
fmt.Println("pinyin: ", phrase.Pinyin(test))
fmt.Println("Initial: ", phrase.Initial("都会区"))
}
``````go
package mainimport (
"fmt""github.com/go-ego/gpy"
)func main() {
hans := "中国话"// 默认
a := gpy.NewArgs()
fmt.Println(gpy.Pinyin(hans, a))
// [[zhong] [guo] [hua]]// 包含声调
a.Style = gpy.Tone
fmt.Println(gpy.Pinyin(hans, a))
// [[zhōng] [guó] [huà]]// 声调用数字表示
a.Style = gpy.Tone2
fmt.Println(gpy.Pinyin(hans, a))
// [[zho1ng] [guo2] [hua4]]// 开启多音字模式
a = gpy.NewArgs()
a.Heteronym = true
fmt.Println(gpy.Pinyin(hans, a))
// [[zhong zhong] [guo] [hua]]
a.Style = gpy.Tone2
fmt.Println(gpy.Pinyin(hans, a))
// [[zho1ng zho4ng] [guo2] [hua4]]fmt.Println(gpy.LazyPinyin(hans, gpy.NewArgs()))
// [zhong guo hua]fmt.Println(gpy.Convert(hans, nil))
// [[zhong] [guo] [hua]]fmt.Println(gpy.LazyConvert(hans, nil))
// [zhong guo hua]
}
```## Related Projects
* [hotoo/pinyin](https://github.com/hotoo/pinyin): 汉语拼音转换工具 Node.js/JavaScript 版。
* [mozillazg/python-pinyin](https://github.com/mozillazg/python-pinyin): 汉语拼音转换工具 Python 版。
* [mozillazg/rust-pinyin](https://github.com/mozillazg/rust-pinyin): 汉语拼音转换工具 Rust 版。## License
Under the MIT License, base on [go-pinyin](https://github.com/mozillazg/go-pinyin).