def fuzzy_match( str_in )
return 0 if str_in == nil
return 1 if self == str_in
graph_A = Array.new
graph_B = Array.new
last = self.length
(0..last).each do |ff|
loc = self.length
break if ff == last - 1
wordB = (1..(last-1)).to_a.reverse!
if (wordB != nil)
wordB.each do |ss|
break if ss == ff
graph_A.push( "#{self[ff..ss]}" )
end
end
end
last = str_in.length
(0..last).each{ |ff|
loc = str_in.length
break if ff == last - 1
wordB = (1..(last-1)).to_a.reverse!
wordB.each do |ss|
break if ss == ff
graph_B.push( "#{str_in[ff..ss]}" )
end
}
matches = Array.new
graph_A.each do |aa|
matches.push( aa ) if( graph_B.include?( aa ) )
end
matches.sort!{|x,y| x.length <=> y.length}
mclone = matches.dup
mclone.each_index do |ii|
reg = Regexp.compile( mclone[ii] )
count = 0.0
matches.each{|xx| count += 1 if xx =~ reg}
matches.delete(mclone[ii]) if count > 1
end
score = 0.0
matches.each{ |mm| score += mm.length }
self.length > str_in.length ? largest = self.length : largest = str_in.length
return score/largest
end