chinese_convt 0.0.5 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +16 -31
- data/chinese_convt.gemspec +2 -2
- data/lib/chinese_convert/zh_convt +35 -1
- data/lib/chinese_convert/zh_convt.rb +9 -11
- data/test/test_chinese_convt.rb +7 -5
- metadata +3 -3
@@ -1,21 +1,19 @@
|
|
1
1
|
module Chinese
|
2
2
|
class Convert
|
3
3
|
def self.zh_convt( arr , str )
|
4
|
-
convt_table =
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
type.first.split(',').each{ |term| convt_table.last.last[ term.split(':').first ] = term.split(':').last }
|
10
|
-
end
|
11
|
-
end
|
4
|
+
convt_table = File.open(File.dirname(__FILE__) + "/zh_convt").read.split("\n&\n").map{ |group|
|
5
|
+
group.split("\n").map{ |type|
|
6
|
+
Hash[ type.split(',').map{ |term| term.split(':') } ]
|
7
|
+
}
|
8
|
+
}
|
12
9
|
begin
|
13
10
|
str0 = String.new( str )
|
14
11
|
str1 = String.new( str )
|
15
|
-
|
12
|
+
n = (str.size < 6)? str.size : 6
|
13
|
+
convt_table.last(n).each do |group|
|
16
14
|
arr.each do |t|
|
17
15
|
group[t].each do |key , value|
|
18
|
-
while
|
16
|
+
while !! q = str0.index( key )
|
19
17
|
str0[q...(q + key.size)] = "#" * value.size
|
20
18
|
str1[q...(q + key.size)] = value
|
21
19
|
end
|
@@ -24,7 +22,7 @@ module Chinese
|
|
24
22
|
end
|
25
23
|
return str1
|
26
24
|
rescue
|
27
|
-
return $!
|
25
|
+
return "[#{$!}]"
|
28
26
|
end
|
29
27
|
end
|
30
28
|
end
|
data/test/test_chinese_convt.rb
CHANGED
@@ -3,11 +3,11 @@ require 'test/unit'
|
|
3
3
|
require 'chinese_convt'
|
4
4
|
|
5
5
|
class TestChineseConvt < Test::Unit::TestCase
|
6
|
-
Str_tra = { 0 => "幹部一干人等幹事不乾不淨", 1 => "
|
7
|
-
Str_sim = { 0 => "干部一干人等干事不干不净", 1 => "
|
8
|
-
Str_tw = { 0 => "幹部一干人等幹事不乾不淨", 1 => "
|
9
|
-
Str_hk = { 0 => "幹部一干人等幹事不乾不淨", 1 => "
|
10
|
-
Str_cn = { 0 => "干部一干人等干事不干不净", 1 => "
|
6
|
+
Str_tra = { 0 => "幹部一干人等幹事不乾不淨", 1 => "線上辭典查詢達文西密碼", 2 => "嘴裡吃著鮪魚三明治", 3 => "觸摸屏取代鼠標對互聯網的影響", 4 => "舊金山檯球冠軍是諧星"}
|
7
|
+
Str_sim = { 0 => "干部一干人等干事不干不净", 1 => "线上辞典查询达文西密码", 2 => "嘴里吃着鲔鱼三明治", 3 => "触摸屏取代鼠标对互联网的影响", 4 => "旧金山台球冠军是谐星"}
|
8
|
+
Str_tw = { 0 => "幹部一干人等幹事不乾不淨", 1 => "線上辭典查詢達文西密碼", 2 => "嘴裡吃著鮪魚三明治", 3 => "觸控螢幕取代滑鼠對網際網路的影響", 4 => "舊金山撞球冠軍是諧星"}
|
9
|
+
Str_hk = { 0 => "幹部一干人等幹事不乾不淨", 1 => "線上辭典查詢達文西密碼", 2 => "嘴裏吃着吞拿魚三文治", 3 => "觸控螢幕取代滑鼠對互聯網的影響", 4 => "三藩市桌球冠軍是諧星"}
|
10
|
+
Str_cn = { 0 => "干部一干人等干事不干不净", 1 => "在线词典查找达芬奇密码", 2 => "嘴里吃着金枪鱼三明治", 3 => "触摸屏取代鼠标对互联网的影响", 4 => "旧金山台球冠军是笑星"}
|
11
11
|
|
12
12
|
def test_zh2tra
|
13
13
|
Str_sim.each{ |i , w| assert_equal( Str_tra[i] , Chinese.zh2tra( w ) ) }
|
@@ -19,10 +19,12 @@ class TestChineseConvt < Test::Unit::TestCase
|
|
19
19
|
|
20
20
|
def test_zh2tw
|
21
21
|
Str_sim.each{ |i , w| assert_equal( Str_tw[i] , Chinese.zh2tw( w ) ) }
|
22
|
+
Str_cn.each{ |i , w| assert_equal( Str_tw[i] , Chinese.zh2tw( w ) ) }
|
22
23
|
end
|
23
24
|
|
24
25
|
def test_zh2hk
|
25
26
|
Str_sim.each{ |i , w| assert_equal( Str_hk[i] , Chinese.zh2hk( w ) ) }
|
27
|
+
Str_tw.each{ |i , w| assert_equal( Str_hk[i] , Chinese.zh2hk( w ) ) }
|
26
28
|
end
|
27
29
|
|
28
30
|
def test_zh2cn
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chinese_convt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.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: 2012-
|
12
|
+
date: 2012-09-22 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Conversion between Traditional and Simplified Chinese. furthermore, adjusting
|
15
15
|
phrases to conform in Taiwan or Hong Kong or China.
|
@@ -45,7 +45,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
45
45
|
version: '0'
|
46
46
|
requirements: []
|
47
47
|
rubyforge_project:
|
48
|
-
rubygems_version: 1.8.
|
48
|
+
rubygems_version: 1.8.23
|
49
49
|
signing_key:
|
50
50
|
specification_version: 3
|
51
51
|
summary: Traditional and Simplified Chinese conversion~~
|