Skip to content

Commit

Permalink
Merge pull request #9 from go-ego/t-pr
Browse files Browse the repository at this point in the history
add WithGse and phrase pinyin []string return support
  • Loading branch information
vcaesar authored Jun 8, 2020
2 parents 06b7c8e + ab0bfb7 commit ac776b6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions phrase/paragraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ var (
}
)

// Pinyin return paragraph []string
func Pinyin(p string, segs ...gse.Segmenter) []string {
return strings.Split(Paragraph(p, segs...), " ")
}

// Paragraph convert a Chinese string paragraph to pinyin,
// including letters, numbers, symbols
func Paragraph(p string, segs ...gse.Segmenter) (s string) {
Expand Down
7 changes: 7 additions & 0 deletions phrase/paragraph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,10 @@ func TestParagraph(t *testing.T) {
}

}

func TestPinyin(t *testing.T) {
seg := gse.New()
WithGse(seg)
p := Pinyin("西雅图太空针")
tt.Equal(t, "[xi ya tu tai kong zhen]", p)
}
6 changes: 6 additions & 0 deletions phrase/phrase.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ func LoadGseDict(files ...string) error {
return seg.LoadDict(files...)
}

// WithGse register gse segmenter
func WithGse(segs gse.Segmenter) {
seg = segs
loaded = true
}

// CutWord cut the string word
func CutWord(s string) []string {
return seg.CutAll(s)
Expand Down

0 comments on commit ac776b6

Please sign in to comment.