Get Pinyin Of Simplified Chinese
In you project root path just run go get github.com/struCoder/Go-pinyin
if you want to run go test
you should open tools.go file and change getDictPath function to
func getDictPath() string {
currentPath, _ := os.Getwd()
return currentPath + "/dict/"
}
and also if you have good idea to avoid this way, I'd appreciate any ideas you could give me!
import (
"fmt"
"github.com/struCoder/Go-pinyin"
)
func main() {
str := "**"
str1 := "重阳"
py := pinyingo.NewPy(pinyingo.STYLE_TONE, pinyingo.NO_SEGMENT) //string with tone -> **: ["zhōng", "guó"]
//py := pinyingo.NewPy(pinyingo.STYLE_NORMAL, pinyingo.NO_SEGMENT) //string without tone -> **: ["zhong", "guo"]
//py := pinyingo.NewPy(pinyingo.STYLE_INITIALS, pinyingo.NO_SEGMENT) // get initials of string -> **: ["zh", "g"]
//segment
py := pinyingo.NewPy(pinyingo.STYLE_TONE, pinyingo.USE_SEGMENT) //string with tone -> 重阳: ["chóng", "yáng"]
fmt.Println(py.Convert(str))
}
- convert han zi to pinyin
- get han zi initial
- deal with segment