ja-sound-index 0.0.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.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "rspec", "~> 2.3.0"
10
+ gem "bundler", "~> 1.0.0"
11
+ gem "jeweler", "~> 1.6.4"
12
+ gem "rcov", ">= 0"
13
+ end
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 tily
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "ja-sound-index"
18
+ gem.homepage = "http://github.com/tily/ruby-ja-sound-index"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{日本語カタカナから母音・子音によるインデックスを作成するライブラリ}
21
+ gem.description = %Q{日本語カタカナから母音・子音によるインデックスを作成するライブラリ}
22
+ gem.email = "tily05@gmail.com"
23
+ gem.authors = ["tily"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'rake/rdoctask'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "ja-sound-index #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -0,0 +1,22 @@
1
+ # -*- coding:utf-8 -*-
2
+
3
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
+ require 'ja/sound_index'
5
+
6
+ katakana = 'オンドゥルルラギッタンディスカー'
7
+
8
+ idx = Ja::SoundIndex.new(:ascii)
9
+
10
+ puts idx.vowel(katakana) # OUUUAIAIUA
11
+ puts idx.consonant(katakana) # ADRRRGTDSK
12
+
13
+ puts idx.vowel(katakana, ['ー']) # OUUUAIAIUA-
14
+ puts idx.consonant(katakana, ['ッ']) # ADRRRG.TDSK
15
+
16
+ idx2 = Ja::SoundIndex.new(:utf_8)
17
+
18
+ puts idx2.vowel(katakana) # オウウウアイアイウア
19
+ puts idx2.consonant(katakana) # アダラララガタダサカ
20
+
21
+ puts idx2.vowel(katakana, ['ー']) # オウウウアイアイウアー
22
+ puts idx2.consonant(katakana, ['ッ']) # アダラララガッタダサカ
@@ -0,0 +1,78 @@
1
+ # -*- coding:utf-8 -*-
2
+ class Ja
3
+ class SoundIndex
4
+ VOWEL = %w[A I U E O]
5
+ CONSONANT = %w[A K S T N H M Y R W G Z D B P]
6
+ LARGE = [
7
+ 'ア', 'イ', 'ウ', 'エ', 'オ', 'カ', 'キ', 'ク', 'ケ', 'コ',
8
+ 'サ', 'シ', 'ス', 'セ', 'ソ', 'タ', 'チ', 'ツ', 'テ', 'ト',
9
+ 'ナ', 'ニ', 'ヌ', 'ネ', 'ノ', 'ハ', 'ヒ', 'フ', 'ヘ', 'ホ',
10
+ 'マ', 'ミ', 'ム', 'メ', 'モ', 'ヤ', nil, 'ユ', nil, 'ヨ',
11
+ 'ラ', 'リ', 'ル', 'レ', 'ロ', 'ワ', 'ヰ', 'ヴ', 'ヱ', 'ヲ',
12
+ 'ガ', 'ギ', 'グ', 'ゲ', 'ゴ', 'ザ', 'ジ', 'ズ', 'ゼ', 'ゾ',
13
+ 'ダ', 'ヂ', 'ヅ', 'デ', 'ド', 'バ', 'ビ', 'ブ', 'ベ', 'ボ',
14
+ 'パ', 'ピ', 'プ', 'ペ', 'ポ',
15
+ ]
16
+ SMALL = [
17
+ 'ァ', 'ィ', 'ゥ', 'ェ', 'ォ', 'ャ', nil, 'ュ', nil, 'ョ',
18
+ 'ヮ'
19
+ ]
20
+ SPECIAL = {'ッ' => '.', 'ー' => '-', 'ン' => 'N'}
21
+
22
+ def initialize(mode)
23
+ @mode = mode
24
+ end
25
+
26
+ def only_katakana?(text)
27
+ text.match /^[#{LARGE.join}#{SMALL.join}#{SPECIAL.keys.join}]+$/u
28
+ end
29
+
30
+ def vowel(text, with=[])
31
+ if !only_katakana?(text)
32
+ raise ArgumentError, 'Error: first param must consist only of katakana.'
33
+ end
34
+ text = text.gsub(/([#{LARGE.join}])([#{SMALL.join}])*/u) {
35
+ map, snd = $2 ? [SMALL, $2] : [LARGE, $1]
36
+ arr = @mode == :ascii ? VOWEL : LARGE
37
+ arr[map.index(snd) % 5]
38
+ }
39
+ special(text, with)
40
+ end
41
+
42
+ def consonant(text, with=[])
43
+ if !only_katakana?(text)
44
+ raise ArgumentError, 'Error: first param must consist only of katakana.'
45
+ end
46
+ text = text.gsub(/([#{LARGE.join}])/u) {
47
+ i = LARGE.index($1) - LARGE.index($1) % 5
48
+ @mode == :ascii ? CONSONANT[i / 5] : LARGE[i]
49
+ }
50
+ text = text.gsub(/[#{SMALL.join}]/u, '')
51
+ special(text, with)
52
+ end
53
+
54
+ private
55
+ def special(text, with)
56
+ if !(without = SPECIAL.keys - with).empty?
57
+ text = text.gsub(/[#{without.join}]/u, '')
58
+ end
59
+ if @mode == :ascii
60
+ SPECIAL.each do |k, v|
61
+ text = text.gsub(/#{k}/u) { v }
62
+ end
63
+ end
64
+ text
65
+ end
66
+ end
67
+ end
68
+
69
+ if __FILE__ == $0
70
+ puts k = STDIN.read.chomp
71
+ [:ascii, :utf_8].each do |mode|
72
+ jsi = Ja::SoundIndex.new(mode)
73
+ [[], ['ー', 'ン', 'ッ']].each do |with|
74
+ puts jsi.vowel(k, with)
75
+ puts jsi.consonant(k, with)
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "JaSoundIndex" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'ja-sound-index'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ja-sound-index
3
+ version: !ruby/object:Gem::Version
4
+ hash: 31
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 0
10
+ version: 0.0.0
11
+ platform: ruby
12
+ authors:
13
+ - tily
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-10-14 00:00:00 +09:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ type: :development
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 2
31
+ - 3
32
+ - 0
33
+ version: 2.3.0
34
+ name: rspec
35
+ version_requirements: *id001
36
+ prerelease: false
37
+ - !ruby/object:Gem::Dependency
38
+ type: :development
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ hash: 23
45
+ segments:
46
+ - 1
47
+ - 0
48
+ - 0
49
+ version: 1.0.0
50
+ name: bundler
51
+ version_requirements: *id002
52
+ prerelease: false
53
+ - !ruby/object:Gem::Dependency
54
+ type: :development
55
+ requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ~>
59
+ - !ruby/object:Gem::Version
60
+ hash: 7
61
+ segments:
62
+ - 1
63
+ - 6
64
+ - 4
65
+ version: 1.6.4
66
+ name: jeweler
67
+ version_requirements: *id003
68
+ prerelease: false
69
+ - !ruby/object:Gem::Dependency
70
+ type: :development
71
+ requirement: &id004 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ hash: 3
77
+ segments:
78
+ - 0
79
+ version: "0"
80
+ name: rcov
81
+ version_requirements: *id004
82
+ prerelease: false
83
+ description: !binary |
84
+ 5pel5pys6Kqe44Kr44K/44Kr44OK44GL44KJ5q+N6Z+z44O75a2Q6Z+z44Gr
85
+ 44KI44KL44Kk44Oz44OH44OD44Kv44K544KS5L2c5oiQ44GZ44KL44Op44Kk
86
+ 44OW44Op44Oq
87
+
88
+ email: tily05@gmail.com
89
+ executables: []
90
+
91
+ extensions: []
92
+
93
+ extra_rdoc_files:
94
+ - LICENSE.txt
95
+ files:
96
+ - .document
97
+ - .rspec
98
+ - Gemfile
99
+ - LICENSE.txt
100
+ - Rakefile
101
+ - VERSION
102
+ - example/test.rb
103
+ - lib/ja/sound_index.rb
104
+ - spec/ja-sound-index_spec.rb
105
+ - spec/spec_helper.rb
106
+ has_rdoc: true
107
+ homepage: http://github.com/tily/ruby-ja-sound-index
108
+ licenses:
109
+ - MIT
110
+ post_install_message:
111
+ rdoc_options: []
112
+
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ hash: 3
121
+ segments:
122
+ - 0
123
+ version: "0"
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ none: false
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ hash: 3
130
+ segments:
131
+ - 0
132
+ version: "0"
133
+ requirements: []
134
+
135
+ rubyforge_project:
136
+ rubygems_version: 1.6.2
137
+ signing_key:
138
+ specification_version: 3
139
+ summary: !binary |
140
+ 5pel5pys6Kqe44Kr44K/44Kr44OK44GL44KJ5q+N6Z+z44O75a2Q6Z+z44Gr
141
+ 44KI44KL44Kk44Oz44OH44OD44Kv44K544KS5L2c5oiQ44GZ44KL44Op44Kk
142
+ 44OW44Op44Oq
143
+
144
+ test_files: []
145
+