| 1 | ###*###################### -*- Mode: Perl -*- ######################### | ||
| 2 | ## | ||
| 3 | ## File : $RCSfile: Raw.pm,v $ | ||
| 4 | ## | ||
| 5 | ## Author : Norbert Gövert | ||
| 6 | ## Created On : Mon Oct 30 11:21:58 2000 | ||
| 7 | ## Last Modified : Time-stamp: <2000-11-09 18:28:11 goevert> | ||
| 8 | ## | ||
| 9 | ## Description : | ||
| 10 | ## | ||
| 11 | ## $Id: Raw.pm,v 1.6 2003/06/13 12:29:30 goevert Exp $ | ||
| 12 | ## | ||
| 13 | ###################################################################### | ||
| 14 | |||
| 15 | |||
| 16 | use strict; | ||
| 17 | |||
| 18 | |||
| 19 | =pod #---------------------------------------------------------------# | ||
| 20 | |||
| 21 | =head1 NAME | ||
| 22 | |||
| 23 | RePrec::Raw - compute precision values | ||
| 24 | |||
| 25 | =head1 SYNOPSIS | ||
| 26 | |||
| 27 | See RePrec(3). | ||
| 28 | |||
| 29 | =head1 DESCRIPTION | ||
| 30 | |||
| 31 | Computation of raw precision values at simple recall points. Precision | ||
| 32 | is not uniquely defined in the case of ranks which don't have relevant | ||
| 33 | documents. Therefore it migth happen that for a given recaqll point | ||
| 34 | more than one precision value is returned. Precision is only defined | ||
| 35 | for simple recall points. | ||
| 36 | |||
| 37 | =head1 METHODS | ||
| 38 | |||
| 39 | See RePrec(3). | ||
| 40 | |||
| 41 | =cut #---------------------------------------------------------------# | ||
| 42 | |||
| 43 | |||
| 44 | package RePrec::Raw; | ||
| 45 | |||
| 46 | |||
| 47 | use base qw(RePrec); | ||
| 48 | |||
| 49 | |||
| 50 | our $VERSION; | ||
| 51 | '$Name: release_0_32 $ 0_0' =~ /(\d+)[-_](\d+)/; $VERSION = sprintf '%d.%03d', $1, $2; | ||
| 52 | |||
| 53 | |||
| 54 | ## public ############################################################ | ||
| 55 | |||
| 56 | sub precision { | ||
| 57 | |||
| 58 | my $self = shift; | ||
| 59 | my @recall = @_; | ||
| 60 | |||
| 61 | my @result; | ||
| 62 | |||
| 63 | foreach my $recall (@recall) { | ||
| 64 | |||
| 65 | return undef unless defined $recall and $recall >= 0 and $recall <= 1; | ||
| 66 | |||
| 67 | # relevant documents found up to recall point $recall | ||
| 68 | my $rels = $recall * $self->{rels}; | ||
| 69 | |||
| 70 | # we only can compute the raw precision for simple recall points | ||
| 71 | return undef unless $rels == int $rels; | ||
| 72 | |||
| 73 | # which ranks do we explore? | ||
| 74 | my @ranks; | ||
| 75 | if (exists $self->{rels_rank}->[$rels]) { | ||
| 76 | # there might be more than one precision value on a single recall point | ||
| 77 | # (in the case that a rank does not contain any relevant document) | ||
| 78 | @ranks = $self->{rels_rank}->[$rels - 1] .. $self->{rels_rank}->[$rels] - 1; | ||
| 79 | } else { | ||
| 80 | @ranks = $self->{rels_rank}->[$rels - 1]; | ||
| 81 | } | ||
| 82 | |||
| 83 | foreach (@ranks) { | ||
| 84 | my $total = $self->{rank_rels_nrels}->[$_]->[0] + $self->{rank_rels_nrels}->[$_]->[1]; | ||
| 85 | push @result, [ $recall, $rels / $total ]; | ||
| 86 | } | ||
| 87 | } | ||
| 88 | |||
| 89 | @result; | ||
| 90 | } | ||
| 91 | |||
| 92 | |||
| 93 | sub precision_rank { | ||
| 94 | |||
| 95 | my $self = shift; | ||
| 96 | |||
| 97 | my @result; | ||
| 98 | foreach (@{$self->{rank_rels_nrels}}) { | ||
| 99 | my $total = $_->[0] + $_->[1]; | ||
| 100 | my $recall = $_->[0] / $self->{rels}; | ||
| 101 | push @result, [ $recall, $_->[0] / $total ]; | ||
| 102 | } | ||
| 103 | |||
| 104 | @result; | ||
| 105 | } | ||
| 106 | |||
| 107 | |||
| 108 | ## private ########################################################### | ||
| 109 | |||
| 110 | |||
| 111 | =pod #---------------------------------------------------------------# | ||
| 112 | |||
| 113 | =head1 BUGS | ||
| 114 | |||
| 115 | Yes. Please let me know! | ||
| 116 | |||
| 117 | =head1 SEE ALSO | ||
| 118 | |||
| 119 | RePrec(3), | ||
| 120 | perl(1). | ||
| 121 | |||
| 122 | =head1 AUTHOR | ||
| 123 | |||
| 124 | Norbert GE<ouml>vert E<lt>F<goevert@ls6.cs.uni-dortmund.de>E<gt> | ||
| 125 | |||
| 126 | =cut #---------------------------------------------------------------# | ||
| 127 | |||
| 128 | |||
| 129 | 1; | ||
| 130 | __END__ |