FST  openfst-1.6.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  for (auto i = 0; i < pairs.size() - 1; ++i) {
14  if (!ArcTypesMatch(*pairs[i].second, *pairs[i + 1].second, "Replace")) {
15  ofst->SetProperties(kError, kError);
16  return;
17  }
18  }
19  if (!ArcTypesMatch(*pairs[0].second, *ofst, "Replace")) {
20  ofst->SetProperties(kError, kError);
21  return;
22  }
23  ReplaceArgs args(pairs, ofst, opts);
24  Apply<Operation<ReplaceArgs>>("Replace", ofst->ArcType(), &args);
25 }
26 
30 
31 } // namespace script
32 } // namespace fst
void Replace(ReplaceArgs *args)
Definition: replace.h:36
const string & ArcType() const override
Definition: fst-class.h:289
REGISTER_FST_OPERATION(Compress, StdArc, CompressArgs)
constexpr uint64 kError
Definition: properties.h:33
bool ArcTypesMatch(const M &m, const N &n, const string &op_name)
Definition: script-impl.h:177
void SetProperties(uint64 props, uint64 mask)
Definition: fst-class.h:455