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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f9f817f4c065ce80aedfdf5b721aba39ffba44bd
4
- data.tar.gz: 0db84cb04de9d0415bded2881f2f7542d430c693
3
+ metadata.gz: bb6f90287f4e101d3f641c2b1742f57b64c092f0
4
+ data.tar.gz: 8d84e26abda0bb4a3bc71cb3fb9dd15f8c67954d
5
5
  SHA512:
6
- metadata.gz: e5449958dd08763332fd4c8d4eaf6b8b0d03a4c55a7d0968da2efb4eb3c87301aa02e2ffc815dc604fd52d20f35ae4cb8286fa72f98415a948e73d8092c013c5
7
- data.tar.gz: 3e10b5d78145948f31d3269db55e90ac04734219a3511ec74b38ae3e32513e6ca1d2cb57d474d5fe0e7fa1eed60c9722d225cbbc7d8af21478219200f622f9e3
6
+ metadata.gz: aaf620aebf493776439459dd701ab10d946180dec0224fe71273dc2d8f23533a7ada25a6bc2c591a2713a51641519fab35a929abc6c7b3ce13e5420df92b669f
7
+ data.tar.gz: 764ed898e4754d1d2784e16d81eb8ffa31dfc452e844cf27a5e725a8dae2a9c24b3e0cfa29ac5f60f79040571c8495d626ddd5047cfda2520b8735f2e775dbd2
Binary file
@@ -1,3 +1,3 @@
1
1
  class LevenshteinRuby
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -1,5 +1,26 @@
1
1
  require "levenshtein_ruby/version"
2
2
  require "levenshtein_ruby/levenshtein_ruby"
3
3
 
4
- class LevenshteinRuby
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.0
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