a-b-chi 1.1.3 → 1.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +55 -0
- data/Rakefile +8 -0
- data/lib/a-b-chi.rb +22 -17
- data/lib/characters.txt +95 -0
- data/test/test_a-b-chi.rb +35 -0
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NTk2NDI4YjNjYTZhZTE4ZWExODgwOGU4MjAwZGY2MDAxMmUyZWQzYw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MzAyYzRlYzdjYjExMGQ4ZTQ0M2U5MjQ1NTg4ZmNhNmE0ZDZlMWFkOQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZTMwZGZlYmY3MjNlZGZmYzkwMzEwNTc3MzVlYTFkNzc2YmM3NzQ4ZmUyMTk1
|
10
|
+
Zjg5NDY2ZTNiN2RkNmY3NjQxNTExMzQ3MmUxYzZkMDRlNjk0ODg3MjU1YTU4
|
11
|
+
NTc5YjFlMDlkNzAyNTUwZjU3NzJmZjFkNDllYmM2ODdiMTUzOTY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZDg2YzU4OWEzYWFjM2U2ZmFkY2E0OGUyYWJkYzZhY2NiOTU2YjhkOTdlMjY1
|
14
|
+
MmJiMjRjYTk5M2ZjYmRkMTBjZjlhYTcyMDQ5Nzk5OTYxNzAxMWRjYTZhMGIz
|
15
|
+
OGQ3MTYyNzk1MDI3MzFkNjRmYzVhN2I1NDk2YTViN2YxYmZiY2U=
|
data/README.md
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
A-B-Chi
|
2
|
+
=========
|
3
|
+
In the Morning!
|
4
|
+
|
5
|
+
A-B-Chi is a RubyGem aimed at making the process of sorting Chinese Traditional characters easy without having to change database collation settings (I personally couldnt work them out).
|
6
|
+
|
7
|
+
I have been wroking in Taiwan for the last year on a CRM-type database and have learned quite a bit about Chinese Traditional characters and their attributes. after pulling my hair out over collation I decided that the best thing to do would be to make my own solution and as I notice that a lot of other people have similar problems I wanted to make this publically available.
|
8
|
+
|
9
|
+
|
10
|
+
There are a few extra functions that I plan to implement in the future which include
|
11
|
+
|
12
|
+
- Character to BoPoMoFo (pronunciation characters) and other various things - perhaps a ruby text function or two.
|
13
|
+
- Handling of English and Chinese Simplified Characters.
|
14
|
+
- Base everything around the utf-8 character codes rather than a list of characters.
|
15
|
+
|
16
|
+
Version
|
17
|
+
-
|
18
|
+
|
19
|
+
1.1.3
|
20
|
+
|
21
|
+
Further Info
|
22
|
+
-----------
|
23
|
+
- I have compiled an extensive database of each Chinese Traditional character and its attributes indluding each different pronunciation of it and will be implementing this in awesome ways in the future. This contains just shy of 16,000 entries.
|
24
|
+
|
25
|
+
- If you want to know about BoPoMoFo, I recommend reading the Wikipedia entry on it: http://en.wikipedia.org/wiki/Bopomofo
|
26
|
+
|
27
|
+
- You should also check out the Taiwan Government's official write-up on their standards which can be found here: http://www.cns11643.gov.tw/AIDB/encodings_en.do
|
28
|
+
|
29
|
+
|
30
|
+
Installation
|
31
|
+
--------------
|
32
|
+
|
33
|
+
```gem install a-b-chi```
|
34
|
+
or for bundler add the following to your Gemfile
|
35
|
+
```gem 'a-b-chi'```
|
36
|
+
|
37
|
+
The sourcecode can be found at https://github.com/nallan/a-b-chi
|
38
|
+
|
39
|
+
Usage
|
40
|
+
--------------
|
41
|
+
|
42
|
+
firstly require the file in your project
|
43
|
+
```require 'a-b-chi'```
|
44
|
+
next you must create a new instance of the ArrayChinese class and populate your array
|
45
|
+
```arr = ArrayChinese.new
|
46
|
+
arr.push "李依恬", "李雲帆", "珍項小珍", "瑞芳", "李宗翰"
|
47
|
+
```
|
48
|
+
finally run the sort method on this. both sort and sort! are supported
|
49
|
+
```arr.sort
|
50
|
+
arr.sort!```
|
51
|
+
|
52
|
+
License
|
53
|
+
-
|
54
|
+
|
55
|
+
MIT
|
data/Rakefile
ADDED
data/lib/a-b-chi.rb
CHANGED
@@ -1,34 +1,39 @@
|
|
1
1
|
#encoding:utf-8
|
2
2
|
|
3
3
|
class ArrayChinese < Array
|
4
|
+
alias array_sort sort
|
5
|
+
alias array_sort_by sort_by
|
6
|
+
alias array_sort_by! sort_by!
|
4
7
|
|
5
8
|
def initialize
|
6
9
|
spec = Gem::Specification.find_by_name("a-b-chi")
|
7
10
|
gem_root = spec.gem_dir
|
8
11
|
gem_lib = gem_root + "/lib"
|
9
12
|
@characters = File.read("#{gem_lib}/characters.txt").split("\n")
|
10
|
-
|
11
13
|
end
|
12
14
|
|
13
15
|
def sort
|
14
|
-
|
15
|
-
search_query = '['
|
16
|
-
for i in 0..max_length
|
17
|
-
unless i == max_length
|
18
|
-
search_query << "@characters.index(sort_string[#{i}]), "
|
19
|
-
else
|
20
|
-
search_query << "@characters.index(sort_string[#{i}])]"
|
21
|
-
end
|
22
|
-
end
|
23
|
-
self.sort_by! { |sort_string| eval(search_query) }
|
16
|
+
self.array_sort_by { |sort_string| eval(get_sort_query) }
|
24
17
|
end
|
25
18
|
|
26
|
-
|
19
|
+
def sort!
|
20
|
+
self.array_sort_by! { |sort_string| eval(get_sort_query) }
|
21
|
+
end
|
27
22
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
23
|
+
# def sort_by(*args)
|
24
|
+
# puts args.inspect
|
25
|
+
# self.array_sort_by! { |sort_string| eval(get_sort_query) }
|
26
|
+
# end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def get_sort_query
|
31
|
+
max_length = self.max_by(&:length).length
|
32
|
+
sort_query = '['
|
33
|
+
(0..max_length).each { |i| sort_query << " @characters.index(sort_string[#{i}])," }
|
34
|
+
sort_query.chop!
|
35
|
+
sort_query << ']'
|
36
|
+
return sort_query
|
32
37
|
end
|
33
|
-
|
38
|
+
|
34
39
|
end
|
data/lib/characters.txt
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
|
1
2
|
八
|
2
3
|
仈
|
3
4
|
巴
|
@@ -13137,3 +13138,97 @@
|
|
13137
13138
|
佣
|
13138
13139
|
醟
|
13139
13140
|
鍀
|
13141
|
+
0
|
13142
|
+
1
|
13143
|
+
2
|
13144
|
+
3
|
13145
|
+
4
|
13146
|
+
5
|
13147
|
+
6
|
13148
|
+
7
|
13149
|
+
8
|
13150
|
+
9
|
13151
|
+
A
|
13152
|
+
a
|
13153
|
+
B
|
13154
|
+
b
|
13155
|
+
C
|
13156
|
+
c
|
13157
|
+
D
|
13158
|
+
d
|
13159
|
+
E
|
13160
|
+
e
|
13161
|
+
F
|
13162
|
+
f
|
13163
|
+
G
|
13164
|
+
g
|
13165
|
+
H
|
13166
|
+
h
|
13167
|
+
I
|
13168
|
+
i
|
13169
|
+
J
|
13170
|
+
j
|
13171
|
+
K
|
13172
|
+
k
|
13173
|
+
L
|
13174
|
+
l
|
13175
|
+
M
|
13176
|
+
m
|
13177
|
+
N
|
13178
|
+
n
|
13179
|
+
O
|
13180
|
+
o
|
13181
|
+
P
|
13182
|
+
p
|
13183
|
+
Q
|
13184
|
+
q
|
13185
|
+
R
|
13186
|
+
r
|
13187
|
+
S
|
13188
|
+
s
|
13189
|
+
T
|
13190
|
+
t
|
13191
|
+
U
|
13192
|
+
u
|
13193
|
+
V
|
13194
|
+
v
|
13195
|
+
W
|
13196
|
+
w
|
13197
|
+
X
|
13198
|
+
x
|
13199
|
+
Y
|
13200
|
+
y
|
13201
|
+
Z
|
13202
|
+
z
|
13203
|
+
_
|
13204
|
+
!
|
13205
|
+
@
|
13206
|
+
#
|
13207
|
+
$
|
13208
|
+
%
|
13209
|
+
^
|
13210
|
+
&
|
13211
|
+
*
|
13212
|
+
(
|
13213
|
+
)
|
13214
|
+
-
|
13215
|
+
=
|
13216
|
+
+
|
13217
|
+
`
|
13218
|
+
~
|
13219
|
+
[
|
13220
|
+
]
|
13221
|
+
{
|
13222
|
+
}
|
13223
|
+
|
|
13224
|
+
\
|
13225
|
+
;
|
13226
|
+
:
|
13227
|
+
'
|
13228
|
+
"
|
13229
|
+
,
|
13230
|
+
.
|
13231
|
+
<
|
13232
|
+
>
|
13233
|
+
/
|
13234
|
+
?
|
@@ -0,0 +1,35 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'a-b-chi'
|
5
|
+
|
6
|
+
class ABChiTest < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def test_string_sort
|
9
|
+
arr = ArrayChinese.new
|
10
|
+
arr.push "李依恬", "李雲帆", "珍項小珍", "瑞芳", "李宗翰", "李彩雲", "李璨亘", "李若喬", "李瑞雰", "李彩喬", "李素霞", "李依帆", "NallaN", "彩依恬", "彩雲恬", "雲李", "雲則欣", "雲彩雲"
|
11
|
+
assert_equal ["李若喬", "李瑞雰", "李宗翰", "李彩喬", "李彩雲", "李璨亘", "李素霞", "李依帆", "李依恬", "李雲帆", "珍項小珍", "瑞芳", "彩依恬", "彩雲恬", "雲李", "雲則欣", "雲彩雲", "NallaN"],
|
12
|
+
arr.sort
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_blank_array
|
16
|
+
arr = ArrayChinese.new
|
17
|
+
arr.push
|
18
|
+
assert_equal [], arr.sort
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_english_after_chinese
|
22
|
+
arr = ArrayChinese.new
|
23
|
+
arr.push "雲Z雲", "NallaN", "雲彩雲"
|
24
|
+
assert_equal ["雲彩雲", "雲Z雲", "NallaN"],
|
25
|
+
arr.sort
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_handling_of_unknown_characters
|
29
|
+
arr = ArrayChinese.new
|
30
|
+
arr.push "Z∂ß", "NallaN", "雲彩雲"
|
31
|
+
assert_equal ["雲彩雲", "NallaN", "Z∂ß"],
|
32
|
+
arr.sort
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: a-b-chi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathanial Allan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-08-
|
11
|
+
date: 2013-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A gem that allows for the user to sort Chinese Traditional characters
|
14
14
|
like a human (phonetically) rather than like a robot (stroke count)
|
@@ -17,15 +17,16 @@ executables: []
|
|
17
17
|
extensions: []
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
|
+
- Rakefile
|
21
|
+
- README.md
|
20
22
|
- lib/a-b-chi.rb
|
21
23
|
- lib/characters.txt
|
24
|
+
- test/test_a-b-chi.rb
|
22
25
|
homepage: http://rubygems.org/gems/a-b-chi
|
23
26
|
licenses:
|
24
27
|
- MIT
|
25
28
|
metadata: {}
|
26
|
-
post_install_message: !
|
27
|
-
|
28
|
-
'
|
29
|
+
post_install_message: ITM!
|
29
30
|
rdoc_options: []
|
30
31
|
require_paths:
|
31
32
|
- lib
|