-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjudge.rb
More file actions
25 lines (20 loc) · 852 Bytes
/
judge.rb
File metadata and controls
25 lines (20 loc) · 852 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
module QualityMonitoring
class Judge
attr_reader :result_links, :expected_links
# Initializes a new instance of Judge for a given set of result links and expected links
def initialize(result_links, expected_links)
@result_links = Array(result_links)
@expected_links = Array(expected_links)
raise ArgumentError, "at least one expected link is required" if expected_links.empty?
end
# Calculates recall (how many of the expected links are in the result links)
def recall
expected_links.count { result_links.include?(_1) }.to_f / expected_links.count
end
# Calculates precision (how many of the result links are in the expected links)
def precision
return 0 if result_links.empty?
result_links.count { expected_links.include?(_1) }.to_f / result_links.count
end
end
end