home_of_phone 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/.rspec +2 -0
- data/.travis.yml +3 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +47 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/home_of_phone.gemspec +23 -0
- data/lib/home_of_phone.rb +10 -0
- data/lib/home_of_phone/base.rb +64 -0
- data/lib/home_of_phone/errors.rb +1 -0
- data/lib/home_of_phone/phonemes.rb +1121168 -0
- data/lib/home_of_phone/tools.rb +36 -0
- data/lib/home_of_phone/version.rb +3 -0
- metadata +89 -0
@@ -0,0 +1,36 @@
|
|
1
|
+
class HomeOfPhone::Tools
|
2
|
+
|
3
|
+
def self.levenshtein_distance(s, t)
|
4
|
+
m = s.length
|
5
|
+
n = t.length
|
6
|
+
return m if n == 0
|
7
|
+
return n if m == 0
|
8
|
+
d = Array.new(m+1) {Array.new(n+1)}
|
9
|
+
|
10
|
+
(0..m).each {|i| d[i][0] = i}
|
11
|
+
(0..n).each {|j| d[0][j] = j}
|
12
|
+
(1..n).each do |j|
|
13
|
+
(1..m).each do |i|
|
14
|
+
d[i][j] = if s[i-1] == t[j-1] # adjust index into string
|
15
|
+
d[i-1][j-1] # no operation required
|
16
|
+
else
|
17
|
+
[ d[i-1][j]+1, # deletion
|
18
|
+
d[i][j-1]+1, # insertion
|
19
|
+
d[i-1][j-1]+1, # substitution
|
20
|
+
].min
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
d[m][n]
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.rhyme_ish(phonemes1, phonemes2)
|
28
|
+
longest = [phonemes1, phonemes2].max_by(&:length)
|
29
|
+
ending = (longest.length / 4.0).ceil
|
30
|
+
phonemes1[-ending..-1] == phonemes2[-ending..-1]
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.remove_phoneme_accents(phonemes)
|
34
|
+
phonemes.map { |p| p.gsub(/[^a-zA-Z ]/,'') }
|
35
|
+
end
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: home_of_phone
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dave
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-09-01 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.8'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.8'
|
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
|
+
description: Test how similar two words sound to each other.
|
42
|
+
email:
|
43
|
+
- dave.schwantes@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- ".rspec"
|
50
|
+
- ".travis.yml"
|
51
|
+
- CODE_OF_CONDUCT.md
|
52
|
+
- Gemfile
|
53
|
+
- LICENSE.txt
|
54
|
+
- README.md
|
55
|
+
- Rakefile
|
56
|
+
- bin/console
|
57
|
+
- bin/setup
|
58
|
+
- home_of_phone.gemspec
|
59
|
+
- lib/home_of_phone.rb
|
60
|
+
- lib/home_of_phone/base.rb
|
61
|
+
- lib/home_of_phone/errors.rb
|
62
|
+
- lib/home_of_phone/phonemes.rb
|
63
|
+
- lib/home_of_phone/tools.rb
|
64
|
+
- lib/home_of_phone/version.rb
|
65
|
+
homepage: https://github.com/dorkrawk/home_of_phone
|
66
|
+
licenses:
|
67
|
+
- MIT
|
68
|
+
metadata: {}
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options: []
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
requirements: []
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 2.4.5
|
86
|
+
signing_key:
|
87
|
+
specification_version: 4
|
88
|
+
summary: Test how similar two words sound to each other.
|
89
|
+
test_files: []
|