feat(Go-StudyExample):2020/12/15: 新增通过pinyin包获取中文拼音的使用示例
This commit is contained in:
@@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* @Author : huangzj
|
||||||
|
* @Time : 2020/12/15 14:29
|
||||||
|
* @Description:
|
||||||
|
*/
|
||||||
|
|
||||||
|
package pinyin
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/mozillazg/go-pinyin"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestPinyin(t *testing.T) {
|
||||||
|
hans := "中国人"
|
||||||
|
|
||||||
|
// 默认
|
||||||
|
a := pinyin.NewArgs()
|
||||||
|
fmt.Println(pinyin.Pinyin(hans, a))
|
||||||
|
// [[zhong] [guo] [ren]]
|
||||||
|
|
||||||
|
// 包含声调
|
||||||
|
a.Style = pinyin.Tone
|
||||||
|
fmt.Println(pinyin.Pinyin(hans, a))
|
||||||
|
// [[zhōng] [guó] [rén]]
|
||||||
|
|
||||||
|
// 声调用数字表示
|
||||||
|
a.Style = pinyin.Tone2
|
||||||
|
fmt.Println(pinyin.Pinyin(hans, a))
|
||||||
|
// [[zho1ng] [guo2] [re2n]]
|
||||||
|
|
||||||
|
// 开启多音字模式
|
||||||
|
a = pinyin.NewArgs()
|
||||||
|
a.Heteronym = true
|
||||||
|
fmt.Println(pinyin.Pinyin(hans, a))
|
||||||
|
// [[zhong zhong] [guo] [ren]]
|
||||||
|
a.Style = pinyin.Tone2
|
||||||
|
fmt.Println(pinyin.Pinyin(hans, a))
|
||||||
|
// [[zho1ng zho4ng] [guo2] [re2n]]
|
||||||
|
|
||||||
|
fmt.Println(pinyin.LazyPinyin(hans, pinyin.NewArgs()))
|
||||||
|
// [zhong guo ren]
|
||||||
|
|
||||||
|
fmt.Println(pinyin.Convert(hans, nil))
|
||||||
|
// [[zhong] [guo] [ren]]
|
||||||
|
|
||||||
|
fmt.Println(pinyin.LazyConvert(hans, nil))
|
||||||
|
// [zhong guo ren]
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
获取拼音包命令: go get -u github.com/mozillazg/go-pinyin
|
||||||
|
|
||||||
|
获取CLI及使用方式:
|
||||||
|
|
||||||
|
获取命令:go get -u github.com/mozillazg/go-pinyin/cmd/pinyin
|
||||||
|
|
||||||
|
Terminal输入:pinyin 中国人
|
||||||
|
|
||||||
|
Terminal输出:zhōng guó rén
|
||||||
@@ -17,6 +17,8 @@ json与struct之间转换处理工具使用示例
|
|||||||
|
|
||||||
2020/12/15: 新增通过gopsutil包读取服务器信息的方法
|
2020/12/15: 新增通过gopsutil包读取服务器信息的方法
|
||||||
|
|
||||||
|
2020/12/15: 新增通过pinyin包获取中文拼音的使用示例
|
||||||
|
|
||||||
# mod vendor模式加载包
|
# mod vendor模式加载包
|
||||||
通过go mod的方式加载的github上面的包会有报红的问题,但是包本身是可以运行的,这样就是会有一个问题,如果你想要点击去看方法的内容,没办法做到
|
通过go mod的方式加载的github上面的包会有报红的问题,但是包本身是可以运行的,这样就是会有一个问题,如果你想要点击去看方法的内容,没办法做到
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user