| 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
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 45 | 0 | ▶ | if (ref $results eq 'ARRAY') { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 46 | 0 | foreach (@{$results}) { | |||||||||||||||||||||||||||
| 47 | 0 | ▶ | croak "Wrong type of search result element" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $_ eq "ARRAY" and @$_ == 2
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 0 | ▶ | croak "wrong type of judgements parameter" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $judgements and $judgements->isa("RePrec::Collection")
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")
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 85 | 0 | ▶ | if ($rank != $_->[0]) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 143 | 0 | ▶ | my $ignore = defined $parm{ignore} ? $parm{ignore} : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 144 | 0 | ▶ | my $docid = defined $parm{docid} ? $parm{docid} : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 145 | 0 | my($rate, $rank) = ( 1, undef ); | |||||||||||||||||||||||||||
| 146 | 0 | ▶ | if (defined $parm{rsv}) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 159 | 0 | chomp; | |||||||||||||||||||||||||||
| 160 | 0 | ▶ | next if defined $ignore and /$ignore/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $ignore and /$ignore/
MC/DC0%0/2
defined $ignore and /$ignore/
defined $ignore
/$ignore/
Truth table0%0/3
A and B
A= defined $ignoreB= /$ignore/
| |||||||||||||||||||||||||||||
| 161 | 0 | my($_rate, $_docid) = (split /$sep/)[$rate, $docid]; | |||||||||||||||||||||||||||
| 162 | 0 | ▶ | $_rate = - $_rate if $rank; # convert rank into RSV if necessary | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 163 | 0 | push @results, [ $_rate, $_docid ]; | |||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 0 | ▶ | if ($parm{sorted}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||