Welcome to mirror list, hosted at ThFree Co, Russian Federation.

trainlm-lmplz.perl « generic « scripts - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 04524867572b1f286973f940675fa216c485ad15 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env perl 

# Compatible with sri LM-creating script, eg.
#    ngram-count -order 5 -interpolate -wbdiscount -unk -text corpus.txt -lm lm.txt
# To use it in the EMS, add this to the [LM] section
#    lm-training = "$moses-script-dir/generic/trainlm-lmplz.perl -lmplz $lmplz"
#    settings = "-T $working-dir/tmp -S 10G"
# Also, make sure that $lmplz is defined (in the [LM] or [GENERAL] section. 
# It should point to the binary file
#    lmplz = /home/waziz/workspace/github/moses/bin/lmplz

use strict;
use FindBin qw($RealBin);
use Getopt::Long qw/GetOptionsFromArray/;
#use Getopt::Long;
Getopt::Long::Configure("pass_through", "no_ignore_case");

my $order = 3; # order of language model (default trigram)
my $corpus; # input text data
my $lm; # generated language model
my $lmplz; # bin directory of IRSTLM 
my $help = 0;

my @optconfig = (
    "-order=s"  => \$order,
    "-text=s"   => \$corpus,
    "-lm=s"     => \$lm,
    "-lmplz=s"  => \$lmplz,
);

GetOptionsFromArray(\@ARGV, @optconfig);
die("ERROR: please set text") unless defined($corpus);
die("ERROR: please set lm") unless defined($lm);
die("ERROR: please set lmplz") unless defined($lmplz);

my $settings = join(' ', @ARGV);
my $cmd = "$lmplz --order $order $settings < $corpus > $lm";

print STDERR "EXECUTING $cmd\n";
`$cmd`;