dice: Do not call `matches` twice

This commit is contained in:
Vicent Marti 2015-09-28 02:07:29 -07:00
parent 76e8c8aef5
commit f14874f6aa
1 changed files with 11 additions and 7 deletions

View File

@ -9,7 +9,17 @@ class Licensee
# than the confidence threshold
def match
return @match if defined? @match
@match = matches.empty? ? nil : matches.max_by { |l, sim| sim }[0]
matches = potential_licenses.map do |license|
if (sim = similarity(license)) >= Licensee.confidence_threshold
[license, sim]
end
end
matches.compact!
@match = if matches.empty?
nil
else
matches.max_by { |l, sim| sim }.first
end
end
# Sort all licenses, in decending order, by difference in
@ -50,12 +60,6 @@ class Licensee
total = @file.wordset.size + license.wordset.size
100.0 * (overlap * 2.0 / total)
end
# Return an array of arrays in the form of [license, similiarity]
def matches
matches = potential_licenses.map { |license| [license, similarity(license)] }
matches.select { |license, similarity| similarity >= Licensee.confidence_threshold }
end
end
end
end