fuzzy ranges on routability tables, value shortcuts

This commit is contained in:
Emil Tin
2013-02-03 13:07:30 +01:00
parent 62cc8f456c
commit b3d517943a
6 changed files with 52 additions and 27 deletions
+9 -2
View File
@@ -71,8 +71,15 @@ def build_ways_from_table table
way << node5
tags = row.dup
tags.delete 'forw'
tags.delete 'backw'
# remove tags that describe expected test result
tags.reject! do |k,v|
k =~ /^forw\b/ ||
k =~ /^backw\b/ ||
k =~ /^bothw\b/
end
##remove empty tags
tags.reject! { |k,v| v=='' }
# sort tag keys in the form of 'node/....'
+26
View File
@@ -0,0 +1,26 @@
class FuzzyMatch
def self.match got, want
if got == want
return true
elsif want.match /(.*)\s+~(.+)%$/ #percentage range: 100 ~5%
margin = 1 - $2.to_f*0.01
from = $1.to_f*margin
to = $1.to_f/margin
return got.to_f >= from && got.to_f <= to
elsif want.match /(.*)\s+\+\-(.+)$/ #absolute range: 100 +-5
margin = $2.to_f
from = $1.to_f-margin
to = $1.to_f+margin
return got.to_f >= from && got.to_f <= to
elsif want =~ /^\/(.*)\/$/ #regex: /a,b,.*/
return got =~ /#{$1}/
else
return false
end
end
end
+3
View File
@@ -0,0 +1,3 @@
def shortcuts_hash
@shortcuts_hash ||= {}
end