Skip to content

Commit

Permalink
Merge pull request #10 from go-ego/i-pr
Browse files Browse the repository at this point in the history
add paragraph pinyin initial support
  • Loading branch information
vcaesar authored Jul 1, 2020
2 parents 211f676 + 143db25 commit 6812ea3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
10 changes: 10 additions & 0 deletions phrase/paragraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ func Pinyin(p string, segs ...gse.Segmenter) []string {
return strings.Split(Paragraph(p, segs...), " ")
}

// Initial return pinyin initial
func Initial(p string, segs ...gse.Segmenter) (s string) {
a := Pinyin(p, segs...)
for _, v := range a {
s += string([]rune(v)[0])
}

return
}

// Paragraph convert a Chinese string paragraph to pinyin,
// including letters, numbers, symbols
func Paragraph(p string, segs ...gse.Segmenter) (s string) {
Expand Down
3 changes: 3 additions & 0 deletions phrase/paragraph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,7 @@ func TestPinyin(t *testing.T) {
AddDict("都会区", "dū huì qū")
p := Pinyin("西雅图都会区, 西雅图太空针")
tt.Equal(t, "[xi ya tu du hui qu, xi ya tu tai kong zhen]", p)

i := Initial("都会区")
tt.Equal(t, "dhq", i)
}

0 comments on commit 6812ea3

Please sign in to comment.