| 1 |
#!/usr/bin/env perl |
| 2 |
|
| 3 |
# Copyright (c) 2003, 2005 MySQL AB |
| 4 |
# Use is subject to license terms |
| 5 |
# |
| 6 |
# This program is free software; you can redistribute it and/or modify |
| 7 |
# it under the terms of the GNU General Public License as published by |
| 8 |
# the Free Software Foundation; version 2 of the License. |
| 9 |
# |
| 10 |
# This program is distributed in the hope that it will be useful, |
| 11 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
# GNU General Public License for more details. |
| 14 |
# |
| 15 |
# You should have received a copy of the GNU General Public License |
| 16 |
# along with this program; if not, write to the Free Software |
| 17 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA |
| 18 |
|
| 19 |
die "Use: $0 eval_output qrels_file\n" unless @ARGV==2; |
| 20 |
|
| 21 |
open(EOUT,$eout=shift) || die "Cannot open $eout: $!"; |
| 22 |
open(RELJ,$relj=shift) || die "Cannot open $relj: $!"; |
| 23 |
|
| 24 |
$_=<EOUT>; |
| 25 |
die "$eout must start with a number!\n "unless /^[1-9][0-9]*\n/; |
| 26 |
$ndocs=$_+0; |
| 27 |
|
| 28 |
$qid=0; |
| 29 |
$relj_str=<RELJ>; |
| 30 |
$eout_str=<EOUT>; |
| 31 |
|
| 32 |
while(!eof(RELJ) || !eof(EOUT)) { |
| 33 |
++$qid; |
| 34 |
%dq=(); |
| 35 |
$A=$B=$AB=0; |
| 36 |
$Ravg=$Pavg=0; |
| 37 |
|
| 38 |
while($relj_str =~ /^0*$qid\s+(\d+)/) { |
| 39 |
++$A; |
| 40 |
$dq{$1+0}=1; |
| 41 |
last unless $relj_str=<RELJ>; |
| 42 |
} |
| 43 |
# Favg measure = 1/(a/Pavg+(1-a)/Ravg) |
| 44 |
sub Favg { my $a=shift; $Pavg*$Ravg ? 1/($a/$Pavg+(1-$a)/$Ravg) : 0; } |
| 45 |
# F0 : a=0 -- ignore precision |
| 46 |
# F5 : a=0.5 |
| 47 |
# F1 : a=1 -- ignore recall |
| 48 |
while($eout_str =~ /^$qid\s+(\d+)\s+(\d+(?:\.\d+)?)/) { |
| 49 |
$B++; |
| 50 |
$AB++ if $dq{$1+0}; |
| 51 |
$Ravg+=$AB; |
| 52 |
$Pavg+=$AB/$B; |
| 53 |
last unless $eout_str=<EOUT>; |
| 54 |
} |
| 55 |
next unless $A; |
| 56 |
|
| 57 |
$Ravg/=$B*$A if $B; |
| 58 |
$Pavg/=$B if $B; |
| 59 |
|
| 60 |
printf "%5d %1.12f %1.12f %1.12f\n", $qid, Favg(0),Favg(0.5),Favg(1); |
| 61 |
} |
| 62 |
|
| 63 |
exit 0; |
| 64 |
|
| 65 |
|