Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
mozillazg committed Jun 13, 2020
2 parents 63be21f + b61fa0f commit 03767c7
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 52 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# Changelog

## [0.18.0] (2020-mm-dd)
* **Changed** 使用 [pinyin-data][pinyin-data] v0.9.0 的拼音数据
* **Bugfixed** 修复自定义的 Fallback 函数可能会导致结果乱码的问题 Fixes [#35]

## [0.17.0] (2020-04-09)

* **Changed** 因为依赖的 gojieba 经常出现安装异常,撤销 v0.16.0 的修改,撤销后 v0.17.0 的代码跟 v0.15.0 基本是一样的。
如果有需要使用 v0.16.0 新增的 ``func Paragraph(p string) string`` 功能的请使用 v0.16.0 版本或者通过 v0.16.0 中相关代码实现类似的需求。


## [0.16.0] (2019-12-05)

* **NEW** 增加 ``func Paragraph(p string) string`` 用于便捷处理大段文字
Expand Down Expand Up @@ -209,6 +212,7 @@
[#20]: https://github.com/mozillazg/go-pinyin/pull/20
[#30]: https://github.com/mozillazg/go-pinyin/pull/30
[#37]: https://github.com/mozillazg/go-pinyin/pull/37
[#35]: https://github.com/mozillazg/go-pinyin/issues/35

[0.1.1]: https://github.com/mozillazg/go-pinyin/compare/v0.1.0...v0.1.1
[0.2.0]: https://github.com/mozillazg/go-pinyin/compare/v0.1.1...v0.2.0
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ func main() {
}
```

注意:

* 默认情况下会忽略没有拼音的字符(可以通过自定义 `Fallback` 参数的值来自定义如何处理没有拼音的字符,
详见 [示例](https://godoc.org/github.com/mozillazg/go-pinyin#example-Pinyin--FallbackCustom1))。
* 根据 [《汉语拼音方案》](http://www.moe.gov.cn/s78/A19/yxs_left/moe_810/s230/195802/t19580201_186000.html) y,w,ü (yu) 都不是声母,
以及不是所有拼音都有什么,如果这不是你预期的话,你可能需要的是首字母风格 `FirstLetter`
[详细信息](https://github.com/mozillazg/python-pinyin#%E4%B8%BA%E4%BB%80%E4%B9%88%E6%B2%A1%E6%9C%89-y-w-yu-%E5%87%A0%E4%B8%AA%E5%A3%B0%E6%AF%8D) )。


Related Projects
-----------------
Expand Down
2 changes: 1 addition & 1 deletion _tools/pinyin-data
4 changes: 2 additions & 2 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ func ExamplePinyin_fallbackCustom1() {
hans := "中国人abc"
a := pinyin.NewArgs()
a.Fallback = func(r rune, a pinyin.Args) []string {
return []string{string(r + 1)}
return []string{string(r)}
}
fmt.Println(pinyin.Pinyin(hans, a))
// Output: [[zhong] [guo] [ren] [b] [c] [d]]
// Output: [[zhong] [guo] [ren] [a] [b] [c]]
}

func ExamplePinyin_fallbackCustom2() {
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
module github.com/mozillazg/go-pinyin

go 1.11
6 changes: 3 additions & 3 deletions pinyin.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const (
Tone = 1 // 声调风格1,拼音声调在韵母第一个字母上。如: zhōng guó
Tone2 = 2 // 声调风格2,即拼音声调在各个韵母之后,用数字 [1-4] 进行表示。如: zho1ng guo2
Tone3 = 8 // 声调风格3,即拼音声调在各个拼音之后,用数字 [1-4] 进行表示。如: zhong1 guo2
Initials = 3 // 声母风格,只返回各个拼音的声母部分。如: zh g
Initials = 3 // 声母风格,只返回各个拼音的声母部分。如: zh g 。注意:不是所有的拼音都有声母
FirstLetter = 4 // 首字母风格,只返回拼音的首字母部分。如: z g
Finals = 5 // 韵母风格,只返回各个拼音的韵母部分,不带声调。如: ong uo
FinalsTone = 6 // 韵母风格1,带声调,声调在韵母第一个字母上。如: ōng uó
Expand Down Expand Up @@ -181,7 +181,7 @@ func toFixed(p string, a Args) string {
switch a.Style {
// 首字母
case FirstLetter:
py = py[:1]
py = string([]rune(py)[0])
// 韵母
case Finals, FinalsTone, FinalsTone2, FinalsTone3:
// 转换为 []rune unicode 编码用于获取第一个拼音字符
Expand Down Expand Up @@ -219,7 +219,7 @@ func SinglePinyin(r rune, a Args) []string {
}
if len(pys) > 0 {
if !a.Heteronym {
pys = pys[:1]
pys = []string{pys[0]}
}
return applyStyle(pys, a)
}
Expand Down
Loading

0 comments on commit 03767c7

Please sign in to comment.