result.rb
1.62 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env ruby
#--
# This file is a part of the mirimiri library
#
# Copyright (C) 2010-2012 Romain Deveaud <romain.deveaud@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#++
module Mirimiri
# This class represents one line of a TREC-formatted retrieval
# result. Typical output of Indri or Terrier.
class TrecResult
attr_accessor :topic, :doc, :rank, :score, :run
def initialize arg
t = arg.split
@topic = t[0]
@doc = t[2]
@rank = t[3]
@score = t[4]
@run = t[5]
end
end
# This class represents the output of trec_eval, when
# -q option is given.
class TrecEval
attr_accessor :metric, :run, :queries
def initialize arg
@queries = {}
arg.each_line do |line|
t = line.split
@metric = t[0] if @metric.nil?
@queries[t[1]] = t[2].to_f if t[1].is_integer?
end
end
end
# An array of TrecResult, or a run.
class TrecResults < Array
def initialize args
super args.collect { |res| TrecResult.new res }
end
end
end