From 1fde2e590792a4b7f0615c6050258ad522c8a4c4 Mon Sep 17 00:00:00 2001 From: vcaesar Date: Sun, 3 Oct 2021 13:42:49 -0400 Subject: [PATCH] optimize handleYW code and update godoc --- gpy.go | 10 +++++++++- phrase/paragraph.go | 8 +++++++- phrase/phrase.go | 10 ++++++++-- pinyin.go | 19 +++++++++++++++---- 4 files changed, 39 insertions(+), 8 deletions(-) diff --git a/gpy.go b/gpy.go index 93174ef..7dfaf9a 100644 --- a/gpy.go +++ b/gpy.go @@ -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 ( @@ -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 diff --git a/phrase/paragraph.go b/phrase/paragraph.go index 8d75d39..34e5c45 100644 --- a/phrase/paragraph.go +++ b/phrase/paragraph.go @@ -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 ( @@ -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) { diff --git a/phrase/phrase.go b/phrase/phrase.go index 899c8e2..b97a267 100644 --- a/phrase/phrase.go +++ b/phrase/phrase.go @@ -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 ( @@ -11,7 +17,7 @@ var ( seg gse.Segmenter loaded bool - // Cut set pinyinPhrase cut + // Cut set the pinyin phrase cut Cut = true ) @@ -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 diff --git a/pinyin.go b/pinyin.go index dc62fbd..59b3134 100755 --- a/pinyin.go +++ b/pinyin.go @@ -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 ( @@ -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