All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
CompactLatticeWeightTpl< WeightType, IntType > Class Template Reference

#include <lattice-weight.h>

Collaboration diagram for CompactLatticeWeightTpl< WeightType, IntType >:

Public Types

typedef WeightType W
 
typedef
CompactLatticeWeightTpl
< WeightType, IntType > 
ReverseWeight
 

Public Member Functions

 CompactLatticeWeightTpl ()
 
 CompactLatticeWeightTpl (const WeightType &w, const vector< IntType > &s)
 
CompactLatticeWeightTploperator= (const CompactLatticeWeightTpl< WeightType, IntType > &w)
 
const WWeight () const
 
const vector< IntType > & String () const
 
void SetWeight (const W &w)
 
void SetString (const vector< IntType > &s)
 
CompactLatticeWeightTpl
< WeightType, IntType > 
Reverse () const
 
bool Member () const
 
CompactLatticeWeightTpl Quantize (float delta=kDelta) const
 
istream & Read (istream &strm)
 
ostream & Write (ostream &strm) const
 
size_t Hash () const
 

Static Public Member Functions

static const
CompactLatticeWeightTpl
< WeightType, IntType > 
Zero ()
 
static const
CompactLatticeWeightTpl
< WeightType, IntType > 
One ()
 
static string GetIntSizeString ()
 
static const string & Type ()
 
static const
CompactLatticeWeightTpl
< WeightType, IntType > 
NoWeight ()
 
static uint64 Properties ()
 

Private Attributes

W weight_
 
vector< IntType > string_
 

Detailed Description

template<class WeightType, class IntType>
class fst::CompactLatticeWeightTpl< WeightType, IntType >

Definition at line 393 of file lattice-weight.h.

Member Typedef Documentation

typedef CompactLatticeWeightTpl<WeightType, IntType> ReverseWeight

Definition at line 397 of file lattice-weight.h.

typedef WeightType W

Definition at line 395 of file lattice-weight.h.

Constructor & Destructor Documentation

Definition at line 406 of file lattice-weight.h.

Referenced by CompactLatticeWeightTpl< WeightType, IntType >::Quantize().

406 { }
CompactLatticeWeightTpl ( const WeightType &  w,
const vector< IntType > &  s 
)
inline

Definition at line 408 of file lattice-weight.h.

408  :
409  weight_(w), string_(s) { }

Member Function Documentation

static string GetIntSizeString ( )
inlinestatic

Definition at line 435 of file lattice-weight.h.

Referenced by CompactLatticeWeightTpl< WeightType, IntType >::Type().

435  {
436  char buf[2];
437  buf[0] = '0' + sizeof(IntType);
438  buf[1] = '\0';
439  return buf;
440  }
size_t Hash ( ) const
inline

Definition at line 511 of file lattice-weight.h.

References rnnlm::i, CompactLatticeWeightTpl< WeightType, IntType >::string_, and CompactLatticeWeightTpl< WeightType, IntType >::weight_.

511  {
512  size_t ans = weight_.Hash();
513  // any weird numbers here are largish primes
514  size_t sz = string_.size(), mult = 6967;
515  for(size_t i = 0; i < sz; i++) {
516  ans += string_[i] * mult;
517  mult *= 7499;
518  }
519  return ans;
520  }
bool Member ( ) const
inline

Definition at line 461 of file lattice-weight.h.

References CompactLatticeWeightTpl< WeightType, IntType >::string_, and CompactLatticeWeightTpl< WeightType, IntType >::weight_.

Referenced by fst::CompactLatticeWeightTest().

461  {
462  // a semiring has only one zero, this is the important property
463  // we're trying to maintain here. So force string_ to be empty if
464  // w_ == zero.
465  if (!weight_.Member()) return false;
466  if (weight_ == WeightType::Zero())
467  return string_.empty();
468  else
469  return true;
470  }
static const CompactLatticeWeightTpl<WeightType, IntType> NoWeight ( )
inlinestatic

Definition at line 447 of file lattice-weight.h.

447  {
448  return CompactLatticeWeightTpl<WeightType, IntType>(
449  WeightType::NoWeight(), std::vector<IntType>());
450  }
static const CompactLatticeWeightTpl<WeightType, IntType> One ( )
inlinestatic
CompactLatticeWeightTpl& operator= ( const CompactLatticeWeightTpl< WeightType, IntType > &  w)
inline

Definition at line 411 of file lattice-weight.h.

References CompactLatticeWeightTpl< WeightType, IntType >::string_, and CompactLatticeWeightTpl< WeightType, IntType >::weight_.

411  {
412  weight_ = w.weight_;
413  string_ = w.string_;
414  return *this;
415  }
static uint64 Properties ( )
inlinestatic

Definition at line 476 of file lattice-weight.h.

476  {
477  return kLeftSemiring | kRightSemiring | kPath | kIdempotent;
478  }
istream& Read ( istream &  strm)
inline

Definition at line 482 of file lattice-weight.h.

References rnnlm::i, KALDI_WARN, CompactLatticeWeightTpl< WeightType, IntType >::string_, and CompactLatticeWeightTpl< WeightType, IntType >::weight_.

Referenced by fst::CompactLatticeWeightTest().

482  {
483  weight_.Read(strm);
484  if (strm.fail()){ return strm; }
485  int32 sz;
486  ReadType(strm, &sz);
487  if (strm.fail()){ return strm; }
488  if (sz < 0) {
489  KALDI_WARN << "Negative string size! Read failure";
490  strm.clear(std::ios::badbit);
491  return strm;
492  }
493  string_.resize(sz);
494  for(int32 i = 0; i < sz; i++) {
495  ReadType(strm, &(string_[i]));
496  }
497  return strm;
498  }
#define KALDI_WARN
Definition: kaldi-error.h:130
CompactLatticeWeightTpl<WeightType, IntType> Reverse ( ) const
inline

Definition at line 453 of file lattice-weight.h.

References rnnlm::i, CompactLatticeWeightTpl< WeightType, IntType >::string_, and CompactLatticeWeightTpl< WeightType, IntType >::weight_.

453  {
454  size_t s = string_.size();
455  vector<IntType> v(s);
456  for(size_t i = 0; i < s; i++)
457  v[i] = string_[s-i-1];
458  return CompactLatticeWeightTpl<WeightType, IntType>(weight_, v);
459  }
void SetString ( const vector< IntType > &  s)
inline

Definition at line 423 of file lattice-weight.h.

References CompactLatticeWeightTpl< WeightType, IntType >::string_.

Referenced by fst::operator>>().

423 { string_ = s; }
static const string& Type ( )
inlinestatic

Definition at line 441 of file lattice-weight.h.

References CompactLatticeWeightTpl< WeightType, IntType >::GetIntSizeString().

441  {
442  static const string type = "compact" + WeightType::Type()
443  + GetIntSizeString();
444  return type;
445  }
static string GetIntSizeString()
ostream& Write ( ostream &  strm) const
inline

Definition at line 502 of file lattice-weight.h.

References rnnlm::i, CompactLatticeWeightTpl< WeightType, IntType >::string_, and CompactLatticeWeightTpl< WeightType, IntType >::weight_.

502  {
503  weight_.Write(strm);
504  if (strm.fail()){ return strm; }
505  int32 sz = static_cast<int32>(string_.size());
506  WriteType(strm, sz);
507  for(int32 i = 0; i < sz; i++)
508  WriteType(strm, string_[i]);
509  return strm;
510  }

Member Data Documentation


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