FST  openfst-1.6.1
OpenFst Library
script-impl.cc
Go to the documentation of this file.
1 // See www.openfst.org for extensive documentation on this weighted
2 // finite-state transducer library.
3 //
4 // Definitions and functions for invoking and using Far main functions that
5 // support multiple and extensible arc types.
6 
8 
9 #include <string>
10 
11 #include <fst/extensions/far/far.h>
12 #include <fstream>
13 
14 namespace fst {
15 namespace script {
16 
17 string LoadArcTypeFromFar(const string &far_fname) {
18  FarHeader hdr;
19  if (!hdr.Read(far_fname)) {
20  LOG(ERROR) << "Error reading FAR: " << far_fname;
21  return "";
22  }
23  string atype = hdr.ArcType();
24  if (atype == "unknown") {
25  LOG(ERROR) << "Empty FST archive: " << far_fname;
26  return "";
27  }
28  return atype;
29 }
30 
31 string LoadArcTypeFromFst(const string &fst_fname) {
32  FstHeader hdr;
33  std::ifstream in(fst_fname.c_str(),
34  std::ios_base::in | std::ios_base::binary);
35  if (!hdr.Read(in, fst_fname)) {
36  LOG(ERROR) << "Error reading FST: " << fst_fname;
37  return "";
38  }
39  return hdr.ArcType();
40 }
41 
42 } // namespace script
43 } // namespace fst
bool Read(const string &filename)
Definition: far.h:38
#define LOG(type)
Definition: log.h:48
const string & ArcType() const
Definition: fst.h:121
bool Read(std::istream &strm, const string &source, bool rewind=false)
Definition: fst.cc:86
const string & ArcType() const
Definition: far.h:34
string LoadArcTypeFromFst(const string &fst_fname)
Definition: script-impl.cc:31
string LoadArcTypeFromFar(const string &far_fname)
Definition: script-impl.cc:17