FST  openfst-1.7.2
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, std::ios_base::in | std::ios_base::binary);
34  if (!hdr.Read(in, fst_fname)) {
35  LOG(ERROR) << "Error reading FST: " << fst_fname;
36  return "";
37  }
38  return hdr.ArcType();
39 }
40 
41 } // namespace script
42 } // 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:58
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