chinese_pinyin 0.8.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -0
- data/CHANGELOG.md +6 -0
- data/README.md +59 -24
- data/bin/ch2py +54 -0
- data/chinese_pinyin.gemspec +3 -0
- data/lib/chinese_pinyin.rb +7 -7
- data/lib/chinese_pinyin/version.rb +1 -1
- metadata +10 -7
- data/.ruby-gemset +0 -1
- data/.ruby-version +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc080c9b7f03c06943898bd0bb415b288179ff64
|
4
|
+
data.tar.gz: 8545806d8f991c6aa1831298e0f665a3e926e658
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d679f93ddfc49e788cb8ec183c8cb394750a2159f0fad93c56f0a689217d4cc74a76e0603eed24c4330055030a7aa3a309bcf1832b30dec30ce934ff64f507c
|
7
|
+
data.tar.gz: 1add5ee967db25b07a2e742c2cf64220f31e151e096b5a15ba0f256bc6e41d39d0b48908171e2c6c97bd916474b451b9ffe2fba9002b475d889ad91c3edc3ca0
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -1,44 +1,79 @@
|
|
1
|
-
ChinesePinyin
|
2
|
-
|
1
|
+
# ChinesePinyin
|
2
|
+
|
3
|
+
[![Build Status](https://secure.travis-ci.org/flyerhzm/chinese_pinyin.png)](http://travis-ci.org/flyerhzm/chinese_pinyin)
|
3
4
|
|
4
5
|
Translate chinese hanzi to pinyin.
|
5
6
|
|
6
7
|
The dict is borrowed from <http://github.com/fayland/perl-lingua-han/tree/master/Lingua-Han-PinYin/>
|
7
8
|
|
8
|
-
Install
|
9
|
-
|
9
|
+
## Install
|
10
|
+
|
11
|
+
```
|
12
|
+
gem install chinese_pinyin
|
13
|
+
```
|
14
|
+
|
15
|
+
or add in Gemfile.
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
gem 'chinese_pinyin'
|
19
|
+
```
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
By CLI
|
24
|
+
|
25
|
+
|
26
|
+
```
|
27
|
+
$ ch2py -h
|
28
|
+
Usage: ch2py [opts]
|
29
|
+
-c, --camelcase Camelcase of each word
|
30
|
+
-i, --stdin Read from stdard input
|
31
|
+
-t, --tone Show tone at end of word
|
32
|
+
-m, --tonemarks Show tone at top of letter, this
|
33
|
+
would cover -t option
|
34
|
+
-s, --splitter <splitter> Splitter of each word, use a space
|
35
|
+
by default
|
36
|
+
-v, --version Show version
|
37
|
+
-h, --help Show this help
|
10
38
|
|
11
|
-
|
39
|
+
$ ch2py 中文
|
40
|
+
zhong wen
|
41
|
+
```
|
12
42
|
|
13
|
-
|
14
|
-
-----
|
43
|
+
By code
|
15
44
|
|
16
|
-
|
17
|
-
|
45
|
+
```
|
46
|
+
require 'chinese_pinyin'
|
18
47
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
48
|
+
Pinyin.t('中国') => "zhong guo"
|
49
|
+
Pinyin.t('你好world') => "ni hao world"
|
50
|
+
Pinyin.t('中国', splitter: '-') => "zhong-guo"
|
51
|
+
Pinyin.t('中国', splitter: '') => "zhongguo"
|
52
|
+
Pinyin.t('中国', tone: true) => "zhong1 guo2"
|
53
|
+
Pinyin.t('中国', tonemarks: true) => "zhōng guó"
|
54
|
+
Pinyin.t('北京') { |letters| letters[0].upcase } => 'BJ'
|
55
|
+
Pinyin.t('北京') { |letters, i| letters[0].upcase if i == 0 } => 'B'
|
56
|
+
```
|
27
57
|
|
28
|
-
Polyphone Issue
|
29
|
-
---------------
|
58
|
+
## Polyphone Issue
|
30
59
|
|
31
60
|
use Words.dat to override default behavior.
|
32
61
|
|
33
62
|
by default
|
34
63
|
|
35
|
-
|
64
|
+
```
|
65
|
+
Pinyin.t('广州') => "yan zhou"
|
66
|
+
```
|
36
67
|
|
37
68
|
add file Words.dat
|
38
69
|
|
39
|
-
|
70
|
+
```
|
71
|
+
广州|guang3 zhou1
|
72
|
+
```
|
40
73
|
|
41
|
-
set ENV['WORDS_FILE'] for Words.dat
|
74
|
+
set `ENV['WORDS_FILE']` for Words.dat
|
42
75
|
|
43
|
-
|
44
|
-
|
76
|
+
```
|
77
|
+
ENV['WORDS_FILE'] = "Words.dat path"
|
78
|
+
Pinyin.t('广州') => "guang zhou"
|
79
|
+
```
|
data/bin/ch2py
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require File.expand_path('../../lib/chinese_pinyin', __FILE__)
|
5
|
+
|
6
|
+
opts = {}
|
7
|
+
|
8
|
+
parser = OptParse.new do |opt|
|
9
|
+
opt.banner = "Usage: ch2py [opts]"
|
10
|
+
|
11
|
+
opt.on('-c', '--camelcase', 'Camelcase of each word') do
|
12
|
+
opts[:camelcase] = true
|
13
|
+
end
|
14
|
+
|
15
|
+
opt.on('-i', '--stdin', 'Read from stdard input') do
|
16
|
+
opts[:stdin] = true
|
17
|
+
end
|
18
|
+
|
19
|
+
opt.on('-t', '--tone', 'Show tone at end of word') do
|
20
|
+
opts[:tone] = true
|
21
|
+
end
|
22
|
+
|
23
|
+
opt.on('-m', '--tonemarks', 'Show tone at top of letter, this would cover -t option') do
|
24
|
+
opts[:tonemarks] = true
|
25
|
+
end
|
26
|
+
|
27
|
+
opt.on('-s', '--splitter <splitter>', 'Splitter of each word, use a space by default') do |sp|
|
28
|
+
opts[:splitter] = sp
|
29
|
+
end
|
30
|
+
|
31
|
+
opt.on('-v', '--version', 'Show version') do
|
32
|
+
puts "ch2py: Version #{ChinesePinyin::VERSION}"
|
33
|
+
exit
|
34
|
+
end
|
35
|
+
|
36
|
+
opt.on('-h', '--help', 'Show this help') do
|
37
|
+
puts parser
|
38
|
+
exit
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
parser.parse!
|
43
|
+
|
44
|
+
args = parser.default_argv
|
45
|
+
|
46
|
+
if opts.fetch(:stdin, false)
|
47
|
+
chars = STDIN.readline
|
48
|
+
elsif args.empty?
|
49
|
+
raise OptParse::MissingArgument
|
50
|
+
else
|
51
|
+
chars = args.join('')
|
52
|
+
end
|
53
|
+
|
54
|
+
STDOUT.puts Pinyin.t(chars, opts)
|
data/chinese_pinyin.gemspec
CHANGED
@@ -6,6 +6,7 @@ require "chinese_pinyin/version"
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "chinese_pinyin"
|
8
8
|
s.version = ChinesePinyin::VERSION
|
9
|
+
s.license = "MIT"
|
9
10
|
s.platform = Gem::Platform::RUBY
|
10
11
|
s.authors = ["Richard Huang", "Hong, Liang"]
|
11
12
|
s.email = ["flyerhzm@gmail.com", "hongliang@bamajia.com"]
|
@@ -18,4 +19,6 @@ Gem::Specification.new do |s|
|
|
18
19
|
s.files = `git ls-files`.split("\n")
|
19
20
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
21
|
s.require_paths = ["lib"]
|
22
|
+
|
23
|
+
s.executables = ["ch2py"]
|
21
24
|
end
|
data/lib/chinese_pinyin.rb
CHANGED
@@ -6,12 +6,12 @@ require 'chinese_pinyin/version'
|
|
6
6
|
class Pinyin
|
7
7
|
|
8
8
|
TONE_MARK = {
|
9
|
-
a: %w(
|
10
|
-
o: %w(
|
11
|
-
e: %w(
|
12
|
-
i: %w(
|
13
|
-
u: %w(
|
14
|
-
v: %w(
|
9
|
+
a: %w(ā á ǎ à a),
|
10
|
+
o: %w(ō ó ǒ ò o),
|
11
|
+
e: %w(ē é ě è e),
|
12
|
+
i: %w(ī í ǐ ì i),
|
13
|
+
u: %w(ū ú ǔ ù u),
|
14
|
+
v: %w(ǖ ǘ ǚ ǜ ü)
|
15
15
|
}
|
16
16
|
|
17
17
|
class <<self
|
@@ -86,7 +86,7 @@ class Pinyin
|
|
86
86
|
tone_index = pinyin[-1].to_i
|
87
87
|
pinyin = pinyin[0...-1]
|
88
88
|
%w(a o e i u v).each { |v|
|
89
|
-
break if pinyin.tr! v, TONE_MARK[v.to_sym][tone_index]
|
89
|
+
break if pinyin.tr! v, TONE_MARK[v.to_sym][tone_index - 1]
|
90
90
|
}
|
91
91
|
end
|
92
92
|
if block_given?
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chinese_pinyin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Huang
|
@@ -9,23 +9,25 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-06-
|
12
|
+
date: 2015-06-22 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: translate chinese hanzi to pinyin.
|
15
15
|
email:
|
16
16
|
- flyerhzm@gmail.com
|
17
17
|
- hongliang@bamajia.com
|
18
|
-
executables:
|
18
|
+
executables:
|
19
|
+
- ch2py
|
19
20
|
extensions: []
|
20
21
|
extra_rdoc_files: []
|
21
22
|
files:
|
22
23
|
- ".gitignore"
|
23
|
-
- ".
|
24
|
-
-
|
24
|
+
- ".travis.yml"
|
25
|
+
- CHANGELOG.md
|
25
26
|
- Gemfile
|
26
27
|
- MIT-LICENSE
|
27
28
|
- README.md
|
28
29
|
- Rakefile
|
30
|
+
- bin/ch2py
|
29
31
|
- chinese_pinyin.gemspec
|
30
32
|
- data/Mandarin.dat
|
31
33
|
- data/pinyin-utf8.dat
|
@@ -35,7 +37,8 @@ files:
|
|
35
37
|
- test/chinese_pinyin_test.rb
|
36
38
|
- test/test_helper.rb
|
37
39
|
homepage: http://github.com/flyerhzm/chinese_pinyin
|
38
|
-
licenses:
|
40
|
+
licenses:
|
41
|
+
- MIT
|
39
42
|
metadata: {}
|
40
43
|
post_install_message:
|
41
44
|
rdoc_options: []
|
@@ -53,7 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
53
56
|
version: 1.3.6
|
54
57
|
requirements: []
|
55
58
|
rubyforge_project:
|
56
|
-
rubygems_version: 2.4.
|
59
|
+
rubygems_version: 2.4.7
|
57
60
|
signing_key:
|
58
61
|
specification_version: 4
|
59
62
|
summary: translate chinese hanzi to pinyin.
|
data/.ruby-gemset
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
chinese_pinyin
|
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
ruby-2.2.2
|