FST  openfst-1.7.7
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 std::string LoadArcTypeFromFar(const std::string &far_source) {
18  FarHeader hdr;
19  if (!hdr.Read(far_source)) {
20  LOG(ERROR) << "Error reading FAR: " << far_source;
21  return "";
22  }
23  std::string atype = hdr.ArcType();
24  if (atype == "unknown") {
25  LOG(ERROR) << "Empty FST archive: " << far_source;
26  return "";
27  }
28  return atype;
29 }
30 
31 std::string LoadArcTypeFromFst(const std::string &fst_source) {
32  FstHeader hdr;
33  std::ifstream in(fst_source, std::ios_base::in | std::ios_base::binary);
34  if (!hdr.Read(in, fst_source)) {
35  LOG(ERROR) << "Error reading FST: " << fst_source;
36  return "";
37  }
38  return hdr.ArcType();
39 }
40 
41 } // namespace script
42 } // namespace fst
bool Read(std::istream &strm, const std::string &source, bool rewind=false)
Definition: fst.cc:60
#define LOG(type)
Definition: log.h:46
std::string LoadArcTypeFromFst(const std::string &fst_source)
Definition: script-impl.cc:31
bool Read(const std::string &source)
Definition: far.h:38
std::string LoadArcTypeFromFar(const std::string &far_source)
Definition: script-impl.cc:17
const std::string & ArcType() const
Definition: far.h:34
const std::string & ArcType() const
Definition: fst.h:123