All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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

typedef Arc::Label Label

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

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

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

typedef Arc::StateId StateId

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

typedef Arc::Weight Weight

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

Constructor & Destructor Documentation

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

Arc::Weight Final ( StateId  s)
virtual

Implements DeterministicOnDemandFst< Arc >.

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

References KALDI_ASSERT, 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_
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 KALDI_ASSERT, and fst::Times().

161  {
162  typedef typename MapType::iterator IterType;
163  KALDI_ASSERT(ilabel != 0);
164  KALDI_ASSERT(s < static_cast<StateId>(state_vec_.size()));
165  const std::pair<StateId, StateId> pr (state_vec_[s]);
166 
167  Arc arc1;
168  if (!fst1_->GetArc(pr.first, ilabel, &arc1)) return false;
169  if (arc1.olabel == 0) { // There is no output label on the
170  // arc, so only the first state changes.
171  std::pair<const std::pair<StateId, StateId>, StateId> new_value(
172  std::pair<StateId, StateId>(arc1.nextstate, pr.second),
173  next_state_);
174 
175  std::pair<IterType, bool> result = state_map_.insert(new_value);
176  oarc->ilabel = ilabel;
177  oarc->olabel = 0;
178  oarc->nextstate = result.first->second;
179  oarc->weight = arc1.weight;
180  if (result.second == true) { // was inserted
181  next_state_++;
182  const std::pair<StateId, StateId> &new_pair (new_value.first);
183  state_vec_.push_back(new_pair);
184  }
185  return true;
186  }
187  // There is an output label, so we need to traverse an arc on the
188  // second fst also.
189  Arc arc2;
190  if (!fst2_->GetArc(pr.second, arc1.olabel, &arc2)) return false;
191  std::pair<const std::pair<StateId, StateId>, StateId> new_value(
192  std::pair<StateId, StateId>(arc1.nextstate, arc2.nextstate),
193  next_state_);
194  std::pair<IterType, bool> result =
195  state_map_.insert(new_value);
196  oarc->ilabel = ilabel;
197  oarc->olabel = arc2.olabel;
198  oarc->nextstate = result.first->second;
199  oarc->weight = Times(arc1.weight, arc2.weight);
200  if (result.second == true) { // was inserted
201  next_state_++;
202  const std::pair<StateId, StateId> &new_pair (new_value.first);
203  state_vec_.push_back(new_pair);
204  }
205  return true;
206 }
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_
virtual StateId Start ( )
inlinevirtual

Member Data Documentation

StateId next_state_
private
std::vector<std::pair<StateId, StateId> > state_vec_
private

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