Skip to content

Commit 870fef3

Browse files
authored
refactor: use .sum instead of .inject for summing (#82)
Replace legacy inject patterns with modern Ruby .sum method: - LSI#highest_relative_content - LSI#classify_with_confidence Fixes #71
1 parent e336297 commit 870fef3

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/classifier/lsi.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def highest_relative_content(max_chunks = 10)
170170
return [] if needs_rebuild?
171171

172172
avg_density = {}
173-
@items.each_key { |x| avg_density[x] = proximity_array_for_content(x).inject(0.0) { |i, j| i + j[1] } }
173+
@items.each_key { |x| avg_density[x] = proximity_array_for_content(x).sum { |pair| pair[1] } }
174174

175175
avg_density.keys.sort_by { |x| avg_density[x] }.reverse[0..(max_chunks - 1)].map
176176
end
@@ -300,7 +300,7 @@ def vote(doc, cutoff = 0.30, &)
300300
# See classify() for argument docs
301301
def classify_with_confidence(doc, cutoff = 0.30, &)
302302
votes = vote(doc, cutoff, &)
303-
votes_sum = votes.values.inject(0.0) { |sum, v| sum + v }
303+
votes_sum = votes.values.sum
304304
return [nil, nil] if votes_sum.zero?
305305

306306
ranking = votes.keys.sort_by { |x| votes[x] }

0 commit comments

Comments
 (0)