ropencc 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +20 -8
- data/lib/ropencc.rb +7 -26
- data/lib/ropencc/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8156250ad99b06ad47c368f22043b859280c4ab8
|
4
|
+
data.tar.gz: 282c25f51ec3a48d1c8b3be4728dda349d0bd980
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff3819906a39e4cfe03a713f174cb03bc155f4a00f257b8f156928e9cab508242f4db0b03fe75c1fc4d1f9eb714870139f7b7b1d8be4cc709ca4db21d356afc6
|
7
|
+
data.tar.gz: ebad92dd5e7b1b5511fdac8a395d6630bc8feaa6acd974c95f922d8926b30222a26a00752a03d77d79030f7b38a296933a5156979503733d8e97b9448934d485
|
data/README.md
CHANGED
@@ -10,7 +10,7 @@ ropencc is a project for conversion between Traditional and Simplified Chinese,
|
|
10
10
|
还有若干语言习惯的问题,例如同一个地名的称呼就不一样,就不一一列举了
|
11
11
|
|
12
12
|
而 Open Chinese Convert(OpenCC)「开放中文转换」,是一个致力于中
|
13
|
-
文简繁转换的项目,由清华大学的 [BYVoid](http://www.byvoid.com/blog/about/) 提供高质量词库和函数库(libopencc)。<a href='
|
13
|
+
文简繁转换的项目,由清华大学的 [BYVoid](http://www.byvoid.com/blog/about/) 提供高质量词库和函数库(libopencc)。<a href='https://github.com/BYVoid/OpenCC'>更多介紹</a>。
|
14
14
|
|
15
15
|
Install
|
16
16
|
-------
|
@@ -37,33 +37,45 @@ Install
|
|
37
37
|
|
38
38
|
brew install opencc
|
39
39
|
|
40
|
-
更多 libopencc 安装介绍请查看: <
|
40
|
+
更多 libopencc 安装介绍请查看: <https://github.com/BYVoid/OpenCC>
|
41
41
|
|
42
42
|
2. 安装 ropencc
|
43
|
-
|
43
|
+
|
44
44
|
gem install ropencc
|
45
45
|
|
46
|
+
预设配置文件
|
47
|
+
-----
|
48
|
+
|
49
|
+
* `s2t.json` Simplified Chinese to Traditional Chinese 簡體到繁體
|
50
|
+
* `t2s.json` Traditional Chinese to Simplified Chinese 繁體到簡體
|
51
|
+
* `s2tw.json` Simplified Chinese to Traditional Chinese (Taiwan Standard) 簡體到臺灣正體
|
52
|
+
* `tw2s.json` Traditional Chinese (Taiwan Standard) to Simplified Chinese 臺灣正體到簡體
|
53
|
+
* `s2hk.json` Simplified Chinese to Traditional Chinese (Hong Kong Standard) 簡體到香港繁體(香港小學學習字詞表標準)
|
54
|
+
* `hk2s.json` Traditional Chinese (Hong Kong Standard) to Simplified Chinese 香港繁體(香港小學學習字詞表標準)到簡體
|
55
|
+
* `s2twp.json` Simplified Chinese to Traditional Chinese (Taiwan Standard) with Taiwanese idiom 簡體到繁體(臺灣正體標準)並轉換爲臺灣常用詞彙
|
56
|
+
* `tw2sp.json` Traditional Chinese (Taiwan Standard) to Simplified Chinese with Mainland Chinese idiom 繁體(臺灣正體標準)到簡體並轉換爲中國大陸常用詞彙
|
57
|
+
|
46
58
|
Usage
|
47
59
|
-----
|
48
60
|
|
49
61
|
简转繁 (Simple Interface)
|
50
62
|
|
51
|
-
Ropencc.conv('
|
63
|
+
Ropencc.conv('s2t.json', str)
|
52
64
|
|
53
65
|
繁转简 (Simple Interface)
|
54
66
|
|
55
|
-
Ropencc.conv('
|
67
|
+
Ropencc.conv('t2s.json', str)
|
56
68
|
|
57
69
|
简转繁 (File-Class like Interface)
|
58
70
|
|
59
|
-
Ropencc.open '
|
60
|
-
rs = cc.convert '新年快乐'
|
71
|
+
Ropencc.open 's2t.json' do |cc|
|
72
|
+
rs = cc.convert '新年快乐'
|
61
73
|
assert_equal '新年快樂', rs
|
62
74
|
end
|
63
75
|
|
64
76
|
繁转简 (File-Class like Interface)
|
65
77
|
|
66
|
-
Ropencc.open '
|
78
|
+
Ropencc.open 't2s.json' do |cc|
|
67
79
|
rs = cc.convert '新年快樂'
|
68
80
|
assert_equal '新年快乐', rs
|
69
81
|
end
|
data/lib/ropencc.rb
CHANGED
@@ -8,29 +8,14 @@ class Ropencc
|
|
8
8
|
ffi_lib 'opencc'
|
9
9
|
attach_function :opencc_open, [:string], :pointer
|
10
10
|
attach_function :opencc_close, [:pointer], :int
|
11
|
+
attach_function :opencc_convert_utf8_to_buffer, [:pointer, :string, :int, :pointer], :int
|
11
12
|
attach_function :opencc_convert_utf8, [:pointer, :string, :int], :pointer
|
12
|
-
attach_function :
|
13
|
-
attach_function :
|
14
|
-
attach_function :opencc_dict_load, [:pointer, :string, :int], :int
|
13
|
+
attach_function :opencc_convert_utf8_free, [:pointer], :void
|
14
|
+
attach_function :opencc_error, [], :string
|
15
15
|
end
|
16
16
|
|
17
|
-
module LibC
|
18
|
-
extend FFI::Library
|
19
|
-
ffi_lib FFI::Library::LIBC
|
20
|
-
attach_function :free, [:pointer], :void
|
21
|
-
end # module LibC
|
22
|
-
|
23
17
|
attr_accessor :descriptor
|
24
18
|
|
25
|
-
CONFIGS = ['zhs2zhtw_p.ini', 'zhs2zhtw_v.ini', 'zhs2zhtw_vp.ini', 'zht2zhtw_p.ini',
|
26
|
-
'zht2zhtw_v.ini', 'zht2zhtw_vp.ini', 'zhtw2zhs.ini', 'zhtw2zht.ini',
|
27
|
-
'zhtw2zhcn_s.ini', 'zhtw2zhcn_t.ini', 'zhs2zht.ini', 'zht2zhs.ini']
|
28
|
-
|
29
|
-
DICTS = {
|
30
|
-
:simp_to_trad => 'zhs2zhtw_vp.ini',
|
31
|
-
:trad_to_simp => 'zhtw2zhcn_s.ini'
|
32
|
-
}
|
33
|
-
|
34
19
|
def initialize(config_file)
|
35
20
|
@descriptor = LibOpenCC.opencc_open config_file
|
36
21
|
@is_open = true
|
@@ -54,26 +39,23 @@ class Ropencc
|
|
54
39
|
end
|
55
40
|
end
|
56
41
|
|
57
|
-
def self.conv(
|
58
|
-
|
59
|
-
od = LibOpenCC.opencc_open DICTS[dicttype.to_sym]
|
42
|
+
def self.conv(config, str)
|
43
|
+
od = LibOpenCC.opencc_open config
|
60
44
|
ptr = LibOpenCC.opencc_convert_utf8(od, str, str.bytesize)
|
61
45
|
out_str = ptr.read_string
|
62
|
-
|
46
|
+
LibOpenCC.opencc_convert_utf8_free ptr
|
63
47
|
LibOpenCC.opencc_close od
|
64
48
|
out_str.force_encoding("UTF-8") if out_str.respond_to?(:force_encoding)
|
65
49
|
out_str
|
66
|
-
|
67
50
|
end
|
68
51
|
|
69
52
|
def convert(str)
|
70
53
|
if @is_open == false
|
71
54
|
raise IOError, 'not opened for conversion'
|
72
55
|
end
|
73
|
-
|
74
56
|
ptr = LibOpenCC.opencc_convert_utf8(@descriptor, str, str.bytesize)
|
75
57
|
out_str = ptr.read_string
|
76
|
-
|
58
|
+
LibOpenCC.opencc_convert_utf8_free ptr
|
77
59
|
out_str.force_encoding("UTF-8") if out_str.respond_to?(:force_encoding)
|
78
60
|
out_str
|
79
61
|
end
|
@@ -87,7 +69,6 @@ class Ropencc
|
|
87
69
|
LibOpenCC.opencc_close @descriptor
|
88
70
|
@descriptor = nil
|
89
71
|
@is_open = false
|
90
|
-
|
91
72
|
return nil
|
92
73
|
end
|
93
74
|
end
|
data/lib/ropencc/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ropencc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Psi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|
@@ -60,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
60
60
|
version: '0'
|
61
61
|
requirements: []
|
62
62
|
rubyforge_project:
|
63
|
-
rubygems_version: 2.
|
63
|
+
rubygems_version: 2.4.5
|
64
64
|
signing_key:
|
65
65
|
specification_version: 4
|
66
66
|
summary: a project for conversion between Traditional and Simplified Chinese.
|