-
Notifications
You must be signed in to change notification settings - Fork 5
/
residual.go
50 lines (44 loc) · 1.41 KB
/
residual.go
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package eval
import (
"fmt"
"github.com/hscells/trecresults"
)
// ResidualEvaluator evaluates using an evaluator in the same manner, however
// it considers all unjudged documents as relevant.
type ResidualEvaluator struct {
Evaluator
}
// Residual is the set of unjudged documents that are retrieved by a query.
// That is, the documents that do not have explicit relevance labels.
func (r ResidualEvaluator) Residual(results *trecresults.ResultList, qrels trecresults.Qrels) trecresults.Qrels {
// Create a copy of the qrels to return.
unjudged := make(trecresults.Qrels)
for k, v := range qrels {
unjudged[k] = v
}
// Add the unjudged documents into the qrels with a positive relevance label.
for _, result := range *results {
d := result.DocId
if _, ok := unjudged[d]; !ok {
unjudged[d] = &trecresults.Qrel{
Topic: result.Topic,
Iteration: "Q0",
DocId: d,
Score: RelevanceGrade + 1,
}
}
}
return unjudged
}
func (r ResidualEvaluator) Name() string {
return fmt.Sprintf("%s%s", "Residual", r.Evaluator.Name())
}
func (r ResidualEvaluator) Score(results *trecresults.ResultList, qrels trecresults.Qrels) float64 {
return r.Evaluator.Score(results, r.Residual(results, qrels))
}
// NewResidualEvaluator creates a new evaluator which wraps an existing evaluator.
func NewResidualEvaluator(evaluator Evaluator) ResidualEvaluator {
return ResidualEvaluator{
Evaluator: evaluator,
}
}