hanzi 0.3.0 → 0.4.0

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.
@@ -1,4 +1,4 @@
1
- = hanzi
1
+ = Hanzi
2
2
 
3
3
  Ruby gem for handling common Hanzi operations. Can convert to pinyin with proper tones for common words (other gems tend to fail on simple words), return english translation, or convert between simplified and traditional. Uses cc-cedict for data.
4
4
  Example usage:
@@ -13,12 +13,30 @@ Example usage:
13
13
  Hanzi.to_english('孔子') # Confucius (551-479 BC), Chinese thinker and social philosopher, also known as 孔夫子[Kong3 fu1 zi3]
14
14
  Hanzi.to_english('老子喜欢') # nil (can only translate exact word matches)
15
15
 
16
- Hanzi.to_traditional('')
17
16
  Hanzi.to_traditional('拉萨') # 拉薩
18
17
  Hanzi.to_traditional('拉薩') # 拉薩
19
18
  Hanzi.to_simplified('拉薩') # 拉萨
20
19
  Hanzi.to_simplified('abc 拉萨') # nil (for now, only supports exact word matches)
21
20
 
21
+ Hanzi.matching_entries('着') # returns an array of the all dict entries with exact hanzi matches
22
+ [{:traditional=>"著",
23
+ :simplified=>"着",
24
+ :pinyin=>"zhao1",
25
+ :english=>"(chess) move/trick/all right!/(dialect) to add"},
26
+ {:traditional=>"著",
27
+ :simplified=>"着",
28
+ :pinyin=>"zhao2",
29
+ :english=>
30
+ "to touch/to come in contact with/to feel/to be affected by/to catch fire/to fall asleep/to burn"},
31
+ {:traditional=>"著",
32
+ :simplified=>"着",
33
+ :pinyin=>"zhe5",
34
+ :english=>"aspect particle indicating action in progress"},
35
+ {:traditional=>"著",
36
+ :simplified=>"着",
37
+ :pinyin=>"zhuo2",
38
+ :english=>"to wear (clothes)/to contact/to use/to apply"}]
39
+
22
40
  To run tests:
23
41
 
24
42
  rake test
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.4.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "hanzi"
8
- s.version = "0.3.0"
8
+ s.version = "0.4.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Steve Jackson"]
12
- s.date = "2013-01-12"
12
+ s.date = "2013-01-23"
13
13
  s.description = "Convert Hanzi to pinyin. Unlike other similar gems, this includes tones and can accurately translate common words."
14
14
  s.email = "steven.j.jackson@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -91,6 +91,14 @@ class Hanzi
91
91
  entry[:traditional] if entry && entry[:traditional]
92
92
  end
93
93
 
94
+ def matching_entries(text)
95
+ load_data if @data.nil?
96
+
97
+ entries = @data.select do |word|
98
+ word[:simplified] == text || word[:traditional] == text
99
+ end
100
+ end
101
+
94
102
  private
95
103
  def find_hanzi_match(text)
96
104
  entry = @data.find do |word|
@@ -34,6 +34,13 @@ class TestHanzi < Test::Unit::TestCase
34
34
  assert_equal 'ni3hao3, wo3shi4kang1yu4chen2。', result
35
35
  end
36
36
 
37
+ def test_can_find_all_matching_entries
38
+ results = Hanzi.matching_entries('着')
39
+ assert results.find { |entry| entry[:pinyin].include?('zhe5') } != nil
40
+ assert results.find { |entry| entry[:pinyin].include?('zhao2') } != nil
41
+ assert results.find { |entry| entry[:english].include?('in progress') } != nil
42
+ end
43
+
37
44
  def test_can_return_english_translation
38
45
  result = Hanzi.to_english('你好')
39
46
  assert result.downcase.include?('hello')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hanzi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
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-01-12 00:00:00.000000000 Z
12
+ date: 2013-01-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rdoc
@@ -78,7 +78,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
78
78
  version: '0'
79
79
  segments:
80
80
  - 0
81
- hash: -552213835099124985
81
+ hash: -3371334032433433338
82
82
  required_rubygems_version: !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements: