30 if (rxfilename ==
"") rxfilename =
"-";
34 if (!hdr.Read(ki.
Stream(), rxfilename))
35 KALDI_ERR <<
"Reading FST: error reading FST header from " 37 FstReadOptions ropts(
"<unspecified>", &hdr);
38 VectorFst<StdArc> *
fst = VectorFst<StdArc>::Read(ki.
Stream(), ropts);
46 if (rxfilename ==
"") rxfilename =
"-";
51 if (!hdr.Read(ki.
Stream(), rxfilename)) {
53 KALDI_ERR <<
"Reading FST: error reading FST header from " 56 KALDI_WARN <<
"We fail to read FST header from " 58 <<
". A NULL pointer is returned.";
63 if (hdr.ArcType() != fst::StdArc::Type()) {
65 KALDI_ERR <<
"FST with arc type " << hdr.ArcType() <<
" is not supported.";
67 KALDI_WARN <<
"Fst with arc type" << hdr.ArcType()
68 <<
" is not supported. A NULL pointer is returned.";
73 FstReadOptions ropts(
"<unspecified>", &hdr);
74 Fst<StdArc> *
fst = NULL;
75 if (hdr.FstType() ==
"const") {
76 fst = ConstFst<StdArc>::Read(ki.
Stream(), ropts);
77 }
else if (hdr.FstType() ==
"vector") {
78 fst = VectorFst<StdArc>::Read(ki.
Stream(), ropts);
87 <<
". A NULL pointer is returned.";
96 std::string real_type = fst->Type();
97 KALDI_ASSERT(real_type ==
"vector" || real_type ==
"const");
98 if (real_type ==
"vector") {
99 return dynamic_cast<VectorFst<StdArc> *
>(fst);
103 VectorFst<StdArc> *new_fst =
new VectorFst<StdArc>(*fst);
116 std::string wxfilename) {
117 if (wxfilename ==
"") wxfilename =
"-";
119 bool write_binary =
true, write_header =
false;
122 fst.Write(ko.
Stream(), wopts);
128 if (ans->Properties(fst::kAcceptor,
true) == 0) {
134 fst::Project(ans, fst::PROJECT_OUTPUT);
136 if (ans->Properties(fst::kILabelSorted,
true) == 0) {
138 fst::ILabelCompare<fst::StdArc> ilabel_comp;
139 fst::ArcSort(ans, ilabel_comp);
Fst< StdArc > * ReadFstKaldiGeneric(std::string rxfilename, bool throw_on_err)
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
fst::StdVectorFst StdVectorFst
fst::VectorFst< fst::StdArc > * ReadAndPrepareLmFst(std::string rxfilename)
#define KALDI_ASSERT(cond)
void WriteFstKaldi(std::ostream &os, bool binary, const VectorFst< Arc > &t)
void ReadFstKaldi(std::istream &is, bool binary, VectorFst< Arc > *fst)
std::string PrintableRxfilename(const std::string &rxfilename)
PrintableRxfilename turns the rxfilename into a more human-readable form for error reporting...
std::string PrintableWxfilename(const std::string &wxfilename)
PrintableWxfilename turns the wxfilename into a more human-readable form for error reporting...
VectorFst< StdArc > * CastOrConvertToVectorFst(Fst< StdArc > *fst)