Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 23 lines (19 sloc) 0.583 kB
280b251 @grobie init
authored
1 require 'amatch'
6bcca11 @grobie fix initial match problem
authored
2 require 'unicode'
280b251 @grobie init
authored
3
4 module Distance
5 include Amatch
6
7 def self.edit_distance(s1, s2)
8 s1,s2 = s1.to_s.downcase,s2.to_s.downcase
9 Levenshtein.new(s1).match(s2).to_f / [s1.size, s2.size].max
10 end
11
12 def self.edit_distance_initial(s1, s2)
6bcca11 @grobie fix initial match problem
authored
13 s1,s2 = Unicode.downcase(s1), Unicode.downcase(s2)
14 if s1 =~ /^[a-zäöüÄÖÜ]\.*/u || s2 =~ /^[a-zäöüÄÖÜ]\.*/u
15 i1 = s1 =~ /^[äöüÄÖÜ]/u ? s1[0,2] : s1[0,1]
16 i2 = s2 =~ /^[äöüÄÖÜ]/u ? s2[0,2] : s2[0,1]
280b251 @grobie init
authored
17 i1 == i2 ? 0 : 1
18 else
19 edit_distance(s1,s2)
20 end
21 end
22
6bcca11 @grobie fix initial match problem
authored
23 end
Something went wrong with that request. Please try again.