hanzi_to_pinyin 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +8 -4
- data/VERSION +1 -1
- data/lib/hanzi_to_pinyin.rb +13 -6
- metadata +5 -5
data/README.rdoc
CHANGED
@@ -4,9 +4,9 @@ translate chinese to pinyin , fetch first letter OR full pinyin
|
|
4
4
|
|
5
5
|
== Install
|
6
6
|
|
7
|
-
rails3
|
7
|
+
rails3
|
8
8
|
|
9
|
-
$ gem 'hanzi_to_pinyin' , '0.
|
9
|
+
$ gem 'hanzi_to_pinyin' , '0.6.0' , require: 'hanzi_to_pinyin'
|
10
10
|
or latest develop version
|
11
11
|
$ gem 'hanzi_to_pinyin' , git: 'git://github.com/wxianfeng/hanzi_to_pinyin.git'
|
12
12
|
or freeze ref version
|
@@ -26,9 +26,13 @@ or freeze ref version
|
|
26
26
|
$ HanziToPinyin.hanzi_2_py("我们") => "wo;men"
|
27
27
|
$ HanziToPinyin.hanzi_2_py("查理Smith") => "cha,zha;li"
|
28
28
|
$ HanziToPinyin.hanzi_2_py("测试1") => "ce;shi;1"
|
29
|
+
$ HanziToPinyin.hanzi_2_py("测_试") => "ce;_;shi"
|
29
30
|
|
30
|
-
$ HanziToPinyin.is_number?("1") => true
|
31
|
-
$ HanziToPinyin.is_number?("a") => false
|
31
|
+
$ HanziToPinyin.is_number?("1".ord) => true
|
32
|
+
$ HanziToPinyin.is_number?("a".ord) => false
|
33
|
+
|
34
|
+
$ HanziToPinyin.is_underline?("_".ord).should be_true
|
35
|
+
$ HanziToPinyin.is_underline?("豆豆").should be_false
|
32
36
|
|
33
37
|
== Test
|
34
38
|
$ rake spec
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.6.
|
1
|
+
0.6.1
|
data/lib/hanzi_to_pinyin.rb
CHANGED
@@ -14,6 +14,9 @@ class HanziToPinyin
|
|
14
14
|
@@number_unicode_start = 48
|
15
15
|
@@number_unicode_end = 57
|
16
16
|
|
17
|
+
# 下划线(10进制)
|
18
|
+
@@underline = 95
|
19
|
+
|
17
20
|
# 汉字 unicode 编码(16进制)
|
18
21
|
@@unicode = YAML.load(IO.read File.expand_path("../data/unicode_to_pinyin.yml",__FILE__))
|
19
22
|
@@py = ::JSON.parse(IO.read File.expand_path("../data/hz2py.json",__FILE__))
|
@@ -41,16 +44,16 @@ class HanziToPinyin
|
|
41
44
|
end
|
42
45
|
|
43
46
|
##
|
44
|
-
#
|
45
|
-
#
|
46
|
-
#
|
47
|
-
#
|
48
|
-
#
|
47
|
+
# 只处理汉字和数字和_ 多音字,分隔 字字之间;分隔
|
48
|
+
# 查理Smith => "cha,zha;li"
|
49
|
+
# 郭轶 => "guo;yi,die"
|
50
|
+
# 我们 => "wo;men"
|
51
|
+
# 宗志强 => "zong;zhi;qiang,jiang"
|
49
52
|
def self.hanzi_2_py(hanzi)
|
50
53
|
hanzi = hanzi.force_encoding("utf-8")
|
51
54
|
str = ''
|
52
55
|
hanzi.each_char do |hz|
|
53
|
-
if is_number?(hz.ord)
|
56
|
+
if is_number?(hz.ord) or is_underline?(hz.ord)
|
54
57
|
if str.length == 0
|
55
58
|
str << hz.chr
|
56
59
|
else
|
@@ -98,5 +101,9 @@ class HanziToPinyin
|
|
98
101
|
def self.is_number?(number_codepoint)
|
99
102
|
number_codepoint >= @@number_unicode_start && number_codepoint <= @@number_unicode_end
|
100
103
|
end
|
104
|
+
|
105
|
+
def self.is_underline?(underline_codepoint)
|
106
|
+
underline_codepoint == @@underline
|
107
|
+
end
|
101
108
|
|
102
109
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hanzi_to_pinyin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,12 +9,12 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-02-
|
12
|
+
date: 2012-02-23 00:00:00.000000000 +08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rspec
|
17
|
-
requirement: &
|
17
|
+
requirement: &75722920 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,7 +22,7 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :development
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *75722920
|
26
26
|
description: chinese hanzi to pinyin , fetch first letter OR full pinyin, written
|
27
27
|
in Ruby.
|
28
28
|
email:
|
@@ -55,7 +55,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
55
55
|
version: '0'
|
56
56
|
segments:
|
57
57
|
- 0
|
58
|
-
hash:
|
58
|
+
hash: 801955645
|
59
59
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
60
|
none: false
|
61
61
|
requirements:
|