ruby-pinyin 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,8 +6,13 @@
6
6
  * 能够显示数字或者UNICODE音调(eg: 'cao1', 'cāo')
7
7
  * 丰富的API
8
8
  * 支持中英文标点混合字符串
9
+ * 中文标点转为英文标点
9
10
  * 支持自定义读音
10
11
 
12
+ ## Installation
13
+
14
+ gem install ruby-pinyin
15
+
11
16
  ## Examples
12
17
 
13
18
  # encoding: utf-8
@@ -33,8 +38,8 @@
33
38
  PinYin.abbr('感谢party感谢guo jia')
34
39
 
35
40
  # return 'gan xie party, gan xie guo jia!'
36
- # PinYin.sentence保留标点符号
37
- PinYin.sentence('感谢party, 感谢guo家!')
41
+ # PinYin.sentence保留标点符号, 同时用对应英文标点代替中文标点
42
+ PinYin.sentence('感谢party 感谢guo家!')
38
43
 
39
44
  # override readings with your own data file
40
45
  PinYin.override_files = [File.expand_path('../my.dat', __FILE__)]
@@ -23,6 +23,16 @@ module PinYin
23
23
  @codes
24
24
  end
25
25
 
26
+ def punctuations
27
+ return @punctuations if @punctuations
28
+
29
+ @punctuations = {}
30
+ src = File.expand_path('../ruby-pinyin/Punctuations.dat', __FILE__)
31
+ load_punctuations_from(src)
32
+
33
+ @punctuations
34
+ end
35
+
26
36
  def of_string(str, tone=nil, include_punctuations=false)
27
37
  res = []
28
38
  return res unless str && !str.empty?
@@ -38,6 +48,7 @@ module PinYin
38
48
  if val =~ /^[_0-9a-zA-Z\s]*$/ # 复原,去除特殊字符,如全角符号等。
39
49
  (res.last && res.last.english? ? res.last : res) << Value.new(val, true) # 如果上一个字符也是非中文则与之合并
40
50
  elsif include_punctuations
51
+ val = [punctuations[code]].pack('H*') if punctuations.has_key?(code)
41
52
  (res.last ? res.last : res) << Value.new(val, false)
42
53
  end
43
54
  end
@@ -74,6 +85,13 @@ module PinYin
74
85
  end
75
86
  end
76
87
 
88
+ def load_punctuations_from(file)
89
+ File.readlines(file).map do |line|
90
+ from, to = line.split(/\s+/)
91
+ @punctuations[from] = to
92
+ end
93
+ end
94
+
77
95
  def format(readings, tone)
78
96
  case tone
79
97
  when :unicode
@@ -0,0 +1,9 @@
1
+ FF0C 2C
2
+ 3002 2E
3
+ FF01 21
4
+ FF1F 3F
5
+ FF1A 3A
6
+ 201C 22
7
+ 201D 22
8
+ 2018 27
9
+ 2019 27
@@ -1,3 +1,3 @@
1
1
  module PinYin
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-pinyin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-05 00:00:00.000000000 Z
12
+ date: 2013-05-18 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Pinyin is a romanization system (phonemic notation) of Chinese characters,
15
15
  this gem helps you to convert Chinese characters into pinyin form.
@@ -23,6 +23,7 @@ files:
23
23
  - lib/ruby-pinyin/version.rb
24
24
  - lib/ruby-pinyin/value.rb
25
25
  - lib/ruby-pinyin/Mandarin.dat
26
+ - lib/ruby-pinyin/Punctuations.dat
26
27
  - MIT-LICENSE
27
28
  - README.markdown
28
29
  homepage: https://github.com/janx/ruby-pinyin