1 // See www.openfst.org for extensive documentation on this weighted
2 // finite-state transducer library.
4 #ifndef FST_SCRIPT_COMPILE_H_
5 #define FST_SCRIPT_COMPILE_H_
9 #include <fst/script/arg-packs.h>
10 #include <fst/script/compile-impl.h>
11 #include <fst/script/fst-class.h>
16 // This operation exists in two forms. 1 is a void operation which writes the
17 // compiled machine to disk; 2 returns an FstClass. I/O should normally be done
18 // using the binary format for efficiency, so users are STRONGLY ENCOURAGED to
19 // use 1 or to construct FSTs using the C++ FST mutation operations.
21 // Note: it is safe to pass these strings as references because
22 // this struct is only used to pass them deeper in the call graph.
23 // Be sure you understand why this is so before using this struct
25 struct CompileFstInnerArgs {
28 const string &fst_type;
29 const fst::SymbolTable *isyms;
30 const fst::SymbolTable *osyms;
31 const fst::SymbolTable *ssyms;
36 const bool allow_negative_labels;
38 CompileFstInnerArgs(std::istream &istrm, const string &source,
39 const string &fst_type, const fst::SymbolTable *isyms,
40 const fst::SymbolTable *osyms,
41 const fst::SymbolTable *ssyms, bool accep, bool ikeep,
42 bool okeep, bool nkeep,
43 bool allow_negative_labels = false)
54 allow_negative_labels(allow_negative_labels) {}
58 using CompileFstArgs = args::WithReturnValue<FstClass *, CompileFstInnerArgs>;
62 void CompileFstInternal(CompileFstArgs *args) {
65 using fst::FstCompiler;
66 FstCompiler<Arc> fstcompiler(
67 args->args.istrm, args->args.source, args->args.isyms, args->args.osyms,
68 args->args.ssyms, args->args.accep, args->args.ikeep, args->args.okeep,
69 args->args.nkeep, args->args.allow_negative_labels);
70 const Fst<Arc> *fst = &fstcompiler.Fst();
71 if (args->args.fst_type != "vector") {
72 fst = Convert<Arc>(*fst, args->args.fst_type);
74 FSTERROR() << "Failed to convert FST to desired type: "
75 << args->args.fst_type;
78 args->retval = fst ? new FstClass(*fst) : nullptr;
82 void CompileFst(std::istream &istrm, const string &source, const string &dest,
83 const string &fst_type, const string &arc_type,
84 const SymbolTable *isyms, const SymbolTable *osyms,
85 const SymbolTable *ssyms, bool accep, bool ikeep, bool okeep,
86 bool nkeep, bool allow_negative_labels);
89 FstClass *CompileFstInternal(std::istream &istrm, const string &source,
90 const string &fst_type, const string &arc_type,
91 const SymbolTable *isyms, const SymbolTable *osyms,
92 const SymbolTable *ssyms, bool accep, bool ikeep,
93 bool okeep, bool nkeep,
94 bool allow_negative_labels);
99 #endif // FST_SCRIPT_COMPILE_H_