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