gimchi 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- data/README.ko.markdown +7 -1
- data/README.markdown +7 -1
- data/lib/gimchi.rb +3 -1
- data/lib/gimchi/korean.rb +18 -5
- data/lib/gimchi/patch_1.8.rb +0 -19
- data/lib/gimchi/pronouncer.rb +2 -2
- data/test/test_gimchi.rb +11 -2
- metadata +12 -12
data/README.ko.markdown
CHANGED
@@ -71,10 +71,16 @@ kc.partial? # true
|
|
71
71
|
kc = ko.korean_char "한"
|
72
72
|
|
73
73
|
# Array of Gimchi::Korean::Char's
|
74
|
-
arr = ko.
|
74
|
+
arr = ko.convert '이것은 한글입니다.'
|
75
75
|
# [이, 것, 은, " ", 한, 글, 입, 니, 다, "."]
|
76
76
|
|
77
77
|
arr[0].class # Gimchi::Korean::Char
|
78
|
+
|
79
|
+
# Dissects given String
|
80
|
+
arr = ko.dissect '이것은 한글입니다.'
|
81
|
+
# ["ㅇ", "ㅣ", "ㄱ", "ㅓ", "ㅅ", "ㅇ", "ㅡ", "ㄴ", " ",
|
82
|
+
# "H", "a", "n", "g", "u", "l", " ", "ㅇ", "ㅣ", "ㅂ",
|
83
|
+
# "ㄴ", "ㅣ", "ㄷ", "ㅏ", "."]
|
78
84
|
```
|
79
85
|
|
80
86
|
### 숫자 읽기
|
data/README.markdown
CHANGED
@@ -70,10 +70,16 @@ kc.partial? # true
|
|
70
70
|
kc = ko.korean_char "한"
|
71
71
|
|
72
72
|
# Array of Gimchi::Korean::Char's
|
73
|
-
arr = ko.
|
73
|
+
arr = ko.convert '이것은 한글입니다.'
|
74
74
|
# [이, 것, 은, " ", 한, 글, 입, 니, 다, "."]
|
75
75
|
|
76
76
|
arr[0].class # Gimchi::Korean::Char
|
77
|
+
|
78
|
+
# Dissects given String
|
79
|
+
arr = ko.dissect '이것은 한글입니다.'
|
80
|
+
# ["ㅇ", "ㅣ", "ㄱ", "ㅓ", "ㅅ", "ㅇ", "ㅡ", "ㄴ", " ",
|
81
|
+
# "H", "a", "n", "g", "u", "l", " ", "ㅇ", "ㅣ", "ㅂ",
|
82
|
+
# "ㄴ", "ㅣ", "ㄷ", "ㅏ", "."]
|
77
83
|
```
|
78
84
|
|
79
85
|
### Reading numbers in Korean
|
data/lib/gimchi.rb
CHANGED
data/lib/gimchi/korean.rb
CHANGED
@@ -51,7 +51,7 @@ class Korean
|
|
51
51
|
# Checks if the given character is a korean character.
|
52
52
|
# @param [String] ch A string of size 1
|
53
53
|
def korean_char? ch
|
54
|
-
raise ArgumentError.new('Lengthy input') if ch
|
54
|
+
raise ArgumentError.new('Lengthy input') if str_length(ch) > 1
|
55
55
|
|
56
56
|
complete_korean_char?(ch) ||
|
57
57
|
(chosungs + jungsungs + jongsungs).include?(ch)
|
@@ -62,7 +62,7 @@ class Korean
|
|
62
62
|
# "Complete" Korean character must have chosung and jungsung, with optional jongsung.
|
63
63
|
# @param [String] ch A string of size 1
|
64
64
|
def complete_korean_char? ch
|
65
|
-
raise ArgumentError.new('Lengthy input') if ch
|
65
|
+
raise ArgumentError.new('Lengthy input') if str_length(ch) > 1
|
66
66
|
|
67
67
|
# Range of Korean chracters in Unicode 2.0: AC00(가) ~ D7A3(힣)
|
68
68
|
ch.unpack('U').all? { | c | c >= 0xAC00 && c <= 0xD7A3 }
|
@@ -71,9 +71,18 @@ class Korean
|
|
71
71
|
# Splits the given string into an array of Korean::Char's and Strings of length 1.
|
72
72
|
# @param [String] str Input string.
|
73
73
|
# @return [Array] Mixed array of Korean::Char instances and Strings of length 1 (for non-korean characters)
|
74
|
-
def
|
74
|
+
def convert str
|
75
75
|
str.each_char.map { |c|
|
76
|
-
korean_char?(c) ?
|
76
|
+
korean_char?(c) ? kchar(c) : c
|
77
|
+
}
|
78
|
+
end
|
79
|
+
|
80
|
+
# Splits the given string into an array of Korean character components
|
81
|
+
# @param [String] str Input string.
|
82
|
+
# @return [Array] Array of Korean character components
|
83
|
+
def dissect str
|
84
|
+
str.each_char.inject([]) { |arr, c|
|
85
|
+
arr += korean_char?(c) ? kchar(c).to_a.compact : [c]
|
77
86
|
}
|
78
87
|
end
|
79
88
|
|
@@ -155,7 +164,7 @@ class Korean
|
|
155
164
|
romanization = ""
|
156
165
|
|
157
166
|
romanize_chunk = lambda do | chunk |
|
158
|
-
|
167
|
+
convert(chunk).each do | kc |
|
159
168
|
kc.to_a.each_with_index do | comp, idx |
|
160
169
|
next if comp.nil?
|
161
170
|
comp = rdata[idx][comp] || comp
|
@@ -187,6 +196,10 @@ class Korean
|
|
187
196
|
end
|
188
197
|
|
189
198
|
private
|
199
|
+
def str_length str
|
200
|
+
str.length
|
201
|
+
end
|
202
|
+
|
190
203
|
def read_number_sub num, next_char
|
191
204
|
nconfig = config['number']
|
192
205
|
|
data/lib/gimchi/patch_1.8.rb
CHANGED
@@ -2,25 +2,6 @@ $KCODE = 'U'
|
|
2
2
|
|
3
3
|
module Gimchi
|
4
4
|
class Korean
|
5
|
-
# Checks if the given character is a korean character.
|
6
|
-
# @param [String] ch A string of size 1
|
7
|
-
def korean_char? ch
|
8
|
-
raise ArgumentError.new('Lengthy input') if str_length(ch) > 1
|
9
|
-
|
10
|
-
complete_korean_char?(ch) ||
|
11
|
-
(chosungs + jungsungs + jongsungs).include?(ch)
|
12
|
-
end
|
13
|
-
|
14
|
-
# Checks if the given character is a "complete" korean character.
|
15
|
-
# "Complete" Korean character must have chosung and jungsung, with optional jongsung.
|
16
|
-
# @param [String] ch A string of size 1
|
17
|
-
def complete_korean_char? ch
|
18
|
-
raise ArgumentError.new('Lengthy input') if str_length(ch) > 1
|
19
|
-
|
20
|
-
# Range of Korean chracters in Unicode 2.0: AC00(가) ~ D7A3(힣)
|
21
|
-
ch.unpack('U').all? { | c | c >= 0xAC00 && c <= 0xD7A3 }
|
22
|
-
end
|
23
|
-
|
24
5
|
private
|
25
6
|
def str_length str
|
26
7
|
str.scan(/./mu).length
|
data/lib/gimchi/pronouncer.rb
CHANGED
@@ -17,7 +17,7 @@ class Korean
|
|
17
17
|
(options[:pronounce_each_char] ? '1' : '2')] - options[:except]
|
18
18
|
|
19
19
|
# Dissecting
|
20
|
-
@chars = @korean.
|
20
|
+
@chars = @korean.convert str
|
21
21
|
@orig_chars = @chars.dup
|
22
22
|
|
23
23
|
# Padding
|
@@ -299,7 +299,7 @@ class Korean
|
|
299
299
|
|
300
300
|
word = @kc.to_s + @next_kc.to_s
|
301
301
|
if map.keys.include? word
|
302
|
-
new_char = @korean.
|
302
|
+
new_char = @korean.kchar(map[word].scan(/./mu)[1])
|
303
303
|
@next_kc.chosung = new_char.chosung
|
304
304
|
@next_kc.jongsung = new_char.jongsung
|
305
305
|
|
data/test/test_gimchi.rb
CHANGED
@@ -52,10 +52,19 @@ class TestGimchi < Test::Unit::TestCase
|
|
52
52
|
assert_raise(ArgumentError) { ko.korean_char?('두자') }
|
53
53
|
end
|
54
54
|
|
55
|
-
|
55
|
+
def test_dissect
|
56
56
|
ko = Gimchi::Korean.new
|
57
57
|
|
58
|
-
arr = ko.dissect '이것은
|
58
|
+
arr = ko.dissect '이것은 Hangul 입니다.'
|
59
|
+
assert_equal ["ㅇ", "ㅣ", "ㄱ", "ㅓ", "ㅅ", "ㅇ", "ㅡ", "ㄴ", " ",
|
60
|
+
"H", "a", "n", "g", "u", "l", " ", "ㅇ", "ㅣ", "ㅂ",
|
61
|
+
"ㄴ", "ㅣ", "ㄷ", "ㅏ", "."], arr
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_convert
|
65
|
+
ko = Gimchi::Korean.new
|
66
|
+
|
67
|
+
arr = ko.convert '이것은 한글입니다.'
|
59
68
|
# [이, 것, 은, " ", 한, 글, 입, 니, 다, "."]
|
60
69
|
|
61
70
|
assert_equal 10, arr.length
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gimchi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-02-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
16
|
-
requirement: &
|
16
|
+
requirement: &2158357040 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 1.0.0
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2158357040
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: jeweler
|
27
|
-
requirement: &
|
27
|
+
requirement: &2158358840 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 1.5.2
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2158358840
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rcov
|
38
|
-
requirement: &
|
38
|
+
requirement: &2158315180 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2158315180
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: ansi
|
49
|
-
requirement: &
|
49
|
+
requirement: &2154666280 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: 1.2.2
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *2154666280
|
58
58
|
description: Gimchi knows how to pronounce Korean strings and how to write them in
|
59
59
|
roman alphabet.
|
60
60
|
email: junegunn.c@gmail.com
|
@@ -93,7 +93,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
93
93
|
version: '0'
|
94
94
|
segments:
|
95
95
|
- 0
|
96
|
-
hash: -
|
96
|
+
hash: -4061568131035276090
|
97
97
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
98
|
none: false
|
99
99
|
requirements:
|
@@ -102,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
102
102
|
version: '0'
|
103
103
|
requirements: []
|
104
104
|
rubyforge_project:
|
105
|
-
rubygems_version: 1.8.
|
105
|
+
rubygems_version: 1.8.15
|
106
106
|
signing_key:
|
107
107
|
specification_version: 3
|
108
108
|
summary: Gimchi reads Korean.
|