All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TrivialFactorWeightFstImpl< A, F > Class Template Reference

#include <trivial-factor-weight.h>

Inheritance diagram for TrivialFactorWeightFstImpl< A, F >:
Collaboration diagram for TrivialFactorWeightFstImpl< A, F >:

Classes

struct  Element
class  ElementEqual
class  ElementKey

Public Types

typedef A Arc
typedef A::Label Label
typedef A::Weight Weight
typedef A::StateId StateId
typedef F FactorIterator

Public Member Functions

 TrivialFactorWeightFstImpl (const Fst< A > &fst, const TrivialFactorWeightOptions< A > &opts)
 TrivialFactorWeightFstImpl (const TrivialFactorWeightFstImpl< A, F > &impl)
 ~TrivialFactorWeightFstImpl ()
StateId Start ()
Weight Final (StateId s)
size_t NumArcs (StateId s)
size_t NumInputEpsilons (StateId s)
size_t NumOutputEpsilons (StateId s)
void InitArcIterator (StateId s, ArcIteratorData< A > *data)
StateId FindState (const Element &e)
void Expand (StateId s)

Private Types

typedef unordered_map< Element,
StateId, ElementKey,
ElementEqual
ElementMap

Private Member Functions

void operator= (const TrivialFactorWeightFstImpl< A, F > &)

Private Attributes

const Fst< A > * fst_
float delta_
uint32 mode_
Label extra_ilabel_
Label extra_olabel_
vector< Elementelements_
ElementMap element_map_

Detailed Description

template<class A, class F>
class fst::TrivialFactorWeightFstImpl< A, F >

Definition at line 100 of file trivial-factor-weight.h.

Member Typedef Documentation

typedef A Arc

Definition at line 114 of file trivial-factor-weight.h.

typedef unordered_map<Element, StateId, ElementKey, ElementEqual> ElementMap
private

Definition at line 308 of file trivial-factor-weight.h.

typedef F FactorIterator

Definition at line 118 of file trivial-factor-weight.h.

typedef A::Label Label

Definition at line 115 of file trivial-factor-weight.h.

typedef A::StateId StateId

Definition at line 117 of file trivial-factor-weight.h.

typedef A::Weight Weight

Definition at line 116 of file trivial-factor-weight.h.

Constructor & Destructor Documentation

TrivialFactorWeightFstImpl ( const Fst< A > &  fst,
const TrivialFactorWeightOptions< A > &  opts 
)
inline

Definition at line 134 of file trivial-factor-weight.h.

: CacheImpl<A>(opts),
fst_(fst.Copy()),
delta_(opts.delta),
extra_ilabel_(opts.extra_ilabel),
extra_olabel_(opts.extra_olabel) {
SetType("factor-weight");
uint64 props = fst.Properties(kFstProperties, false);
SetProperties(FactorWeightProperties(props), kCopyProperties);
SetInputSymbols(fst.InputSymbols());
SetOutputSymbols(fst.OutputSymbols());
}
TrivialFactorWeightFstImpl ( const TrivialFactorWeightFstImpl< A, F > &  impl)
inline

Definition at line 148 of file trivial-factor-weight.h.

: CacheImpl<A>(impl),
fst_(impl.fst_->Copy(true)),
delta_(impl.delta_),
extra_ilabel_(impl.extra_ilabel_),
extra_olabel_(impl.extra_olabel_) {
SetType("factor-weight");
SetProperties(impl.Properties(), kCopyProperties);
SetInputSymbols(impl.InputSymbols());
SetOutputSymbols(impl.OutputSymbols());
}

Definition at line 160 of file trivial-factor-weight.h.

References TrivialFactorWeightFstImpl< A, F >::fst_.

{
delete fst_;
}

Member Function Documentation

void Expand ( StateId  s)
inline

Definition at line 244 of file trivial-factor-weight.h.

References TrivialFactorWeightFstImpl< A, F >::delta_, TrivialFactorWeightFstImpl< A, F >::elements_, TrivialFactorWeightFstImpl< A, F >::extra_ilabel_, TrivialFactorWeightFstImpl< A, F >::extra_olabel_, TrivialFactorWeightFstImpl< A, F >::FindState(), and TrivialFactorWeightFstImpl< A, F >::fst_.

Referenced by TrivialFactorWeightFstImpl< A, F >::InitArcIterator(), TrivialFactorWeightFstImpl< A, F >::NumArcs(), TrivialFactorWeightFstImpl< A, F >::NumInputEpsilons(), and TrivialFactorWeightFstImpl< A, F >::NumOutputEpsilons().

{
CHECK(static_cast<size_t>(s) < elements_.size());
Element e = elements_[s];
if (e.weight != Weight::One()) {
FactorIterator fit(e.weight);
if (fit.Done()) { // Cannot be factored-> create a link to dest state directly
if (e.state != kNoStateId) {
StateId dest = FindState(Element(e.state, Weight::One()));
PushArc(s, Arc(extra_ilabel_, extra_olabel_, e.weight, dest));
} // else we're done. This is a final state.
} else { // Can be factored.
const pair<Weight, Weight> &p = fit.Value();
StateId dest = FindState(Element(e.state, p.second.Quantize(delta_)));
PushArc(s, Arc(extra_ilabel_, extra_olabel_, p.first, dest));
}
} else { // Unit weight. This corresponds to a "real" state.
CHECK(e.state != kNoStateId);
for (ArcIterator< Fst<A> > ait(*fst_, e.state);
!ait.Done();
ait.Next()) {
const A &arc = ait.Value();
FactorIterator fit(arc.weight);
if (fit.Done()) { // cannot be factored->just link directly to dest.
StateId dest = FindState(Element(arc.nextstate, Weight::One()));
PushArc(s, Arc(arc.ilabel, arc.olabel, arc.weight, dest));
} else {
const pair<Weight, Weight> &p = fit.Value();
StateId dest = FindState(Element(arc.nextstate, p.second.Quantize(delta_)));
PushArc(s, Arc(arc.ilabel, arc.olabel, p.first, dest));
}
}
// See if we have to add arcs for final-states [only if final-weight is factorable].
Weight final_w = fst_->Final(e.state);
if (final_w != Weight::Zero()) {
FactorIterator fit(final_w);
if (!fit.Done()) {
const pair<Weight, Weight> &p = fit.Value();
StateId dest = FindState(Element(kNoStateId, p.second.Quantize(delta_)));
PushArc(s, Arc(extra_ilabel_, extra_olabel_, p.first, dest));
}
}
}
this->SetArcs(s);
}
Weight Final ( StateId  s)
inline

Definition at line 175 of file trivial-factor-weight.h.

References TrivialFactorWeightFstImpl< A, F >::elements_, TrivialFactorWeightFstImpl< A, F >::fst_, TrivialFactorWeightFstImpl< A, F >::Element::state, and TrivialFactorWeightFstImpl< A, F >::Element::weight.

{
if (!HasFinal(s)) {
const Element &e = elements_[s];
Weight w;
if (e.state == kNoStateId) { // extra state inserted to represent final weights.
FactorIterator fit(e.weight);
if (fit.Done()) { // cannot be factored.
w = e.weight; // so it's final
} else {
w = Weight::Zero(); // need another transition.
}
} else {
if (e.weight != Weight::One()) { // Not a real state.
w = Weight::Zero();
} else { // corresponds to a "real" state.
w = fst_->Final(e.state);
if (!fit.Done()) // we would have intermediate states representing this final state.
w = Weight::Zero();
}
}
this->SetFinal(s, w);
return w;
} else {
}
}
StateId FindState ( const Element e)
inline

Definition at line 230 of file trivial-factor-weight.h.

References TrivialFactorWeightFstImpl< A, F >::element_map_, and TrivialFactorWeightFstImpl< A, F >::elements_.

Referenced by TrivialFactorWeightFstImpl< A, F >::Expand(), and TrivialFactorWeightFstImpl< A, F >::Start().

{
typename ElementMap::iterator eit = element_map_.find(e);
if (eit != element_map_.end()) {
return (*eit).second;
} else {
StateId s = elements_.size();
elements_.push_back(e);
element_map_.insert(pair<const Element, StateId>(e, s));
return s;
}
}
void InitArcIterator ( StateId  s,
ArcIteratorData< A > *  data 
)
inline
size_t NumArcs ( StateId  s)
inline

Definition at line 203 of file trivial-factor-weight.h.

References TrivialFactorWeightFstImpl< A, F >::Expand().

{
if (!HasArcs(s))
Expand(s);
}
size_t NumInputEpsilons ( StateId  s)
inline

Definition at line 209 of file trivial-factor-weight.h.

References TrivialFactorWeightFstImpl< A, F >::Expand().

{
if (!HasArcs(s))
Expand(s);
}
size_t NumOutputEpsilons ( StateId  s)
inline

Definition at line 215 of file trivial-factor-weight.h.

References TrivialFactorWeightFstImpl< A, F >::Expand().

{
if (!HasArcs(s))
Expand(s);
}
void operator= ( const TrivialFactorWeightFstImpl< A, F > &  )
private
StateId Start ( )
inline

Definition at line 164 of file trivial-factor-weight.h.

References TrivialFactorWeightFstImpl< A, F >::FindState(), and TrivialFactorWeightFstImpl< A, F >::fst_.

{
if (!HasStart()) {
StateId s = fst_->Start();
if (s == kNoStateId)
return kNoStateId;
StateId start = this->FindState(Element(fst_->Start(), Weight::One()));
this->SetStart(start);
}
}

Member Data Documentation

float delta_
private

Definition at line 311 of file trivial-factor-weight.h.

Referenced by TrivialFactorWeightFstImpl< A, F >::Expand().

ElementMap element_map_
private
Label extra_ilabel_
private

Definition at line 313 of file trivial-factor-weight.h.

Referenced by TrivialFactorWeightFstImpl< A, F >::Expand().

Label extra_olabel_
private

Definition at line 314 of file trivial-factor-weight.h.

Referenced by TrivialFactorWeightFstImpl< A, F >::Expand().

uint32 mode_
private

Definition at line 312 of file trivial-factor-weight.h.


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