| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
######################### -*- Mode: Perl -*- ######################### |
|
2
|
|
|
|
|
|
|
## |
|
3
|
|
|
|
|
|
|
## File : $RCSfile: Searchresult.pm,v $ |
|
4
|
|
|
|
|
|
|
## |
|
5
|
|
|
|
|
|
|
## Author : Norbert Goevert |
|
6
|
|
|
|
|
|
|
## Created On : Mon Nov 9 16:54:39 1998 |
|
7
|
|
|
|
|
|
|
## Last Modified : Time-stamp: <2000-12-20 16:49:12 goevert> |
|
8
|
|
|
|
|
|
|
## |
|
9
|
|
|
|
|
|
|
## Description : |
|
10
|
|
|
|
|
|
|
## |
|
11
|
|
|
|
|
|
|
## $Id: Searchresult.pm,v 1.28 2003/06/13 12:29:30 goevert Exp $ |
|
12
|
|
|
|
|
|
|
## |
|
13
|
|
|
|
|
|
|
###################################################################### |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
1
|
|
|
1
|
|
570
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
48
|
|
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
## ################################################################### |
|
20
|
|
|
|
|
|
|
## package RePrec::Searchresult |
|
21
|
|
|
|
|
|
|
## ################################################################### |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
package RePrec::Searchresult; |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
|
26
|
1
|
|
|
1
|
|
7
|
use Carp; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
944
|
|
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
our $VERSION; |
|
30
|
|
|
|
|
|
|
'$Name: release_0_32 $ 0_0' =~ /(\d+)[-_](\d+)/; $VERSION = sprintf '%d.%03d', $1, $2; |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
## public ############################################################ |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub new { |
|
36
|
|
|
|
|
|
|
|
|
37
|
0
|
|
|
0
|
1
|
|
my $proto = shift; |
|
38
|
0
|
|
0
|
|
|
|
my $class = ref($proto) || $proto; |
|
39
|
0
|
|
|
|
|
|
my $self = {}; |
|
40
|
0
|
|
|
|
|
|
my($qid, $results, @parms) = @_; |
|
41
|
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
bless $self => $class; |
|
43
|
|
|
|
|
|
|
|
|
44
|
0
|
0
|
|
|
|
|
if (defined $results) { |
|
45
|
0
|
0
|
|
|
|
|
if (ref $results eq 'ARRAY') { |
|
|
|
0
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
foreach (@{$results}) { |
|
|
0
|
|
|
|
|
|
|
|
47
|
0
|
0
|
0
|
|
|
|
croak "Wrong type of search result element" |
|
48
|
|
|
|
|
|
|
unless ref $_ eq 'ARRAY' and @$_ == 2; |
|
49
|
|
|
|
|
|
|
} |
|
50
|
0
|
|
|
|
|
|
$self->{results} = $results; |
|
51
|
|
|
|
|
|
|
} elsif (ref $results) { |
|
52
|
0
|
|
|
|
|
|
croak "Wrong reference type for results parameter"; |
|
53
|
|
|
|
|
|
|
} else { |
|
54
|
0
|
|
|
|
|
|
$self->_init($results, @parms); |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
} else { |
|
57
|
0
|
|
|
|
|
|
croak "filename or array with searchresults needed"; |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
$self->{qid} = $qid; |
|
61
|
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
return $self; |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub distribution { |
|
67
|
|
|
|
|
|
|
|
|
68
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
69
|
0
|
|
|
|
|
|
my $judgements = shift; |
|
70
|
|
|
|
|
|
|
|
|
71
|
0
|
0
|
|
|
|
|
return $self->{distribution} if $self->{distribution}; |
|
72
|
|
|
|
|
|
|
|
|
73
|
0
|
0
|
0
|
|
|
|
croak "wrong type of judgements parameter" |
|
74
|
|
|
|
|
|
|
unless ref $judgements and $judgements->isa('RePrec::Collection'); |
|
75
|
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
$self->{numdocs} = $judgements->get_numdocs; |
|
77
|
0
|
|
|
|
|
|
$self->{rels} = 0; |
|
78
|
0
|
|
|
|
|
|
$self->{nrels} = 0; |
|
79
|
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
my @distribution; |
|
81
|
0
|
|
|
|
|
|
my($rels, $nrels) = (0, 0); |
|
82
|
0
|
|
|
|
|
|
my $rank; |
|
83
|
0
|
|
|
|
|
|
foreach (@{$self->{results}}) { |
|
|
0
|
|
|
|
|
|
|
|
84
|
0
|
0
|
|
|
|
|
$rank = $_->[0] unless $rank; |
|
85
|
0
|
0
|
|
|
|
|
if ($rank != $_->[0]) { |
|
86
|
0
|
|
|
|
|
|
push @distribution, [ $rels, $nrels ]; |
|
87
|
0
|
|
|
|
|
|
$rank = $_->[0]; |
|
88
|
0
|
|
|
|
|
|
($rels, $nrels) = (0, 0); |
|
89
|
|
|
|
|
|
|
} |
|
90
|
0
|
0
|
|
|
|
|
if ($judgements->relevant($self->{qid}, $_->[1])) { |
|
91
|
0
|
|
|
|
|
|
$rels++; |
|
92
|
0
|
|
|
|
|
|
$self->{rels}++; |
|
93
|
|
|
|
|
|
|
} else { |
|
94
|
0
|
|
|
|
|
|
$nrels++; |
|
95
|
0
|
|
|
|
|
|
$self->{nrels}++; |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
} |
|
98
|
0
|
|
|
|
|
|
push @distribution, [ $rels, $nrels ]; |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# create entry for very last rank if necessary |
|
101
|
0
|
0
|
|
|
|
|
if ($self->{numdocs} > $self->{rels} + $self->{nrels}) { |
|
102
|
0
|
|
|
|
|
|
my $rels_tot = $judgements->get_numrels($self->{qid}); |
|
103
|
0
|
|
|
|
|
|
my $nrels_tot = $self->{numdocs} - $rels_tot; |
|
104
|
0
|
|
|
|
|
|
push @distribution, [ $rels_tot - $self->{rels}, |
|
105
|
|
|
|
|
|
|
$nrels_tot - $self->{nrels} |
|
106
|
|
|
|
|
|
|
]; |
|
107
|
|
|
|
|
|
|
} |
|
108
|
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
$self->{distribution} = \@distribution; |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub numdocs { |
|
114
|
|
|
|
|
|
|
|
|
115
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
116
|
0
|
|
|
|
|
|
$self->{numdocs} |
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub rels { |
|
121
|
|
|
|
|
|
|
|
|
122
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
123
|
0
|
|
|
|
|
|
$self->{rels}; |
|
124
|
|
|
|
|
|
|
} |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub nrels { |
|
128
|
|
|
|
|
|
|
|
|
129
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
130
|
0
|
|
|
|
|
|
$self->{nrels}; |
|
131
|
|
|
|
|
|
|
} |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
## private ########################################################### |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub _init { |
|
137
|
|
|
|
|
|
|
|
|
138
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
139
|
0
|
|
|
|
|
|
my $file = shift; |
|
140
|
0
|
|
|
|
|
|
my %parm = @_; |
|
141
|
|
|
|
|
|
|
|
|
142
|
0
|
0
|
|
|
|
|
my $sep = defined $parm{separator} ? $parm{separator} : '\s+'; |
|
143
|
0
|
0
|
|
|
|
|
my $ignore = defined $parm{ignore} ? $parm{ignore} : undef; |
|
144
|
0
|
0
|
|
|
|
|
my $docid = defined $parm{docid} ? $parm{docid} : 0; |
|
145
|
0
|
|
|
|
|
|
my($rate, $rank) = ( 1, undef ); |
|
146
|
0
|
0
|
|
|
|
|
if (defined $parm{rsv}) { |
|
|
|
0
|
|
|
|
|
|
|
147
|
0
|
|
|
|
|
|
$rate = $parm{rsv}; |
|
148
|
|
|
|
|
|
|
} elsif (defined $parm{rank}) { |
|
149
|
0
|
|
|
|
|
|
$rate = $parm{rank}; |
|
150
|
0
|
|
|
|
|
|
$rank = 1; |
|
151
|
|
|
|
|
|
|
} |
|
152
|
|
|
|
|
|
|
|
|
153
|
0
|
0
|
|
|
|
|
my $fh = IO::File->new($file) |
|
154
|
|
|
|
|
|
|
or croak "Couldn't read open file `$file': $!\n"; |
|
155
|
|
|
|
|
|
|
|
|
156
|
0
|
|
|
|
|
|
my @results; |
|
157
|
0
|
|
|
|
|
|
local $_; |
|
158
|
0
|
|
|
|
|
|
while (<$fh>) { |
|
159
|
0
|
|
|
|
|
|
chomp; |
|
160
|
0
|
0
|
0
|
|
|
|
next if defined $ignore and /$ignore/; |
|
161
|
0
|
|
|
|
|
|
my($_rate, $_docid) = (split /$sep/)[$rate, $docid]; |
|
162
|
0
|
0
|
|
|
|
|
$_rate = - $_rate if $rank; # convert rank into RSV if necessary |
|
163
|
0
|
|
|
|
|
|
push @results, [ $_rate, $_docid ]; |
|
164
|
|
|
|
|
|
|
} |
|
165
|
|
|
|
|
|
|
|
|
166
|
0
|
0
|
|
|
|
|
if ($parm{sorted}) { |
|
167
|
0
|
|
|
|
|
|
$self->{results} = \@results; |
|
168
|
|
|
|
|
|
|
} else { |
|
169
|
0
|
|
|
|
|
|
$self->{results} = [ sort { $b->[0] <=> $a->[0] } @results ]; |
|
|
0
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
} |
|
171
|
|
|
|
|
|
|
} |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
1; |
|
175
|
|
|
|
|
|
|
__END__ |