72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/asker/data/concept.rb', line 72
def calculate_nearness_to_concept(other)
weights = ProjectData.instance.get(:weights).split(",").map(&:to_f)
max1 = @context.count
max2 = @data[:tags].count
max3 = @data[:tables].count
alike1 = alike2 = alike3 = 0.0
@context.each { |i| alike1 += 1.0 unless other.context.index(i).nil? }
@data[:tags].each { |i| alike2 += 1.0 unless other.tags.index(i).nil? }
@data[:tables].each { |i| alike3 += 1.0 unless other.tables.index(i).nil? }
alike = (alike1 * weights[0] + alike2 * weights[1] + alike3 * weights[2])
max = (max1 * weights[0] + max2 * weights[1] + max3 * weights[2])
(alike * 100.0 / max)
end
|