damerau-levenshtein 1.0.3 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rspec +2 -0
- data/.rubocop.yml +15 -0
- data/.ruby-version +1 -1
- data/.travis.yml +3 -2
- data/{CHANGELOG → CHANGELOG.md} +6 -1
- data/Gemfile +1 -17
- data/LICENSE.txt +1 -1
- data/README.md +84 -69
- data/Rakefile +9 -20
- data/damerau-levenshtein.gemspec +32 -18
- data/ext/damerau_levenshtein/extconf.rb +3 -3
- data/lib/damerau-levenshtein.rb +4 -3
- data/lib/damerau-levenshtein/damerau_levenshtein.so +0 -0
- data/lib/damerau-levenshtein/version.rb +2 -1
- metadata +159 -24
- data/Gemfile.lock +0 -83
- data/features/damerau-levenshtein.feature +0 -39
- data/features/step_definitions/damerau-levenshtein_steps.rb +0 -15
- data/features/support/env.rb +0 -13
- data/spec/damerau-levenshtein_spec.rb +0 -24
- data/spec/damerau_levenshtein_test.txt +0 -89
- data/spec/spec_helper.rb +0 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 069786523f2031b397b0c45af0841793ba696751
|
4
|
+
data.tar.gz: fae6b9bf74312f37b2bed2b032a46b7ae483da33
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 13fb0c92038b6a3d21cf4ab4988996d841f3819d445129309a6db5a53a409151af45c2c2fed042c5f38a0a3921f9ae3346d7a32a5a038d22f5d58ceb0259b78c
|
7
|
+
data.tar.gz: fe8cbd5abd96ee8b2980d8b754cd4817e9529586d612f9816dcc1cafeaa7d3d67dd131b4e6569040081986e16230cb7d445d9732591ed3ad02897872c4b8eb8c
|
data/.gitignore
CHANGED
data/.rspec
CHANGED
data/.rubocop.yml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
AllCops:
|
2
|
+
Exclude:
|
3
|
+
- features/**/*
|
4
|
+
- db/**/*
|
5
|
+
- bundle_bin/**/*
|
6
|
+
Include:
|
7
|
+
- damerau-levenshtein.gemspec
|
8
|
+
Metrics/ModuleLength:
|
9
|
+
Max: 1000
|
10
|
+
Style/StringLiterals:
|
11
|
+
EnforcedStyle: double_quotes
|
12
|
+
Style/DotPosition:
|
13
|
+
EnforcedStyle: trailing
|
14
|
+
Style/FileName:
|
15
|
+
Enabled: false
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.1.6
|
data/.travis.yml
CHANGED
data/{CHANGELOG → CHANGELOG.md}
RENAMED
@@ -1,7 +1,12 @@
|
|
1
|
+
damerau-levenshtein CHANGELOG
|
2
|
+
=============================
|
3
|
+
|
4
|
+
1.1.0 -- relax and update gem dependencies, update specs
|
5
|
+
|
1
6
|
1.0.3 -- gems update
|
2
7
|
|
3
8
|
1.0.2 -- includes refactoring by https://github.com/luislavena to remove
|
4
|
-
dependency on jeweler
|
9
|
+
dependency on jeweler
|
5
10
|
|
6
11
|
1.0.1 -- fixed gem dependencies
|
7
12
|
|
data/Gemfile
CHANGED
@@ -1,19 +1,3 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
|
4
|
-
gem 'rake', '~> 10.0'
|
5
|
-
gem 'rake-compiler', '~> 0.8'
|
6
|
-
gem 'json', '~> 1.7.7'
|
7
|
-
|
8
|
-
group :development do
|
9
|
-
gem 'debugger', '~> 1.6'
|
10
|
-
end
|
11
|
-
|
12
|
-
group :test do
|
13
|
-
gem 'rspec', '~> 2.13'
|
14
|
-
gem 'cucumber', '~> 1.3'
|
15
|
-
gem 'ruby-prof', '~> 0.13'
|
16
|
-
gem 'shoulda', '~> 3.5'
|
17
|
-
gem 'coveralls', require: false
|
18
|
-
end
|
19
|
-
|
3
|
+
gemspec
|
data/LICENSE.txt
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
The MIT License (MIT)
|
2
2
|
|
3
|
-
Copyright (c) 2011-
|
3
|
+
Copyright (c) 2011-2015 Marine Biological Laboratory
|
4
4
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining
|
6
6
|
a copy of this software and associated documentation files (the
|
data/README.md
CHANGED
@@ -1,64 +1,78 @@
|
|
1
1
|
damerau-levenshtein
|
2
2
|
===================
|
3
3
|
|
4
|
-
[![Gem Version][
|
5
|
-
[![Continuous Integration Status][
|
6
|
-
[![Dependency Status][
|
7
|
-
[![Coverage Status][
|
8
|
-
|
9
|
-
The damerau-levenshtein gem allows to find edit distance between two UTF-8
|
10
|
-
or ASCII encoded strings with O(N
|
11
|
-
|
12
|
-
This gem implements pure Levenshtein algorithm, Damerau modification of it
|
13
|
-
(where 2 character transposition counts as 1 edit distance). It also includes
|
14
|
-
Boehmer & Rees 2008 modification of Damerau algorithm, where transposition
|
15
|
-
of bigger than 1 character blocks is taken in account as well
|
4
|
+
[![Gem Version][gem_svg]][gem]
|
5
|
+
[![Continuous Integration Status][ci_svg]][ci]
|
6
|
+
[![Dependency Status][dep_svg]][dep]
|
7
|
+
[![Coverage Status][cov_svg]][cov]
|
8
|
+
|
9
|
+
The damerau-levenshtein gem allows to find edit distance between two UTF-8
|
10
|
+
or ASCII encoded strings with O(N\*M) efficiency.
|
11
|
+
|
12
|
+
This gem implements pure Levenshtein algorithm, Damerau modification of it
|
13
|
+
(where 2 character transposition counts as 1 edit distance). It also includes
|
14
|
+
Boehmer & Rees 2008 modification of Damerau algorithm, where transposition
|
15
|
+
of bigger than 1 character blocks is taken in account as well
|
16
16
|
(Boehmer & Rees 2008).
|
17
|
-
|
18
|
-
require 'damerau-levenshtein'
|
19
|
-
DamerauLevenshtein.distance('Something', 'Smoething') #returns 1
|
20
17
|
|
21
|
-
|
18
|
+
```ruby
|
19
|
+
require 'damerau-levenshtein'
|
20
|
+
DamerauLevenshtein.distance('Something', 'Smoething') #returns 1
|
21
|
+
```
|
22
|
+
|
23
|
+
Gem damerau-levenshtein is compatible with ruby versions 1.8.7
|
22
24
|
and 1.9.2 and higher, as well as 2.0.0 and higher
|
23
25
|
|
24
26
|
Installation
|
25
27
|
------------
|
26
28
|
|
27
|
-
gem install damerau-levenshtein
|
29
|
+
$ gem install damerau-levenshtein
|
28
30
|
|
29
31
|
Examples
|
30
32
|
--------
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
require 'rubygems' #not needed for ruby >= 1.9.0
|
36
|
+
require 'damerau-levenshtein'
|
37
|
+
dl = DamerauLevenshtein
|
38
|
+
```
|
35
39
|
|
36
40
|
* compare using Damerau Levenshtein algorithm
|
37
41
|
|
38
|
-
|
42
|
+
```ruby
|
43
|
+
dl.distance("Something", "Smoething") #returns 1
|
44
|
+
```
|
39
45
|
|
40
46
|
* compare using Levensthein algorithm
|
41
|
-
|
42
|
-
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
dl.distance("Something", "Smoething", 0) #returns 2
|
50
|
+
```
|
43
51
|
|
44
52
|
* compare using Boehmer & Rees modification
|
45
53
|
|
46
|
-
|
54
|
+
```ruby
|
55
|
+
dl.distance("Something", "meSothing", 2) #returns 2 instead of 4
|
56
|
+
```
|
47
57
|
|
48
58
|
* comparison of words with utf-8 characters should work fine:
|
49
59
|
|
50
|
-
|
60
|
+
```ruby
|
61
|
+
dl.distance("Sjöstedt", "Sjostedt") #returns 1
|
62
|
+
```
|
51
63
|
|
52
64
|
API Description
|
53
65
|
-----------
|
54
66
|
|
55
67
|
Gem defines two methods
|
56
68
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
69
|
+
```ruby
|
70
|
+
DamerauLevenshtein.version
|
71
|
+
#returns version number of the gem
|
72
|
+
|
73
|
+
DamerauLevenshtein.distance(string1, string2, block_size, max_distance)
|
74
|
+
#returns [edit distance][ed] between 2 strings
|
75
|
+
```
|
62
76
|
|
63
77
|
|
64
78
|
|
@@ -71,79 +85,80 @@ DamerauLevenshtein.distance takes 4 arguments:
|
|
71
85
|
|
72
86
|
`block_size` determines maximum number of characters in a transposition block:
|
73
87
|
|
74
|
-
block_size = 0
|
88
|
+
block_size = 0
|
75
89
|
(transposition does not count -- it is a pure Levenshtein algorithm)
|
76
|
-
|
77
|
-
block_size = 1
|
78
|
-
(transposition between 2 adjustent characters --
|
90
|
+
|
91
|
+
block_size = 1
|
92
|
+
(transposition between 2 adjustent characters --
|
79
93
|
it is pure Damerau-Levenshtein algorithm)
|
80
|
-
|
81
|
-
block_size = 2
|
82
|
-
(transposition between blocks as big as 2 characters -- so abcd and cdab
|
94
|
+
|
95
|
+
block_size = 2
|
96
|
+
(transposition between blocks as big as 2 characters -- so abcd and cdab
|
83
97
|
counts as edit distance 2, not 4)
|
84
|
-
|
85
|
-
block_size = 3
|
86
|
-
(transposition between blocks as big as 3 characters --
|
98
|
+
|
99
|
+
block_size = 3
|
100
|
+
(transposition between blocks as big as 3 characters --
|
87
101
|
so abcdef and defabc counts as edit distance 3, not 6)
|
88
|
-
|
102
|
+
|
89
103
|
etc.
|
90
104
|
|
91
|
-
`max_distance` -- is a threshold after which algorithm gives up and
|
105
|
+
`max_distance` -- is a threshold after which algorithm gives up and
|
92
106
|
returns max_distance instead of real edit distance.
|
93
107
|
|
94
|
-
Levenshtein algorithm is expensive, so it makes sense to give up when edit
|
108
|
+
Levenshtein algorithm is expensive, so it makes sense to give up when edit
|
95
109
|
distance is becoming too big. The argument max_distance does just that.
|
96
110
|
|
97
|
-
|
98
|
-
|
99
|
-
|
111
|
+
```ruby
|
112
|
+
DamerauLevenshtein.distance('abcdefg', '1234567', 0, 3)
|
113
|
+
# output: 4 -- it gave up when edit distance exceeded 3
|
114
|
+
```
|
100
115
|
|
101
116
|
Contributing to damerau-levenshtein
|
102
117
|
-----------------------------------
|
103
|
-
|
104
|
-
* Check out the latest master to make sure the feature hasn't been
|
118
|
+
|
119
|
+
* Check out the latest master to make sure the feature hasn't been
|
105
120
|
implemented or the bug hasn't been fixed yet
|
106
|
-
* Check out the issue tracker to make sure someone already hasn't requested
|
121
|
+
* Check out the issue tracker to make sure someone already hasn't requested
|
107
122
|
it and/or contributed it
|
108
123
|
* Fork the project
|
109
124
|
* Start a feature/bugfix branch
|
110
125
|
* Commit and push until you are happy with your contribution
|
111
|
-
* Make sure to add tests for it. This is important so I don't break it
|
126
|
+
* Make sure to add tests for it. This is important so I don't break it
|
112
127
|
in a future version unintentionally.
|
113
|
-
* Please try not to mess with the Rakefile, version, or history. If you want
|
114
|
-
to have your own version, or is otherwise necessary, that is fine, but please
|
128
|
+
* Please try not to mess with the Rakefile, version, or history. If you want
|
129
|
+
to have your own version, or is otherwise necessary, that is fine, but please
|
115
130
|
isolate to its own commit so I can cherry-pick around it.
|
116
131
|
|
117
132
|
Versioning
|
118
133
|
----------
|
119
134
|
|
120
|
-
This gem is following practices of [Semantic Versioning][
|
135
|
+
This gem is following practices of [Semantic Versioning][semver]
|
121
136
|
|
122
137
|
Authors
|
123
138
|
-------
|
124
139
|
|
125
|
-
[Dmitry Mozzherin][
|
140
|
+
[Dmitry Mozzherin][dimus]
|
126
141
|
|
127
142
|
Contributors
|
128
143
|
------------
|
129
144
|
|
130
|
-
[lazylester][
|
145
|
+
[lazylester][lazylester]
|
131
146
|
|
132
147
|
Copyright
|
133
148
|
---------
|
134
149
|
|
135
|
-
Copyright (c) 2011-
|
150
|
+
Copyright (c) 2011-2015 Marine Biological Laboratory. See LICENSE.txt for
|
136
151
|
further details.
|
137
152
|
|
138
|
-
[
|
139
|
-
[
|
140
|
-
[
|
141
|
-
[
|
142
|
-
[
|
143
|
-
[
|
144
|
-
[
|
145
|
-
[
|
146
|
-
[
|
147
|
-
[
|
148
|
-
[
|
149
|
-
[
|
153
|
+
[gem_svg]: https://badge.fury.io/rb/damerau-levenshtein.svg
|
154
|
+
[gem]: http://badge.fury.io/rb/damerau-levenshtein
|
155
|
+
[ci_svg]: https://secure.travis-ci.org/GlobalNamesArchitecture/damerau-levenshtein.svg
|
156
|
+
[ci]: http://travis-ci.org/GlobalNamesArchitecture/damerau-levenshtein
|
157
|
+
[dep_svg]: https://gemnasium.com/GlobalNamesArchitecture/damerau-levenshtein.svg
|
158
|
+
[dep]: https://gemnasium.com/GlobalNamesArchitecture/damerau-levenshtein
|
159
|
+
[cov_svg]: https://coveralls.io/repos/GlobalNamesArchitecture/damerau-levenshtein/badge.svg?branch=master
|
160
|
+
[cov]: https://coveralls.io/r/GlobalNamesArchitecture/damerau-levenshtein?branch=master
|
161
|
+
[ed]: http://en.wikipedia.org/wiki/Edit_distance
|
162
|
+
[semver]: http://semver.org/
|
163
|
+
[dimus]: https://github.com/dimus
|
164
|
+
[lazylester]: https://github.com/lazylester
|
data/Rakefile
CHANGED
@@ -1,29 +1,16 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require '
|
4
|
-
require
|
5
|
-
|
6
|
-
Bundler::GemHelper.install_tasks
|
7
|
-
|
8
|
-
begin
|
9
|
-
Bundler.setup(:default, :development)
|
10
|
-
rescue Bundler::BundlerError => e
|
11
|
-
$stderr.puts e.message
|
12
|
-
$stderr.puts 'Run `bundle install` to install missing gems'
|
13
|
-
exit e.status_code
|
14
|
-
end
|
15
|
-
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rspec/core/rake_task"
|
3
|
+
require 'cucumber/rake/task'
|
4
|
+
require "rubocop/rake_task"
|
16
5
|
require 'rake/dsl_definition'
|
17
6
|
require 'rake'
|
18
7
|
require 'rake/extensiontask'
|
19
8
|
require 'rspec'
|
20
|
-
require 'rspec/core/rake_task'
|
21
9
|
|
22
|
-
RSpec::Core::RakeTask.new(:spec) do |
|
23
|
-
|
10
|
+
RSpec::Core::RakeTask.new(:spec) do |rspec|
|
11
|
+
rspec.pattern = FileList['spec/**/*_spec.rb']
|
24
12
|
end
|
25
13
|
|
26
|
-
require 'cucumber/rake/task'
|
27
14
|
Cucumber::Rake::Task.new(:features)
|
28
15
|
|
29
16
|
Rake::ExtensionTask.new('damerau_levenshtein') do |extension|
|
@@ -33,4 +20,6 @@ end
|
|
33
20
|
|
34
21
|
Rake::Task[:spec].prerequisites << :compile
|
35
22
|
Rake::Task[:features].prerequisites << :compile
|
36
|
-
|
23
|
+
|
24
|
+
RuboCop::RakeTask.new
|
25
|
+
task :default => [:rubocop, :spec]
|
data/damerau-levenshtein.gemspec
CHANGED
@@ -1,23 +1,37 @@
|
|
1
|
-
|
1
|
+
$LOAD_PATH.push File.expand_path("../lib", __FILE__)
|
2
2
|
|
3
|
-
require
|
3
|
+
require "damerau-levenshtein/version"
|
4
4
|
|
5
|
-
# Describe your gem and declare its dependencies:
|
6
5
|
Gem::Specification.new do |s|
|
7
|
-
s.name =
|
6
|
+
s.name = "damerau-levenshtein"
|
8
7
|
s.version = DamerauLevenshtein::VERSION
|
9
|
-
s.homepage =
|
10
|
-
s.
|
11
|
-
s.
|
12
|
-
|
13
|
-
s.
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
s.
|
8
|
+
s.homepage = "https://github.com/GlobalNamesArchitecture/damerau-levenshtein"
|
9
|
+
s.authors = ["Dmitry Mozzherin"]
|
10
|
+
s.email = "dmozzherin@gmail.com"
|
11
|
+
s.license = "MIT"
|
12
|
+
s.summary = "Calculation of editing distance for 2 strings " \
|
13
|
+
"using Levenshtein or Damerau-Levenshtein algorithms"
|
14
|
+
s.description = "This gem implements pure Levenshtein algorithm, " \
|
15
|
+
"Damerau modification of it (where 2 character " \
|
16
|
+
"transposition counts as 1 edit distance). It also " \
|
17
|
+
"includes Boehmer & Rees 2008 modification " \
|
18
|
+
"of Damerau algorithm, where transposition of bigger than " \
|
19
|
+
"1 character blocks is taken in account as well " \
|
20
|
+
"(Boehmer & Rees 2008)."
|
21
|
+
s.files = `git ls-files -z`.split("\x0").
|
22
|
+
reject { |f| f.match(%r{^(test|spec|features)/}) }
|
23
|
+
s.extensions = ["ext/damerau_levenshtein/extconf.rb"]
|
24
|
+
s.require_paths = ["lib", "lib/damerau-levenshtein"]
|
25
|
+
|
26
|
+
s.add_dependency "bundler", "~> 1.7"
|
27
|
+
s.add_dependency "rake", "~> 10.4"
|
28
|
+
s.add_dependency "rake-compiler", "~> 0.9"
|
29
|
+
s.add_dependency "json", "~> 1.8"
|
30
|
+
|
31
|
+
s.add_development_dependency "rspec", "~> 3.2"
|
32
|
+
s.add_development_dependency "cucumber", "~> 2.0"
|
33
|
+
s.add_development_dependency "ruby-prof", "~> 0.15"
|
34
|
+
s.add_development_dependency "shoulda", "~> 3.5"
|
35
|
+
s.add_development_dependency "rubocop", "~> 0.30"
|
36
|
+
s.add_development_dependency "coveralls", "~> 0.8"
|
23
37
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# Loads mkmf which is used to make makefiles for Ruby extensions
|
2
|
-
require
|
2
|
+
require "mkmf"
|
3
3
|
|
4
4
|
# The destination
|
5
|
-
dir_config(
|
5
|
+
dir_config("damerau-levenshtein/damerau_levenshtein")
|
6
6
|
|
7
7
|
# Do the work
|
8
|
-
create_makefile(
|
8
|
+
create_makefile("damerau-levenshtein/damerau_levenshtein")
|
data/lib/damerau-levenshtein.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "damerau-levenshtein/version"
|
4
|
+
require "damerau-levenshtein/damerau_levenshtein"
|
5
5
|
|
6
|
+
# Damerau-Levenshtein algorithm
|
6
7
|
module DamerauLevenshtein
|
7
8
|
extend DamerauLevenshteinBinding
|
8
9
|
|
@@ -11,6 +12,6 @@ module DamerauLevenshtein
|
|
11
12
|
end
|
12
13
|
|
13
14
|
def self.distance(str1, str2, block_size = 1, max_distance = 10)
|
14
|
-
distance_utf(str1.unpack(
|
15
|
+
distance_utf(str1.unpack("U*"), str2.unpack("U*"), block_size, max_distance)
|
15
16
|
end
|
16
17
|
end
|
Binary file
|
metadata
CHANGED
@@ -1,47 +1,182 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: damerau-levenshtein
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmitry Mozzherin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
11
|
+
date: 2015-05-20 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.7'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
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.4'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.4'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake-compiler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.9'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.9'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: json
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.8'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.8'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.2'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.2'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: cucumber
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '2.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '2.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: ruby-prof
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.15'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.15'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: shoulda
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '3.5'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '3.5'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rubocop
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0.30'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0.30'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: coveralls
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0.8'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0.8'
|
153
|
+
description: This gem implements pure Levenshtein algorithm, Damerau modification
|
154
|
+
of it (where 2 character transposition counts as 1 edit distance). It also includes
|
155
|
+
Boehmer & Rees 2008 modification of Damerau algorithm, where transposition of bigger
|
156
|
+
than 1 character blocks is taken in account as well (Boehmer & Rees 2008).
|
17
157
|
email: dmozzherin@gmail.com
|
18
158
|
executables: []
|
19
159
|
extensions:
|
20
160
|
- ext/damerau_levenshtein/extconf.rb
|
21
161
|
extra_rdoc_files: []
|
22
162
|
files:
|
23
|
-
- .document
|
24
|
-
- .gitignore
|
25
|
-
- .rspec
|
26
|
-
- .
|
27
|
-
- .
|
28
|
-
-
|
163
|
+
- ".document"
|
164
|
+
- ".gitignore"
|
165
|
+
- ".rspec"
|
166
|
+
- ".rubocop.yml"
|
167
|
+
- ".ruby-version"
|
168
|
+
- ".travis.yml"
|
169
|
+
- CHANGELOG.md
|
29
170
|
- Gemfile
|
30
|
-
- Gemfile.lock
|
31
171
|
- LICENSE.txt
|
32
172
|
- README.md
|
33
173
|
- Rakefile
|
34
174
|
- damerau-levenshtein.gemspec
|
35
175
|
- ext/damerau_levenshtein/damerau_levenshtein.c
|
36
176
|
- ext/damerau_levenshtein/extconf.rb
|
37
|
-
- features/damerau-levenshtein.feature
|
38
|
-
- features/step_definitions/damerau-levenshtein_steps.rb
|
39
|
-
- features/support/env.rb
|
40
177
|
- lib/damerau-levenshtein.rb
|
178
|
+
- lib/damerau-levenshtein/damerau_levenshtein.so
|
41
179
|
- lib/damerau-levenshtein/version.rb
|
42
|
-
- spec/damerau-levenshtein_spec.rb
|
43
|
-
- spec/damerau_levenshtein_test.txt
|
44
|
-
- spec/spec_helper.rb
|
45
180
|
homepage: https://github.com/GlobalNamesArchitecture/damerau-levenshtein
|
46
181
|
licenses:
|
47
182
|
- MIT
|
@@ -53,19 +188,19 @@ require_paths:
|
|
53
188
|
- lib/damerau-levenshtein
|
54
189
|
required_ruby_version: !ruby/object:Gem::Requirement
|
55
190
|
requirements:
|
56
|
-
- -
|
191
|
+
- - ">="
|
57
192
|
- !ruby/object:Gem::Version
|
58
193
|
version: '0'
|
59
194
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
195
|
requirements:
|
61
|
-
- -
|
196
|
+
- - ">="
|
62
197
|
- !ruby/object:Gem::Version
|
63
198
|
version: '0'
|
64
199
|
requirements: []
|
65
200
|
rubyforge_project:
|
66
|
-
rubygems_version: 2.
|
201
|
+
rubygems_version: 2.2.3
|
67
202
|
signing_key:
|
68
203
|
specification_version: 4
|
69
|
-
summary: Calculation of editing distance for 2 strings
|
204
|
+
summary: Calculation of editing distance for 2 strings using Levenshtein or Damerau-Levenshtein
|
70
205
|
algorithms
|
71
206
|
test_files: []
|
data/Gemfile.lock
DELETED
@@ -1,83 +0,0 @@
|
|
1
|
-
GEM
|
2
|
-
remote: https://rubygems.org/
|
3
|
-
specs:
|
4
|
-
activesupport (4.0.0)
|
5
|
-
i18n (~> 0.6, >= 0.6.4)
|
6
|
-
minitest (~> 4.2)
|
7
|
-
multi_json (~> 1.3)
|
8
|
-
thread_safe (~> 0.1)
|
9
|
-
tzinfo (~> 0.3.37)
|
10
|
-
atomic (1.1.13)
|
11
|
-
builder (3.2.2)
|
12
|
-
colorize (0.5.8)
|
13
|
-
columnize (0.3.6)
|
14
|
-
coveralls (0.6.7)
|
15
|
-
colorize
|
16
|
-
multi_json (~> 1.3)
|
17
|
-
rest-client
|
18
|
-
simplecov (>= 0.7)
|
19
|
-
thor
|
20
|
-
cucumber (1.3.6)
|
21
|
-
builder (>= 2.1.2)
|
22
|
-
diff-lcs (>= 1.1.3)
|
23
|
-
gherkin (~> 2.12.0)
|
24
|
-
multi_json (~> 1.7.5)
|
25
|
-
multi_test (>= 0.0.2)
|
26
|
-
debugger (1.6.1)
|
27
|
-
columnize (>= 0.3.1)
|
28
|
-
debugger-linecache (~> 1.2.0)
|
29
|
-
debugger-ruby_core_source (~> 1.2.3)
|
30
|
-
debugger-linecache (1.2.0)
|
31
|
-
debugger-ruby_core_source (1.2.3)
|
32
|
-
diff-lcs (1.2.4)
|
33
|
-
gherkin (2.12.1)
|
34
|
-
multi_json (~> 1.3)
|
35
|
-
i18n (0.6.5)
|
36
|
-
json (1.7.7)
|
37
|
-
mime-types (1.25)
|
38
|
-
minitest (4.7.5)
|
39
|
-
multi_json (1.7.9)
|
40
|
-
multi_test (0.0.2)
|
41
|
-
rake (10.1.0)
|
42
|
-
rake-compiler (0.9.1)
|
43
|
-
rake
|
44
|
-
rest-client (1.6.7)
|
45
|
-
mime-types (>= 1.16)
|
46
|
-
rspec (2.14.1)
|
47
|
-
rspec-core (~> 2.14.0)
|
48
|
-
rspec-expectations (~> 2.14.0)
|
49
|
-
rspec-mocks (~> 2.14.0)
|
50
|
-
rspec-core (2.14.5)
|
51
|
-
rspec-expectations (2.14.2)
|
52
|
-
diff-lcs (>= 1.1.3, < 2.0)
|
53
|
-
rspec-mocks (2.14.3)
|
54
|
-
ruby-prof (0.13.0)
|
55
|
-
shoulda (3.5.0)
|
56
|
-
shoulda-context (~> 1.0, >= 1.0.1)
|
57
|
-
shoulda-matchers (>= 1.4.1, < 3.0)
|
58
|
-
shoulda-context (1.1.5)
|
59
|
-
shoulda-matchers (2.3.0)
|
60
|
-
activesupport (>= 3.0.0)
|
61
|
-
simplecov (0.7.1)
|
62
|
-
multi_json (~> 1.0)
|
63
|
-
simplecov-html (~> 0.7.1)
|
64
|
-
simplecov-html (0.7.1)
|
65
|
-
thor (0.18.1)
|
66
|
-
thread_safe (0.1.2)
|
67
|
-
atomic
|
68
|
-
tzinfo (0.3.37)
|
69
|
-
|
70
|
-
PLATFORMS
|
71
|
-
ruby
|
72
|
-
|
73
|
-
DEPENDENCIES
|
74
|
-
bundler (~> 1.3)
|
75
|
-
coveralls
|
76
|
-
cucumber (~> 1.3)
|
77
|
-
debugger (~> 1.6)
|
78
|
-
json (~> 1.7.7)
|
79
|
-
rake (~> 10.0)
|
80
|
-
rake-compiler (~> 0.8)
|
81
|
-
rspec (~> 2.13)
|
82
|
-
ruby-prof (~> 0.13)
|
83
|
-
shoulda (~> 3.5)
|
@@ -1,39 +0,0 @@
|
|
1
|
-
Feature: something something
|
2
|
-
In order to something something
|
3
|
-
A user something something
|
4
|
-
something something something
|
5
|
-
|
6
|
-
Scenario: find edit distance between two unicode (utf8) strings
|
7
|
-
Given strings "Sjostedt" and "Sojstedt", block size "0", and a maximum allowed distance "4"
|
8
|
-
When I run "DamerauLevenshtein" method "distance"
|
9
|
-
Then I should receive edit distance "2"
|
10
|
-
|
11
|
-
Scenario: find edit distance between two unicode (utf8) strings
|
12
|
-
Given strings "Sjostedt" and "Sojstedt", block size "1", and a maximum allowed distance "4"
|
13
|
-
When I run "DamerauLevenshtein" method "distance"
|
14
|
-
Then I should receive edit distance "1"
|
15
|
-
|
16
|
-
Scenario: find edit distance between two unicode (utf8) strings
|
17
|
-
Given strings "Choriozopella trägårdhi" and "Choriozopella tragardhi", block size "1", and a maximum allowed distance "4"
|
18
|
-
When I run "DamerauLevenshtein" method "distance"
|
19
|
-
Then I should receive edit distance "2"
|
20
|
-
|
21
|
-
Scenario: find edit distance between two strings with non-alphanumeric characters
|
22
|
-
Given strings "abcd" and "ab-cd", block size "1", and a maximum allowed distance "4"
|
23
|
-
When I run "DamerauLevenshtein" method "distance"
|
24
|
-
Then I should receive edit distance "1"
|
25
|
-
|
26
|
-
Scenario: find edit distance between one-character and multicharacter strings
|
27
|
-
Given strings "a" and "ab", block size "0", and a maximum allowed distance "4"
|
28
|
-
When I run "DamerauLevenshtein" method "distance"
|
29
|
-
Then I should receive edit distance "1"
|
30
|
-
|
31
|
-
Scenario: find edit distance between one-character and multicharacter strings
|
32
|
-
Given strings "a" and "ab", block size "1", and a maximum allowed distance "4"
|
33
|
-
When I run "DamerauLevenshtein" method "distance"
|
34
|
-
Then I should receive edit distance "1"
|
35
|
-
|
36
|
-
Scenario: limit distance to maximum distance + 1
|
37
|
-
Given strings "abcdefg#$%123" and "higklmnop(*&ç123", block size "0", and a maximum allowed distance "4"
|
38
|
-
When I run "DamerauLevenshtein" method "distance"
|
39
|
-
Then I should receive edit distance "5"
|
@@ -1,15 +0,0 @@
|
|
1
|
-
Given /^strings "([^\"]*)" and "([^\"]*)", block size "([^\"]*)", and a maximum allowed distance "([^\"]*)"$/ do |str1, str2, block_size, max_distance|
|
2
|
-
@str1 = str1
|
3
|
-
@str2 = str2
|
4
|
-
@block_size = block_size.to_i
|
5
|
-
@max_distance = max_distance.to_i
|
6
|
-
end
|
7
|
-
|
8
|
-
When /^I run "([^\"]*)" method "([^\"]*)"$/ do |klass, meth|
|
9
|
-
dl = eval(klass)
|
10
|
-
@distance = dl.distance(@str1, @str2, @block_size, @max_distance)
|
11
|
-
end
|
12
|
-
|
13
|
-
Then /^I should receive edit distance "([^\"]*)"$/ do |edit_distance|
|
14
|
-
@distance.should == edit_distance.to_i
|
15
|
-
end
|
data/features/support/env.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
require 'bundler'
|
2
|
-
begin
|
3
|
-
Bundler.setup(:default, :development)
|
4
|
-
rescue Bundler::BundlerError => e
|
5
|
-
$stderr.puts e.message
|
6
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
7
|
-
exit e.status_code
|
8
|
-
end
|
9
|
-
|
10
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
|
11
|
-
require 'damerau-levenshtein'
|
12
|
-
|
13
|
-
require 'rspec/expectations'
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
describe DamerauLevenshtein do
|
4
|
-
|
5
|
-
it 'should return version' do
|
6
|
-
ver = DamerauLevenshtein::VERSION
|
7
|
-
ver.should =~ /^\d+\.\d+\.\d+$/
|
8
|
-
DamerauLevenshtein::version.should == ver
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'should get tests' do
|
12
|
-
tests = File.expand_path(File.dirname(__FILE__)) +
|
13
|
-
'/damerau_levenshtein_test.txt'
|
14
|
-
|
15
|
-
read_test_file(tests, 5) do |y|
|
16
|
-
dl = DamerauLevenshtein
|
17
|
-
if y
|
18
|
-
res = dl.distance(y[0], y[1], y[3].to_i, y[2].to_i)
|
19
|
-
puts y if res != y[4].to_i
|
20
|
-
res.should == y[4].to_i
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,89 +0,0 @@
|
|
1
|
-
######################
|
2
|
-
# Tests for modified Damerau Levenshtein Distance algorithm (UTF-8 compatible)
|
3
|
-
#
|
4
|
-
# * B. Boehmer, T. Rees, Modified Damerau-Levenshtein Distance, Boehmer & Rees 2008
|
5
|
-
# * F.J. Damerau. A technique for computer detection and correction of spelling errors, Communications of the ACM, 1964
|
6
|
-
#
|
7
|
-
# Fields:
|
8
|
-
# String1|String2|maximum distance|transposition block size|expected distance
|
9
|
-
# - String1, String2
|
10
|
-
# compared strings
|
11
|
-
# - maximum distance
|
12
|
-
# stops execution of the algorithm when calculated distance exceeds the maximum distance number
|
13
|
-
# - transosition block size
|
14
|
-
# determines how many characters can be transposed. Block size 1 returns score according to Damerau-Levenshtein algorithm
|
15
|
-
# - expected distance
|
16
|
-
# resulting distance that has to be achieved by the algorithm
|
17
|
-
# Note: algorithm does not try to normalize or interpret strings in any way.
|
18
|
-
######################
|
19
|
-
|
20
|
-
#it whould recognize the exact match
|
21
|
-
Pomatomus|Pomatomus|10|1|0
|
22
|
-
|
23
|
-
#it should not try to normalize incoming strings
|
24
|
-
Pomatomus|Pomatomus|10|1|1
|
25
|
-
Pomatomus|pomatomus|10|1|1
|
26
|
-
|
27
|
-
#it should calculate special cases
|
28
|
-
Pomatomus||10|1|9
|
29
|
-
|Pomatomus|10|1|9
|
30
|
-
P|p|10|1|1
|
31
|
-
ab|a|10|0|1
|
32
|
-
a|ab|10|0|1
|
33
|
-
ab|a|10|1|1
|
34
|
-
-b|-|10|0|1
|
35
|
-
-b|-|10|1|1
|
36
|
-
ab|-|10|0|2
|
37
|
-
a|ab|10|1|1
|
38
|
-
L|Linneaus|10|1|7
|
39
|
-
|
40
|
-
|
41
|
-
#it should calculate Damerau Levenshtein distance with 1 character transpositions, insertions, deletions, substitutions (block size 1)
|
42
|
-
# 1 substitution
|
43
|
-
Pomatomus|Pomatomux|10|1|1
|
44
|
-
# 1 deletion
|
45
|
-
Pmatomus|Pomatomus|10|1|1
|
46
|
-
# 1 deletion
|
47
|
-
Pomatomus|Pmatomus|10|1|1
|
48
|
-
# 1 substitution
|
49
|
-
Rpmatomus|Pomatomus|10|1|2
|
50
|
-
# 1 substitution
|
51
|
-
Pommtomus|Pomatomus|10|1|1
|
52
|
-
# 2 substitutions
|
53
|
-
Potamomus|Pomatomus|10|1|2
|
54
|
-
# 1 utf-8 substitution
|
55
|
-
Cedarinia scabra Sjöstedt 1921|Cedarinia scabra Sjostedt 1921|10|1|1
|
56
|
-
# transposition (Levenshtein takes it as 2 substitutions)
|
57
|
-
Pomatomus|oPmatomus|10|0|2
|
58
|
-
Pomatomus|oPmatomus|10|1|1
|
59
|
-
# transposition (Levenshtein takes it as 2 substitutions)
|
60
|
-
Pomatomus|Pomatomsu|10|0|2
|
61
|
-
Pomatomus|Pomatomsu|10|1|1
|
62
|
-
# transposition
|
63
|
-
Pomtaomus|Pomatomus|10|0|2
|
64
|
-
Pomtaomus|Pomatomus|10|1|1
|
65
|
-
# transposition
|
66
|
-
Pomatoums|Pomatomus|10|0|2
|
67
|
-
Pomatoums|Pomatomus|10|1|1
|
68
|
-
# transposition + substitution
|
69
|
-
PoamtosusPomatomus|10|0|3
|
70
|
-
PoamtosusPomatomus|10|1|2
|
71
|
-
|
72
|
-
# transposition with utf-8 char
|
73
|
-
Cedarinia scabra Sjöstedt 1921|Cedarinia scabra Söjstedt 1921|10|0|2
|
74
|
-
Cedarinia scabra Sjöstedt 1921|Cedarinia scabra Söjstedt 1921|10|1|1
|
75
|
-
|
76
|
-
#it should calculate Modified Damerau Levenshtein distance with 2 or more characters transposition (block size > 2)
|
77
|
-
serrulatus|serratulus|10|2|2
|
78
|
-
Pomatomus|Poomumats|10|3|3
|
79
|
-
vesiculosus|vecusilosus|10|1|4
|
80
|
-
vesiculosus|vecusilosus|10|2|2
|
81
|
-
trimerophyton|mertriophyton|10|1|6
|
82
|
-
trimerophyton|mertriophyton|10|3|3
|
83
|
-
|
84
|
-
#it should stop trying if distance exceeds maximum allowed distance
|
85
|
-
Pxxxxomus|Pomatomus|10|1|4
|
86
|
-
Pxxxxomus|Pomatomus|2|1|3
|
87
|
-
|
88
|
-
#
|
89
|
-
PUNCTATA|PUNCTATA|10|1|0
|
data/spec/spec_helper.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'coveralls'
|
2
|
-
Coveralls.wear!
|
3
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
4
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
5
|
-
require 'rspec'
|
6
|
-
require 'damerau-levenshtein'
|
7
|
-
|
8
|
-
# Requires supporting files with custom matchers and macros, etc,
|
9
|
-
# in ./support/ and its subdirectories.
|
10
|
-
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
11
|
-
|
12
|
-
RSpec.configure do |config|
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
def read_test_file(file, fields_num)
|
17
|
-
f = open(file)
|
18
|
-
f.each do |line|
|
19
|
-
fields = line.split("|")
|
20
|
-
if line.match(/^\s*#/) == nil && fields.size == fields_num
|
21
|
-
fields[-1] = fields[-1].split('#')[0].strip
|
22
|
-
yield(fields)
|
23
|
-
else
|
24
|
-
yield(nil)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|