Hi Zhou

I don't think you're looking at the latest version, but in any case the latest 
from git was buggy too. I've checked in a fix which works for me - can you try 
it?

cheers - Barry


On Monday 19 Dec 2011 06:48:49 zhou weitao wrote:
> Hi, guys:
> 
>     I think I have found a bug in the scripts file "reuese-weights.perl" of
> Moses.(The path is in "/home/zhou/tools/scripts/reusese-weights.perl" to my
> example).
> 
> In the source codes line 17,the regular expressions is wrong, I think it's
> "elsif ($current_weight && /^([\-\d\.e]+)\s*$/) {"  instead   "elsif
> ($current_weight && /^([\-\d\.]+)\s*$/) {"
> 
> as the weight-d,weight-l may be Scientific notation  in the conf file
> moses.ini.
> 
> debug source code:
> #!/usr/bin/perl
> 
> use strict;
> 
> die("ERROR: syntax: reuse-weights.perl weights.ini < moses.ini >
> weighted.ini")
>     unless scalar @ARGV == 1;
> my ($weight_file) = @ARGV;
> 
> my %WEIGHT;
> my $current_weight = "";
> open(WEIGHT,$weight_file)
> 
>     || die("ERROR: could not open weight file: $weight_file");
> 
> while(<WEIGHT>) {
>     if (/^\[weight\-(\S+)\]/) {
> $current_weight = $1;
>     }
>     elsif ($current_weight && /^*([\-\d\.e]+*)\s*$/) {
> push @{$WEIGHT{$current_weight}},$1;
>     }
>     elsif (/^\[/) {
> $current_weight = "";
>     }
> }
> close(WEIGHT);
> 
> my %IGNORE;
> while(<STDIN>) {
>     if (/^\[weight\-(\S+)\]/) {
> $current_weight = $1;
> if (!defined($WEIGHT{$current_weight})) {
>     print STDERR "(reuse-weights) WARNING: no weights for weight-$1,
> deleting\n";
>     $current_weight = "xxx";
> }
> else {
>     print $_;
>     foreach (@{$WEIGHT{$current_weight}}) {
> print $_."\n";
>     }
> }
>     }
>     elsif ($current_weight && /^([\-\d\.]+)\s*$/) {
> $IGNORE{$current_weight}++;
>     }
>     elsif (/^\[/) {
> $current_weight = "";
> print $_;
>     }
>     else {
> print $_;
>     }
> }
> 
> foreach my $weight (keys %WEIGHT) {
>     if (! defined($IGNORE{$weight})) {
> print STDERR "(reuse-weights) WARNING: new weights weight-$weight\n";
> print "\n[weight-$weight]\n";
> foreach (@{$WEIGHT{$weight}}) {
>     print $_."\n";
> }
>     }
>     else {
> print STDERR "(reuse-weights) weight-$weight updated ($IGNORE{$weight} ->
> ".(scalar @{$WEIGHT{$weight}}).")\n";
> if ($IGNORE{$weight} != scalar @{$WEIGHT{$weight}}) {
>     print STDERR "(reuse-weights) WARNING: number of weights changed\n";
> }
>     }
> }
> 
> 
> 
>                                              freshman
> 
_______________________________________________
Moses-support mailing list
[email protected]
http://mailman.mit.edu/mailman/listinfo/moses-support

Reply via email to