FST  openfst-1.7.1
OpenFst Library
replace.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 #include <fst/script/fst-class.h>
5 #include <fst/script/replace.h>
7 
8 namespace fst {
9 namespace script {
10 
11 void Replace(const std::vector<LabelFstClassPair> &pairs, MutableFstClass *ofst,
12  const ReplaceOptions &opts) {
13  if (!pairs.empty()) {
14  for (auto it = pairs.begin(); it != pairs.end() - 1; ++it) {
15  if (!internal::ArcTypesMatch(*it->second, *(it + 1)->second, "Replace")) {
16  ofst->SetProperties(kError, kError);
17  return;
18  }
19  }
20  if (!internal::ArcTypesMatch(*pairs[0].second, *ofst, "Replace")) {
21  ofst->SetProperties(kError, kError);
22  return;
23  }
24  }
25  ReplaceArgs args(pairs, ofst, opts);
26  Apply<Operation<ReplaceArgs>>("Replace", ofst->ArcType(), &args);
27 }
28 
32 
33 } // namespace script
34 } // namespace fst
void Replace(ReplaceArgs *args)
Definition: replace.h:39
const string & ArcType() const final
Definition: fst-class.h:290
REGISTER_FST_OPERATION(Compress, StdArc, CompressArgs)
bool ArcTypesMatch(const M &m, const N &n, const string &op_name)
Definition: script-impl.h:176
std::tuple< const std::vector< LabelFstClassPair > &, MutableFstClass *, const ReplaceOptions & > ReplaceArgs
Definition: replace.h:36
constexpr uint64 kError
Definition: properties.h:33
void SetProperties(uint64 props, uint64 mask)
Definition: fst-class.h:452