#!/usr/bin/perl -w use strict; my $header = ""; my @INI = ; my %TTABLE_IMPLEMENTATION = ( 0 => "PhraseDictionaryMemory", 1 => "PhraseDictionaryBinary" ); my %LM_IMPLEMENTATION = ( 0 => "SRILM", 8 => "KENLM lazyken=0" ); my (%FEATURE,%WEIGHT); my $i=0; my ($has_sparse_ttable_features,$sparse_weight_file) = (0); for(; $i creating new sparse weight file '$sparse_weight_file.new'\n"; print "$sparse_weight_file.new\n"; } else { print "$sparse_weight_file\n"; } } elsif ($section =~ /weight-(.+)/ && $section ne "weight-file") { $WEIGHT{$1} = &get_data(); } elsif ($section eq "report-sparse-features") { &get_data(); # ignore } else { print STDERR "include section [$section] verbatim.\n"; print $header.$line; my $SECTION = &get_data(); foreach (@{$SECTION}) { print $_."\n"; } } $header = ""; } else { $header .= $line; } } print $header; if ($has_sparse_ttable_features) { open(SPARSE,$sparse_weight_file); open(NEW,">$sparse_weight_file.new"); while() { if (!/^stm/) { print NEW $_; } else { s/^stm//; for (my $i=0;$i= $i; $feature .= "\n"; $weight .= "TranslationModel$i=".&get_weights(\@W,$weight_count)."\n"; $i++; } } elsif ($section eq "generation-file") { my $i = 0; my @W = @{$WEIGHT{"generation"}}; foreach my $line (@{$FEATURE{$section}}) { my ($input_factor,$output_factor,$weight_count,$file) = split(/ /,$line); $feature .= "Generation name=GenerationModel$i num-features=$weight_count path=$file input-factor=$input_factor output-factor=$output_factor\n"; $weight .= "GenerationModel$i=".&get_weights(\@W,$weight_count)."\n"; $i++; } } elsif ($section eq "distortion-file") { my $i = 0; my @W = @{$WEIGHT{"d"}}; my $ignore = shift @W; foreach my $line (@{$FEATURE{$section}}) { my ($factors,$type,$weight_count,$file) = split(/ /,$line); my ($input_factor,$output_factor) = split(/\-/, $factors); $feature .= "LexicalReordering name=LexicalReordering$i num-features=$weight_count type=$type input-factor=$input_factor output-factor=$output_factor path=$file\n"; $weight .= "LexicalReordering$i=".&get_weights(\@W,$weight_count)."\n"; $i++; } } elsif ($section eq "lmodel-file") { my $i = 0; my @W = @{$WEIGHT{"l"}}; foreach my $line (@{$FEATURE{$section}}) { my ($imp,$factor,$order,$file) = split(/ /,$line); my $implementation = $LM_IMPLEMENTATION{$imp}; if (!defined($implementation)) { print STDERR "ERROR: Unknown language model implementation: $implementation\n"; $implementation = "UNKNOWN"; } $feature .= "$implementation name=LM$i factor=$factor path=$file order=$order\n"; $weight .= "LM$i=".&get_weights(\@W,1)."\n"; $i++; } } } print "\n[feature]\n$feature\n"; print "\n[weight]\n$weight\n"; sub get_data { my ($pattern) = @_; my @DATA; while (++$i < scalar(@INI) && $INI[$i] !~ /^\s*$/ && $INI[$i] !~ /^\[/ && $INI[$i] !~ /^\#/) { push @DATA,$INI[$i]; } $i--; chop(@DATA); return \@DATA; } sub get_weights { my ($W,$count) = @_; my $list = ""; for(my $w=0;$w<$count;$w++) { my $value = shift @{$W}; $list .= " $value"; } return $list; }