20 #ifndef FST_REPLACE_H_ 21 #define FST_REPLACE_H_ 40 #include <unordered_map> 78 template <
class S,
class P>
94 template <
class StateId,
class PrefixId>
102 template <
class StateId,
class PrefixId>
111 template <
class StateId,
class PrefixId>
115 : size_array_(size_array) {}
118 return tuple.
prefix_id * size_array_->back() +
123 const std::vector<uint64_t> *size_array_;
127 template <
class StateId,
class PrefixId>
136 template <
typename S,
typename P>
160 static constexpr
size_t prime0 = 7853;
161 static constexpr
size_t prime1 = 9001;
162 static constexpr
size_t prime2 = 100003;
168 template <
class Label,
class StateId>
182 : prefix_(other.prefix_) {}
188 void Pop() { prefix_.pop_back(); }
192 size_t Depth()
const {
return prefix_.size(); }
199 template <
class Label,
class StateId>
203 for (
size_t i = 0; i < x.
prefix_.size(); ++i) {
213 template <
class Label,
class StateId>
218 for (
const auto &pair : prefix.
prefix_) {
219 static constexpr
size_t prime = 7863;
220 sum += pair.fst_id + pair.nextstate * prime;
230 template <
class Arc,
class P = s
size_t>
250 const std::vector<std::pair<
Label,
const Fst<Arc> *>> &fst_list,
253 size_array_.push_back(0);
254 for (
const auto &[label,
fst] : fst_list) {
257 size_array_.push_back(size_array_.back());
259 size_array_.push_back(size_array_.back() +
263 state_table_ = std::make_unique<StateTable>(
264 ReplaceRootSelector<StateId, PrefixId>(),
265 ReplaceFstStateFingerprint<StateId, PrefixId>(),
267 root_size_ + size_array_.back());
272 : root_size_(table.root_size_),
273 size_array_(table.size_array_),
274 prefix_table_(table.prefix_table_) {
275 state_table_ = std::make_unique<StateTable>(
276 ReplaceRootSelector<StateId, PrefixId>(),
277 ReplaceFstStateFingerprint<StateId, PrefixId>(),
279 root_size_ + size_array_.back());
283 return state_table_->FindState(tuple);
289 return prefix_table_.FindId(prefix);
293 return prefix_table_.FindEntry(
id);
298 std::vector<uint64_t> size_array_;
299 std::unique_ptr<StateTable> state_table_;
304 template <
class Arc,
class P >
307 ReplaceHash<typename Arc::StateId, P>> {
321 using StateTable::FindState;
322 using StateTable::Tuple;
328 :
StateTable(), prefix_table_(table.prefix_table_) {}
331 return prefix_table_.FindId(prefix);
335 return prefix_table_.FindEntry(
id);
345 template <
class Arc,
class StateTable = DefaultReplaceStateTable<Arc>,
346 class CacheStore = DefaultCacheStore<Arc>>
362 bool take_ownership =
false;
364 StateTable *state_table =
nullptr;
385 call_label_type(call_label_type),
386 return_label_type(return_label_type),
387 return_label(return_label) {}
393 call_label_type(call_label_type),
394 return_label_type(return_label_type),
395 call_output_label(call_output_label),
396 return_label(return_label) {}
400 opts.return_label_type, opts.return_label) {}
409 call_output_label(epsilon_replace_arc ? 0 :
kNoLabel) {}
413 template <
class Arc,
class StateTable,
class CacheStore>
417 using FstList = std::vector<std::pair<typename Arc::Label, const Fst<Arc> *>>;
432 template <
class Label>
435 Label call_output_label) {
449 typename Arc::Label call_output_label,
450 bool *sorted_and_non_empty) {
451 using Label =
typename Arc::Label;
452 std::vector<uint64_t> inprops;
453 bool all_ilabel_sorted =
true;
454 bool all_olabel_sorted =
true;
455 bool all_non_empty =
true;
457 bool all_negative =
true;
459 bool dense_range =
true;
460 Label root_fst_idx = 0;
461 for (Label i = 0; i < fst_list.size(); ++i) {
462 const auto label = fst_list[i].first;
463 if (label >= 0) all_negative =
false;
464 if (label > fst_list.size() || label <= 0) dense_range =
false;
465 if (label == root_label) root_fst_idx = i;
466 const auto *
fst = fst_list[i].second;
477 all_non_empty, all_ilabel_sorted, all_olabel_sorted,
478 all_negative || dense_range);
480 *sorted_and_non_empty = all_non_empty && sorted;
489 template <
class Arc,
class StateTable,
class CacheStore>
491 :
public CacheBaseImpl<typename CacheStore::State, CacheStore> {
497 using State =
typename CacheStore::State;
512 using CacheImpl::HasArcs;
513 using CacheImpl::HasFinal;
514 using CacheImpl::HasStart;
515 using CacheImpl::PushArc;
516 using CacheImpl::SetArcs;
517 using CacheImpl::SetFinal;
518 using CacheImpl::SetStart;
525 call_label_type_(opts.call_label_type),
526 return_label_type_(opts.return_label_type),
527 call_output_label_(opts.call_output_label),
528 return_label_(opts.return_label),
529 state_table_(opts.state_table ? opts.state_table
530 : new StateTable(fst_list, opts.root)) {
536 if (!fst_list.empty()) {
537 SetInputSymbols(fst_list[0].second->InputSymbols());
538 SetOutputSymbols(fst_list[0].second->OutputSymbols());
540 fst_array_.push_back(
nullptr);
541 for (
Label i = 0; i < fst_list.size(); ++i) {
542 const auto label = fst_list[i].first;
543 const auto *
fst = fst_list[i].second;
544 nonterminal_hash_[label] = fst_array_.size();
545 nonterminal_set_.insert(label);
549 FSTERROR() <<
"ReplaceFstImpl: Input symbols of FST " << i
550 <<
" do not match input symbols of base FST (0th FST)";
554 FSTERROR() <<
"ReplaceFstImpl: Output symbols of FST " << i
555 <<
" do not match output symbols of base FST (0th FST)";
560 const auto nonterminal = nonterminal_hash_[opts.
root];
561 if ((nonterminal == 0) && (fst_array_.size() > 1)) {
562 FSTERROR() <<
"ReplaceFstImpl: No FST corresponding to root label " 563 << opts.
root <<
" in the input tuple vector";
566 root_ = (nonterminal > 0) ? nonterminal : 1;
567 bool all_non_empty_and_sorted =
false;
569 return_label_type_, call_output_label_,
570 &all_non_empty_and_sorted));
572 always_cache_ = !all_non_empty_and_sorted;
573 VLOG(2) <<
"ReplaceFstImpl::ReplaceFstImpl: always_cache = " 574 << (always_cache_ ?
"true" :
"false");
579 call_label_type_(impl.call_label_type_),
580 return_label_type_(impl.return_label_type_),
581 call_output_label_(impl.call_output_label_),
582 return_label_(impl.return_label_),
583 always_cache_(impl.always_cache_),
584 state_table_(new StateTable(*(impl.state_table_))),
585 nonterminal_set_(impl.nonterminal_set_),
586 nonterminal_hash_(impl.nonterminal_hash_),
592 fst_array_.reserve(impl.fst_array_.size());
593 fst_array_.emplace_back(
nullptr);
594 for (
Label i = 1; i < impl.fst_array_.size(); ++i) {
595 fst_array_.emplace_back(impl.fst_array_[i]->Copy(
true));
610 if (fst_array_.size() == 1) {
614 const auto fst_start = fst_array_[root_]->Start();
618 state_table_->FindState(
StateTuple(prefix, root_, fst_start));
623 return CacheImpl::Start();
629 const auto &tuple = state_table_->Tuple(s);
630 auto weight = Weight::Zero();
631 if (tuple.prefix_id == 0) {
633 weight = fst_array_[tuple.fst_id]->Final(
fst_state);
635 if (always_cache_ || HasArcs(s)) SetFinal(s, weight);
642 }
else if (always_cache_) {
646 const auto tuple = state_table_->Tuple(s);
648 auto num_arcs = fst_array_[tuple.fst_id]->NumArcs(tuple.fst_state);
649 if (ComputeFinalArc(tuple,
nullptr)) ++num_arcs;
656 if (label < *nonterminal_set_.begin() ||
657 label > *nonterminal_set_.rbegin()) {
660 return nonterminal_hash_.count(label);
680 const auto tuple = state_table_->Tuple(s);
686 num = fst_array_[tuple.fst_id]->NumInputEpsilons(tuple.fst_state);
691 for (; !aiter.
Done() && ((aiter.
Value().ilabel == 0) ||
692 IsNonTerminal(aiter.
Value().olabel));
698 ComputeFinalArc(tuple,
nullptr)) {
716 const auto tuple = state_table_->Tuple(s);
722 num = fst_array_[tuple.fst_id]->NumOutputEpsilons(tuple.fst_state);
727 for (; !aiter.
Done() && ((aiter.
Value().olabel == 0) ||
728 IsNonTerminal(aiter.
Value().olabel));
734 ComputeFinalArc(tuple,
nullptr)) {
746 for (
Label i = 1; i < fst_array_.size(); ++i) {
747 if (fst_array_[i]->Properties(kError,
false)) {
748 SetProperties(kError, kError);
758 if (!HasArcs(s))
Expand(s);
759 CacheImpl::InitArcIterator(s, data);
767 const auto tuple = state_table_->Tuple(s);
775 if (ComputeFinalArc(tuple, &arc)) PushArc(s, std::move(arc));
777 for (; !aiter.
Done(); aiter.
Next()) {
778 if (ComputeArc(tuple, aiter.
Value(), &arc)) PushArc(s, std::move(arc));
792 if (ComputeFinalArc(tuple, &arc)) AddArc(s, arc);
794 for (; !aiter.
Done(); aiter.
Next()) {
795 if (ComputeArc(tuple, aiter.
Value(), &arc)) AddArc(s, arc);
810 arcp->ilabel = (
EpsilonOnInput(return_label_type_)) ? 0 : return_label_;
814 const auto &stack = state_table_->GetStackPrefix(tuple.
prefix_id);
816 const auto &top = stack.Top();
817 arcp->nextstate = state_table_->FindState(
840 if (arc.olabel == 0 || arc.olabel < *nonterminal_set_.begin() ||
841 arc.olabel > *nonterminal_set_.rbegin()) {
842 const auto nextstate =
844 ? state_table_->FindState(
847 *arcp = Arc(arc.ilabel, arc.olabel, arc.weight, nextstate);
850 const auto it = nonterminal_hash_.find(arc.olabel);
851 if (it != nonterminal_hash_.end()) {
852 const auto nonterminal = it->second;
853 const auto nt_prefix =
854 PushPrefix(state_table_->GetStackPrefix(tuple.
prefix_id),
855 tuple.
fst_id, arc.nextstate);
858 const auto nt_start = fst_array_[nonterminal]->Start();
862 nt_prefix, nonterminal, nt_start))
869 : ((call_output_label_ ==
kNoLabel) ? arc.olabel
870 : call_output_label_);
871 *arcp = Arc(ilabel, olabel, arc.weight, nt_nextstate);
876 const auto nextstate =
878 ? state_table_->FindState(
881 *arcp = Arc(arc.ilabel, arc.olabel, arc.weight, nextstate);
897 return fst_array_[
fst_id].get();
901 const auto it = nonterminal_hash_.find(nonterminal);
902 if (it == nonterminal_hash_.end()) {
903 FSTERROR() <<
"ReplaceFstImpl::GetFstId: Nonterminal not found: " 915 return state_table_->FindPrefixId(prefix);
921 return GetPrefixId(prefix);
926 prefix.
Push(fst_id, nextstate);
927 return GetPrefixId(prefix);
933 int64_t call_output_label_;
934 int64_t return_label_;
938 std::unique_ptr<StateTable> state_table_;
941 std::set<Label> nonterminal_set_;
943 std::vector<std::unique_ptr<const Fst<Arc>>> fst_array_;
982 template <
class A,
class T ,
985 :
public ImplToFst<internal::ReplaceFstImpl<A, T, CacheStore>> {
994 using State =
typename CacheStore::State;
1025 GetMutableImpl()->InitArcIterator(s, data);
1029 if ((GetImpl()->ArcIteratorFlags() &
kArcNoCache) &&
1035 VLOG(2) <<
"Not using replace matcher";
1043 return *GetImpl()->GetStateTable();
1047 return *GetImpl()->GetFst(GetImpl()->GetFstId(nonterminal));
1058 template <
class Arc,
class StateTable,
class CacheStore>
1064 fst, fst.GetMutableImpl()) {}
1086 template <
class Arc,
class StateTable,
class CacheStore>
1102 cache_data_.ref_count =
nullptr;
1103 local_data_.ref_count =
nullptr;
1105 if (!(fst_.GetImpl()->ArcIteratorFlags() &
kArcNoCache) &&
1106 !(fst_.GetImpl()->HasArcs(s_))) {
1107 fst_.GetMutableImpl()->Expand(s_);
1110 if (fst_.GetImpl()->HasArcs(s_)) {
1112 ->internal::template CacheBaseImpl<
1113 typename CacheStore::State,
1114 CacheStore>::InitArcIterator(s_, &cache_data_);
1115 num_arcs_ = cache_data_.narcs;
1116 arcs_ = cache_data_.arcs;
1119 tuple_ = fst_.GetImpl()->GetStateTable()->Tuple(s_);
1128 const auto *rfst = fst_.GetImpl()->GetFst(tuple_.fst_id);
1129 rfst->InitArcIterator(tuple_.fst_state, &local_data_);
1131 arcs_ = local_data_.arcs;
1134 bool has_final_arc = fst_.GetMutableImpl()->ComputeFinalArc(
1139 num_arcs_ = local_data_.narcs;
1140 if (has_final_arc) ++num_arcs_;
1144 offset_ = num_arcs_ - local_data_.narcs;
1153 if (cache_data_.ref_count) --(*cache_data_.ref_count);
1154 if (local_data_.ref_count) --(*local_data_.ref_count);
1163 fst_.InitArcIterator(s_, &cache_data_);
1164 arcs_ = cache_data_.arcs;
1172 arcs_ = local_data_.arcs;
1175 if (!fst_.GetMutableImpl()->EpsilonOnCallInput()) {
1180 offset_ = num_arcs_ - local_data_.narcs;
1186 bool Done()
const {
return pos_ >= num_arcs_; }
1194 FSTERROR() <<
"ReplaceFst: Inconsistent arc iterator flags";
1198 if (pos_ - offset_ >= 0) {
1199 const auto &arc = arcs_[pos_ - offset_];
1206 fst_.GetMutableImpl()->ComputeArc(tuple_, arc, &arc_,
1207 flags_ & kArcValueFlags);
1215 fst_.GetMutableImpl()->ComputeFinalArc(tuple_, &final_arc_,
1216 flags_ & kArcValueFlags);
1229 void Seek(
size_t pos) { pos_ = pos; }
1231 uint8_t
Flags()
const {
return flags_; }
1237 flags_ |= (flags & fst_.GetImpl()->ArcIteratorFlags());
1242 if (!fst_.GetImpl()->HasArcs(s_)) data_flags_ = 0;
1246 if ((flags & kArcNoCache) && (!data_flags_)) Init();
1255 mutable ssize_t offset_;
1263 mutable const Arc *arcs_;
1264 mutable uint8_t data_flags_;
1265 mutable Arc final_arc_;
1266 mutable uint8_t final_flags_;
1272 template <
class Arc,
class StateTable,
class CacheStore>
1287 : owned_fst_(fst.Copy()),
1289 impl_(fst_.GetMutableImpl()),
1291 match_type_(match_type),
1292 current_loop_(false),
1296 std::swap(loop_.ilabel, loop_.olabel);
1305 impl_(fst_.GetMutableImpl()),
1307 match_type_(match_type),
1308 current_loop_(false),
1312 std::swap(loop_.ilabel, loop_.olabel);
1319 : owned_fst_(matcher.fst_.Copy(safe)),
1321 impl_(fst_.GetMutableImpl()),
1323 match_type_(matcher.match_type_),
1324 current_loop_(false),
1328 std::swap(loop_.ilabel, loop_.olabel);
1338 const auto &fst_array = impl_->fst_array_;
1339 matcher_.resize(fst_array.size());
1340 for (
Label i = 0; i < fst_array.size(); ++i) {
1342 matcher_[i] = std::make_unique<LocalMatcher>(
1344 auto it = impl_->nonterminal_set_.begin();
1345 for (; it != impl_->nonterminal_set_.end(); ++it) {
1346 matcher_[i]->AddMultiEpsLabel(*it);
1357 if (match_type_ ==
MATCH_NONE)
return match_type_;
1358 const auto true_prop =
1360 const auto false_prop =
1362 const auto props = fst_.Properties(true_prop | false_prop, test);
1363 if (props & true_prop) {
1365 }
else if (props & false_prop) {
1374 uint64_t
Properties(uint64_t props)
const override {
return props; }
1378 if (s_ == s)
return;
1380 tuple_ = impl_->GetStateTable()->Tuple(s_);
1386 current_matcher_ = matcher_[tuple_.fst_id].get();
1387 current_matcher_->SetState(tuple_.fst_state);
1388 loop_.nextstate = s_;
1402 if (label_ == 0 || label_ ==
kNoLabel) {
1405 current_loop_ =
true;
1409 final_arc_ = impl_->ComputeFinalArc(tuple_,
nullptr);
1410 found = current_matcher_->Find(
kNoLabel) || final_arc_ || found;
1413 found = current_matcher_->Find(label_);
1419 return !current_loop_ && !final_arc_ && current_matcher_->Done();
1423 if (current_loop_)
return loop_;
1425 impl_->ComputeFinalArc(tuple_, &arc_);
1428 const auto &component_arc = current_matcher_->Value();
1429 impl_->ComputeArc(tuple_, component_arc, &arc_);
1434 if (current_loop_) {
1435 current_loop_ =
false;
1442 current_matcher_->Next();
1448 std::unique_ptr<const ReplaceFst<Arc, StateTable, CacheStore>> owned_fst_;
1452 std::vector<std::unique_ptr<LocalMatcher>> matcher_;
1457 mutable bool current_loop_;
1458 mutable bool final_arc_;
1466 template <
class Arc,
class StateTable,
class CacheStore>
1470 std::make_unique<StateIterator<ReplaceFst<Arc, StateTable, CacheStore>>>(
1489 template <
class Arc>
1499 template <
class Arc>
1507 template <
class Arc>
1511 bool epsilon_on_replace) {
1515 template <
class Arc>
1524 #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
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