Skip to content

Commit

Permalink
optimize handleYW code and update godoc
Browse files Browse the repository at this point in the history
  • Loading branch information
vcaesar committed Oct 3, 2021
1 parent 843c92c commit 1fde2e5
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 8 deletions.
10 changes: 9 additions & 1 deletion gpy.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
// Copyright (c) 2016 mozillazg
// Copyright (c) 2017 go-ego
//
// All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.

package gpy

import (
Expand All @@ -11,7 +18,8 @@ import (
const (
// Version get the gpy version
Version = "v0.40.0.133"
// License = "MIT"
// License get the license
License = "MIT"
)

// GetVersion get the version
Expand Down
8 changes: 7 additions & 1 deletion phrase/paragraph.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
// Copyright (c) 2017 go-ego
//
// All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.

package phrase

import (
Expand Down Expand Up @@ -74,7 +80,7 @@ func Paragraph(p string, segs ...gse.Segmenter) (s string) {

s += " " + string(result[0][0]) + " "
} else {
// Other chars
// Not han chars
char := string(r)

if allowCharsRegexp.MatchString(char) {
Expand Down
10 changes: 8 additions & 2 deletions phrase/phrase.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
// Copyright (c) 2017 go-ego
//
// All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.

package phrase

import (
Expand All @@ -11,7 +17,7 @@ var (
seg gse.Segmenter
loaded bool

// Cut set pinyinPhrase cut
// Cut set the pinyin phrase cut
Cut = true
)

Expand All @@ -21,7 +27,7 @@ func LoadGseDict(files ...string) error {
return seg.LoadDict(files...)
}

// WithGse register gse segmenter
// WithGse register the gse segmenter
func WithGse(segs gse.Segmenter) {
seg = segs
loaded = true
Expand Down
19 changes: 15 additions & 4 deletions pinyin.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
// Copyright (c) 2016 mozillazg
// Copyright (c) 2017 go-ego
//
// All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.

package gpy

import (
Expand Down Expand Up @@ -118,13 +125,17 @@ func handleYW(p string) string {
// 特例 y/w
if strings.HasPrefix(p, "yu") {
p = "v" + p[2:] // yu -> v
} else if strings.HasPrefix(p, "yi") {
}
if strings.HasPrefix(p, "yi") {
p = p[1:] // yi -> i
} else if strings.HasPrefix(p, "y") {
}
if strings.HasPrefix(p, "y") {
p = "i" + p[1:] // y -> i
} else if strings.HasPrefix(p, "wu") {
}
if strings.HasPrefix(p, "wu") {
p = p[1:] // wu -> u
} else if strings.HasPrefix(p, "w") {
}
if strings.HasPrefix(p, "w") {
p = "u" + p[1:] // w -> u
}
return p
Expand Down

0 comments on commit 1fde2e5

Please sign in to comment.