#!/usr/local/bin/perl # $Id: irex-seikai-trec.perl,v 3.0 1998/11/19 07:12:09 tsuchiya Exp $ # This file is part of IREX tools. # Please refer "Copyright file" at the root directory. # (C) IREX committee IREX実行委員会. All rights reserved. require 5.000; use lib ( "$ENV{IREX_ROOT}/IR_TOOLS/perl", "$ENV{IREX_ROOT}/perl" ); use IREX::Tougou qw( :parser %TREE ); use TREC::Seikai qw( :generator ); use File::Basename; $PROGRAM = basename( $0 ); #------------------------------------------------------------ # 判定関数 #------------------------------------------------------------ # スコアが A, A?, B, B? の場合を正解とする判定関数 sub a_or_b { my( $topic_id, $docno, %judge )=@_; my $pid = $PID ? $PID : ( sort { $b <=> $a; } keys %judge )[$[]; $judge{$pid} =~ /^[AB]\??$/; } # スコアが A, A? の場合を正解とする判定関数 sub a_only { my( $topic_id, $docno, %judge )=@_; my $pid = $PID ? $PID : ( sort { $b <=> $a; } keys %judge )[$[]; $judge{$pid} =~ /^A\??$/; } #------------------------------------------------------------ # コマンドラインオプションの解析 #------------------------------------------------------------ while( $_=shift(@ARGV) ){ if( /^-(h|\?|-help)$/ ){ &print_usage; } elsif( /^-(f|-file)$/ ){ $FILENAME = shift; } elsif( /^-(l|-logic)$/ ){ $FUNC = undef; $FUNC_FILENAME = shift; } elsif( /^-(a|-aonly)$/ ){ $FUNC = \&a_only; } elsif( /^-(b|-aorb|-?a\+b)$/ ){ $FUNC = \&a_or_b; } elsif( /^-(p|-pid)$/ ){ $PID = shift; ( $PID =~ /\D/ ) && &print_usage; } elsif( /^-(q|-quiet)$/ ){ $SILENT = 1; } else { push( @FILE,$_ ); } } unless( @FILE ){ push( @FILE,"STDIN" ); $STDIN = 1; } unless( $FUNC ){ if( $FUNC_FILENAME ){ # ユーザー定義判定関数を読み込む my $dir; chomp( $dir=`pwd` ); unshift( @INC,$dir ); require "$FUNC_FILENAME" or die "Failure to require: $FUNC_FILENAME\n"; ref($FUNC) eq "CODE" or die "Illegal description of function: $INC{$FUNC_FILENAME}\n"; } else { # デフォルトの判定関数 $FUNC = \&a_only; } } #------------------------------------------------------------ # 本体 #------------------------------------------------------------ for $f ( @FILE ){ if( $STDIN ){ @BUF = ; } else { open( FILE,"< $f" ) or warn( "Can't open file to read: $f\n" ), &print_usage; print STDERR "Reading $f\n" unless $SILENT; @BUF = ; close FILE; } print STDERR "Parsing $f ...\n" unless $SILENT; &parse() || die "Parse error occured: $f\n"; } #------------------------------------------------------------ # データを整列して出力 #------------------------------------------------------------ if( $FILENAME ){ ( ! -f $FILENAME )|| die "File is already exists: $FILENAME\nStop.\n"; open( FILE,"> $FILENAME" )||die "Can't open file to write: $FILENAME\n"; select FILE; print STDERR "Writing $FILENAME ...\n" unless $SILENT; } else { print STDERR "Printing data ...\n" unless $SILENT; } &generate( $FUNC ); if( $FILENAME ){ close FILE; select STDOUT; } #------------------------------------------------------------ # 簡易ヘルプ #------------------------------------------------------------ sub print_usage { die <<"__END_OF_USAGE__"; Usage: $PROGRAM [tougou_1 tougou_2 ... tougou_n] 複数の結果統合ファイル tougou_1 tougou_2 ... tougou_n をマージして、 1つの TREC 正解ファイルを標準出力に出力する。 ファイルを指定しなかった場合は、標準入力からデータを取り出す。 -q オプションを指定しなければ、処理の進行状況を標準エラー出力に出 力する。 __END_OF_USAGE__ }