Method: AI_calculate#reorder_list_with_row

Defined in:
lib/asker/ai/ai_calculate.rb

#reorder_list_with_row(list, row) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/asker/ai/ai_calculate.rb', line 37

def reorder_list_with_row(list, row)
  # evaluate every row of the list2
  list.each do |r|
    if r[:id] == row[:id]
      r[:weight] = -300
    else
      val = 0
      s = row[:data].count
      s.times do |i|
        val += calculate_nearness_between_texts(row[:data][i], r[:data][i])
      end
      val /= s
      r[:weight] = val
    end
  end
  list.sort! { |a, b| a[:weight] <=> b[:weight] }
  list.reverse!
end