diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 0531cdf..e2d59cf 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -5,25 +5,19 @@ jobs: name: Build runs-on: ubuntu-latest steps: + - name: Install Dependencies + run: | + sudo apt-get update + sudo apt-get install -y build-essential cmake - name: Set up Go uses: actions/setup-go@v1 with: - go-version: 1.14 + go-version: 1.21 id: go - - name: Check out code into the Go module directory - uses: actions/checkout@v1 - - - name: Get dependencies - run: | - if ! go get code.google.com/p/go.tools/cmd/cover; then go get golang.org/x/tools/cmd/cover; fi - go get github.com/axw/gocov/gocov - go get github.com/mattn/goveralls - go get ./cmd/pinyin + - name: Check Code + uses: actions/checkout@v4 - name: Test run: | - go run cmd/pinyin/main.go abc - go run cmd/pinyin/main.go -s zhao abc - echo "abc" | go run cmd/pinyin/main.go - echo "abc" > abc.txt && go run cmd/pinyin/main.go < abc.txt + make test diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index b9987df..0000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,221 +0,0 @@ -# Changelog - -## [1.1.0] (2020-07-28) - -* **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` 用于便捷处理大段文字 - (thanks [@huacnlee] via [#37][#37]) - -## [0.15.0] (2019-04-06) - -- **Changed** 使用 [pinyin-data][pinyin-data] v0.7.0 的拼音数据 -- **NEW** 添加 go.mod 文件 - -## [0.14.0] (2018-08-05) - -- **Changed** 使用 [pinyin-data][pinyin-data] v0.6.1 的拼音数据 -- **Changed** 命令行工具移到 `cmd/pinyin/` 目录下,现在需要改为使用 - `go get -u github.com/longbridgeapp/go-pinyin/cmd/pinyin` 来安装命令行工具。 - -## [0.13.0] (2018-04-29) - -- **Changed** 使用 [pinyin-data][pinyin-data] v0.5.1 的拼音数据 (via [#30]) -- **Changed** 修改命令行工具 `-s` 参数的值 (thanks [@wdscxsj][@wdscxsj] via [#19][#19]): - - `Normal` 改为 `zhao` - - `Tone` 改为 `zh4ao` - - `Tone2` 改为 `zha4o` - - `Tone3` 改为 `zhao4` - - `Initials` 改为 `zh` - - `FirstLetter` 改为 `z` - - `Finals` 改为 `ao` - - `FinalsTone` 改为 `4ao` - - `FinalsTone2` 改为 `a4o` - - `FinalsTone3` 改为 `ao4` -- **Changed** 严格限制命令行参数中 `-s` 选项的值 (thanks [@wdscxsj][@wdscxsj] via [#20][#20]): - -## [0.12.0] (2017-04-25) - -- **NEW** 命令行程序支持通过 -s 指定新增的 `Tone3` 和 `FinalsTone3` 拼音风格 - - $ pinyin -s Tone3 请至少输入一个汉字 - qing3 zhi4 shao3 shu1 ru4 yi1 ge4 han4 zi4 - - $ pinyin -s FinalsTone3 请至少输入一个汉字 - ing3 i4 ao3 u1 u4 i1 e4 an4 i4 - -- **Changed** use [pinyin-data](https://github.com/mozillazg/pinyin-data) v0.4.1 - -## [0.11.0] (2016-10-28) - -- **Changed** 不再使用 `0` 表示轻声(因为之前并没有正确的实现这个功能,同时也觉得这个功能没必要)。 - 顺便修复了 Tone2 中 `ü` 标轻声的问题(像 `侵略 -> qi1n lv0e4` ) -- **NEW** 新增 `Tone3` 和 `FinalsTone3` 拼音风格。 - - hans := "中国人" - args := pinyin.NewArgs() - args.Style = pinyin.Tone3 - fmt.Println("Tone3:", pinyin.Pinyin(hans, args)) - // Output: Tone3: [[zhong1] [guo2] [ren2]] - - args.Style = pinyin.FinalsTone3 - fmt.Println("FinalsTone3:", pinyin.Pinyin(hans, args)) - // Output: FinalsTone3: [[ong1] [uo2] [en2]] - -## [0.10.0] (2016-10-18) - -- **Changed** use [pinyin-data](https://github.com/mozillazg/pinyin-data) v0.4.0 - -## [0.9.0] (2016-09-04): - -- **NEW** 新增 `func Convert(s string, a *Args) [][]string` -- **NEW** 新增 `func LazyConvert(s string, a *Args) []string` - -之所以增加这两个函数是希望 `a` 参数支持 `nil` - -## [0.8.0] (2016-08-19) - -- **Changed** use [pinyin-data](https://github.com/mozillazg/pinyin-data) v0.3.0 - - Fixed [#13](https://github.com/longbridgeapp/go-pinyin/issues/13) . thanks [@aisq2008](https://github.com/aisq2008) - - Fixed pinyin of 罗 - -## [0.7.0] (2016-08-02) - -- **Changed** use [pinyin-data](https://github.com/mozillazg/pinyin-data) v0.2.0 -- **Improved** golint and gofmt - -## [0.6.0] (2016-05-14) - -- **NEW** 命令行程序支持指定拼音风格: - - ```shell - $ pinyin -s Normal 你好 - ni hao - ``` - -- **Bugfixed** 解决韵母 i, u, ü 的问题:根据以下拼音方案,还原出正确的韵母 - [#8](https://github.com/longbridgeapp/go-pinyin/pull/8), [python-pinyin#26](https://github.com/mozillazg/python-pinyin/pull/26) - - > i 行的韵母,前面没有声母的时候,写成:yi(衣),yɑ(呀),ye(耶), - > yɑo(腰),you(忧),yɑn(烟),yin(因),yɑnɡ(央),yinɡ(英),yonɡ(雍)。 - > - > u 行的韵母,前面没有声母的时候,写成 wu(乌),wɑ(蛙),wo(窝), - > wɑi(歪),wei(威),wɑn(弯),wen(温),wɑnɡ(汪),wenɡ(翁)。 - > - > ü 行的韵母跟声母 j,q,x 拼的时候,写成 ju(居),qu(区),xu(虚), - > ü 上两点也省略;但是跟声母 l,n 拼的时候,仍然写成 lü(吕),nü(女)。 - - **注意** `y` 既不是声母也不是韵母。详见 [汉语拼音方案](http://www.edu.cn/20011114/3009777.shtml) - -- **Bugfixed** 解决未正确处理鼻音 ḿ, ń, ň, ǹ 的问题:包含鼻音的拼音不应该有声母 - -## [0.5.0] (2016-03-12) - -- **CHANGE** 改为使用来自 [pinyin-data](https://github.com/mozillazg/pinyin-data) 的拼音数据。 -- **NEW** 命令行程序支持从标准输入读取数据(支持管道和重定向输入): - - ```shell - $ echo "你好" | pinyin - nǐ hǎo - $ pinyin < hello.txt - nǐ hǎo - ``` - -## [0.4.0] (2016-01-29) - -- **NEW** `Args` 结构体新增 field: `Fallback func(r rune, a Args) []string` - 用于处理没有拼音的字符(默认忽略没有拼音的字符): - - ```go - a := pinyin.NewArgs() - a.Fallback = func(r rune, a pinyin.Args) []string { - return []string{string(r + 1)} - } - fmt.Println(pinyin.Pinyin("中国人abc", a)) - // Output: [[zhong] [guo] [ren] [b] [c] [d]] - - // or - pinyin.Fallback = func(r rune, a pinyin.Args) []string { - return []string{string(r)} - } - fmt.Println(pinyin.Pinyin("中国人abc", pinyin.NewArgs())) - // Output: [[zhong] [guo] [ren] [a] [b] [c]] - ``` - -## [0.3.0] (2015-12-29) - -- fix "当字符串中有非中文的时候,会出现下标越界的情况"(影响 `pinyin.LazyPinyin` 和 `pinyin.Slug` ([#1](https://github.com/longbridgeapp/go-pinyin/issues/1))) -- 调整对非中文字符的处理:当遇到没有拼音的字符时,直接忽略 - - ```go - // before - fmt.Println(pinyin.Pinyin("中国人abc", pinyin.NewArgs())) - [[zhong] [guo] [ren] [] [] []] - - // after - fmt.Println(pinyin.Pinyin("中国人abc", pinyin.NewArgs())) - [[zhong] [guo] [ren]] - ``` - -## [0.2.1] (2015-08-26) - -- `yu`, `y`, `w` 不是声母 - -## [0.2.0] (2015-01-04) - -- 新增 `func NewArgs() Args` -- 解决 `Args.Separator` 无法赋值为 `""` 的 BUG -- 规范命名: - - `NORMAL` -> `Normal` - - `TONE` -> `Tone` - - `TONE2` -> `Tone2` - - `INITIALS` -> `Initials` - - `FIRST_LETTER` -> `FirstLetter` - - `FINALS` -> `Finals` - - `FINALS_TONE` -> `FinalsTone` - - `FINALS_TONE2` -> `FinalsTone2` - -## [0.1.1] (2014-12-07) - -- 更新拼音库 - -## 0.1.0 (2014-11-23) - -- Initial Release - -[pinyin-data]: https://github.com/mozillazg/pinyin-data -[@wdscxsj]: https://github.com/wdscxsj -[@huacnlee]: https://github.com/huacnlee -[#19]: https://github.com/mozillazg/go-pinyin/pull/19 -[#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 -[0.2.1]: https://github.com/mozillazg/go-pinyin/compare/v0.2.0...v0.2.1 -[0.3.0]: https://github.com/mozillazg/go-pinyin/compare/v0.2.1...v0.3.0 -[0.4.0]: https://github.com/mozillazg/go-pinyin/compare/v0.3.0...v0.4.0 -[0.5.0]: https://github.com/mozillazg/go-pinyin/compare/v0.4.0...v0.5.0 -[0.6.0]: https://github.com/mozillazg/go-pinyin/compare/v0.5.0...v0.6.0 -[0.7.0]: https://github.com/mozillazg/go-pinyin/compare/v0.6.0...v0.7.0 -[0.8.0]: https://github.com/mozillazg/go-pinyin/compare/v0.7.0...v0.8.0 -[0.9.0]: https://github.com/mozillazg/go-pinyin/compare/v0.8.0...v0.9.0 -[0.10.0]: https://github.com/mozillazg/go-pinyin/compare/v0.9.0...v0.10.0 -[0.11.0]: https://github.com/mozillazg/go-pinyin/compare/v0.10.0...v0.11.0 -[0.12.0]: https://github.com/mozillazg/go-pinyin/compare/v0.11.0...v0.12.0 -[0.13.0]: https://github.com/mozillazg/go-pinyin/compare/v0.12.0...v0.13.0 -[0.14.0]: https://github.com/mozillazg/go-pinyin/compare/v0.13.0...v0.14.0 -[0.15.0]: https://github.com/mozillazg/go-pinyin/compare/v0.14.0...v0.15.0 -[0.16.0]: https://github.com/mozillazg/go-pinyin/compare/v0.15.0...v0.16.0 -[0.17.0]: https://github.com/mozillazg/go-pinyin/compare/v0.16.0...v0.17.0 -[0.18.0]: https://github.com/mozillazg/go-pinyin/compare/v0.17.0...v0.18.0 diff --git a/README.md b/README.md index cc95cf9..4a4b2f6 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # go-pinyin -[![Go](https://github.com/longbridgeapp/go-pinyin/actions/workflows/go.yml/badge.svg)](https://github.com/longbridgeapp/go-pinyin/actions/workflows/go.yml) +[![Go](https://github.com/longbridge/go-pinyin/actions/workflows/go.yml/badge.svg)](https://github.com/longbridge/go-pinyin/actions/workflows/go.yml) 汉语拼音转换工具 Go 版。 @@ -9,13 +9,13 @@ ## Installation ``` -go get -u github.com/longbridgeapp/go-pinyin +go get -u github.com/longbridge/go-pinyin ``` install CLI tool: ``` -go get -u github.com/longbridgeapp/go-pinyin/cmd/pinyin +go get -u github.com/longbridge/go-pinyin/cmd/pinyin $ pinyin 中国人 zhōng guó rén ``` @@ -23,7 +23,7 @@ zhōng guó rén ## Documentation API documentation can be found here: -https://pkg.go.dev/github.com/longbridgeapp/go-pinyin +https://pkg.go.dev/github.com/longbridge/go-pinyin ## Usage @@ -32,7 +32,7 @@ package main import ( "fmt" - "github.com/longbridgeapp/go-pinyin" + "github.com/longbridge/go-pinyin" ) func main() { @@ -79,11 +79,11 @@ func main() { 注意: -* 默认情况下会忽略没有拼音的字符(可以通过自定义 `Fallback` 参数的值来自定义如何处理没有拼音的字符, +- 默认情况下会忽略没有拼音的字符(可以通过自定义 `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) 都不是声母, +- 根据 [《汉语拼音方案》](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) )。 + ( [详细信息](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 diff --git a/cmd/pinyin/main.go b/cmd/pinyin/main.go index c3562a7..03c0af0 100644 --- a/cmd/pinyin/main.go +++ b/cmd/pinyin/main.go @@ -7,7 +7,7 @@ import ( "os" "strings" - "github.com/longbridgeapp/go-pinyin" + "github.com/longbridge/go-pinyin" "github.com/mattn/go-isatty" ) diff --git a/doc.go b/doc.go index 18c5cdb..380e73f 100644 --- a/doc.go +++ b/doc.go @@ -7,7 +7,7 @@ Usage import ( "fmt" - "github.com/longbridgeapp/go-pinyin" + "github.com/longbridge/go-pinyin" ) func main() { diff --git a/example_test.go b/example_test.go index 9c2cfb1..5ec0f75 100644 --- a/example_test.go +++ b/example_test.go @@ -3,7 +3,7 @@ package pinyin_test import ( "fmt" - "github.com/longbridgeapp/go-pinyin" + "github.com/longbridge/go-pinyin" ) func ExampleConvert() { diff --git a/go.mod b/go.mod index 8babf01..1f90512 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,8 @@ -module github.com/longbridgeapp/go-pinyin +module github.com/longbridge/go-pinyin -go 1.13 +go 1.18 require ( github.com/mattn/go-isatty v0.0.10 - github.com/yanyiwu/gojieba v1.1.0 + github.com/yanyiwu/gojieba v1.4.4 ) diff --git a/go.sum b/go.sum index 69249fe..ef83887 100644 --- a/go.sum +++ b/go.sum @@ -2,5 +2,7 @@ github.com/mattn/go-isatty v0.0.10 h1:qxFzApOv4WsAL965uUPIsXzAKCZxN2p9UqdhFS4ZW1 github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84= github.com/yanyiwu/gojieba v1.1.0 h1:rx+kNP0L7zn+4Zyo1d8aLCfXt3BmIkWQ26FCbGnw1bc= github.com/yanyiwu/gojieba v1.1.0/go.mod h1:0AAj9tOG6WWXQ5FNffl4ruBy/hP7bHl2gs+YiDi1aYs= +github.com/yanyiwu/gojieba v1.4.4 h1:Iukkf8WlIfqAKtsGZjUhGR1ArKa7DtLDNmW8bvUI8JI= +github.com/yanyiwu/gojieba v1.4.4/go.mod h1:JUq4DddFVGdHXJHxxepxRmhrKlDpaBxR8O28v6fKYLY= golang.org/x/sys v0.0.0-20191008105621-543471e840be h1:QAcqgptGM8IQBC9K/RC4o+O9YmqEm0diQn9QmZw/0mU= golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=