kanakana 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a50f96b8811260660edcb00c07fce2b8fecc262f9a8a948e2b06ff0907a95e38
4
+ data.tar.gz: bf678e3b08cd097856e0ae21f9e9cdf5265d84ab44eb785316518245d3f4b121
5
+ SHA512:
6
+ metadata.gz: f7a5b1d1744e3765a3228a484b9c775834bd99406e17916d216dfd1850a213a04be44913a08ef6cd18971bd50988015d9e5d0c48bf5200c6df5d1ef1c06cfff4
7
+ data.tar.gz: 8d667ce3fb9db72527dfca943750728212fe4ace8fea3ef4f4587f14f7ee7caf1c5edc33cb607362d381bcc81d42fc6e0bcde14b2862997bc7c734fda92c55db
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ Gemfile.lock
14
+
15
+ personal_memo.md
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,37 @@
1
+ AllCops:
2
+ NewCops: enable
3
+ TargetRubyVersion: 2.7
4
+
5
+ Gemspec/RequireMFA:
6
+ AutoCorrect: false
7
+
8
+ Layout/ExtraSpacing:
9
+ Exclude:
10
+ - '*.gemspec'
11
+
12
+ Lint/ShadowingOuterLocalVariable:
13
+ Exclude:
14
+ - 'spec/kanakana_spec.rb'
15
+
16
+ Layout/SpaceAroundOperators:
17
+ Exclude:
18
+ - '*.gemspec'
19
+
20
+ Metrics:
21
+ Enabled: false
22
+
23
+ Style/AsciiComments:
24
+ Enabled: false
25
+
26
+ Style/FrozenStringLiteralComment:
27
+ Enabled: false
28
+
29
+ Style/HashSyntax:
30
+ Exclude:
31
+ - 'Rakefile'
32
+
33
+ Style/MutableConstant:
34
+ Enabled: false
35
+
36
+ Style/StringLiterals:
37
+ Enabled: false
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at universato@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in kanakana.gemspec
4
+ gemspec
5
+
6
+ gem 'rake', '~> 12.0'
7
+ gem 'rspec', '~> 3.0'
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 universato
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # Kanakana
2
+
3
+ 自分の実験用にGem化させるRubyライブラリです。
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'kanakana'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install kanakana
20
+
21
+ ## Usage
22
+
23
+ [TODO]
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
+
29
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/kanakana. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/kanakana/blob/master/CODE_OF_CONDUCT.md).
34
+
35
+
36
+ ## License
37
+
38
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
39
+
40
+ ## Code of Conduct
41
+
42
+ Everyone interacting in the Kanakana project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/kanakana/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'kanakana'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/kanakana.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ require_relative 'lib/kanakana/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "kanakana"
5
+ spec.version = Kanakana::VERSION
6
+ spec.authors = ["universato"]
7
+ spec.email = ["universato@gmail.com"]
8
+
9
+ spec.summary = "日本語の変換サポート(Converter for Japanese language)"
10
+ spec.description = "日本語(特に仮名、ひらがな、カタカナ)の変換をサポートします。"
11
+ spec.homepage = "https://github.com/universato/kanakana"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.7")
14
+
15
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/universato/kanakana"
19
+ # spec.metadata["changelog_uri"] = "https://github.com/universato/kanakana//blob/main/CHANGELOG.md"
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+ end
@@ -0,0 +1,3 @@
1
+ module Kanakana
2
+ VERSION = "0.0.1"
3
+ end
data/lib/kanakana.rb ADDED
@@ -0,0 +1,141 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'kanakana/version'
4
+ require 'nkf'
5
+
6
+ # Kanakana
7
+ module Kanakana
8
+ # p ("ア".."ワ").map{ |c| NKF.nkf("-Ww --hiragana", c) }.push("を", "ん")
9
+ # 五十音
10
+ HIRAGANA = %w[
11
+ あ い う え お
12
+ か き く け こ
13
+ さ し す せ そ
14
+ た ち つ て と
15
+ な に ぬ ね の
16
+ は ひ ふ へ ほ
17
+ ま み む め も
18
+ や ゆ よ
19
+ ら り る れ ろ
20
+ わ を ん
21
+ ].freeze
22
+
23
+ KATAKANA = %w[
24
+ ア イ ウ エ オ
25
+ カ キ ク ケ コ
26
+ サ シ ス セ ソ
27
+ タ チ ツ テ ト
28
+ ナ ニ ヌ ネ ノ
29
+ ハ ヒ フ ヘ ホ
30
+ マ ミ ム メ モ
31
+ ヤ ユ ヨ
32
+ ラ リ ル レ ロ
33
+ ワ ヲ ン
34
+ ].freeze
35
+
36
+ # DAKUON_BY_HIRAGANA
37
+ # DAKUON_BY_SEION
38
+ DAKUON_HIRAGANA = {
39
+ 'か' => 'が', 'き' => 'ぎ', 'く' => 'ぐ', 'け' => 'げ', 'こ' => 'ご',
40
+ 'さ' => 'ざ', 'し' => 'じ', 'す' => 'ず', 'せ' => 'ぜ', 'そ' => 'ぞ',
41
+ 'た' => 'だ', 'ち' => 'ぢ', 'つ' => 'づ', 'て' => 'で', 'と' => 'ど',
42
+ 'は' => 'ば', 'ひ' => 'び', 'ふ' => 'ぶ', 'へ' => 'べ', 'ほ' => 'ぼ',
43
+ 'う' => 'ゔ', 'ゝ' => 'ゞ'
44
+ }.freeze
45
+ DAKUTENABLE_HIRAGANA = DAKUON_HIRAGANA.keys
46
+
47
+ DAKUON_KATAKANA = {
48
+ 'カ' => 'ガ', 'キ' => 'ギ', 'ク' => 'グ', 'ケ' => 'ゲ', 'コ' => 'ゴ',
49
+ 'サ' => 'ザ', 'シ' => 'ジ', 'ス' => 'ズ', 'セ' => 'ゼ', 'ソ' => 'ゾ',
50
+ 'タ' => 'ダ', 'チ' => 'ヂ', 'ツ' => 'ヅ', 'テ' => 'デ', 'ト' => 'ド',
51
+ 'ハ' => 'バ', 'ヒ' => 'ビ', 'フ' => 'ブ', 'ヘ' => 'ベ', 'ホ' => 'ボ',
52
+ 'ウ' => 'ヴ', 'ヽ' => 'ヾ',
53
+ 'ワ' => 'ヷ', 'ヰ' => 'ヸ', 'ヱ' => 'ヹ', 'ヲ' => 'ヺ'
54
+ }.freeze
55
+ DAKUTENABLE_KATAKANA = DAKUON_KATAKANA.keys
56
+
57
+ DAKUON_TABLE = DAKUON_HIRAGANA.merge(DAKUON_KATAKANA)
58
+ DAKUTENABLES = DAKUTENABLE_HIRAGANA + DAKUTENABLE_KATAKANA
59
+
60
+ HANDAKUON_TABLE = {
61
+ 'は' => 'ぱ', 'ひ' => 'ぴ', 'ふ' => 'ぷ', 'へ' => 'ぺ', 'ほ' => 'ぽ',
62
+ 'ハ' => 'パ', 'ヒ' => 'ピ', 'フ' => 'プ', 'ヘ' => 'ペ', 'ホ' => 'ポ'
63
+ }.freeze
64
+
65
+ KOGAKI_HIRAGANA = {
66
+ 'ぁ' => 'あ', 'ぃ' => 'い', 'ぅ' => 'う', 'ぇ' => 'え', 'ぉ' => 'お',
67
+ 'ゕ' => 'か', 'ゖ' => 'け',
68
+ 'っ' => 'つ',
69
+ 'ゃ' => 'や', 'ゅ' => 'ゆ', 'ょ' => 'よ',
70
+ 'ゎ' => 'わ'
71
+ }.freeze
72
+
73
+ KOGAKI_KATAKANA = {
74
+ 'ァ' => 'ア', 'ィ' => 'イ', 'ゥ' => 'ウ', 'ェ' => 'エ', 'ォ' => 'オ',
75
+ 'ヵ' => 'カ', 'ヶ' => 'ケ',
76
+ 'ッ' => 'ツ',
77
+ 'ャ' => 'ヤ', 'ュ' => 'ユ', 'ョ' => 'ヨ',
78
+ 'ヮ' => 'ワ'
79
+ }.freeze
80
+
81
+ HIRAGANA_SMALL_LIST = KOGAKI_HIRAGANA.keys
82
+
83
+ ITAIJI = {
84
+ 'ゐ' => 'い', 'ゑ' => 'え',
85
+ 'ヰ' => 'イ', 'ヱ' => 'エ', 'ヲ' => 'オ'
86
+ }.freeze
87
+
88
+ NOT_DAKUTENABLE_HIRAGANA = HIRAGANA - DAKUON_HIRAGANA.keys
89
+ NOT_DAKUTENABLE_KATAKANA = KATAKANA - DAKUON_KATAKANA.keys
90
+ NOT_DAKUTENABLES = NOT_DAKUTENABLE_HIRAGANA + NOT_DAKUTENABLE_KATAKANA
91
+
92
+ class << self
93
+ def nigorize(str)
94
+ pattern = /[#{DAKUTENABLES.join}]/
95
+ str.unicode_normalize.gsub(pattern, DAKUON_TABLE)
96
+ end
97
+
98
+ def hyper_nigorize(str)
99
+ pattern = /([#{NOT_DAKUTENABLES.join}])/
100
+ nigorize(str).gsub(pattern) { "#{Regexp.last_match(1)}\u3099" }
101
+ end
102
+
103
+ def hiraganize(str)
104
+ NKF.nkf('-w --hiragana', str)
105
+ end
106
+
107
+ def katakanize(str)
108
+ NKF.nkf('-w --katakana', str)
109
+ end
110
+
111
+ def make_ascii(str)
112
+ # NKF.nkf('-m0Z1 -w', str)
113
+ NKF.nkf('-m0Z1 -W -w', str)
114
+ NKF.nkf('-Z1 -Ww', str)
115
+ # str.tr("0-9a-zA-Z.,@−", "0-9a-zA-Z.,@-")
116
+ # str.tr('!-~', '!-~')
117
+ # str.tr(' -~', ' -~')
118
+ end
119
+
120
+ def unicodes(str)
121
+ # str.unpack('U*').map { |c| "U+#{c.to_s(16).upcase}" }
122
+ str.codepoints.map { |c| "U+#{c.to_s(16).upcase}" }
123
+ end
124
+
125
+ def escape(str)
126
+ # str.unpack('U*').map { |c| "\\u#{c.to_s(16).upcase}" }.join
127
+ str.codepoints.map { |c| "\\u#{c.to_s(16).upcase}" }.join
128
+ end
129
+
130
+ def ords
131
+ str.chars.zip(str.codepoints.map(&:ord)).to_h
132
+ end
133
+
134
+ # charset
135
+ def table(str)
136
+ str.chars.zip(str.codepoints.map { |c| "\\u{#{c.to_s(16).upcase}}" }).to_h
137
+ end
138
+ end
139
+ end
140
+
141
+ KanaKana = Kanakana
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kanakana
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - universato
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-11-25 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: 日本語(特に仮名、ひらがな、カタカナ)の変換をサポートします。
14
+ email:
15
+ - universato@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - ".rspec"
22
+ - ".rubocop.yml"
23
+ - CODE_OF_CONDUCT.md
24
+ - Gemfile
25
+ - LICENSE.txt
26
+ - README.md
27
+ - Rakefile
28
+ - bin/console
29
+ - bin/setup
30
+ - kanakana.gemspec
31
+ - lib/kanakana.rb
32
+ - lib/kanakana/version.rb
33
+ homepage: https://github.com/universato/kanakana
34
+ licenses:
35
+ - MIT
36
+ metadata:
37
+ homepage_uri: https://github.com/universato/kanakana
38
+ source_code_uri: https://github.com/universato/kanakana
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '2.7'
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubygems_version: 3.3.3
55
+ signing_key:
56
+ specification_version: 4
57
+ summary: 日本語の変換サポート(Converter for Japanese language)
58
+ test_files: []