conv_ja_char 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 57c3fd15e6ddfbec1787f943d2e20999e4912c30
4
+ data.tar.gz: c20b412c7734f64ba05ac9a8bc4763c6b089666b
5
+ SHA512:
6
+ metadata.gz: 6848b175134d2d6cfb40d76cb80411249a8ef205f249ee028d9e3774c68d7502fdc3c861c58ed0bef3739a89f3d5f2d2bcddfa1e202d07105e2c397c360eea6d
7
+ data.tar.gz: 1aa59395f3a0ff11923bef678a9276d9feedacdb893c5ecc25aef7903e21e14018afd8e681537c831c2e943b3df446d575fe2fbe2d2f27e2dcfaa752c38fa361
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
13
+ .idea
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.15.3
@@ -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 lica@nii.ac.jp. 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 [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ #source "https://rubygems.org"
2
+
3
+ #git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in conv_ja_char.gemspec
6
+ gemspec
7
+
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Lica Okamoto
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,43 @@
1
+ # ConvJaChar
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/conv_ja_char`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'conv_ja_char'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install conv_ja_char
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ 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.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/conv_ja_char. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the ConvJaChar project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/conv_ja_char/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 "conv_ja_char"
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
@@ -0,0 +1,42 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "conv_ja_char/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "conv_ja_char"
8
+ spec.version = ConvJaChar::VERSION
9
+ spec.authors = ["LicaOka"]
10
+ spec.email = ["lica.oka@gmail.com"]
11
+
12
+ spec.summary = %q{a library to convert Japanese character, like Hiragana or Katanaka, to Romaji.}
13
+ spec.description = %q{this library converts Hiragana or Katakana (both, UTF-8 without BOM) to Romaji form (using roman alphabet).}
14
+ spec.homepage = "https://github.com/LicaOka/conv_ja_char"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ # to allow pushing to any host
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.14"
34
+ spec.add_development_dependency "rake", "~> 12.0"
35
+ spec.add_development_dependency "rspec", "~> 3"
36
+
37
+ spec.add_development_dependency "rubocop", "~> 0.49.1"
38
+ spec.add_development_dependency "onkcop", "~> 0.49.1"
39
+ spec.add_development_dependency "pry", "~> 0.10"
40
+ spec.add_development_dependency "pry-byebug", "~> 3.4"
41
+ spec.add_development_dependency "debase", "~> 0.2.1"
42
+ end
data/gemtest/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+ source "https://rubygems.org"
3
+
4
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
5
+
6
+ # gem "rails"
7
+
8
+ gem "conv_ja_char", path: "../conv_jachar"
data/gemtest/test.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'conv_ja_char'
2
+
3
+ ConvJaChar.to_romaji('か', 'Hebon')
@@ -0,0 +1,23 @@
1
+ # encoding: utf-8
2
+
3
+ require 'conv_ja_char/version'
4
+
5
+ module ConvJaChar
6
+ class CharTypeCheck
7
+ def self.kanji?(str)
8
+ return nil unless str
9
+
10
+ regexp_kanji = /[一-龠々]+/
11
+
12
+ str =~ regexp_kanji # nil: not match, not nil: the position number that the matched char starts
13
+ end
14
+
15
+ def self.symbol?(str)
16
+ return nil unless str
17
+
18
+ regexp_symbol = /[!"#%&()*+,.\/:;<=>?@^_`{|}~]+/ # without white space, dollar sign($), single quotation(') and hyphen(-)
19
+
20
+ str =~ regexp_symbol # nil: not match, not nil: the position number that the matched char starts
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,77 @@
1
+ # encoding: utf-8
2
+
3
+ module ConvJaChar
4
+ KATANA_TO_HEBON_FORM = {
5
+ 'ア' => 'a', 'イ' => 'i', 'ウ' => 'u', 'エ' => 'e', 'オ' => 'o',
6
+ 'カ' => 'ka', 'キ' => 'ki', 'ク' => 'ku', 'ケ' => 'ke', 'コ' => 'ko',
7
+ 'サ' => 'sa', 'シ' => 'shi', 'ス' => 'su', 'セ' => 'se', 'ソ' => 'so',
8
+ 'タ' => 'ta', 'チ' => 'chi', 'ツ' => 'tsu', 'テ' => 'te', 'ト' => 'to',
9
+ 'ナ' => 'na', 'ニ' => 'ni', 'ヌ' => 'nu', 'ネ' => 'ne', 'ノ' => 'no',
10
+ 'ハ' => 'ha', 'ヒ' => 'hi', 'フ' => 'fu', 'ヘ' => 'he', 'ホ' => 'ho',
11
+ 'マ' => 'ma', 'ミ' => 'mi', 'ム' => 'mu', 'メ' => 'me', 'モ' => 'mo',
12
+ 'ヤ' => 'ya', 'ユ' => 'yu', 'ヨ' => 'yo',
13
+ 'ラ' => 'ra', 'リ' => 'ri', 'ル' => 'ru', 'レ' => 're', 'ロ' => 'ro',
14
+ 'ワ' => 'wa', 'ヰ' => 'wi', 'ヱ' => 'we', 'ヲ' => 'wo', 'ー' => '-',
15
+ 'ガ' => 'ga', 'ギ' => 'gi', 'グ' => 'gu', 'ゲ' => 'ge', 'ゴ' => 'go',
16
+ 'ザ' => 'za', 'ジ' => 'ji', 'ズ' => 'zu', 'ゼ' => 'ze', 'ゾ' => 'zo',
17
+ 'ダ' => 'da', 'ヂ' => 'di', 'ヅ' => 'du', 'デ' => 'de', 'ド' => 'do',
18
+ 'バ' => 'ba', 'ビ' => 'bi', 'ブ' => 'bu', 'ベ' => 'be', 'ボ' => 'bo',
19
+ 'パ' => 'pa', 'ピ' => 'pi', 'プ' => 'pu', 'ペ' => 'pe', 'ポ' => 'po',
20
+ 'ウィ' => 'wi','ウェ' => 'we', 'クヮ' => 'kwa', 'グヮ' => 'gwa', 'ン' => 'n',
21
+ 'キャ' => 'kya', 'キィ' => 'kyi', 'キュ' => 'kyu', 'キェ' => 'kye', 'キョ' => 'kyo',
22
+ 'ギャ' => 'gya', 'ギィ' => 'gyi', 'ギュ' => 'gyu', 'ギェ' => 'gye', 'ギョ' => 'gyo',
23
+ 'シャ' => 'sha', 'シィ' => 'syi', 'シュ' => 'shu', 'シェ' => 'she', 'ショ' => 'sho',
24
+ 'ジャ' => 'ja', 'ジィ' => 'jyi', 'ジュ' => 'ju', 'ジェ' => 'je', 'ジョ' => 'jo',
25
+ 'チャ' => 'cha', 'チィ' => 'cyi', 'チュ' => 'chu', 'チェ' => 'che', 'チョ' => 'cho',
26
+ 'ヂャ' => 'dya', 'ヂィ' => 'dyi', 'ヂュ' => 'dyu', 'ヂェ' => 'dye', 'ヂョ' => 'dyo',
27
+ 'テャ' => 'tha', 'ティ' => 'thi', 'テュ' => 'thu', 'テェ' => 'the', 'テョ' => 'tho',
28
+ 'デャ' => 'dha', 'ディ' => 'dhi', 'デュ' => 'dhu', 'デェ' => 'dhe', 'デョ' => 'dho',
29
+ 'ニャ' => 'nya', 'ニィ' => 'nyi', 'ニュ' => 'nyu', 'ニェ' => 'nye', 'ニョ' => 'nyo',
30
+ 'ヒャ' => 'hya', 'ヒィ' => 'hyi', 'ヒュ' => 'hyu', 'ヒェ' => 'hye', 'ヒョ' => 'hyo',
31
+ 'ビャ' => 'bya', 'ビィ' => 'byi', 'ビュ' => 'byu', 'ビェ' => 'bye', 'ビョ' => 'byo',
32
+ 'ピャ' => 'pya', 'ピィ' => 'pyi', 'ピュ' => 'pyu', 'ピェ' => 'pye', 'ピョ' => 'pyo',
33
+ 'ファ' => 'fa', 'フィ' => 'fi', 'フュ' => 'fyu', 'フェ' => 'fe', 'フォ' => 'fo',
34
+ 'ミャ' => 'mya', 'ミィ' => 'myi', 'ミュ' => 'myu', 'ミェ' => 'mye', 'ミョ' => 'myo',
35
+ 'リャ' => 'rya', 'リィ' => 'ryi', 'リュ' => 'ryu', 'リェ' => 'rye', 'リョ' => 'ryo',
36
+ 'ヴァ' => 'va', 'ヴィ' => 'vi', 'ヴ' => 'vu', 'ヴェ' => 've', 'ヴォ' => 'vo'
37
+ }.freeze
38
+
39
+ KATANA_TO_KUNREI_FORM = {
40
+ 'ア' => 'a', 'イ' => 'i', 'ウ' => 'u', 'エ' => 'e', 'オ' => 'o',
41
+ 'カ' => 'ka', 'キ' => 'ki', 'ク' => 'ku', 'ケ' => 'ke', 'コ' => 'ko',
42
+ 'サ' => 'sa', 'シ' => 'si', 'ス' => 'su', 'セ' => 'se', 'ソ' => 'so',
43
+ 'タ' => 'ta', 'チ' => 'ti', 'ツ' => 'tu', 'テ' => 'te', 'ト' => 'to',
44
+ 'ナ' => 'na', 'ニ' => 'ni', 'ヌ' => 'nu', 'ネ' => 'ne', 'ノ' => 'no',
45
+ 'ハ' => 'ha', 'ヒ' => 'hi', 'フ' => 'fu', 'ヘ' => 'he', 'ホ' => 'ho',
46
+ 'マ' => 'ma', 'ミ' => 'mi', 'ム' => 'mu', 'メ' => 'me', 'モ' => 'mo',
47
+ 'ヤ' => 'ya', 'ユ' => 'yu', 'ヨ' => 'yo',
48
+ 'ラ' => 'ra', 'リ' => 'ri', 'ル' => 'ru', 'レ' => 're', 'ロ' => 'ro',
49
+ 'ワ' => 'wa', 'ヰ' => 'wi', 'ヱ' => 'we', 'ヲ' => 'wo', 'ー' => '-',
50
+ 'ガ' => 'ga', 'ギ' => 'gi', 'グ' => 'gu', 'ゲ' => 'ge', 'ゴ' => 'go',
51
+ 'ザ' => 'za', 'ジ' => 'zi', 'ズ' => 'zu', 'ゼ' => 'ze', 'ゾ' => 'zo',
52
+ 'ダ' => 'da', 'ヂ' => 'zi', 'ヅ' => 'zu', 'デ' => 'de', 'ド' => 'do',
53
+ 'バ' => 'ba', 'ビ' => 'bi', 'ブ' => 'bu', 'ベ' => 'be', 'ボ' => 'bo',
54
+ 'パ' => 'pa', 'ピ' => 'pi', 'プ' => 'pu', 'ペ' => 'pe', 'ポ' => 'po',
55
+ 'ウィ' => 'wi', 'ウェ' => 'we', 'クヮ' => 'kwa', 'グヮ' => 'gwa', 'ン' => 'n',
56
+ 'キャ' => 'kya', 'キィ' => 'kyi', 'キュ' => 'kyu', 'キェ' => 'kye', 'キョ' => 'kyo',
57
+ 'ギャ' => 'gya', 'ギィ' => 'gyi', 'ギュ' => 'gyu', 'ギェ' => 'gye', 'ギョ' => 'gyo',
58
+ 'シャ' => 'sya', 'シィ' => 'syi', 'シュ' => 'syu', 'シェ' => 'sye', 'ショ' => 'syo',
59
+ 'ジャ' => 'zya', 'ジィ' => 'zyi', 'ジュ' => 'zyu', 'ジェ' => 'zye', 'ジョ' => 'zyo',
60
+ 'チャ' => 'tya', 'チィ' => 'tyi', 'チュ' => 'tyu', 'チェ' => 'tye', 'チョ' => 'tyo',
61
+ 'ヂャ' => 'zya', 'ヂィ' => 'zyi', 'ヂュ' => 'zyu', 'ヂェ' => 'zye', 'ヂョ' => 'zyo',
62
+ 'テャ' => 'tha', 'ティ' => 'thi', 'テュ' => 'thu', 'テェ' => 'the', 'テョ' => 'tho',
63
+ 'デャ' => 'dha', 'ディ' => 'dhi', 'デュ' => 'dhu', 'デェ' => 'dhe', 'デョ' => 'dho',
64
+ 'ニャ' => 'nya', 'ニィ' => 'nyi', 'ニュ' => 'nyu', 'ニェ' => 'nye', 'ニョ' => 'nyo',
65
+ 'ヒャ' => 'hya', 'ヒィ' => 'hyi', 'ヒュ' => 'hyu', 'ヒェ' => 'hye', 'ヒョ' => 'hyo',
66
+ 'ビャ' => 'bya', 'ビィ' => 'byi', 'ビュ' => 'byu', 'ビェ' => 'bye', 'ビョ' => 'byo',
67
+ 'ピャ' => 'pya', 'ピィ' => 'pyi', 'ピュ' => 'pyu', 'ピェ' => 'pye', 'ピョ' => 'pyo',
68
+ 'ファ' => 'fa', 'フィ' => 'fi', 'フュ' => 'fyu', 'フェ' => 'fe', 'フォ' => 'fo',
69
+ 'ミャ' => 'mya', 'ミィ' => 'myi', 'ミュ' => 'myu', 'ミェ' => 'mye', 'ミョ' => 'myo',
70
+ 'リャ' => 'rya', 'リィ' => 'ryi', 'リュ' => 'ryu', 'リェ' => 'rye', 'リョ' => 'ryo',
71
+ 'ヴァ' => 'va', 'ヴィ' => 'vi', 'ヴ' => 'vu', 'ヴェ' => 've', 'ヴォ' => 'vo'
72
+ }.freeze
73
+
74
+ SMALL_KANA_FOR_CONTRACTED_SOUND = %w(ァ ィ ェ ォ ャ ュ ョ ヮ).freeze
75
+
76
+ DOUBLE_CONSONANT_SOUND = 'ッ'.freeze
77
+ end
@@ -0,0 +1,18 @@
1
+ # encoding: utf-8
2
+
3
+ require 'nkf'
4
+ require 'conv_ja_char/version'
5
+
6
+ module ConvJaChar
7
+ class Normalization
8
+ def self.kana(str)
9
+ return '' unless str
10
+ # -Z1 : convert from X0208 white sapce to ASCII white space
11
+ # -X : convert from X0201 half-size katanaka to X0208 full-size katakana
12
+ # -w : output UTF-8 without BOM
13
+ # --katakana : convert from hiragana to katakana
14
+ NKF.nkf('-Z1 -X -w --katakana', "#{str}").downcase
15
+ end
16
+ end
17
+ end
18
+
@@ -0,0 +1,3 @@
1
+ module ConvJaChar
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,165 @@
1
+ # encoding: utf-8
2
+
3
+ require 'nkf'
4
+ require 'conv_ja_char/version'
5
+ require 'conv_ja_char/constants/katakana_romaji'
6
+ require 'conv_ja_char/normalization'
7
+ require 'conv_ja_char/check_char'
8
+
9
+ # conv_ja_char return value
10
+ # something romaji string : when ConvJaChar.to_romaji successes
11
+ # nil : when ConvJaChar.to_romaji has some errors
12
+
13
+ # conv_ja_char does not accept Kanji char currently.
14
+
15
+ module ConvJaChar
16
+ class << self
17
+ def to_romaji(str, option)
18
+ return str unless str.nil?
19
+ if str == ''
20
+ return str
21
+ end
22
+
23
+ @opt = ''
24
+ set_option(option)
25
+
26
+ binding.pry
27
+
28
+ if ConvJaChar::CharTypeCheck::kanji?(str) != nil
29
+ p "there seems to be Kanji char in #{str}. conv_ja_char does not accept Kanji char currently."
30
+ return str
31
+ end
32
+
33
+ binding.pry
34
+
35
+ @t = set_char_table(@opt)
36
+
37
+ @chars = ConvJaChar::Normalization.kana(str).split(//u)
38
+
39
+ @romaji = ''
40
+ @pos = 0
41
+ while @pos < @chars.size
42
+ @c = @chars[@pos]
43
+
44
+ if @c == (' ' || '$' || '-' || '\'')
45
+ @romaji += @c
46
+ @pos += 1
47
+ next
48
+ end
49
+
50
+ if ConvJaChar::CharTypeCheck::symbol?(@c) != nil
51
+ @romaji += @c
52
+ @pos += 1
53
+ next
54
+ end
55
+
56
+ @c_next = ''
57
+ set_next_char
58
+
59
+ case @c
60
+ when 'ン'
61
+ process_nasal_sound_change
62
+ next
63
+ when 'ッ'
64
+ process_sound_change_to_double_consonant
65
+ next
66
+ when 'ウ','キ','ギ','ク','グ','シ','ジ','チ','ヂ','テ','デ','ニ','ヒ','ビ','ピ','フ','ミ','リ','ヴ'
67
+ if @c_next.nil?
68
+ process_normal_char
69
+ next
70
+ end
71
+ if SMALL_KANA_FOR_CONTRACTED_SOUND.include?(@c_next)
72
+ process_contracted_sound
73
+ next
74
+ else
75
+ process_normal_char
76
+ next
77
+ end
78
+ else
79
+ process_normal_char
80
+ end
81
+ end
82
+
83
+ @romaji
84
+ end
85
+
86
+ private
87
+
88
+ def set_option(option)
89
+ case option
90
+ when 'Kunrei'
91
+ @opt = 'Kunrei'
92
+ when 'Hebon'
93
+ @opt = 'Hebon'
94
+ else
95
+ @opt = 'Kunrei'
96
+ end
97
+ end
98
+
99
+ def set_next_char
100
+ if (@pos + 1) < @chars.size
101
+ @c_next = @chars[@pos+1]
102
+ else
103
+ @c_next = nil
104
+ end
105
+ end
106
+
107
+ def set_char_table(op)
108
+ case op
109
+ when 'Hebon'
110
+ ConvJaChar::KATANA_TO_HEBON_FORM
111
+ when 'Kunrei'
112
+ ConvJaChar::KATANA_TO_KUNREI_FORM
113
+ else
114
+ ConvJaChar::KATANA_TO_KUNREI_FORM
115
+ end
116
+ end
117
+
118
+ def process_normal_char
119
+ @romaji += @t[@c]
120
+ @pos += 1
121
+ end
122
+
123
+ def process_nasal_sound_change(op) # ex.:'ン'
124
+ s = @t[@c_next]
125
+
126
+ case op
127
+ when 'Hebon'
128
+ if ['p','b','m'].include?(s[0])
129
+ @romaji += 'm'
130
+ else
131
+ @romaji += @t[@c]
132
+ if ['a','i','u','e','o','y','n'].include?(s[0])
133
+ @romaji += '\''
134
+ end
135
+ end
136
+ when 'Kunrei'
137
+ @romaji += @t[@c]
138
+ if ['a','i','u','e','o','y','n'].include?(s[0])
139
+ @romaji += '\''
140
+ end
141
+ end
142
+
143
+ @pos += 1
144
+ end
145
+
146
+ def process_sound_change_to_double_consonant # ex.:'ッ'
147
+ r = @t[@c_next]
148
+ if @c_next == DOUBLE_CONSONANT_SOUND || ['a','i','u','e','o','n',nil].include?(r[0]) || r.nil?
149
+ @romaji += 'xtsu'
150
+ else
151
+ @romaji += r[0].slice(0,1)
152
+ end
153
+ @pos += 1
154
+ end
155
+
156
+ def process_contracted_sound # ex.:'キャ'
157
+ s = @c + @c_next
158
+ @romaji += @t[s]
159
+ @pos += 2
160
+ end
161
+ end
162
+
163
+ # class Romaji TODO: to be implemented
164
+ # class Kanji TODO: to be implemented
165
+ end
metadata ADDED
@@ -0,0 +1,175 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: conv_ja_char
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - LicaOka
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-08-03 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.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '12.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '12.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.49.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.49.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: onkcop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.49.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.49.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.10'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.10'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry-byebug
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.4'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.4'
111
+ - !ruby/object:Gem::Dependency
112
+ name: debase
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 0.2.1
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 0.2.1
125
+ description: this library converts Hiragana or Katakana (both, UTF-8 without BOM)
126
+ to Romaji form (using roman alphabet).
127
+ email:
128
+ - lica.oka@gmail.com
129
+ executables: []
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - ".gitignore"
134
+ - ".rspec"
135
+ - ".travis.yml"
136
+ - CODE_OF_CONDUCT.md
137
+ - Gemfile
138
+ - LICENSE.txt
139
+ - README.md
140
+ - Rakefile
141
+ - bin/console
142
+ - bin/setup
143
+ - conv_ja_char.gemspec
144
+ - gemtest/Gemfile
145
+ - gemtest/test.rb
146
+ - lib/conv_ja_char.rb
147
+ - lib/conv_ja_char/check_char.rb
148
+ - lib/conv_ja_char/constants/katakana_romaji.rb
149
+ - lib/conv_ja_char/normalization.rb
150
+ - lib/conv_ja_char/version.rb
151
+ homepage: https://github.com/LicaOka/conv_ja_char
152
+ licenses:
153
+ - MIT
154
+ metadata: {}
155
+ post_install_message:
156
+ rdoc_options: []
157
+ require_paths:
158
+ - lib
159
+ required_ruby_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ required_rubygems_version: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ requirements: []
170
+ rubyforge_project:
171
+ rubygems_version: 2.5.1
172
+ signing_key:
173
+ specification_version: 4
174
+ summary: a library to convert Japanese character, like Hiragana or Katanaka, to Romaji.
175
+ test_files: []