为译文信息打分的程序
来源:互联网 发布:sql向表中填中文数据 编辑:程序博客网 时间:2024/05/15 17:12
#!usr/bin/perl
#
use strict; # always use strict, it's a good habit
######
# Intro
my ($date, $time) = date_time_stamp();
print "MT evaluation run on $date at $time/n";
print "command line: ", $0, " ", join(" ", @ARGV), "/n";
my $usage = "/n/n Usage: $0 [-h] [-s score range ] [-r ref FILENAME] [-t translation FILEHANDLE]/n".
"-h :打印帮助信息/n".
"-c :打印需要保存的bleu分值范围,“0.8”表示大与0.8, 不给任何参数时全部打印/n".
"-r ref_file :参考译文文件路径/n".
"-t trans_file :译文信息文件路径/n".
"-o result_file :结果文件路径/n".
"/n";
use vars qw ($opt_r $opt_t $opt_h $opt_c $opt_o);
use Getopt::Std; # see "perldoc Getopt::Std"
my %options;
getopts('r:t:hc:o:', /%options); # read the options with getopts
# uncomment the following two lines to see what the options hash contains
#use Data::Dumper;
#print Dumper /%options;
$options{h} && usage(); # the -h switch
# use the -t switch, if it's given, or use a default input trans_info filename
my $trans_info_file = $options{t} || 'trans_info.file';
# use the -r switch, if it's given, or use a default input ref filename
my $ref_file = $options{r} || 'ref.file';
# use the -c switch, if it's given, or use a default input ref filename
my $sel_score = $options{c} || '0.0';#默认全部输出
# use the -o switch, if it's given, or use a default input ref filename
my $result_file = $options{o} || 'out.file';#默认全部输出
print "Translation file is $trans_info_file/n";
print "Ref file is $ref_file/n";
print "Will output the info whose score greater that $sel_score to the file $result_file/n";
#打开输入文件
die $usage if defined($opt_h);
#必须给定
die "Error in command line: ref_file not defined$usage" unless defined $ref_file;
die "Error in command line: trans_file not defined$usage" unless defined $trans_info_file;
die "Error in command line: sel_score not defined$usage" unless defined $sel_score;
open (TRANS_FILE, $trans_info_file) or die "/nUnable to open translation data file $trans_info_file", $usage;
#开始处理输入译文信息文件
my $count =0;
while(!eof(TRANS_FILE)){
my $line = <TRANS_FILE>;
$count++;
if($line=~//#/#/#/#/#/)
{
print "A new sentence begin:/n";
}elsif($line =~//$/$/$/$/$ path_file/)
{
print "A path_file begin:/n";
}
else{
my $path = $line ;
print "/n path is: $path";
$count++;
die "/n在$count 行 发生格式错误/n" unless (!eof(TRANS_FILE));
my $feature = <TRANS_FILE>;
print "/n feature is: $feature";
die "/n在$count 行 发生格式错误/n" unless (!eof(TRANS_FILE));
my $trans = <TRANS_FILE>;
print "/n trans is: $trans";
evaluate($path,$feature,$trans,$ref_file,$sel_score,$result_file);
}
}
########################################
# print out the help and exit
sub usage
{
print <<EOHELP;
make_corel [-h] [-s score range ] [-r ref FILENAME] [-t translation FILEHANDLE]
-h :打印帮助信息
-c :打印需要保存的bleu分值范围,“0.8”表示大与0.8, 不给任何参数时全部打印
-r ref_file :参考译文文件路径
-t trans_file :译文信息文件路径
-o result_file :结果文件路径
EOHELP
exit;
}
##########################################
## 评测分数
sub evaluate
{
print "/neval/n";
my ($path_info,$feature_info,$trans_info,$ref_info,$score_info,$result_file_info) =@_;
print $path_info,$feature_info,$trans_info,$ref_info,$score_info,$result_file_info;
my ($Bleu_score);
#打开需要的零时文件,输入必要数据
open TRANS,">trans.file.temp" or die "can not open file trans.file.temp $!/n";
open FEATURE,">feature.file.temp" or die "can not open file feature.file.temp $!/n";
print TRANS $trans_info;
print FEATURE $feature_info;
close(TRANS);
close( FEATURE);
#打开存放最终结果的文件
open OUT,">>$result_file_info" or die "can not open file $result_file_info $!/n";
#把译文写道$trans_info文件里,调用make_score进行评测,结果在$result_file_info中
print system("make_score.exe trans.file.temp $ref_info result.file.temp feature.file.temp");
#把结果文件result.file.temp中的结果析取出来
open RESULT,"result.file.temp" or die "can not open file result.file.temp $!/n";
my $temp_line = <RESULT>;
my @temp_scores = split//s+/,$temp_line;
if($temp_scores[0] >= $score_info)
{
print OUT $temp_scores[0],"/n";
print OUT $path_info;
print OUT $feature_info;
print OUT $trans_info;
close(RESULT);
close(OUT);
return ;
}else
{
close(RESULT);
close(OUT);
return ;}
}
#################################
sub date_time_stamp {
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime();
my @months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
my ($date, $time);
$time = sprintf "%2.2d:%2.2d:%2.2d", $hour, $min, $sec;
$date = sprintf "%4.4s %3.3s %s", 1900+$year, $months[$mon], $mday;
return ($date, $time);
}
- 为译文信息打分的程序
- 为运动员打分的程序及我所犯的错误
- 如何为csdn的资源打分
- 文档合并打分程序
- 类似打分程序
- iOS程序内进入 App Store 打分的代码
- iOS程序内进入 App Store 打分的代码
- 预编译文件信息以及iPhone的尺寸
- 为 VC6 程序的 Release 版本添加调试信息
- 为 VC6 程序的 Release 版本添加调试信息
- Qt 为创建的Window程序(exe)添加属性信息
- 为程序输出日志信息
- 《弟子规》全集译文,为孩子的明天存下来!
- 评委打分的注意事项
- 打分
- 为程序设置版本和帮助信息
- 发送信息的程序
- 一个不错的打分页面
- 请花父母血汗钱的朋友,在出手前再感激父母一下--ZT
- Eclipse快速上手Hibernate--2. 利用Hbm映射文件开发
- Eclipse快速上手Hibernate--3. 利用XDoclet开发
- Eclipse快速上手Hibernate--4. 继承映射(1)
- Eclipse快速上手Hibernate--4. 继承映射(2)
- 为译文信息打分的程序
- Eclipse快速上手Hibernate--4. 继承映射(3)
- Eclipse快速上手Hibernate--5. 组件映射
- Eclipse快速上手Hibernate--6. 关联映射(一对一)
- Eclipse快速上手Hibernate--7. 关联映射(一对多) (1)
- Eclipse快速上手Hibernate--7. 关联映射(一对多) (2)
- Eclipse快速上手Hibernate--7. 关联映射(一对多) (3)
- Eclipse快速上手Hibernate--8. 关联映射(多对多)
- 快速上手Spring--1.收集的一些资料