00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef FST_SCRIPT_COMPILE_H_
00018 #define FST_SCRIPT_COMPILE_H_
00019
00020 #include <fst/script/arg-packs.h>
00021 #include <fst/script/fst-class.h>
00022 #include <fst/script/compile-impl.h>
00023
00024 namespace fst {
00025 namespace script {
00026
00027
00028
00029
00030
00031 struct FstCompileArgs {
00032 fst::istream &istrm;
00033 const string &source;
00034 const string &dest;
00035 const string &fst_type;
00036 const fst::SymbolTable *isyms;
00037 const fst::SymbolTable *osyms;
00038 const fst::SymbolTable *ssyms;
00039 const bool accep;
00040 const bool ikeep;
00041 const bool okeep;
00042 const bool nkeep;
00043 const bool allow_negative_labels;
00044
00045 FstCompileArgs(istream &istrm, const string &source, const string &dest,
00046 const string &fst_type, const fst::SymbolTable *isyms,
00047 const fst::SymbolTable *osyms,
00048 const fst::SymbolTable *ssyms,
00049 bool accep, bool ikeep, bool okeep, bool nkeep,
00050 bool allow_negative_labels = false) :
00051 istrm(istrm), source(source), dest(dest), fst_type(fst_type),
00052 isyms(isyms), osyms(osyms), ssyms(ssyms), accep(accep), ikeep(ikeep),
00053 okeep(okeep), nkeep(nkeep),
00054 allow_negative_labels(allow_negative_labels) { }
00055 };
00056
00057 template<class Arc>
00058 void CompileFst(FstCompileArgs *args) {
00059 using fst::FstCompiler;
00060 using fst::Convert;
00061 using fst::Fst;
00062
00063 FstCompiler<Arc> fstcompiler(args->istrm, args->source, args->isyms,
00064 args->osyms, args->ssyms,
00065 args->accep, args->ikeep,
00066 args->okeep, args->nkeep,
00067 args->allow_negative_labels);
00068
00069 const Fst<Arc> *fst = &fstcompiler.Fst();
00070 if (args->fst_type != "vector") {
00071 fst = Convert<Arc>(*fst, args->fst_type);
00072 if (!fst) {
00073 LOG(FATAL) << "Failed to convert FST to desired type: "
00074 << args->fst_type;
00075 }
00076 }
00077
00078 fst->Write(args->dest);
00079 }
00080
00081 void CompileFst(istream &istrm, const string &source, const string &dest,
00082 const string &fst_type, const string &arc_type,
00083 const SymbolTable *isyms,
00084 const SymbolTable *osyms, const SymbolTable *ssyms,
00085 bool accep, bool ikeep, bool okeep, bool nkeep,
00086 bool allow_negative_labels);
00087
00088 }
00089 }
00090
00091 #endif /// FST_SCRIPT_COMPILE_H_
00092