RePrec/Collection.pm

filter: Statementstmt 24.4% 12 / 49 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 37.5% 3 / 8 Podpod 100% 4 / 4 totaltotal 20.4% 19 / 93 CC 14 SCAR 45.1
CC
14
Cov
16%
_init
156.0
new
6.0
get_numrels
6.0
CRAP 90.6
« RePrec/Searchresult.pm ↑ Summary RePrec/Tools.pm »
1 ######################### -*- Mode: Perl -*- #########################
2 ##
3 ## File : $RCSfile: Collection.pm,v $
4 ##
5 ## Author : Norbert Goevert
6 ## Created On : Thu Feb 6 17:43:59 1997
7 ## Last Modified : Time-stamp: <2000-11-23 17:40:56 goevert>
8 ##
9 ## Description :
10 ##
11 ## $Id: Collection.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::Collection
21 ## ###################################################################
22  
23 package RePrec::Collection;
24  
25  
26 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
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=2 SCAR=17.9
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 %params = @_;
40  
41 0 my $self = {};
42  
43 0 bless $self => $class;
44  
45 0 $self->_init(%params);
46  
47 0 return $self;
48 }
49  
50  
51 0 ▶sub get_numdocs {
Subroutine get_numdocs: not called CC=1 SCAR=6.9
Pod documented
52  
53 0 my $self = shift;
54 0 return $self->{numdocs};
55 }
56  
57  
58 0 ▶sub relevant {
Subroutine relevant: not called CC=1 SCAR=6.9
Pod documented
59  
60 0 my $self = shift;
61 0 my($qid, $docid) = @_;
62  
63 0 $self->{qrels}->{$qid}->{$docid};
64 }
65  
66  
67 0 ▶sub get_numrels {
Subroutine get_numrels: not called CC=2 SCAR=17.9
Pod documented
68  
69 0 my $self = shift;
70 0 my $qid = shift;
71  
72 0 ▶ return 0 unless defined $self->{numrels}->{$qid};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"numrels"}{$qid} 0 0 0
73  
74 0 $self->{numrels}->{$qid};
75 }
76  
77  
78 ## private ###########################################################
79  
80 0 ▶sub _init {
Subroutine _init: not called CC=12 SCAR=50.5
81  
82 0 my $self = shift;
83 0 my %parms = @_;
84  
85 0 my $file = $parms{file};
86 0 ▶ my $sep = defined $parms{separator} ? $parms{separator} : ' +';
Branch: 1 branch
BranchTrueFalseTotal
defined $parms{'separator'} ? : 0 0 0
87 0 ▶ my $ignore = defined $parms{ignore} ? $parms{ignore} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $parms{'ignore'} ? : 0 0 0
88 0 ▶ my $qid = defined $parms{qid} ? $parms{qid} : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $parms{'qid'} ? : 0 0 0
89 0 ▶ my $docid = defined $parms{docid} ? $parms{docid} : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $parms{'docid'} ? : 0 0 0
90 0 ▶ my $judge = defined $parms{judge} ? $parms{judge} : 2;
Branch: 1 branch
BranchTrueFalseTotal
defined $parms{'judge'} ? : 0 0 0
91 $self->{numdocs} = $parms{numdocs}
92 0 ▶ or croak "`Number of documents in collection' parameter missing\n";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"numdocs"} = $parms{"numdocs"} or croak("`Number of documents in collection' parameter missing\n") 0 0 0
93  
94 0 ▶ my $QRELS = IO::File->new($file)
Branch: 1 branch
BranchTrueFalseTotal
my $QRELS = "IO::File"->new($file) or croak("Couldn't read open file `${file}': $!\n") 0 0 0
95 or croak "Couldn't read open file `$file': $!\n";
96  
97 0 my(%qrels, %numrels);
98 0 local $_;
99 0 ▶ while (<$QRELS>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $QRELS)) 0 0 0
100 0 chomp;
101 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
102 0 my($_qid, $_docid, $_judge) = (split /$sep/)[$qid, $docid, $judge];
103 0 ▶ if ($_judge == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_judge == 1) 0 0 0
104 0 $qrels{$_qid}->{$_docid} = 1;
105 0 $numrels{$_qid}++;
106 }
107 }
108  
109 0 $self->{qrels} = \%qrels;
110 0 $self->{numrels} = \%numrels;
111 }
112  
113  
114 1 1;
115 __END__
« RePrec/Searchresult.pm ↑ Summary RePrec/Tools.pm »