Skip to content

Instantly share code, notes, and snippets.

@fridim

fridim/main.rb

Created Aug 13, 2010
Embed
What would you like to do?
def score(r)
return 0 if r.nil?
weight = {
:name => 1,
:street_number => 1,
:street_name => 1,
:suburb => 1,
:zero => 0
}
value = {
:name => self.place_name.jaro_similar(r.place_name),
:street_number => street_number_match(r),
:street_name => street_name_match(r),
:suburb => suburb_match(r),
:zero => 0
}
minimum = {
:name => 0,
:street_number => 0.5,
:street_name => 0.5,
:suburb => 0.5,
:zero => 0
}
if !self.vhr_number.to_s.empty? && !r.vhr_number.to_s.empty?
if vhr_number != r.vhr_number
weight[:zero] += 2
end
end
#######################
# Street number
# if fields are empty
if self.street_number.to_s.strip == '' ||
r.street_number.to_s.strip == ''
weight[:street_number] = 0
end
if value[:street_number] < 0.95
weight[:zero] += 3
end
#######################
# Street name
# if street_name differ it's really unlikely to be the same place
if value[:street_name] < 0.7
minimum[:name] > 0.95
minimum[:suburb] > 0.95
weight[:zero] += 3
end
#######################
# Suburd
if value[:suburb] < 0.85
minimum[:name] > 0.95
minimum[:street_name] > 0.95
weight[:zero] += 3
end
if value[:street_name] > 0.95 && value[:street_number] > 0.95
weight[:name] = 1
weight[:street_name] = 3
weight[:street_number] = 3
end
value.each_key { |k|
value[k] = (value[k] < minimum[k]) ? 0 : value[k]
}
sum = value.keys.map {|k| value[k] * weight[k]}.sum
n = weight.values.sum
return sum / n
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.