#!/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; for(; $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}; chop($value); $list .= " $value"; } return $list; }