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 396 of file lattice-weight.h.

Member Typedef Documentation

typedef CompactLatticeWeightTpl<WeightType, IntType> ReverseWeight

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

typedef WeightType W

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

Constructor & Destructor Documentation

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

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

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

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

411  :
412  weight_(w), string_(s) { }

Member Function Documentation

static string GetIntSizeString ( )
inlinestatic

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

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

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

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

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

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

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

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

Referenced by fst::CompactLatticeWeightTest().

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

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

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

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

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

414  {
415  weight_ = w.weight_;
416  string_ = w.string_;
417  return *this;
418  }
static uint64 Properties ( )
inlinestatic

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

479  {
480  return kLeftSemiring | kRightSemiring | kPath | kIdempotent;
481  }
istream& Read ( istream &  strm)
inline

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

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

Referenced by fst::CompactLatticeWeightTest().

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

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

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

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

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

References CompactLatticeWeightTpl< WeightType, IntType >::string_.

Referenced by fst::operator>>().

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

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

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

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

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

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

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

Member Data Documentation


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