20 #ifndef FST_REPLACE_H_ 21 #define FST_REPLACE_H_ 23 #include <sys/types.h> 49 #include <unordered_map> 87 template <
class S,
class P>
108 template <
class StateId,
class PrefixId>
116 template <
class StateId,
class PrefixId>
125 template <
class StateId,
class PrefixId>
129 : size_array_(size_array) {}
132 return tuple.
prefix_id * size_array_->back() +
137 const std::vector<uint64_t> *size_array_;
141 template <
class StateId,
class PrefixId>
150 template <
typename S,
typename P>
170 static constexpr
size_t prime0 = 7853;
171 static constexpr
size_t prime1 = 9001;
172 static constexpr
size_t prime2 = 100003;
178 template <
class Label,
class StateId>
192 : prefix_(other.prefix_) {}
198 void Pop() { prefix_.pop_back(); }
202 size_t Depth()
const {
return prefix_.size(); }
209 template <
class Label,
class StateId>
213 for (
size_t i = 0; i < x.
prefix_.size(); ++i) {
223 template <
class Label,
class StateId>
228 for (
const auto &pair : prefix.
prefix_) {
229 static constexpr
size_t prime = 7863;
230 sum += pair.fst_id + pair.nextstate * prime;
240 template <
class Arc,
class P = s
size_t>
260 const std::vector<std::pair<
Label,
const Fst<Arc> *>> &fst_list,
263 size_array_.push_back(0);
264 for (
const auto &[label,
fst] : fst_list) {
267 size_array_.push_back(size_array_.back());
272 state_table_ = std::make_unique<StateTable>(
273 ReplaceRootSelector<StateId, PrefixId>(),
274 ReplaceFstStateFingerprint<StateId, PrefixId>(),
276 root_size_ + size_array_.back());
281 : root_size_(table.root_size_),
282 size_array_(table.size_array_),
283 prefix_table_(table.prefix_table_) {
284 state_table_ = std::make_unique<StateTable>(
285 ReplaceRootSelector<StateId, PrefixId>(),
286 ReplaceFstStateFingerprint<StateId, PrefixId>(),
288 root_size_ + size_array_.back());
292 return state_table_->FindState(tuple);
298 return prefix_table_.FindId(prefix);
302 return prefix_table_.FindEntry(
id);
307 std::vector<uint64_t> size_array_;
308 std::unique_ptr<StateTable> state_table_;
313 template <
class Arc,
class P >
316 ReplaceHash<typename Arc::StateId, P>> {
330 using StateTable::FindState;
331 using StateTable::Tuple;
337 :
StateTable(), prefix_table_(table.prefix_table_) {}
340 return prefix_table_.FindId(prefix);
344 return prefix_table_.FindEntry(
id);
354 template <
class Arc,
class StateTable = DefaultReplaceStateTable<Arc>,
355 class CacheStore = DefaultCacheStore<Arc>>
371 bool take_ownership =
false;
373 StateTable *state_table =
nullptr;
394 call_label_type(call_label_type),
395 return_label_type(return_label_type),
396 return_label(return_label) {}
402 call_label_type(call_label_type),
403 return_label_type(return_label_type),
404 call_output_label(call_output_label),
405 return_label(return_label) {}
409 opts.return_label_type, opts.return_label) {}
418 call_output_label(epsilon_replace_arc ? 0 :
kNoLabel) {}
422 template <
class Arc,
class StateTable,
class CacheStore>
426 using FstList = std::vector<std::pair<typename Arc::Label, const Fst<Arc> *>>;
441 template <
class Label>
444 Label call_output_label) {
458 typename Arc::Label call_output_label,
459 bool *sorted_and_non_empty) {
460 using Label =
typename Arc::Label;
461 std::vector<uint64_t> inprops;
462 bool all_ilabel_sorted =
true;
463 bool all_olabel_sorted =
true;
464 bool all_non_empty =
true;
466 bool all_negative =
true;
468 bool dense_range =
true;
469 Label root_fst_idx = 0;
470 for (Label i = 0; i < fst_list.size(); ++i) {
471 const auto label = fst_list[i].first;
472 if (label >= 0) all_negative =
false;
473 if (label > fst_list.size() || label <= 0) dense_range =
false;
474 if (label == root_label) root_fst_idx = i;
475 const auto *
fst = fst_list[i].second;
486 all_non_empty, all_ilabel_sorted, all_olabel_sorted,
487 all_negative || dense_range);
489 *sorted_and_non_empty = all_non_empty && sorted;
498 template <
class Arc,
class StateTable,
class CacheStore>
500 :
public CacheBaseImpl<typename CacheStore::State, CacheStore> {
506 using State =
typename CacheStore::State;
521 using CacheImpl::HasArcs;
522 using CacheImpl::HasFinal;
523 using CacheImpl::HasStart;
524 using CacheImpl::PushArc;
525 using CacheImpl::SetArcs;
526 using CacheImpl::SetFinal;
527 using CacheImpl::SetStart;
534 call_label_type_(opts.call_label_type),
535 return_label_type_(opts.return_label_type),
536 call_output_label_(opts.call_output_label),
537 return_label_(opts.return_label),
538 state_table_(opts.state_table ? opts.state_table
539 : new StateTable(fst_list, opts.root)) {
545 if (!fst_list.empty()) {
546 SetInputSymbols(fst_list[0].second->InputSymbols());
547 SetOutputSymbols(fst_list[0].second->OutputSymbols());
549 fst_array_.push_back(
nullptr);
550 for (
Label i = 0; i < fst_list.size(); ++i) {
551 const auto label = fst_list[i].first;
552 const auto *
fst = fst_list[i].second;
553 nonterminal_hash_[label] = fst_array_.size();
554 nonterminal_set_.insert(label);
558 FSTERROR() <<
"ReplaceFstImpl: Input symbols of FST " << i
559 <<
" do not match input symbols of base FST (0th FST)";
563 FSTERROR() <<
"ReplaceFstImpl: Output symbols of FST " << i
564 <<
" do not match output symbols of base FST (0th FST)";
569 const auto nonterminal = nonterminal_hash_[opts.
root];
570 if ((nonterminal == 0) && (fst_array_.size() > 1)) {
571 FSTERROR() <<
"ReplaceFstImpl: No FST corresponding to root label " 572 << opts.
root <<
" in the input tuple vector";
575 root_ = (nonterminal > 0) ? nonterminal : 1;
576 bool all_non_empty_and_sorted =
false;
578 return_label_type_, call_output_label_,
579 &all_non_empty_and_sorted));
581 always_cache_ = !all_non_empty_and_sorted;
582 VLOG(2) <<
"ReplaceFstImpl::ReplaceFstImpl: always_cache = " 583 << (always_cache_ ?
"true" :
"false");
588 call_label_type_(impl.call_label_type_),
589 return_label_type_(impl.return_label_type_),
590 call_output_label_(impl.call_output_label_),
591 return_label_(impl.return_label_),
592 always_cache_(impl.always_cache_),
593 state_table_(new StateTable(*(impl.state_table_))),
594 nonterminal_set_(impl.nonterminal_set_),
595 nonterminal_hash_(impl.nonterminal_hash_),
601 fst_array_.reserve(impl.fst_array_.size());
602 fst_array_.emplace_back(
nullptr);
603 for (
Label i = 1; i < impl.fst_array_.size(); ++i) {
604 fst_array_.emplace_back(impl.fst_array_[i]->Copy(
true));
619 if (fst_array_.size() == 1) {
623 const auto fst_start = fst_array_[root_]->Start();
627 state_table_->FindState(
StateTuple(prefix, root_, fst_start));
632 return CacheImpl::Start();
638 const auto &tuple = state_table_->Tuple(s);
639 auto weight = Weight::Zero();
640 if (tuple.prefix_id == 0) {
642 weight = fst_array_[tuple.fst_id]->Final(
fst_state);
644 if (always_cache_ || HasArcs(s)) SetFinal(s, weight);
651 }
else if (always_cache_) {
655 const auto tuple = state_table_->Tuple(s);
657 auto num_arcs = fst_array_[tuple.fst_id]->NumArcs(tuple.fst_state);
658 if (ComputeFinalArc(tuple,
nullptr)) ++num_arcs;
665 if (label < *nonterminal_set_.begin() ||
666 label > *nonterminal_set_.rbegin()) {
669 return nonterminal_hash_.count(label);
689 const auto tuple = state_table_->Tuple(s);
695 num = fst_array_[tuple.fst_id]->NumInputEpsilons(tuple.fst_state);
700 for (; !aiter.
Done() && ((aiter.
Value().ilabel == 0) ||
701 IsNonTerminal(aiter.
Value().olabel));
707 ComputeFinalArc(tuple,
nullptr)) {
725 const auto tuple = state_table_->Tuple(s);
731 num = fst_array_[tuple.fst_id]->NumOutputEpsilons(tuple.fst_state);
736 for (; !aiter.
Done() && ((aiter.
Value().olabel == 0) ||
737 IsNonTerminal(aiter.
Value().olabel));
743 ComputeFinalArc(tuple,
nullptr)) {
755 for (
Label i = 1; i < fst_array_.size(); ++i) {
756 if (fst_array_[i]->Properties(kError,
false)) {
757 SetProperties(kError, kError);
767 if (!HasArcs(s))
Expand(s);
768 CacheImpl::InitArcIterator(s, data);
776 const auto tuple = state_table_->Tuple(s);
784 if (ComputeFinalArc(tuple, &arc)) PushArc(s, std::move(arc));
786 for (; !aiter.
Done(); aiter.
Next()) {
787 if (ComputeArc(tuple, aiter.
Value(), &arc)) PushArc(s, std::move(arc));
801 if (ComputeFinalArc(tuple, &arc)) AddArc(s, arc);
803 for (; !aiter.
Done(); aiter.
Next()) {
804 if (ComputeArc(tuple, aiter.
Value(), &arc)) AddArc(s, arc);
819 arcp->ilabel = (
EpsilonOnInput(return_label_type_)) ? 0 : return_label_;
823 const auto &stack = state_table_->GetStackPrefix(tuple.
prefix_id);
825 const auto &top = stack.Top();
826 arcp->nextstate = state_table_->FindState(
849 if (arc.olabel == 0 || arc.olabel < *nonterminal_set_.begin() ||
850 arc.olabel > *nonterminal_set_.rbegin()) {
851 const auto nextstate =
853 ? state_table_->FindState(
856 *arcp = Arc(arc.ilabel, arc.olabel, arc.weight, nextstate);
859 if (
const auto it = nonterminal_hash_.find(arc.olabel);
860 it != nonterminal_hash_.end()) {
861 const auto nonterminal = it->second;
862 const auto nt_prefix =
863 PushPrefix(state_table_->GetStackPrefix(tuple.
prefix_id),
864 tuple.
fst_id, arc.nextstate);
867 const auto nt_start = fst_array_[nonterminal]->Start();
871 nt_prefix, nonterminal, nt_start))
878 : ((call_output_label_ ==
kNoLabel) ? arc.olabel
879 : call_output_label_);
880 *arcp = Arc(ilabel, olabel, arc.weight, nt_nextstate);
885 const auto nextstate =
887 ? state_table_->FindState(
890 *arcp = Arc(arc.ilabel, arc.olabel, arc.weight, nextstate);
906 return fst_array_[
fst_id].get();
910 const auto it = nonterminal_hash_.find(nonterminal);
911 if (it == nonterminal_hash_.end()) {
912 FSTERROR() <<
"ReplaceFstImpl::GetFstId: Nonterminal not found: " 924 return state_table_->FindPrefixId(prefix);
930 return GetPrefixId(prefix);
935 prefix.
Push(fst_id, nextstate);
936 return GetPrefixId(prefix);
942 int64_t call_output_label_;
943 int64_t return_label_;
947 std::unique_ptr<StateTable> state_table_;
950 std::set<Label> nonterminal_set_;
952 std::vector<std::unique_ptr<const Fst<Arc>>> fst_array_;
991 template <
class A,
class T ,
994 :
public ImplToFst<internal::ReplaceFstImpl<A, T, CacheStore>> {
1003 using State =
typename CacheStore::State;
1034 GetMutableImpl()->InitArcIterator(s, data);
1038 if ((GetImpl()->ArcIteratorFlags() &
kArcNoCache) &&
1044 VLOG(2) <<
"Not using replace matcher";
1052 return *GetImpl()->GetStateTable();
1056 return *GetImpl()->GetFst(GetImpl()->GetFstId(nonterminal));
1067 template <
class Arc,
class StateTable,
class CacheStore>
1073 fst, fst.GetMutableImpl()) {}
1095 template <
class Arc,
class StateTable,
class CacheStore>
1111 cache_data_.ref_count =
nullptr;
1112 local_data_.ref_count =
nullptr;
1114 if (!(fst_.GetImpl()->ArcIteratorFlags() &
kArcNoCache) &&
1115 !(fst_.GetImpl()->HasArcs(s_))) {
1116 fst_.GetMutableImpl()->Expand(s_);
1119 if (fst_.GetImpl()->HasArcs(s_)) {
1121 ->internal::template CacheBaseImpl<
1122 typename CacheStore::State,
1123 CacheStore>::InitArcIterator(s_, &cache_data_);
1124 num_arcs_ = cache_data_.narcs;
1125 arcs_ = cache_data_.arcs;
1128 tuple_ = fst_.GetImpl()->GetStateTable()->Tuple(s_);
1137 const auto *rfst = fst_.GetImpl()->GetFst(tuple_.fst_id);
1138 rfst->InitArcIterator(tuple_.fst_state, &local_data_);
1140 arcs_ = local_data_.arcs;
1143 bool has_final_arc = fst_.GetMutableImpl()->ComputeFinalArc(
1148 num_arcs_ = local_data_.narcs;
1149 if (has_final_arc) ++num_arcs_;
1153 offset_ = num_arcs_ - local_data_.narcs;
1162 if (cache_data_.ref_count) --(*cache_data_.ref_count);
1163 if (local_data_.ref_count) --(*local_data_.ref_count);
1172 fst_.InitArcIterator(s_, &cache_data_);
1173 arcs_ = cache_data_.arcs;
1181 arcs_ = local_data_.arcs;
1184 if (!fst_.GetMutableImpl()->EpsilonOnCallInput()) {
1189 offset_ = num_arcs_ - local_data_.narcs;
1195 bool Done()
const {
return pos_ >= num_arcs_; }
1203 FSTERROR() <<
"ReplaceFst: Inconsistent arc iterator flags";
1207 if (pos_ - offset_ >= 0) {
1208 const auto &arc = arcs_[pos_ - offset_];
1215 fst_.GetMutableImpl()->ComputeArc(tuple_, arc, &arc_,
1216 flags_ & kArcValueFlags);
1224 fst_.GetMutableImpl()->ComputeFinalArc(tuple_, &final_arc_,
1225 flags_ & kArcValueFlags);
1238 void Seek(
size_t pos) { pos_ = pos; }
1240 uint8_t
Flags()
const {
return flags_; }
1246 flags_ |= (flags & fst_.GetImpl()->ArcIteratorFlags());
1251 if (!fst_.GetImpl()->HasArcs(s_)) data_flags_ = 0;
1255 if ((flags & kArcNoCache) && (!data_flags_)) Init();
1264 mutable ssize_t offset_;
1272 mutable const Arc *arcs_;
1273 mutable uint8_t data_flags_;
1274 mutable Arc final_arc_;
1275 mutable uint8_t final_flags_;
1281 template <
class Arc,
class StateTable,
class CacheStore>
1296 : owned_fst_(fst.Copy()),
1298 impl_(fst_.GetMutableImpl()),
1300 match_type_(match_type),
1301 current_loop_(false),
1305 std::swap(loop_.ilabel, loop_.olabel);
1314 impl_(fst_.GetMutableImpl()),
1316 match_type_(match_type),
1317 current_loop_(false),
1321 std::swap(loop_.ilabel, loop_.olabel);
1328 : owned_fst_(matcher.fst_.Copy(safe)),
1330 impl_(fst_.GetMutableImpl()),
1332 match_type_(matcher.match_type_),
1333 current_loop_(false),
1337 std::swap(loop_.ilabel, loop_.olabel);
1347 const auto &fst_array = impl_->fst_array_;
1348 matcher_.resize(fst_array.size());
1349 for (
Label i = 0; i < fst_array.size(); ++i) {
1351 matcher_[i] = std::make_unique<LocalMatcher>(*fst_array[i], match_type_,
1353 auto it = impl_->nonterminal_set_.begin();
1354 for (; it != impl_->nonterminal_set_.end(); ++it) {
1355 matcher_[i]->AddMultiEpsLabel(*it);
1366 if (match_type_ ==
MATCH_NONE)
return match_type_;
1367 const auto true_prop =
1369 const auto false_prop =
1371 const auto props = fst_.Properties(true_prop | false_prop, test);
1372 if (props & true_prop) {
1374 }
else if (props & false_prop) {
1383 uint64_t
Properties(uint64_t props)
const override {
return props; }
1387 if (s_ == s)
return;
1389 tuple_ = impl_->GetStateTable()->Tuple(s_);
1395 current_matcher_ = matcher_[tuple_.fst_id].get();
1396 current_matcher_->SetState(tuple_.fst_state);
1397 loop_.nextstate = s_;
1411 if (label_ == 0 || label_ ==
kNoLabel) {
1414 current_loop_ =
true;
1418 final_arc_ = impl_->ComputeFinalArc(tuple_,
nullptr);
1419 found = current_matcher_->Find(
kNoLabel) || final_arc_ || found;
1422 found = current_matcher_->Find(label_);
1428 return !current_loop_ && !final_arc_ && current_matcher_->Done();
1432 if (current_loop_)
return loop_;
1434 impl_->ComputeFinalArc(tuple_, &arc_);
1437 const auto &component_arc = current_matcher_->Value();
1438 impl_->ComputeArc(tuple_, component_arc, &arc_);
1443 if (current_loop_) {
1444 current_loop_ =
false;
1451 current_matcher_->Next();
1457 std::unique_ptr<const ReplaceFst<Arc, StateTable, CacheStore>> owned_fst_;
1461 std::vector<std::unique_ptr<LocalMatcher>> matcher_;
1466 mutable bool current_loop_;
1467 mutable bool final_arc_;
1475 template <
class Arc,
class StateTable,
class CacheStore>
1479 std::make_unique<StateIterator<ReplaceFst<Arc, StateTable, CacheStore>>>(
1498 template <
class Arc>
1508 template <
class Arc>
1516 template <
class Arc>
1520 bool epsilon_on_replace) {
1524 template <
class Arc>
1533 #endif // FST_REPLACE_H_
ssize_t NumOutputEpsilons(const ExpandedFst< Arc > &fst, typename Arc::StateId s)
ReplaceFstOptions(const CacheOptions &opts, Label root=kNoLabel)
void ExpandAndCache() const
ReplaceFingerprint(const std::vector< uint64_t > *size_array)
uint64_t Properties(uint64_t mask) const override
typename Arc::Label Label
typename CacheStore::State State
void SetState(StateId s) final
constexpr uint8_t kArcValueFlags
ArcIterator(const ReplaceFst< Arc, StateTable, CacheStore > &fst, StateId s)
const StateTuple & Tuple(StateId id) const
std::vector< PrefixTuple > prefix_
MatcherBase< Arc > * InitMatcher(MatchType match_type) const override
void Expand(StateId s, const StateTuple &tuple, const ArcIteratorData< Arc > &data)
constexpr uint8_t kArcNoCache
const StateTable & GetStateTable() const
const StackPrefix & GetStackPrefix(PrefixId id) const
const Fst< Arc > * GetFst(Label fst_id) const
ReplaceStateTuple(PrefixId prefix_id=-1, StateId fst_id=kNoStateId, StateId fst_state=kNoStateId)
typename StateTable::PrefixId PrefixId
PrefixId FindPrefixId(const StackPrefix &prefix)
ReplaceFstOptions(const ReplaceUtilOptions &opts)
size_t NumOutputEpsilons(StateId s)
bool EpsilonOnOutput(ReplaceLabelType label_type)
ReplaceFstMatcher(const ReplaceFst< Arc, StateTable, CacheStore > *fst, MatchType match_type)
typename CacheStore::State State
Arc::Weight Final(const ExpandedFst< Arc > &fst, typename Arc::StateId s)
constexpr uint32_t kMultiEpsList
const SymbolTable * OutputSymbols() const
uint8_t ArcIteratorFlags() const
typename Arc::Weight Weight
uint64_t Properties(uint64_t props) const override
constexpr uint64_t kError
uint64_t Properties() const override
ReplaceFst(const std::vector< std::pair< Label, const Fst< Arc > * >> &fst_array, const ReplaceFstOptions< Arc, StateTable, CacheStore > &opts)
void InitArcIterator(StateId s, ArcIteratorData< Arc > *data) const override
bool ReplaceTransducer(ReplaceLabelType call_label_type, ReplaceLabelType return_label_type, Label call_output_label)
uint64_t operator()(const ReplaceStateTuple< StateId, PrefixId > &tuple) const
void Push(StateId fst_id, StateId nextstate)
VectorHashReplaceStateTable(const VectorHashReplaceStateTable< Arc, PrefixId > &table)
MatchType Type(bool test) const override
typename Arc::Weight Weight
typename ReplaceFst< Arc, StateTable, CacheStore >::Arc Arc
constexpr uint8_t kArcILabelValue
ssize_t NumArcs(const ExpandedFst< Arc > &fst, typename Arc::StateId s)
constexpr uint64_t kNotOLabelSorted
bool EpsilonOnInput(ReplaceLabelType label_type)
void Replace(const std::vector< std::pair< typename Arc::Label, const Fst< Arc > * >> &ifst_array, MutableFst< Arc > *ofst, std::vector< std::pair< typename Arc::Label, typename Arc::Label >> *parens, const PdtReplaceOptions< Arc > &opts)
bool CyclicDependencies() const
VectorHashReplaceStateTable(const std::vector< std::pair< Label, const Fst< Arc > * >> &fst_list, Label root)
ReplaceFstOptions(const CacheImplOptions< CacheStore > &opts, Label root=kNoLabel)
bool Find(Label label) final
const PrefixTuple & Top() const
const Fst< Arc > & GetFst(Label nonterminal) const
const Arc & Value() const
DefaultReplaceStateTable(const DefaultReplaceStateTable< Arc, PrefixId > &table)
void InitArcIterator(StateId s, ArcIteratorData< Arc > *data)
const Arc & Value() const
std::vector< std::pair< typename Arc::Label, const Fst< Arc > * >> FstList
typename StateTable::StateTuple StateTuple
bool ComputeArc(const StateTuple &tuple, const Arc &arc, Arc *arcp, uint8_t flags=kArcValueFlags)
bool ComputeFinalArc(const StateTuple &tuple, Arc *arcp, uint8_t flags=kArcValueFlags)
ReplaceFstImpl(const ReplaceFstImpl &impl)
size_t operator()(const ReplaceStateTuple< S, P > &t) const
constexpr uint64_t kNotILabelSorted
typename Arc::Weight Weight
ssize_t NumInputEpsilons(const ExpandedFst< Arc > &fst, typename Arc::StateId s)
void InitStateIterator(StateIteratorData< Arc > *data) const override
constexpr uint64_t kOLabelSorted
constexpr uint64_t kCopyProperties
typename Arc::StateId StateId
uint64_t ReplaceProperties(const std::vector< uint64_t > &inprops, size_t root, bool epsilon_on_call, bool epsilon_on_return, bool out_epsilon_on_call, bool out_epsilon_on_return, bool replace_transducer, bool no_empty_fst, bool all_ilabel_sorted, bool all_olabel_sorted, bool all_negative_or_dense)
const Fst< Arc > & GetFst() const override
typename Arc::Label Label
ReplaceFstOptions(int64_t root, bool epsilon_replace_arc)
size_t NumArcs(StateId s)
typename Arc::Label Label
ReplaceFst * Copy(bool safe=false) const override
std::unique_ptr< StateIteratorBase< Arc > > base
PrefixId FindPrefixId(const StackPrefix &prefix)
const StackPrefix & GetStackPrefix(PrefixId id) const
ReplaceFst(const std::vector< std::pair< Label, const Fst< Arc > * >> &fst_array, Label root)
ReplaceFstOptions(Label root, ReplaceLabelType call_label_type, ReplaceLabelType return_label_type, Label return_label)
bool EpsilonOnCallInput()
uint64_t operator()(const ReplaceStateTuple< StateId, PrefixId > &tuple) const
typename Arc::Label Label
constexpr uint8_t kArcWeightValue
constexpr uint64_t kILabelSorted
ReplaceFstMatcher * Copy(bool safe=false) const override
uint64_t ReplaceFstProperties(typename Arc::Label root_label, const FstList< Arc > &fst_list, ReplaceLabelType call_label_type, ReplaceLabelType return_label_type, typename Arc::Label call_output_label, bool *sorted_and_non_empty)
constexpr uint64_t kFstProperties
ReplaceFst(const ReplaceFst &fst, bool safe=false)
const Arc & Value() const final
Label GetFstId(Label nonterminal) const
typename internal::ReplaceFstImpl< Arc, StateTable, CacheStore >::Arc Arc
const SymbolTable * InputSymbols() const
Arc::StateId CountStates(const Fst< Arc > &fst)
constexpr uint8_t kArcNextStateValue
bool CyclicDependencies() const
typename Arc::Label Label
friend H AbslHashValue(H h, const ReplaceStateTuple &t)
size_t operator()(const ReplaceStackPrefix< Label, StateId > &prefix) const
size_t NumInputEpsilons(StateId s)
ssize_t Priority(StateId s) final
ReplaceFstOptions(Label root, ReplaceLabelType call_label_type, ReplaceLabelType return_label_type, Label call_output_label, Label return_label)
ReplaceFstMatcher(const ReplaceFstMatcher &matcher, bool safe=false)
ReplaceFstOptions(Label root)
bool operator==(const ErrorWeight &, const ErrorWeight &)
bool CyclicDependencies() const
typename StateTable::StateTuple StateTuple
ReplaceFstImpl(const FstList< Arc > &fst_list, const ReplaceFstOptions< Arc, StateTable, CacheStore > &opts)
typename Arc::StateId StateId
ReplaceFstMatcher(const ReplaceFst< Arc, StateTable, CacheStore > &fst, MatchType match_type)
typename Arc::StateId StateId
bool CompatSymbols(const SymbolTable *syms1, const SymbolTable *syms2, bool warning=true)
void Expand(const Fst< Arc > &ifst, const std::vector< std::pair< typename Arc::Label, typename Arc::Label >> &parens, const std::vector< typename Arc::Label > &assignments, MutableFst< Arc > *ofst, const MPdtExpandOptions &opts)
void SetFlags(uint8_t flags, uint8_t mask)
ReplaceStackPrefix(const ReplaceStackPrefix &other)
typename Arc::StateId StateId
typename Arc::StateId StateId
StateId FindState(const StateTuple &tuple)
bool IsNonTerminal(Label label) const
typename Arc::StateId StateId
DefaultReplaceStateTable(const std::vector< std::pair< Label, const Fst< Arc > * >> &, Label)
StateIterator(const ReplaceFst< Arc, StateTable, CacheStore > &fst)
typename Arc::Label Label
PrefixTuple(Label fst_id=kNoLabel, StateId nextstate=kNoStateId)
bool operator()(const ReplaceStateTuple< StateId, PrefixId > &tuple) const
StateTable * GetStateTable() const
std::unordered_map< Label, Label > NonTerminalHash