k2j 0.1.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.
- checksums.yaml +7 -0
- data/.gitignore +35 -0
- data/README.md +2 -0
- data/lib/k2j.rb +9 -0
- data/lib/k2j/converter.rb +96 -0
- data/lib/k2j/maps.rb +41 -0
- data/lib/k2j/version.rb +4 -0
- metadata +50 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e1a85f920c5c33e26186de2b016e0b687de4ef4c
|
4
|
+
data.tar.gz: c380f39b4bc67d4b2081cf7fc13768591f0d8b0f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3a911bb6092e74c08fe227bb753c1b798d53907257257f2a8fde54ab71f89237b1ab4922be24f685f744e487b2b8f1a81791fef8d5278dc24600714b0421427c
|
7
|
+
data.tar.gz: 013d9d90b6110f5dce941b3ca73e272b3738bae51a2b4f8f5274b7723447da5bded6cbf9b0019ea0b599c6749b7d372b58eb1bb85845ad47e4fffa72bfba0048
|
data/.gitignore
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/test/tmp/
|
9
|
+
/test/version_tmp/
|
10
|
+
/tmp/
|
11
|
+
|
12
|
+
## Specific to RubyMotion:
|
13
|
+
.dat*
|
14
|
+
.repl_history
|
15
|
+
build/
|
16
|
+
|
17
|
+
## Documentation cache and generated files:
|
18
|
+
/.yardoc/
|
19
|
+
/_yardoc/
|
20
|
+
/doc/
|
21
|
+
/rdoc/
|
22
|
+
|
23
|
+
## Environment normalisation:
|
24
|
+
/.bundle/
|
25
|
+
/vendor/bundle
|
26
|
+
/lib/bundler/man/
|
27
|
+
|
28
|
+
# for a library or gem, you might want to ignore these files since the code is
|
29
|
+
# intended to run in multiple environments; otherwise, check them in:
|
30
|
+
# Gemfile.lock
|
31
|
+
# .ruby-version
|
32
|
+
# .ruby-gemset
|
33
|
+
|
34
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
35
|
+
.rvmrc
|
data/README.md
ADDED
data/lib/k2j.rb
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'k2j/maps'
|
3
|
+
|
4
|
+
module K2J
|
5
|
+
# K2J Converter
|
6
|
+
#
|
7
|
+
# @version 0.1.0
|
8
|
+
class Converter
|
9
|
+
class << self
|
10
|
+
initialized = false
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
break_map(K2J::Map::CHO, K2J::Map.method(:cho))
|
14
|
+
break_map(K2J::Map::JOONG, K2J::Map.method(:joong))
|
15
|
+
break_map(K2J::Map::JONG, K2J::Map.method(:jong))
|
16
|
+
|
17
|
+
@initialized = true
|
18
|
+
end
|
19
|
+
|
20
|
+
def convert(str)
|
21
|
+
initialize unless @initialized
|
22
|
+
|
23
|
+
result = ''
|
24
|
+
str.size.times do |i|
|
25
|
+
ch = str[i]
|
26
|
+
|
27
|
+
special = special_case(str[i - 1], ch, str[i + 1])
|
28
|
+
unless special.nil?
|
29
|
+
result << special
|
30
|
+
next
|
31
|
+
end
|
32
|
+
|
33
|
+
col = index_of(K2J::Map::CHO, K2J::Map.cho(ch))
|
34
|
+
row = index_of(K2J::Map::JOONG, K2J::Map.joong(ch))
|
35
|
+
gana = K2J::Map::HIRAGANA[col * 13 + row]
|
36
|
+
|
37
|
+
result << (gana.nil? ? ch : gana)
|
38
|
+
|
39
|
+
ad = index_of(K2J::Map::JONG, K2J::Map.jong(ch))
|
40
|
+
case ad
|
41
|
+
when 0
|
42
|
+
result << "ん"
|
43
|
+
when 1
|
44
|
+
result << "っ"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
result
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
def special_case(ch1, ch2, ch3)
|
53
|
+
case ch2
|
54
|
+
when '-'
|
55
|
+
if ch1 != '-' and ch3 != '-'
|
56
|
+
"う"
|
57
|
+
elsif ch1 != '-'
|
58
|
+
'-'
|
59
|
+
else
|
60
|
+
''
|
61
|
+
end
|
62
|
+
when '.'
|
63
|
+
"。"
|
64
|
+
when '와'
|
65
|
+
'わ'
|
66
|
+
when '워'
|
67
|
+
'を'
|
68
|
+
when "\n"
|
69
|
+
"\n"
|
70
|
+
when ' '
|
71
|
+
' '
|
72
|
+
else
|
73
|
+
nil
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def index_of(map, ch)
|
78
|
+
map.each_with_index do |k, i|
|
79
|
+
k.size.times do |j|
|
80
|
+
if map[i][j] == ch
|
81
|
+
return i
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def break_map(map, func)
|
88
|
+
map.each_with_index do |k, i|
|
89
|
+
k.size.times do |j|
|
90
|
+
map[i] = map[i].gsub(map[i][j], func.call(map[i][j]))
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
data/lib/k2j/maps.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module K2J
|
4
|
+
module Map
|
5
|
+
KEY = ['ㅁ', 'ㅠ', 'ㅊ', 'ㅇ', 'ㄷ', 'ㄹ', 'ㅎ', 'ㅗ', 'ㅑ', 'ㅓ', 'ㅏ', 'ㅣ', 'ㅡ', 'ㅜ', 'ㅐ', 'ㅔ', 'ㅂ', 'ㄱ', 'ㄴ', 'ㅅ', 'ㅕ', 'ㅍ', 'ㅈ', 'ㅌ', 'ㅛ', 'ㅋ']
|
6
|
+
CHO = ["아", "카까", "가", "사", "자", "타차짜따", "다", "나", "하", "바", "파빠", "마", "라"]
|
7
|
+
JOONG = ["아", "이", "우으", "에", "오", "x", "x", "x", "x", "x", "야", "유", "요"]
|
8
|
+
JONG = ["안앙암", "앗앚앋앛압악"]
|
9
|
+
HIRAGANA = [
|
10
|
+
"あ", "い", "う", "え", "お", "ぁ", "ぃ", "ぅ", "ぇ", "ぉ", "や", "ゆ", "よ",
|
11
|
+
"か", "き", "く", "け", "こ", "x", "x", "x", "x", "x", "きゃ", "きゅ", "きょ",
|
12
|
+
"が", "ぎ", "ぐ", "げ", "ご", "x", "x", "x", "x", "x", "ぎゃ", "ぎゅ", "ぎょ",
|
13
|
+
"さ", "し", "す", "せ", "そ", "x", "x", "x", "x", "x", "しゃ", "しゅ", "しょ",
|
14
|
+
"ざ", "じ", "ず", "ぜ", "ぞ", "x", "x", "x", "x", "x", "じゃ", "じゅ", "じょ",
|
15
|
+
"た", "ち", "つ", "て", "と", "x", "x", "x", "x", "x", "ちゃ", "ちゅ", "ちょ",
|
16
|
+
"だ", "ぢ", "づ", "で", "ど", "x", "x", "x", "x", "x", "ぢゃ", "ぢゅ", "ぢょ",
|
17
|
+
"な", "に", "ぬ", "ね", "の", "x", "x", "x", "x", "x", "にゃ", "にゅ", "にょ",
|
18
|
+
"は", "ひ", "ふ", "へ", "ほ", "x", "x", "x", "x", "x", "ひゃ", "ひゅ", "ひょ",
|
19
|
+
"ば", "び", "ぶ", "べ", "ぼ", "x", "x", "x", "x", "x", "びゃ", "びゅ", "びょ",
|
20
|
+
"ぱ", "ぴ", "ぷ", "ぺ", "ぽ", "x", "x", "x", "x", "x", "ぴゃ", "ぴゅ", "ぴょ",
|
21
|
+
"ま", "み", "む", "め", "も", "x", "x", "x", "x", "x", "みゃ", "みゅ", "みょ",
|
22
|
+
"ら", "り", "る", "れ", "ろ", "x", "x", "x", "x", "x", "りゃ", "りゅ", "りょ"]
|
23
|
+
|
24
|
+
def cho(a)
|
25
|
+
r = ((a[0].ord - 44032) / 28) / 21
|
26
|
+
(r + 4352).chr(Encoding::UTF_8)
|
27
|
+
end
|
28
|
+
|
29
|
+
def joong(a)
|
30
|
+
r = ((a[0].ord - 44032) / 28) % 21
|
31
|
+
(r + 4449).chr(Encoding::UTF_8)
|
32
|
+
end
|
33
|
+
|
34
|
+
def jong(a)
|
35
|
+
r = (a[0].ord - 44032) % 28
|
36
|
+
(r + 4520 - 1).chr(Encoding::UTF_8)
|
37
|
+
end
|
38
|
+
|
39
|
+
module_function :cho, :joong, :jong
|
40
|
+
end
|
41
|
+
end
|
data/lib/k2j/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: k2j
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- SuHun Han (ssut)
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-12-12 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Hangul to hiragana.
|
14
|
+
email: ssut@ssut.me
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- ".gitignore"
|
20
|
+
- README.md
|
21
|
+
- lib/k2j.rb
|
22
|
+
- lib/k2j/converter.rb
|
23
|
+
- lib/k2j/maps.rb
|
24
|
+
- lib/k2j/version.rb
|
25
|
+
homepage: https://github.com/ssut/k2j.rb
|
26
|
+
licenses:
|
27
|
+
- MIT
|
28
|
+
metadata: {}
|
29
|
+
post_install_message:
|
30
|
+
rdoc_options: []
|
31
|
+
require_paths:
|
32
|
+
- lib
|
33
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
requirements: []
|
44
|
+
rubyforge_project:
|
45
|
+
rubygems_version: 2.4.5
|
46
|
+
signing_key:
|
47
|
+
specification_version: 4
|
48
|
+
summary: Hangul to hiragana.
|
49
|
+
test_files: []
|
50
|
+
has_rdoc:
|