chinese_pinyin 0.4.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/README.md +4 -3
- data/data/Mandarin.dat +1 -1
- data/lib/chinese_pinyin.rb +7 -2
- data/lib/chinese_pinyin/version.rb +1 -1
- data/test/chinese_pinyin_test.rb +10 -5
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a9f52834ca02f14942f04d417cd8b2ca6d85122c
|
4
|
+
data.tar.gz: 9ef90e6814d79ff3d64aa689c83470ecc3a43b32
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7cb52230fd8925c6890a29cd66f6f83efc556620ba1fce0ba350a71ee2d3486b85d93b5f33cd651a188f09e9cd36f1ec533c7a2d36d8f2ced02dd32addb4fa9
|
7
|
+
data.tar.gz: 5f2aedc8e48604305fad99266729c9aed4aff66ae589c31522c35e2409060df6eff57892e785d3450a8b1d4373c7a41a43f4a2a0f15e4da64e12a7de381fb6d5
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
chinese_pinyin
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.0.0
|
data/README.md
CHANGED
@@ -17,9 +17,10 @@ Usage
|
|
17
17
|
require 'chinese_pinyin'
|
18
18
|
|
19
19
|
Pinyin.t('中国') => "zhong guo"
|
20
|
-
Pinyin.t('中国', '-') => "zhong-guo"
|
21
|
-
Pinyin.t('中国', '') => "zhongguo"
|
22
20
|
Pinyin.t('你好world') => "ni hao world"
|
21
|
+
Pinyin.t('中国', splitter: '-') => "zhong-guo"
|
22
|
+
Pinyin.t('中国', splitter: '') => "zhongguo"
|
23
|
+
Pinyin.t('中国', tone: true) => "zhong1 guo2"
|
23
24
|
|
24
25
|
Polyphone Issue
|
25
26
|
---------------
|
@@ -32,7 +33,7 @@ by default
|
|
32
33
|
|
33
34
|
add file Words.dat
|
34
35
|
|
35
|
-
广州|
|
36
|
+
广州|guang3 zhou1
|
36
37
|
|
37
38
|
set ENV['WORDS_FILE'] for Words.dat
|
38
39
|
|
data/data/Mandarin.dat
CHANGED
data/lib/chinese_pinyin.rb
CHANGED
@@ -31,7 +31,10 @@ class Pinyin
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
def translate(chars,
|
34
|
+
def translate(chars, options={})
|
35
|
+
splitter = options[:splitter] || ' '
|
36
|
+
tone = options[:tone] || false
|
37
|
+
|
35
38
|
init_word_table
|
36
39
|
return @words_table[chars].gsub(' ', splitter) if @words_table[chars]
|
37
40
|
|
@@ -42,7 +45,9 @@ class Pinyin
|
|
42
45
|
key = sprintf("%X", char.unpack("U").first)
|
43
46
|
if @table[key]
|
44
47
|
results << splitter if is_english
|
45
|
-
|
48
|
+
pinyin = @table[key].chomp.split(' ', 2)[0].downcase
|
49
|
+
pinyin.chop! unless tone
|
50
|
+
results << pinyin
|
46
51
|
results << splitter
|
47
52
|
is_english = false
|
48
53
|
else
|
data/test/chinese_pinyin_test.rb
CHANGED
@@ -6,12 +6,17 @@ ENV["WORDS_FILE"] = File.dirname(__FILE__) + '/Words.dat'
|
|
6
6
|
class PinyinTest < Test::Unit::TestCase
|
7
7
|
def test_t
|
8
8
|
assert_equal("zhong guo", Pinyin.t('中国'))
|
9
|
-
assert_equal("zhong-guo", Pinyin.t('中国', '-'))
|
10
|
-
|
11
|
-
assert_equal("huangzhimin", Pinyin.t('黄志敏', ''))
|
12
|
-
|
13
9
|
assert_equal("zhong guo english ri", Pinyin.t('中国english日'))
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_t_with_splitter
|
13
|
+
assert_equal("zhong-guo", Pinyin.t('中国', splitter: '-'))
|
14
|
+
assert_equal("huangzhimin", Pinyin.t('黄志敏', splitter: ''))
|
15
|
+
assert_equal("guang-zhou", Pinyin.t('广州', splitter: '-'))
|
16
|
+
end
|
14
17
|
|
15
|
-
|
18
|
+
def test_t_with_tone
|
19
|
+
assert_equal("zhong1 guo2", Pinyin.t('中国', tone: true))
|
20
|
+
assert_equal("huang2 zhi4 min3", Pinyin.t('黄志敏', tone: true))
|
16
21
|
end
|
17
22
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chinese_pinyin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Huang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: translate chinese hanzi to pinyin.
|
14
14
|
email:
|
@@ -18,6 +18,8 @@ extensions: []
|
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
20
|
- .gitignore
|
21
|
+
- .ruby-gemset
|
22
|
+
- .ruby-version
|
21
23
|
- Gemfile
|
22
24
|
- MIT-LICENSE
|
23
25
|
- README.md
|
@@ -48,7 +50,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
48
50
|
version: 1.3.6
|
49
51
|
requirements: []
|
50
52
|
rubyforge_project:
|
51
|
-
rubygems_version: 2.0.
|
53
|
+
rubygems_version: 2.0.3
|
52
54
|
signing_key:
|
53
55
|
specification_version: 4
|
54
56
|
summary: translate chinese hanzi to pinyin.
|