45 #include "EST_simplestats.h"
48 static int wfst_run_main(
int argc,
char **argv);
82 int main(
int argc,
char **argv)
85 wfst_run_main(argc,argv);
91 static int wfst_run_main(
int argc,
char **argv)
101 float sumlogp=0,isumlogp;
102 float count=0,icount;
106 EST_String(
"[WFSTFILE] [input file0] ... [-o output file]\n")+
107 "Summary: Recognize/transduce using a WFST on data\n"+
108 "-wfst <ifile> The WFST to use\n"+
109 "-transduce Transduce input to output (default)\n"+
110 "-recog Recognize input consists of pairs\n"+
111 "-cumulate_into <ofile>\n"+
112 " Cumulate transitions to give new weights\n"+
113 " save new WFST into ofile\n"+
114 "-itype <string> char or token\n"+
115 "-quiet No extraneous messages\n"+
116 "-perplexity Calculate perplexity on given data set\n"+
117 "-heap <int> {210000}\n"+
118 " Set size of Lisp heap, needed for large wfsts\n"+
119 "-o <ofile> Output file for transduced forms\n",
124 if ((ofd=fopen(al.
val(
"-o"),
"w")) == NULL)
125 EST_error(
"can't open output file for writing \"%s\"",
126 (
const char *)al.
val(
"-o"));
132 wfstfile = al.
val(
"-wfst");
134 EST_error(
"no WFST specified");
136 siod_init(al.
ival(
"-heap"));
141 if (wfst.load(wfstfile) != format_ok)
142 EST_error(
"failed to read WFST from \"%s\"",
143 (
const char *)wfstfile);
145 if (al.
present(
"-cumulate_into"))
146 wfst.start_cumulate();
148 for (f=files.head(); f != 0; f=f->next())
151 ts.
open(stdin,FALSE);
153 if (ts.
open(files(f)) != 0)
154 EST_error(
"failed to read WFST data file from \"%s\"",
155 (
const char *)files(f));
163 while((!ts.
eof()) && (!ts.
eoln()));
169 r = recognize_for_perplexity(wfst,istrs,
180 r = recognize(wfst,istrs,al.
present(
"-quiet"));
184 r = transduce(wfst,istrs,ostrs);
196 cout <<
"OK." << endl;
198 cout <<
"failed." << endl;
204 if (al.
present(
"-cumulate_into"))
206 wfst.stop_cumulate();
207 if (wfst.save(al.
val(
"-cumulate_into")) != write_ok)
208 EST_error(
"failed to write cumulated WFST to \"%s\"",
209 (
const char *)al.
val(
"-cumulate_into"));
212 printf(
"total %d OK %f%% failed %f%%\n",
216 printf(
"perplexity is %f\n", pow(
float(2.0),
float(-1.0 * (sumlogp/count))));