RePrec/Searchresult.pm

filter: Statementstmt 11.9% 10 / 84 Branchbran 0.0% 0 / 40 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 25.0% 2 / 8 Podpod 80.0% 4 / 5 totaltotal 10.1% 16 / 157 CC 27 SCAR 45.6
CC
27
Cov
7%
_init
156.0
distribution
90.0
new
72.0
CRAP 96.1
↑ Summary RePrec/Collection.pm »
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 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18  
19 ## ###################################################################
20 ## package RePrec::Searchresult
21 ## ###################################################################
22  
23 package RePrec::Searchresult;
24  
25  
26 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28  
29 1 our $VERSION;
30 1 '$Name: release_0_32 $ 0_0' =~ /(\d+)[-_](\d+)/; $VERSION = sprintf '%d.%03d', $1, $2;
31  
32  
33 ## public ############################################################
34  
35 0 ▶sub new {
Subroutine new: not called CC=8 SCAR=42.8
Pod documented
36  
37 0 my $proto = shift;
38 0 ▶ my $class = ref($proto) || $proto;
Condition0%0/3
ref $proto || $proto
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
39 0 my $self = {};
40 0 my($qid, $results, @parms) = @_;
41  
42 0 bless $self => $class;
43  
44 0 ▶ if (defined $results) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $results) { } 0 0 0
45 0 ▶ if (ref $results eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $results eq 'ARRAY') { } 0 0 0
elsif (ref $results) { } 0 0 0
46 0 foreach (@{$results}) {
47 0 ▶ croak "Wrong type of search result element"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_ eq "ARRAY" and @$_ == 2 0 0 0
Condition0%0/3
ref $_ eq "ARRAY" and @$_ == 2
!ll&&!rl&&r
000
MC/DC0%0/2
ref $_ eq "ARRAY" and @$_ == 2
ref $_ eq "ARRAY" @$_ == 2
Truth table0%0/3
A and B
A= ref $_ eq "ARRAY"B= @$_ == 2
ABresult
0X0
100
111
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 0 ▶sub distribution {
Subroutine distribution: not called CC=9 SCAR=45.0
Pod documented
67  
68 0 my $self = shift;
69 0 my $judgements = shift;
70  
71 0 ▶ return $self->{distribution} if $self->{distribution};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"distribution"} 0 0 0
72  
73 0 ▶ croak "wrong type of judgements parameter"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $judgements and $judgements->isa("RePrec::Collection") 0 0 0
Condition0%0/3
ref $judgements and $judgements->isa("RePrec::Collection")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $judgements and $judgements->isa("RePrec::Collection")
ref $judgements $judgements->isa("RePrec::Collection")
Truth table0%0/3
A and B
A= ref $judgementsB= $judgements->isa("RePrec::Collection")
ABresult
0X0
100
111
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}}) {
84 0 ▶ $rank = $_->[0] unless $rank;
Branch: 1 branch
BranchTrueFalseTotal
unless $rank 0 0 0
85 0 ▶ if ($rank != $_->[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rank != $_->[0]) 0 0 0
86 0 push @distribution, [ $rels, $nrels ];
87 0 $rank = $_->[0];
88 0 ($rels, $nrels) = (0, 0);
89 }
90 0 ▶ if ($judgements->relevant($self->{qid}, $_->[1])) {
Branch: 1 branch
BranchTrueFalseTotal
if ($judgements->relevant($self->{'qid'}, $_->[1])) { } 0 0 0
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 ▶ if ($self->{numdocs} > $self->{rels} + $self->{nrels}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"numdocs"} > $self->{"rels"} + $self->{"nrels"}) 0 0 0
102 0 my $rels_tot = $judgements->get_numrels($self->{qid});
103 0 my $nrels_tot = $self->{numdocs} - $rels_tot;
104 push @distribution, [ $rels_tot - $self->{rels},
105 $nrels_tot - $self->{nrels}
106 0 ];
107 }
108  
109 0 $self->{distribution} = \@distribution;
110 }
111  
112  
113 0 ▶sub numdocs {
Subroutine numdocs: not called CC=1 SCAR=6.9
Pod undocumented
114  
115 0 my $self = shift;
116 $self->{numdocs}
117 0 }
118  
119  
120 0 ▶sub rels {
Subroutine rels: not called CC=1 SCAR=6.9
Pod documented
121  
122 0 my $self = shift;
123 0 $self->{rels};
124 }
125  
126  
127 0 ▶sub nrels {
Subroutine nrels: not called CC=1 SCAR=6.9
Pod documented
128  
129 0 my $self = shift;
130 0 $self->{nrels};
131 }
132  
133  
134 ## private ###########################################################
135  
136 0 ▶sub _init {
Subroutine _init: not called CC=12 SCAR=50.5
137  
138 0 my $self = shift;
139 0 my $file = shift;
140 0 my %parm = @_;
141  
142 0 ▶ my $sep = defined $parm{separator} ? $parm{separator} : '\s+';
Branch: 1 branch
BranchTrueFalseTotal
defined $parm{'separator'} ? : 0 0 0
143 0 ▶ my $ignore = defined $parm{ignore} ? $parm{ignore} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $parm{'ignore'} ? : 0 0 0
144 0 ▶ my $docid = defined $parm{docid} ? $parm{docid} : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $parm{'docid'} ? : 0 0 0
145 0 my($rate, $rank) = ( 1, undef );
146 0 ▶ if (defined $parm{rsv}) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $parm{'rsv'}) { } 0 0 0
elsif (defined $parm{'rank'}) { } 0 0 0
147 0 $rate = $parm{rsv};
148 } elsif (defined $parm{rank}) {
149 0 $rate = $parm{rank};
150 0 $rank = 1;
151 }
152  
153 0 ▶ my $fh = IO::File->new($file)
Branch: 1 branch
BranchTrueFalseTotal
my $fh = "IO::File"->new($file) or croak("Couldn't read open file `${file}': $!\n") 0 0 0
154 or croak "Couldn't read open file `$file': $!\n";
155  
156 0 my @results;
157 0 local $_;
158 0 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 0 0 0
159 0 chomp;
160 0 ▶ next if defined $ignore and /$ignore/;
Branch: 1 branch
BranchTrueFalseTotal
if defined $ignore and /$ignore/ 0 0 0
Condition0%0/3
defined $ignore and /$ignore/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ignore and /$ignore/
defined $ignore /$ignore/
Truth table0%0/3
A and B
A= defined $ignoreB= /$ignore/
ABresult
0X0
100
111
161 0 my($_rate, $_docid) = (split /$sep/)[$rate, $docid];
162 0 ▶ $_rate = - $_rate if $rank; # convert rank into RSV if necessary
Branch: 1 branch
BranchTrueFalseTotal
if $rank 0 0 0
163 0 push @results, [ $_rate, $_docid ];
164 }
165  
166 0 ▶ if ($parm{sorted}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parm{'sorted'}) { } 0 0 0
167 0 $self->{results} = \@results;
168 } else {
169 0 $self->{results} = [ sort { $b->[0] <=> $a->[0] } @results ];
170 }
171 }
172  
173  
174 1 1;
175 __END__
↑ Summary RePrec/Collection.pm »