dam_lev 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/Gemfile +3 -2
- data/Gemfile.lock +25 -0
- data/README.md +1 -1
- data/Rakefile +4 -45
- data/dam_lev.gemspec +22 -0
- data/lib/dam_lev.rb +9 -5
- data/lib/dam_lev/version.rb +3 -0
- data/spec/{DamLev_spec.rb → dam_lev_spec.rb} +2 -2
- data/spec/spec_helper.rb +2 -9
- metadata +26 -21
- data/VERSION +0 -1
- data/spec/spec.opts +0 -1
data/.gitignore
CHANGED
data/Gemfile
CHANGED
@@ -1,2 +1,3 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
source :gemcutter
|
2
|
+
|
3
|
+
gemspec
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
dam_lev (1.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: http://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.1.2)
|
10
|
+
rspec (2.1.0)
|
11
|
+
rspec-core (~> 2.1.0)
|
12
|
+
rspec-expectations (~> 2.1.0)
|
13
|
+
rspec-mocks (~> 2.1.0)
|
14
|
+
rspec-core (2.1.0)
|
15
|
+
rspec-expectations (2.1.0)
|
16
|
+
diff-lcs (~> 1.1.2)
|
17
|
+
rspec-mocks (2.1.0)
|
18
|
+
|
19
|
+
PLATFORMS
|
20
|
+
ruby
|
21
|
+
|
22
|
+
DEPENDENCIES
|
23
|
+
bundler (>= 1.0.0)
|
24
|
+
dam_lev!
|
25
|
+
rspec (~> 2.1.0)
|
data/README.md
CHANGED
@@ -16,7 +16,7 @@ DamLev implements the [Damerau–Levenshtein distance algorithm][1]. It is an al
|
|
16
16
|
DamLev.distance("DamLev", "Damev") # => 1 # deletion
|
17
17
|
DamLev.distance("DamLev", "DamLiev") # => 1 # insertion
|
18
18
|
DamLev.distance("DamLev", "Dam7ev") # => 1 # substitution
|
19
|
-
DamLev.distance("DamLev", "DameLv") # =>
|
19
|
+
DamLev.distance("DamLev", "DameLv") # => 1 # transposition
|
20
20
|
|
21
21
|
## Note on Patches/Pull Requests
|
22
22
|
|
data/Rakefile
CHANGED
@@ -1,46 +1,5 @@
|
|
1
|
-
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
2
3
|
|
3
|
-
require '
|
4
|
-
|
5
|
-
|
6
|
-
begin
|
7
|
-
require 'jeweler'
|
8
|
-
Jeweler::Tasks.new do |gem|
|
9
|
-
gem.name = "dam_lev"
|
10
|
-
gem.summary = %Q{Measure the distance between two strings.}
|
11
|
-
gem.description = %Q{Measures the distance between two strings using the Damerau–Levenshtein distance algorithm. For more, see http://en.wikipedia.org/wiki/Damerau%E2%80%93Levenshtein_distance }
|
12
|
-
gem.email = "blatyo@gmail.com"
|
13
|
-
gem.homepage = "http://github.com/blatyo/DamLev"
|
14
|
-
gem.authors = ["Allen Madsen"]
|
15
|
-
gem.add_development_dependency "rspec", ">= 1.2.9"
|
16
|
-
gem.add_development_dependency "yard", ">= 0"
|
17
|
-
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
18
|
-
end
|
19
|
-
Jeweler::GemcutterTasks.new
|
20
|
-
rescue LoadError
|
21
|
-
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
22
|
-
end
|
23
|
-
|
24
|
-
require 'spec/rake/spectask'
|
25
|
-
Spec::Rake::SpecTask.new(:spec) do |spec|
|
26
|
-
spec.libs << 'lib' << 'spec'
|
27
|
-
spec.spec_files = FileList['spec/**/*_spec.rb']
|
28
|
-
end
|
29
|
-
|
30
|
-
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
31
|
-
spec.libs << 'lib' << 'spec'
|
32
|
-
spec.pattern = 'spec/**/*_spec.rb'
|
33
|
-
spec.rcov = true
|
34
|
-
end
|
35
|
-
|
36
|
-
task :spec => :check_dependencies
|
37
|
-
task :default => :spec
|
38
|
-
|
39
|
-
begin
|
40
|
-
require 'yard'
|
41
|
-
YARD::Rake::YardocTask.new
|
42
|
-
rescue LoadError
|
43
|
-
task :yardoc do
|
44
|
-
abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
|
45
|
-
end
|
46
|
-
end
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
RSpec::Core::RakeTask.new(:spec)
|
data/dam_lev.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path("../lib/dam_lev/version", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "dam_lev"
|
6
|
+
s.version = DamLev::VERSION
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = ["Allen Madsen"]
|
9
|
+
s.email = ["blatyo@gmail.com"]
|
10
|
+
s.homepage = "http://github.com/blatyo/DamLev"
|
11
|
+
s.summary = %q{Measure the distance between two strings.}
|
12
|
+
s.description = %q{Measures the distance between two strings using the Damerau–Levenshtein distance algorithm. For more, see http://en.wikipedia.org/wiki/Damerau%E2%80%93Levenshtein_distance }
|
13
|
+
|
14
|
+
s.required_rubygems_version = ">= 1.3.6"
|
15
|
+
s.add_development_dependency "rspec", "~> 2.1.0"
|
16
|
+
s.add_development_dependency "bundler", ">= 1.0.0"
|
17
|
+
|
18
|
+
s.files = `git ls-files`.split("\n")
|
19
|
+
s.test_files = `git ls-files`.split("\n").map{|f| f =~ /^(spec\/.*)/ ? $1 : nil}.compact
|
20
|
+
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^(bin\/.*)/ ? $1 : nil}.compact
|
21
|
+
s.require_path = 'lib'
|
22
|
+
end
|
data/lib/dam_lev.rb
CHANGED
@@ -9,13 +9,17 @@ class DamLev
|
|
9
9
|
(1..str2.length).each do |j|
|
10
10
|
sub_cost = str1[i-1] == str2[j-1] ? 0 : 1
|
11
11
|
|
12
|
-
distance_matrix[i][j] = [
|
13
|
-
|
14
|
-
|
12
|
+
distance_matrix[i][j] = [
|
13
|
+
distance_matrix[i-1][j] + 1, # deletion
|
14
|
+
distance_matrix[i][j-1] + 1, # insertion
|
15
|
+
distance_matrix[i-1][j-1] + sub_cost # substitution
|
16
|
+
].min
|
15
17
|
|
16
18
|
if i > 1 && j > 1 && str1[i-1] == str2[j-2] && str1[i-2] == str2[j-1]
|
17
|
-
distance_matrix[i
|
18
|
-
|
19
|
+
distance_matrix[i][j] = [
|
20
|
+
distance_matrix[i][j],
|
21
|
+
distance_matrix[i-2][j-2] + sub_cost # transposition
|
22
|
+
].min
|
19
23
|
end
|
20
24
|
end
|
21
25
|
end
|
@@ -18,8 +18,8 @@ describe DamLev do
|
|
18
18
|
DamLev.distance("DamLev", "Dam7ev").should == 1
|
19
19
|
end
|
20
20
|
|
21
|
-
it "should calculate a distance of
|
22
|
-
DamLev.distance("DamLev", "DameLv").should ==
|
21
|
+
it "should calculate a distance of one when two characters have been swapped between two strings" do
|
22
|
+
DamLev.distance("DamLev", "DameLv").should == 1
|
23
23
|
end
|
24
24
|
|
25
25
|
it "should calculate a distance equal to the longest string if the other is empty" do
|
data/spec/spec_helper.rb
CHANGED
@@ -1,9 +1,2 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'dam_lev'
|
4
|
-
require 'spec'
|
5
|
-
require 'spec/autorun'
|
6
|
-
|
7
|
-
Spec::Runner.configure do |config|
|
8
|
-
|
9
|
-
end
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'lib', 'dam_lev')
|
2
|
+
require 'rspec'
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 1.0.
|
8
|
+
- 1
|
9
|
+
version: 1.0.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Allen Madsen
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-11-15 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -23,17 +23,17 @@ dependencies:
|
|
23
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
24
|
none: false
|
25
25
|
requirements:
|
26
|
-
- -
|
26
|
+
- - ~>
|
27
27
|
- !ruby/object:Gem::Version
|
28
28
|
segments:
|
29
|
-
- 1
|
30
29
|
- 2
|
31
|
-
-
|
32
|
-
|
30
|
+
- 1
|
31
|
+
- 0
|
32
|
+
version: 2.1.0
|
33
33
|
type: :development
|
34
34
|
version_requirements: *id001
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
|
-
name:
|
36
|
+
name: bundler
|
37
37
|
prerelease: false
|
38
38
|
requirement: &id002 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
@@ -41,39 +41,42 @@ dependencies:
|
|
41
41
|
- - ">="
|
42
42
|
- !ruby/object:Gem::Version
|
43
43
|
segments:
|
44
|
+
- 1
|
44
45
|
- 0
|
45
|
-
|
46
|
+
- 0
|
47
|
+
version: 1.0.0
|
46
48
|
type: :development
|
47
49
|
version_requirements: *id002
|
48
50
|
description: "Measures the distance between two strings using the Damerau\xE2\x80\x93Levenshtein distance algorithm. For more, see http://en.wikipedia.org/wiki/Damerau%E2%80%93Levenshtein_distance "
|
49
|
-
email:
|
51
|
+
email:
|
52
|
+
- blatyo@gmail.com
|
50
53
|
executables: []
|
51
54
|
|
52
55
|
extensions: []
|
53
56
|
|
54
|
-
extra_rdoc_files:
|
55
|
-
|
56
|
-
- README.md
|
57
|
+
extra_rdoc_files: []
|
58
|
+
|
57
59
|
files:
|
58
60
|
- .document
|
59
61
|
- .gitignore
|
60
62
|
- .rvmrc
|
61
63
|
- Gemfile
|
64
|
+
- Gemfile.lock
|
62
65
|
- LICENSE
|
63
66
|
- README.md
|
64
67
|
- Rakefile
|
65
|
-
-
|
68
|
+
- dam_lev.gemspec
|
66
69
|
- lib/dam_lev.rb
|
67
|
-
-
|
68
|
-
- spec/
|
70
|
+
- lib/dam_lev/version.rb
|
71
|
+
- spec/dam_lev_spec.rb
|
69
72
|
- spec/spec_helper.rb
|
70
73
|
has_rdoc: true
|
71
74
|
homepage: http://github.com/blatyo/DamLev
|
72
75
|
licenses: []
|
73
76
|
|
74
77
|
post_install_message:
|
75
|
-
rdoc_options:
|
76
|
-
|
78
|
+
rdoc_options: []
|
79
|
+
|
77
80
|
require_paths:
|
78
81
|
- lib
|
79
82
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -90,8 +93,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
93
|
- - ">="
|
91
94
|
- !ruby/object:Gem::Version
|
92
95
|
segments:
|
93
|
-
-
|
94
|
-
|
96
|
+
- 1
|
97
|
+
- 3
|
98
|
+
- 6
|
99
|
+
version: 1.3.6
|
95
100
|
requirements: []
|
96
101
|
|
97
102
|
rubyforge_project:
|
@@ -100,5 +105,5 @@ signing_key:
|
|
100
105
|
specification_version: 3
|
101
106
|
summary: Measure the distance between two strings.
|
102
107
|
test_files:
|
103
|
-
- spec/
|
108
|
+
- spec/dam_lev_spec.rb
|
104
109
|
- spec/spec_helper.rb
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
1.0.0
|
data/spec/spec.opts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--color
|