levenshtein_ruby 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/levenshtein_ruby-0.1.0.gem +0 -0
- data/lib/levenshtein_ruby/version.rb +1 -1
- data/lib/levenshtein_ruby.rb +22 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb6f90287f4e101d3f641c2b1742f57b64c092f0
|
4
|
+
data.tar.gz: 8d84e26abda0bb4a3bc71cb3fb9dd15f8c67954d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aaf620aebf493776439459dd701ab10d946180dec0224fe71273dc2d8f23533a7ada25a6bc2c591a2713a51641519fab35a929abc6c7b3ce13e5420df92b669f
|
7
|
+
data.tar.gz: 764ed898e4754d1d2784e16d81eb8ffa31dfc452e844cf27a5e725a8dae2a9c24b3e0cfa29ac5f60f79040571c8495d626ddd5047cfda2520b8735f2e775dbd2
|
Binary file
|
data/lib/levenshtein_ruby.rb
CHANGED
@@ -1,5 +1,26 @@
|
|
1
1
|
require "levenshtein_ruby/version"
|
2
2
|
require "levenshtein_ruby/levenshtein_ruby"
|
3
3
|
|
4
|
-
class
|
4
|
+
class Levenshtein
|
5
|
+
def normalized_distance(a1, a2, threshold=nil, options={})
|
6
|
+
size = [a1.size, a2.size].max
|
7
|
+
|
8
|
+
if a1.size == 0 and a2.size == 0
|
9
|
+
0.0
|
10
|
+
elsif a1.size == 0
|
11
|
+
a2.size.to_f/size
|
12
|
+
elsif a2.size == 0
|
13
|
+
a1.size.to_f/size
|
14
|
+
else
|
15
|
+
if threshold
|
16
|
+
if d = self.distance(a1, a2, (threshold*size).to_i+1)
|
17
|
+
d.to_f/size
|
18
|
+
else
|
19
|
+
nil
|
20
|
+
end
|
21
|
+
else
|
22
|
+
self.distance(a1, a2).to_f/size
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
5
26
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: levenshtein_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- meriy100
|
@@ -73,6 +73,7 @@ files:
|
|
73
73
|
- bin/setup
|
74
74
|
- ext/levenshtein_ruby/extconf.rb
|
75
75
|
- ext/levenshtein_ruby/levenshtein_ruby.c
|
76
|
+
- levenshtein_ruby-0.1.0.gem
|
76
77
|
- levenshtein_ruby.gemspec
|
77
78
|
- lib/levenshtein_ruby.rb
|
78
79
|
- lib/levenshtein_ruby/version.rb
|