klang 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +34 -0
- data/Rakefile +2 -0
- data/klang.gemspec +24 -0
- data/lib/klang/version.rb +3 -0
- data/lib/klang.rb +115 -0
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: da69a04cf2f5c3483f9672dde287e3f0c92bcd23
|
4
|
+
data.tar.gz: 6bb472d5a04d1597e53584a43d726e8d809c26f4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b812121d6a80075044e961dfad4587e09978225f1af957b2bd0780b0b37912e19cbb447cc4f90522158a5da458b2684c8b08f97426da30aefe4c1258f5bff493
|
7
|
+
data.tar.gz: 84bd09db71bf8a54cfee4eae0e1539566ee679e172fb593c25aa811d943bdeb395e13146b4e76fcca09db9bf87091bd17647a499185764c94470646a747d7449
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 shunirr
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# Klang
|
2
|
+
|
3
|
+
Parse korean hangle language.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'klang'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install klang
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
word = '아'
|
25
|
+
Klang::Klang.new(word).to_alphabet # => a
|
26
|
+
```
|
27
|
+
|
28
|
+
## Contributing
|
29
|
+
|
30
|
+
1. Fork it ( https://github.com/[my-github-username]/klang/fork )
|
31
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
32
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
33
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
34
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/klang.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'klang/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "klang"
|
8
|
+
spec.version = Klang::VERSION
|
9
|
+
spec.authors = ["shunirr"]
|
10
|
+
spec.email = ["m@s5r.jp"]
|
11
|
+
spec.summary = %q{Parse korean hangle language.}
|
12
|
+
spec.description = %q{Parse korean hangle language.}
|
13
|
+
spec.homepage = "https://github.com/shunirr/klang-ruby"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "unicode"
|
24
|
+
end
|
data/lib/klang.rb
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
require "klang/version"
|
2
|
+
require 'unicode'
|
3
|
+
|
4
|
+
module Klang
|
5
|
+
class Klang
|
6
|
+
CONSONANT = {
|
7
|
+
0x1100 => 'g', # ㄱ
|
8
|
+
0x1101 => 'kk', # ㄲ
|
9
|
+
0x1102 => 'n', # ㄴ
|
10
|
+
0x1103 => 'd', # ㄷ
|
11
|
+
0x1104 => 'tt', # ㄸ
|
12
|
+
0x1105 => 'r', # ㄹ
|
13
|
+
0x1106 => 'm', # ㅁ
|
14
|
+
0x1107 => 'b', # ㅂ
|
15
|
+
0x1108 => 'pp', # ㅃ
|
16
|
+
0x1109 => 's', # ㅅ
|
17
|
+
0x110A => 'ss', # ㅆ
|
18
|
+
0x110B => '', # ㅇ
|
19
|
+
0x110C => 'j', # ㅈ
|
20
|
+
0x110D => 'jj', # ㅉ
|
21
|
+
0x110E => 'ch', # ㅊ
|
22
|
+
0x110F => 'k', # ㅋ
|
23
|
+
0x1110 => 't', # ㅌ
|
24
|
+
0x1111 => 'p', # ㅍ
|
25
|
+
0x1112 => 'h', # ㅎ
|
26
|
+
}
|
27
|
+
VOWEL = {
|
28
|
+
0x1161 => 'a', # ㅏ
|
29
|
+
0x1162 => 'ae', # ㅐ
|
30
|
+
0x1163 => 'ya', # ㅑ
|
31
|
+
0x1164 => 'yae', # ㅒ
|
32
|
+
0x1165 => 'eo', # ㅓ
|
33
|
+
0x1166 => 'e', # ㅔ
|
34
|
+
0x1167 => 'yeo', # ㅕ
|
35
|
+
0x1168 => 'ye', # ㅖ
|
36
|
+
0x1169 => 'o', # ㅗ
|
37
|
+
0x116A => 'wa', # ㅘ
|
38
|
+
0x116B => 'wae', # ㅙ
|
39
|
+
0x116C => 'oe', # ㅚ
|
40
|
+
0x116D => 'yo', # ㅛ
|
41
|
+
0x116E => 'u', # ㅜ
|
42
|
+
0x116F => 'wo', # ㅝ
|
43
|
+
0x1170 => 'we', # ㅞ
|
44
|
+
0x1171 => 'wi', # ㅟ
|
45
|
+
0x1172 => 'yu', # ㅠ
|
46
|
+
0x1173 => 'eu', # ㅡ
|
47
|
+
0x1174 => 'ui', # ㅢ
|
48
|
+
0x1175 => 'i', # ㅣ
|
49
|
+
}
|
50
|
+
PATCHIM = {
|
51
|
+
0x11A8 => 'k', # ㄱ
|
52
|
+
0x11A9 => 'kk', # ㄲ
|
53
|
+
0x11AA => 'k', # ㄳ
|
54
|
+
0x11AB => 'n', # ㄴ
|
55
|
+
0x11AC => 'n', # ㄵ
|
56
|
+
0x11AD => 'n', # ㄶ
|
57
|
+
0x11AE => 't', # ㄷ
|
58
|
+
0x11AF => 'r', # ㄹ
|
59
|
+
0x11B0 => 'r', # ㄺ
|
60
|
+
0x11B1 => 'm', # ㄻ
|
61
|
+
0x11B2 => 'r', # ㄼ
|
62
|
+
0x11B3 => 'r', # ㄽ
|
63
|
+
0x11B4 => 'r', # ㄾ
|
64
|
+
0x11B5 => 'p', # ㄿ
|
65
|
+
0x11B6 => 'r', # ㅀ
|
66
|
+
0x11B7 => 'm', # ㅁ
|
67
|
+
0x11B8 => 'p', # ㅂ
|
68
|
+
0x11B9 => 'p', # ㅄ
|
69
|
+
0x11BA => 's', # ㅅ
|
70
|
+
0x11BB => 'ss', # ㅆ
|
71
|
+
0x11BC => 'ng', # ㅇ
|
72
|
+
0x11BD => 'j', # ㅈ
|
73
|
+
0x11BE => 'ch', # ㅊ
|
74
|
+
0x11BF => 'k', # ㅋ
|
75
|
+
0x11C0 => 't', # ㅌ
|
76
|
+
0x11C1 => 'p', # ㅍ
|
77
|
+
0x11C2 => 'h', # ㅎ
|
78
|
+
}
|
79
|
+
|
80
|
+
def initialize(str)
|
81
|
+
@raw = str
|
82
|
+
@alphabet = nil
|
83
|
+
end
|
84
|
+
|
85
|
+
def to_alphabet
|
86
|
+
parse_hangul unless @alphabet
|
87
|
+
@alphabet
|
88
|
+
end
|
89
|
+
|
90
|
+
private
|
91
|
+
def parse_hangul
|
92
|
+
alpha = []
|
93
|
+
@raw.each_char do |c|
|
94
|
+
unless hangul?(c)
|
95
|
+
alpha << c
|
96
|
+
next
|
97
|
+
end
|
98
|
+
consonant, vowel, patchim = Unicode::nfkd(c).chars
|
99
|
+
alpha << CONSONANT[consonant.ord] if consonant
|
100
|
+
alpha << VOWEL[vowel.ord] if vowel
|
101
|
+
alpha << PATCHIM[patchim.ord] || CONSONANT[patchim.ord] if patchim
|
102
|
+
end
|
103
|
+
@alphabet = alpha.join
|
104
|
+
end
|
105
|
+
|
106
|
+
def hangul?(char)
|
107
|
+
o = char.ord
|
108
|
+
((o >= 0x1100 && o <= 0x11FF) ||
|
109
|
+
(o >= 0xA960 && o <= 0xA97F) ||
|
110
|
+
(o >= 0xD7B0 && o <= 0xD7FF) ||
|
111
|
+
(o >= 0x3130 && o <= 0x318F) ||
|
112
|
+
(o >= 0xAC00 && o <= 0xD7AF))
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: klang
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- shunirr
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: unicode
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Parse korean hangle language.
|
56
|
+
email:
|
57
|
+
- m@s5r.jp
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- klang.gemspec
|
68
|
+
- lib/klang.rb
|
69
|
+
- lib/klang/version.rb
|
70
|
+
homepage: https://github.com/shunirr/klang-ruby
|
71
|
+
licenses:
|
72
|
+
- MIT
|
73
|
+
metadata: {}
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
requirements: []
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 2.0.14
|
91
|
+
signing_key:
|
92
|
+
specification_version: 4
|
93
|
+
summary: Parse korean hangle language.
|
94
|
+
test_files: []
|