50 static int wfst_run_main(
int argc,
char **argv);
53 int main(
int argc,
char **argv)
56 wfst_run_main(argc,argv);
62 static int wfst_run_main(
int argc,
char **argv)
72 float sumlogp=0,isumlogp;
77 EST_String(
"[WFSTFILE] [input file0] ... [-o output file]\n")+
78 "Summary: Recognize/transduce using a WFST on data\n"+
79 "-wfst <ifile> The WFST to use\n"+
80 "-transduce Transduce input to output (default)\n"+
81 "-recog Recognize input consists of pairs\n"+
82 "-cumulate_into <ofile>\n"+
83 " Cumulate transitions to give new weights\n"+
84 " save new WFST into ofile\n"+
85 "-itype <string> char or token\n"+
86 "-quiet No extraneous messages\n"+
87 "-perplexity Calculate perplexity on given data set\n"+
88 "-heap <int> {210000}\n"+
89 " Set size of Lisp heap, needed for large wfsts\n"+
90 "-o <ofile> Output file for transduced forms\n",
95 if ((ofd=fopen(al.
val(
"-o"),
"w")) ==
NULL)
96 EST_error(
"can't open output file for writing \"%s\"",
97 (
const char *)al.
val(
"-o"));
103 wfstfile = al.
val(
"-wfst");
113 EST_error(
"failed to read WFST from \"%s\"",
114 (
const char *)wfstfile);
116 if (al.
present(
"-cumulate_into"))
117 wfst.start_cumulate();
119 for (f=files.
head(); f != 0; f=f->
next())
124 if (ts.
open(files(f)) != 0)
125 EST_error(
"failed to read WFST data file from \"%s\"",
126 (
const char *)files(f));
134 while((!ts.
eof()) && (!ts.
eoln()));
167 cout <<
"OK." << endl;
169 cout <<
"failed." << endl;
175 if (al.
present(
"-cumulate_into"))
177 wfst.stop_cumulate();
178 if (wfst.save(al.
val(
"-cumulate_into")) !=
write_ok)
179 EST_error(
"failed to write cumulated WFST to \"%s\"",
180 (
const char *)al.
val(
"-cumulate_into"));
183 printf(
"total %d OK %f%% failed %f%%\n",
187 printf(
"perplexity is %f\n", pow(
float(2.0),
float(-1.0 * (sumlogp/count))));
int transduce(const EST_WFST &wfst, const EST_StrList &in, EST_StrList &out)
EST_TokenStream & get(EST_Token &t)
get next token in stream
a call representing a weighted finite-state transducer
int ival(const EST_String &rkey, int m=1) const
double mean(void) const
mean of currently cummulated values
void close(void)
Close stream.
int open(const EST_String &filename)
open a EST_TokenStream for a file.
int recognize(const EST_WFST &wfst, const EST_StrList &in, int quiet)
int main(int argc, char **argv)
The file was written successfully.
const V & val(const K &rkey, bool m=0) const
return value according to key (const)
void append(const T &item)
add item onto end of list
double samples(void)
number of samples in set
int present(const K &rkey) const
Returns true if key is present.
int siod_init(int heap_size=DEFAULT_HEAP_SIZE)
int parse_command_line(int argc, char *argv[], const EST_String &usage, EST_StrList &files, EST_Option &al, int make_stdio=1)
int recognize_for_perplexity(const EST_WFST &wfst, const EST_StrList &in, int quiet, float &count, float &sumlogp)