00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <stdio.h>
00021 #include <stdlib.h>
00022 #include <string.h>
00023
00024 #include "ngram.h"
00025 #include "toolkit.h"
00026 #include "pc_libs/pc_general.h"
00027 #include "rr_libs/general.h"
00028 #include "idngram2lm.h"
00029 #include "evallm.h"
00030
00035 void main (int argc,char **argv) {
00036
00037 char *bin_path;
00038 int verbosity;
00039 ng_t ng;
00040
00041 if (pc_flagarg(&argc,argv,"-help") || argc == 1) {
00042 fprintf(stderr,"binlm2arpa : Convert a binary format language model to ARPA format.\n");
00043 fprintf(stderr,"Usage : binlm2arpa -binary .binlm\n");
00044 fprintf(stderr," -arpa .arpa\n");
00045 fprintf(stderr," [ -verbosity n ]\n");
00046 exit(1);
00047 }
00048
00049 report_version(&argc,argv);
00050
00051 verbosity = pc_intarg(&argc,argv,"-verbosity",DEFAULT_VERBOSITY);
00052
00053 bin_path = salloc(pc_stringarg(&argc,argv,"-binary",""));
00054
00055 if (!strcmp(bin_path,"")) {
00056 quit(-1,"Error : must specify a binary language model file.\n");
00057 }
00058
00059 ng.arpa_filename = salloc(pc_stringarg(&argc,argv,"-arpa",""));
00060
00061 if (!strcmp(ng.arpa_filename,"")) {
00062 quit(-1,"Error : must specify an ARPA language model file.\n");
00063 }
00064
00065 ng.arpa_fp = rr_oopen(ng.arpa_filename);
00066
00067 pc_report_unk_args(&argc,argv,verbosity);
00068
00069 pc_message(verbosity,1,"Reading binary language model from %s...",bin_path);
00070
00071 load_lm(&ng,bin_path);
00072
00073 if (verbosity>=2) {
00074 display_stats(&ng);
00075 }
00076
00077 pc_message(verbosity,1,"Done\n");
00078
00079 write_arpa_lm(&ng,verbosity);
00080
00081 pc_message(verbosity,0,"binlm2arpa : Done.\n");
00082
00083 exit(0);
00084
00085 }