60 static int wfst_build_main(
int argc,
char **argv);
63 int main(
int argc,
char **argv)
66 wfst_build_main(argc,argv);
72 static int wfst_build_main(
int argc,
char **argv)
81 EST_String(
"[option] [rulefile0] [rulefile1] ...\n")+
82 "Summary: Build a weighted finite state transducer from rules/wfsts\n"+
83 "-type <string> {kk} Input rule type: kk, lts, rg, tl, compose, regex\n"+
84 " union, intersect, concat, asis\n"+
85 "-determinize Determinize WFST before saving it\n"+
86 "-detmin Determinize and minimize WFST before saving it\n"+
87 "-o <ofile> Output file for saved WFST (default stdout)\n"+
88 "-otype <string> {ascii}\n"+
89 " Output type, ascii or binary\n"+
90 "-heap <int> {210000}\n"+
91 " Set size of Lisp heap, needed for large rulesets\n"+
92 "-q Quiet mode, no summary generated\n",
96 outfile = al.
val(
"-o");
100 siod_init(al.
ival(
"-heap"));
103 LISP inalpha, outalpha;
105 gc_protect(&ruleset);
107 if (al.
val(
"-type") ==
"kk")
109 ruleset = car(vload(files(files.head()),1));
110 kkcompile(ruleset,*wfst);
112 else if (al.
val(
"-type") ==
"lts")
114 ruleset = car(vload(files(files.head()),1));
115 ltscompile(ruleset,*wfst);
117 else if (al.
val(
"-type") ==
"rg")
119 ruleset = car(vload(files(files.head()),1));
120 rgcompile(ruleset,*wfst);
122 else if (al.
val(
"-type") ==
"tl")
124 ruleset = car(vload(files(files.head()),1));
125 tlcompile(ruleset,*wfst);
127 else if (al.
val(
"-type") ==
"asis")
129 if (wfst->
load(files.
nth(0)) != format_ok) exit(-1);
131 else if (al.
val(
"-type") ==
"compose")
135 if (files.length() != 2)
136 EST_error(
"compose requires two WFSTs to combine");
138 if (a.
load(files.
nth(0)) != format_ok) exit(-1);
139 if (b.
load(files.
nth(1)) != format_ok) exit(-1);
143 else if (al.
val(
"-type") ==
"union")
147 if (files.length() != 2)
148 EST_error(
"union requires two WFSTs to combine");
150 if (a.
load(files.
nth(0)) != format_ok) exit(-1);
151 if (b.
load(files.
nth(1)) != format_ok) exit(-1);
155 else if (al.
val(
"-type") ==
"intersect")
159 if (files.length() != 2)
160 EST_error(
"intersect requires two WFSTs to combine");
161 if (a.
load(files.
nth(0)) != format_ok) exit(-1);
162 if (b.
load(files.
nth(1)) != format_ok) exit(-1);
166 else if (al.
val(
"-type") ==
"concat")
170 if (files.length() != 2)
171 EST_error(
"concat requires two WFSTs to combine");
172 if (a.
load(files.
nth(0)) != format_ok) exit(-1);
173 if (b.
load(files.
nth(1)) != format_ok) exit(-1);
177 else if (al.
val(
"-type") ==
"difference")
181 if (files.length() != 2)
182 EST_error(
"difference requires two WFSTs to combine");
183 if (a.
load(files.
nth(0)) != format_ok) exit(-1);
184 if (b.
load(files.
nth(1)) != format_ok) exit(-1);
188 else if (al.
val(
"-type") ==
"regex")
190 ruleset = car(vload(files(files.head()),1));
191 inalpha = siod_nth(0,ruleset);
192 outalpha = siod_nth(1,ruleset);
193 wfst->build_from_regex(inalpha,outalpha,car(cdr(cdr(ruleset))));
197 cerr <<
"wfst_build: unknown rule type \"" << al.
val(
"-type")
202 if (al.
present(
"-determinize"))
208 cout <<
"wfst_build summary: " << endl;
209 cout <<
" non-deterministic wfst: " <<
210 wfst->summary() << endl;
211 cout <<
" deterministic wfst: " <<
212 dwfst->summary() << endl;
217 else if (al.
present(
"-detmin"))
221 cout <<
"wfst_build summary: " << endl;
222 cout <<
" non-deterministic wfst: " <<
223 wfst->summary() << endl;
229 cout <<
" deterministic wfst: " <<
230 dwfst->summary() << endl;
234 cout <<
" minimized wfst: " <<
235 mwfst->summary() << endl;
242 cout <<
"wfst_build: " << wfst->summary() << endl;
245 wfst->
save(outfile,al.
val(
"-otype"));
247 gc_unprotect(&ruleset);
void minimize(const EST_WFST &a)
Build minimized form of a.
a call representing a weighted finite-state transducer
int ival(const EST_String &rkey, int m=1) const
void intersection(EST_TList< EST_WFST > &wl)
T & nth(int n)
return the Nth value
void determinize(const EST_WFST &a)
Build determinized form of a.
void compose(const EST_WFST &a, const EST_WFST &b)
EST_write_status save(const EST_String &filename, const EST_String type="ascii")
?
void concat(const EST_WFST &a, const EST_WFST &b)
void uunion(EST_TList< EST_WFST > &wl)
const int present(const K &rkey) const
Returns true if key is present.
const V & val(const K &rkey, bool m=0) const
return value according to key (const)
void difference(const EST_WFST &a, const EST_WFST &b)
EST_read_status load(const EST_String &filename)
?