phonem_encoder 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in phonem_encoder.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Arndt Touby
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,47 @@
1
+ # PHOMEN Encoder
2
+
3
+ Encode a string with the PHONEM algorithm. This gem can be used for finding strings by their phonetic sound - optimized for the german language.
4
+
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'phonem_encoder'
12
+ ```
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install phonem_encoder
20
+
21
+
22
+ ## Usage
23
+
24
+ Call `phonetic_encode` on any string to get the phonetic code of the string.
25
+
26
+ ```ruby
27
+ "Müller".phonetic_code
28
+ ```
29
+
30
+ This will output "mylr"
31
+
32
+
33
+ ## Development
34
+
35
+ Questions or problems? Please post them on the [issue tracker](https://github.com/arndttouby/phonem_encoder/issues).
36
+
37
+
38
+ ## Contributing
39
+
40
+ 1. Fork it
41
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
42
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
43
+ 4. Push to the branch (`git push origin my-new-feature`)
44
+ 5. Create new Pull Request
45
+
46
+
47
+ This gem is craeted by Arndt Touby and is under the MIT License.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,3 @@
1
+ ## v0.0.1
2
+
3
+ * Initial release
@@ -0,0 +1,3 @@
1
+ module PhonemEncoder
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,74 @@
1
+ require "phonem_encoder/version"
2
+
3
+ module PhonemEncoder
4
+ class << self
5
+ def encode_string(string, length=2)
6
+ raise("length must be 1 or 2") if ![1,2].include?(length)
7
+
8
+ code = ''
9
+ string = string.downcase.gsub('ß','ss').gsub('ä', 'ae').gsub('ü', 'ue').scan(/./)
10
+
11
+ string.each_cons(length) do |chars|
12
+ if length == 2
13
+ case chars.join
14
+ when /^(sc|sz|cz|tz|ts)/ then
15
+ code << 'c'
16
+ when /^(ae)/ then
17
+ code << 'e'
18
+ when /^(pf)/ then
19
+ code << 'v'
20
+ when /^(ks)/ then
21
+ code << 'x'
22
+ when /^(qu)/ then
23
+ code << 'kw'
24
+ when /^(ow)/ then
25
+ code << 'ö'
26
+ when /^(ei|ey)/ then
27
+ code << 'ay'
28
+ when /^(eu)/ then
29
+ code << 'oy'
30
+ when /^(ou)/ then
31
+ code << 'u'
32
+ else
33
+ code << chars.join
34
+ end
35
+ else
36
+ case chars.join
37
+ when /^(z|k|g|q)/ then
38
+ code << 'c'
39
+ when /^(i|j)/ then
40
+ code << 'y'
41
+ when /^(f|w)/ then
42
+ code << 'v'
43
+ when /^(p)/ then
44
+ code << 'b'
45
+ when /^(t)/ then
46
+ code << 'd'
47
+ else
48
+ code << chars.join
49
+ end
50
+ end
51
+ end
52
+
53
+ code = encode_string(code, 1) if length == 2
54
+
55
+ reduce_multiples(code).scan(/[abcdlmnorsuvwxyö]/).join
56
+ end
57
+
58
+ def reduce_multiples(code)
59
+ unless code.gsub!(/(.)\1/, '\1').nil?
60
+ reduce_multiples(code)
61
+ end
62
+
63
+ code
64
+ end
65
+ end
66
+
67
+ def phonetic_code
68
+ PhonemEncoder.encode_string self.to_s
69
+ end
70
+ end
71
+
72
+ class String
73
+ include PhonemEncoder
74
+ end
@@ -0,0 +1,16 @@
1
+ require File.expand_path('../lib/phonem_encoder/version', __FILE__)
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.authors = ["Arndt Touby"]
5
+ gem.email = ["arndt@touby.eu"]
6
+ gem.description = %q{This gem can be used for finding strings by their phonetic sound - optimized for the german language}
7
+ gem.summary = %q{Encode a string with the PHONEM algorithm}
8
+ gem.homepage = "http://github.com/arndttouby/phonem_encoder"
9
+
10
+ gem.files = `git ls-files`.split($\)
11
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
12
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
13
+ gem.name = "phonem_encoder"
14
+ gem.require_paths = ["lib"]
15
+ gem.version = PhonemEncoder::VERSION
16
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: phonem_encoder
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Arndt Touby
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-09-12 00:00:00 Z
19
+ dependencies: []
20
+
21
+ description: This gem can be used for finding strings by their phonetic sound - optimized for the german language
22
+ email:
23
+ - arndt@touby.eu
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - .gitignore
32
+ - Gemfile
33
+ - LICENSE
34
+ - README.md
35
+ - Rakefile
36
+ - lib/phonem_encoder.rb
37
+ - lib/phonem_encoder/CHANGELOG
38
+ - lib/phonem_encoder/version.rb
39
+ - phonem_encoder.gemspec
40
+ homepage: http://github.com/arndttouby/phonem_encoder
41
+ licenses: []
42
+
43
+ post_install_message:
44
+ rdoc_options: []
45
+
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ hash: 3
54
+ segments:
55
+ - 0
56
+ version: "0"
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ hash: 3
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ requirements: []
67
+
68
+ rubyforge_project:
69
+ rubygems_version: 1.8.22
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: Encode a string with the PHONEM algorithm
73
+ test_files: []
74
+