sort_kana_jisx4061 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +32 -0
- data/Rakefile +10 -0
- data/lib/sort_kana_jisx4061/version.rb +3 -0
- data/lib/sort_kana_jisx4061.rb +97 -0
- data/sort_kana_jisx4061.gemspec +23 -0
- metadata +93 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d6f0c5c42b2e0b2dadfc08ed0ae0d2112283776d
|
4
|
+
data.tar.gz: 5bb7731e8526efc259bec4c9a95f4aac00db0365
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: babaa39b79f465ffc4a1d76bb3c83bee419fcdb9bbb401d414c795294411e5168d39e9af75ae6bbf74e34c86fd5b72aad2e38f795258b1ccbe3f790deb0bcd25
|
7
|
+
data.tar.gz: 8ffac04a94ac36f11ba1d6332dedaea1ed1bf290ce851af7f14826714591cac37bee1be5d0c21f5001ff9f7971a916a9a3b32fe2edc28c45ff37f19a76a437f7
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2018 Masakazu Takahashi (emasaka)
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# SortKanaJisx4061
|
2
|
+
|
3
|
+
Sort Japanese Kana strings by [JIS X 4061 (日本語文字列照合順番)](http://kikakurui.com/x4/X4061-1996-01.html) order in Ruby.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
```
|
8
|
+
require 'sort_kana_jisx4061'
|
9
|
+
|
10
|
+
words = [
|
11
|
+
{ original: '春', yomi: 'ハル' },
|
12
|
+
{ original: '夏', yomi: 'ナツ' },
|
13
|
+
{ original: '秋', yomi: 'アキ' },
|
14
|
+
{ original: '冬', yomi: 'フユ' },
|
15
|
+
]
|
16
|
+
|
17
|
+
words_sorted = sort_kana_jisx4061_by(words) {|x| x[:yomi] }
|
18
|
+
# => [{:original=>"秋", :yomi=>"アキ"}, {:original=>"夏", :yomi=>"ナツ"}, {:original=>"春", :yomi=>"ハル"}, {:original=>"冬", :yomi=>"フユ"}]
|
19
|
+
```
|
20
|
+
|
21
|
+
## Note
|
22
|
+
|
23
|
+
* Sorting Kanji is not supported
|
24
|
+
* Hiragana is converted to Katakana internally
|
25
|
+
|
26
|
+
## License
|
27
|
+
|
28
|
+
This software is released under the MIT License, see LICENSE.txt.
|
29
|
+
|
30
|
+
## Contributing
|
31
|
+
|
32
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/emasaka/sort_kana_jisx4061 .
|
data/Rakefile
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "sort_kana_jisx4061/version"
|
4
|
+
|
5
|
+
module SortKanaJisx4061 # :nodoc:
|
6
|
+
# JIS X 4061 character classes
|
7
|
+
CC_SPACE = 1
|
8
|
+
CC_PUNCTUATION = 2
|
9
|
+
CC_PAREN = 3
|
10
|
+
CC_OPRATOR = 4 # unused
|
11
|
+
CC_SYMBOL = 5
|
12
|
+
CC_UNIT = 6 # unused
|
13
|
+
CC_NUMBER = 7
|
14
|
+
CC_GREEK = 8 # unused
|
15
|
+
CC_LATIN = 9
|
16
|
+
CC_KANA = 10
|
17
|
+
CC_KANJI = 11 # unused
|
18
|
+
CC_GETA = 12 # unused
|
19
|
+
|
20
|
+
class << self
|
21
|
+
def process_yomi(str)
|
22
|
+
r = []
|
23
|
+
str.each_char do |c|
|
24
|
+
c = c.downcase
|
25
|
+
c = c.tr('ぁ-ん', 'ァ-ン') # Hiragana -> Katakana
|
26
|
+
c = base_char(c)
|
27
|
+
if c == 'ー'
|
28
|
+
c = process_onbiki(c, r.last[1])
|
29
|
+
end
|
30
|
+
r << [jisx4061_charclass(c), c]
|
31
|
+
end
|
32
|
+
r
|
33
|
+
end
|
34
|
+
|
35
|
+
# for test
|
36
|
+
def compare(str1, str2)
|
37
|
+
process_yomi(str1) <=> process_yomi(str2)
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def jisx4061_charclass(c)
|
43
|
+
case c
|
44
|
+
when /[[:space:]]/ then CC_SPACE
|
45
|
+
when %r{[??、。,.,.・…‥:;:;//-]} then CC_PUNCTUATION
|
46
|
+
when /[(){}\[\]()[l]“”「」『』{}{}【】"']/ then CC_PAREN
|
47
|
+
when /\d/ then CC_NUMBER
|
48
|
+
when /[[:alpha:]]/ then CC_LATIN
|
49
|
+
when /\p{KataKana}/ then CC_KANA
|
50
|
+
else CC_SYMBOL
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
BASE_CHAR_TBL = {
|
55
|
+
'ァ' => 'ア', 'ィ' => 'イ', 'ゥ' => 'ウ', 'ェ' => 'エ', 'ォ' => 'オ',
|
56
|
+
'ガ' => 'カ', 'ギ' => 'キ', 'グ' => 'ク', 'ゲ' => 'ケ', 'ゴ' => 'コ',
|
57
|
+
'ザ' => 'サ', 'ジ' => 'シ', 'ズ' => 'ス', 'ゼ' => 'セ', 'ゾ' => 'ソ',
|
58
|
+
'ダ' => 'タ', 'ヂ' => 'チ', 'ヅ' => 'ツ', 'デ' => 'テ', 'ド' => 'ト',
|
59
|
+
'バ' => 'ハ', 'ビ' => 'ヒ', 'ブ' => 'フ', 'ベ' => 'ヘ', 'ボ' => 'ホ',
|
60
|
+
'パ' => 'ハ', 'ピ' => 'ヒ', 'プ' => 'フ', 'ペ' => 'ヘ', 'ポ' => 'ホ',
|
61
|
+
'ャ' => 'ヤ', 'ュ' => 'ユ', 'ョ' => 'ヨ', 'ッ' => 'ツ', 'ヮ' => 'ワ',
|
62
|
+
}
|
63
|
+
|
64
|
+
def base_char(c)
|
65
|
+
BASE_CHAR_TBL[c] || c
|
66
|
+
end
|
67
|
+
|
68
|
+
def process_onbiki(c, pre)
|
69
|
+
case pre
|
70
|
+
when /[アカサタナハマヤラワ]/ then 'ア'
|
71
|
+
when /[イキシチニヒミリ]/ then 'イ'
|
72
|
+
when /[ウクスツヌフムユル]/ then 'ウ'
|
73
|
+
when /[エケセテネヘメレ]/ then 'エ'
|
74
|
+
when /[オコソトノホモヨロヲ]/ then 'オ'
|
75
|
+
when 'ン' then 'ン'
|
76
|
+
else c
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# sort Japanese Kana strings by JIS X 4061 order
|
83
|
+
#
|
84
|
+
# == Usage
|
85
|
+
# require 'sort_kana_jisx4061'
|
86
|
+
#
|
87
|
+
# words = [
|
88
|
+
# { original: '春', yomi: 'ハル' },
|
89
|
+
# { original: '夏', yomi: 'ナツ' },
|
90
|
+
# { original: '秋', yomi: 'アキ' },
|
91
|
+
# { original: '冬', yomi: 'フユ' },
|
92
|
+
# ]
|
93
|
+
#
|
94
|
+
# words_sorted = sort_kana_jisx4061_by(words) {|x| x[:yomi] }
|
95
|
+
def sort_kana_jisx4061_by(enum)
|
96
|
+
enum.sort_by {|x| SortKanaJisx4061::process_yomi(yield(x)) }
|
97
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "sort_kana_jisx4061/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "sort_kana_jisx4061"
|
7
|
+
spec.version = SortKanaJisx4061::VERSION
|
8
|
+
spec.authors = ["emasaka (Masakazu Takahashi)"]
|
9
|
+
spec.email = ["emasaka@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = %q{sort Japanese Kana strings by JIS X 4061 order}
|
12
|
+
spec.description = %q{sort Japanese Kana strings by JIS X 4061 order in Ruby}
|
13
|
+
spec.homepage = "https://github.com/emasaka/sort_kana_jisx4061"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
16
|
+
f.match(%r{^(test|spec|features)/})
|
17
|
+
end
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
21
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
22
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sort_kana_jisx4061
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- emasaka (Masakazu Takahashi)
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-05-12 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.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
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: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
description: sort Japanese Kana strings by JIS X 4061 order in Ruby
|
56
|
+
email:
|
57
|
+
- emasaka@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- lib/sort_kana_jisx4061.rb
|
68
|
+
- lib/sort_kana_jisx4061/version.rb
|
69
|
+
- sort_kana_jisx4061.gemspec
|
70
|
+
homepage: https://github.com/emasaka/sort_kana_jisx4061
|
71
|
+
licenses: []
|
72
|
+
metadata: {}
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
requirements: []
|
88
|
+
rubyforge_project:
|
89
|
+
rubygems_version: 2.4.8
|
90
|
+
signing_key:
|
91
|
+
specification_version: 4
|
92
|
+
summary: sort Japanese Kana strings by JIS X 4061 order
|
93
|
+
test_files: []
|