ComposeDeterministicOnDemandFst< Arc > Class Template Reference

#include <deterministic-fst.h>

Inheritance diagram for ComposeDeterministicOnDemandFst< Arc >:
Collaboration diagram for ComposeDeterministicOnDemandFst< Arc >:

Public Types

typedef Arc::StateId StateId
 
typedef Arc::Weight Weight
 
typedef Arc::Label Label
 
- Public Types inherited from DeterministicOnDemandFst< Arc >
typedef Arc::StateId StateId
 
typedef Arc::Weight Weight
 
typedef Arc::Label Label
 

Public Member Functions

 ComposeDeterministicOnDemandFst (DeterministicOnDemandFst< Arc > *fst1, DeterministicOnDemandFst< Arc > *fst2)
 Note: constructor does not "take ownership" of the input fst's. More...
 
virtual StateId Start ()
 
virtual Weight Final (StateId s)
 
virtual bool GetArc (StateId s, Label ilabel, Arc *oarc)
 Note: ilabel must not be epsilon. More...
 
- Public Member Functions inherited from DeterministicOnDemandFst< Arc >
virtual ~DeterministicOnDemandFst ()
 

Private Types

typedef unordered_map< std::pair< StateId, StateId >, StateId, kaldi::PairHasher< StateId > > MapType
 

Private Attributes

DeterministicOnDemandFst< Arc > * fst1_
 
DeterministicOnDemandFst< Arc > * fst2_
 
MapType state_map_
 
std::vector< std::pair< StateId, StateId > > state_vec_
 
StateId next_state_
 
StateId start_state_
 

Detailed Description

template<class Arc>
class fst::ComposeDeterministicOnDemandFst< Arc >

Definition at line 199 of file deterministic-fst.h.

Member Typedef Documentation

◆ Label

typedef Arc::Label Label

Definition at line 203 of file deterministic-fst.h.

◆ MapType

typedef unordered_map<std::pair<StateId, StateId>, StateId, kaldi::PairHasher<StateId> > MapType
private

Definition at line 221 of file deterministic-fst.h.

◆ StateId

typedef Arc::StateId StateId

Definition at line 201 of file deterministic-fst.h.

◆ Weight

typedef Arc::Weight Weight

Definition at line 202 of file deterministic-fst.h.

Constructor & Destructor Documentation

◆ ComposeDeterministicOnDemandFst()

Note: constructor does not "take ownership" of the input fst's.

The input fst's should be treated as const, in that their contents do not change, but they are not const as the DeterministicOnDemandFst's data-access functions are not const, for reasons relating to caching.

Definition at line 136 of file deterministic-fst-inl.h.

References ComposeDeterministicOnDemandFst< Arc >::fst1_, ComposeDeterministicOnDemandFst< Arc >::fst2_, KALDI_ASSERT, ComposeDeterministicOnDemandFst< Arc >::next_state_, ComposeDeterministicOnDemandFst< Arc >::start_state_, ComposeDeterministicOnDemandFst< Arc >::state_map_, and ComposeDeterministicOnDemandFst< Arc >::state_vec_.

138  : fst1_(fst1), fst2_(fst2) {
139  KALDI_ASSERT(fst1 != NULL && fst2 != NULL);
140  if (fst1_->Start() == -1 || fst2_->Start() == -1) {
141  start_state_ = -1;
142  next_state_ = 0; // actually we don't care about this value.
143  } else {
144  start_state_ = 0;
145  std::pair<StateId,StateId> start_pair(fst1_->Start(), fst2_->Start());
146  state_map_[start_pair] = start_state_;
147  state_vec_.push_back(start_pair);
148  next_state_ = 1;
149  }
150 }
DeterministicOnDemandFst< Arc > * fst1_
DeterministicOnDemandFst< Arc > * fst2_
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
std::vector< std::pair< StateId, StateId > > state_vec_

Member Function Documentation

◆ Final()

Arc::Weight Final ( StateId  s)
virtual

Implements DeterministicOnDemandFst< Arc >.

Definition at line 153 of file deterministic-fst-inl.h.

References ComposeDeterministicOnDemandFst< Arc >::fst1_, ComposeDeterministicOnDemandFst< Arc >::fst2_, KALDI_ASSERT, ComposeDeterministicOnDemandFst< Arc >::state_vec_, and fst::Times().

153  {
154  KALDI_ASSERT(s < static_cast<StateId>(state_vec_.size()));
155  const std::pair<StateId, StateId> &pr (state_vec_[s]);
156  return Times(fst1_->Final(pr.first), fst2_->Final(pr.second));
157 }
DeterministicOnDemandFst< Arc > * fst1_
LatticeWeightTpl< FloatType > Times(const LatticeWeightTpl< FloatType > &w1, const LatticeWeightTpl< FloatType > &w2)
DeterministicOnDemandFst< Arc > * fst2_
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
std::vector< std::pair< StateId, StateId > > state_vec_

◆ GetArc()

bool GetArc ( StateId  s,
Label  ilabel,
Arc *  oarc 
)
virtual

Note: ilabel must not be epsilon.

Implements DeterministicOnDemandFst< Arc >.

Definition at line 160 of file deterministic-fst-inl.h.

References ComposeDeterministicOnDemandFst< Arc >::fst1_, ComposeDeterministicOnDemandFst< Arc >::fst2_, KALDI_ASSERT, ComposeDeterministicOnDemandFst< Arc >::next_state_, ComposeDeterministicOnDemandFst< Arc >::state_map_, ComposeDeterministicOnDemandFst< Arc >::state_vec_, and fst::Times().

161  {
162  typedef typename MapType::iterator IterType;
163  KALDI_ASSERT(ilabel != 0 &&
164  "This program expects epsilon-free compact lattices as input");
165  KALDI_ASSERT(s < static_cast<StateId>(state_vec_.size()));
166  const std::pair<StateId, StateId> pr (state_vec_[s]);
167 
168  Arc arc1;
169  if (!fst1_->GetArc(pr.first, ilabel, &arc1)) return false;
170  if (arc1.olabel == 0) { // There is no output label on the
171  // arc, so only the first state changes.
172  std::pair<const std::pair<StateId, StateId>, StateId> new_value(
173  std::pair<StateId, StateId>(arc1.nextstate, pr.second),
174  next_state_);
175 
176  std::pair<IterType, bool> result = state_map_.insert(new_value);
177  oarc->ilabel = ilabel;
178  oarc->olabel = 0;
179  oarc->nextstate = result.first->second;
180  oarc->weight = arc1.weight;
181  if (result.second == true) { // was inserted
182  next_state_++;
183  const std::pair<StateId, StateId> &new_pair (new_value.first);
184  state_vec_.push_back(new_pair);
185  }
186  return true;
187  }
188  // There is an output label, so we need to traverse an arc on the
189  // second fst also.
190  Arc arc2;
191  if (!fst2_->GetArc(pr.second, arc1.olabel, &arc2)) return false;
192  std::pair<const std::pair<StateId, StateId>, StateId> new_value(
193  std::pair<StateId, StateId>(arc1.nextstate, arc2.nextstate),
194  next_state_);
195  std::pair<IterType, bool> result =
196  state_map_.insert(new_value);
197  oarc->ilabel = ilabel;
198  oarc->olabel = arc2.olabel;
199  oarc->nextstate = result.first->second;
200  oarc->weight = Times(arc1.weight, arc2.weight);
201  if (result.second == true) { // was inserted
202  next_state_++;
203  const std::pair<StateId, StateId> &new_pair (new_value.first);
204  state_vec_.push_back(new_pair);
205  }
206  return true;
207 }
DeterministicOnDemandFst< Arc > * fst1_
LatticeWeightTpl< FloatType > Times(const LatticeWeightTpl< FloatType > &w1, const LatticeWeightTpl< FloatType > &w2)
DeterministicOnDemandFst< Arc > * fst2_
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
std::vector< std::pair< StateId, StateId > > state_vec_

◆ Start()

Member Data Documentation

◆ fst1_

◆ fst2_

◆ next_state_

◆ start_state_

StateId start_state_
private

◆ state_map_

◆ state_vec_


The documentation for this class was generated from the following files: