FST  openfst-1.7.2
OpenFst Library
encode.h
Go to the documentation of this file.
1 // See www.openfst.org for extensive documentation on this weighted
2 // finite-state transducer library.
3 //
4 // Class to encode and decode an FST.
5 
6 #ifndef FST_ENCODE_H_
7 #define FST_ENCODE_H_
8 
9 #include <iostream>
10 #include <memory>
11 #include <string>
12 #include <unordered_map>
13 #include <utility>
14 #include <vector>
15 
16 #include <fst/log.h>
17 #include <fstream>
18 
19 #include <fst/arc-map.h>
20 #include <fst/rmfinalepsilon.h>
21 
22 
23 namespace fst {
24 
25 enum EncodeType { ENCODE = 1, DECODE = 2 };
26 
27 static constexpr uint32 kEncodeLabels = 0x0001;
28 static constexpr uint32 kEncodeWeights = 0x0002;
29 static constexpr uint32 kEncodeFlags = 0x0003;
30 
31 namespace internal {
32 
33 static constexpr uint32 kEncodeHasISymbols = 0x0004;
34 static constexpr uint32 kEncodeHasOSymbols = 0x0008;
35 
36 // Identifies stream data as an encode table (and its endianity)
37 static const int32 kEncodeMagicNumber = 2129983209;
38 
39 // The following class encapsulates implementation details for the encoding and
40 // decoding of label/weight tuples used for encoding and decoding of FSTs. The
41 // EncodeTable is bidirectional. I.e, it stores both the Tuple of encode labels
42 // and weights to a unique label, and the reverse.
43 template <class Arc>
44 class EncodeTable {
45  public:
46  using Label = typename Arc::Label;
47  using Weight = typename Arc::Weight;
48 
49  // Encoded data consists of arc input/output labels and arc weight.
50  struct Tuple {
51  Tuple() {}
52 
53  Tuple(Label ilabel_, Label olabel_, Weight weight_)
54  : ilabel(ilabel_), olabel(olabel_), weight(std::move(weight_)) {}
55 
56  Tuple(const Tuple &tuple)
57  : ilabel(tuple.ilabel),
58  olabel(tuple.olabel),
59  weight(std::move(tuple.weight)) {}
60 
64  };
65 
66  // Comparison object for hashing EncodeTable Tuple(s).
67  class TupleEqual {
68  public:
69  bool operator()(const Tuple *x, const Tuple *y) const {
70  return (x->ilabel == y->ilabel && x->olabel == y->olabel &&
71  x->weight == y->weight);
72  }
73  };
74 
75  // Hash function for EncodeTabe Tuples. Based on the encode flags
76  // we either hash the labels, weights or combination of them.
77  class TupleKey {
78  public:
79  TupleKey() : encode_flags_(kEncodeLabels | kEncodeWeights) {}
80 
81  TupleKey(const TupleKey &key) : encode_flags_(key.encode_flags_) {}
82 
83  explicit TupleKey(uint32 encode_flags) : encode_flags_(encode_flags) {}
84 
85  size_t operator()(const Tuple *x) const {
86  size_t hash = x->ilabel;
87  static constexpr int lshift = 5;
88  static constexpr int rshift = CHAR_BIT * sizeof(size_t) - 5;
89  if (encode_flags_ & kEncodeLabels) {
90  hash = hash << lshift ^ hash >> rshift ^ x->olabel;
91  }
92  if (encode_flags_ & kEncodeWeights) {
93  hash = hash << lshift ^ hash >> rshift ^ x->weight.Hash();
94  }
95  return hash;
96  }
97 
98  private:
99  int32 encode_flags_;
100  };
101 
102  explicit EncodeTable(uint32 encode_flags)
103  : flags_(encode_flags), encode_hash_(1024, TupleKey(encode_flags)) {}
104 
105  using EncodeHash = std::unordered_map<const Tuple *, Label, TupleKey,
107 
108  // Given an arc, encodes either input/output labels or input/costs or both.
109  Label Encode(const Arc &arc) {
110  std::unique_ptr<Tuple> tuple(
111  new Tuple(arc.ilabel, flags_ & kEncodeLabels ? arc.olabel : 0,
112  flags_ & kEncodeWeights ? arc.weight : Weight::One()));
113  auto insert_result = encode_hash_.insert(
114  std::make_pair(tuple.get(), encode_tuples_.size() + 1));
115  if (insert_result.second) encode_tuples_.push_back(std::move(tuple));
116  return insert_result.first->second;
117  }
118 
119  // Given an arc, looks up its encoded label or returns kNoLabel if not found.
120  Label GetLabel(const Arc &arc) const {
121  const Tuple tuple(arc.ilabel, flags_ & kEncodeLabels ? arc.olabel : 0,
122  flags_ & kEncodeWeights ? arc.weight : Weight::One());
123  auto it = encode_hash_.find(&tuple);
124  return (it == encode_hash_.end()) ? kNoLabel : it->second;
125  }
126 
127  // Given an encoded arc label, decodes back to input/output labels and costs.
128  const Tuple *Decode(Label key) const {
129  if (key < 1 || key > encode_tuples_.size()) {
130  LOG(ERROR) << "EncodeTable::Decode: Unknown decode key: " << key;
131  return nullptr;
132  }
133  return encode_tuples_[key - 1].get();
134  }
135 
136  size_t Size() const { return encode_tuples_.size(); }
137 
138  bool Write(std::ostream &strm, const string &source) const;
139 
140  static EncodeTable<Arc> *Read(std::istream &strm, const string &source);
141 
142  uint32 Flags() const { return flags_ & kEncodeFlags; }
143 
144  const SymbolTable *InputSymbols() const { return isymbols_.get(); }
145 
146  const SymbolTable *OutputSymbols() const { return osymbols_.get(); }
147 
148  void SetInputSymbols(const SymbolTable *syms) {
149  if (syms) {
150  isymbols_.reset(syms->Copy());
151  flags_ |= kEncodeHasISymbols;
152  } else {
153  isymbols_.reset();
154  flags_ &= ~kEncodeHasISymbols;
155  }
156  }
157 
158  void SetOutputSymbols(const SymbolTable *syms) {
159  if (syms) {
160  osymbols_.reset(syms->Copy());
161  flags_ |= kEncodeHasOSymbols;
162  } else {
163  osymbols_.reset();
164  flags_ &= ~kEncodeHasOSymbols;
165  }
166  }
167 
168  private:
169  uint32 flags_;
170  std::vector<std::unique_ptr<Tuple>> encode_tuples_;
171  EncodeHash encode_hash_;
172  std::unique_ptr<SymbolTable> isymbols_; // Pre-encoded input symbol table.
173  std::unique_ptr<SymbolTable> osymbols_; // Pre-encoded output symbol table.
174 
175  EncodeTable(const EncodeTable &) = delete;
176  EncodeTable &operator=(const EncodeTable &) = delete;
177 };
178 
179 template <class Arc>
180 bool EncodeTable<Arc>::Write(std::ostream &strm,
181  const string &source) const {
182  WriteType(strm, kEncodeMagicNumber);
183  WriteType(strm, flags_);
184  const int64 size = encode_tuples_.size();
185  WriteType(strm, size);
186  for (const auto &tuple : encode_tuples_) {
187  WriteType(strm, tuple->ilabel);
188  WriteType(strm, tuple->olabel);
189  tuple->weight.Write(strm);
190  }
191  if (flags_ & kEncodeHasISymbols) isymbols_->Write(strm);
192  if (flags_ & kEncodeHasOSymbols) osymbols_->Write(strm);
193  strm.flush();
194  if (!strm) {
195  LOG(ERROR) << "EncodeTable::Write: Write failed: " << source;
196  return false;
197  }
198  return true;
199 }
200 
201 template <class Arc>
203  const string &source) {
204  int32 magic_number = 0;
205  ReadType(strm, &magic_number);
206  if (magic_number != kEncodeMagicNumber) {
207  LOG(ERROR) << "EncodeTable::Read: Bad encode table header: " << source;
208  return nullptr;
209  }
210  uint32 flags;
211  ReadType(strm, &flags);
212  int64 size;
213  ReadType(strm, &size);
214  if (!strm) {
215  LOG(ERROR) << "EncodeTable::Read: Read failed: " << source;
216  return nullptr;
217  }
218  std::unique_ptr<EncodeTable<Arc>> table(new EncodeTable<Arc>(flags));
219  for (int64 i = 0; i < size; ++i) {
220  std::unique_ptr<Tuple> tuple(new Tuple());
221  ReadType(strm, &tuple->ilabel);
222  ReadType(strm, &tuple->olabel);
223  tuple->weight.Read(strm);
224  if (!strm) {
225  LOG(ERROR) << "EncodeTable::Read: Read failed: " << source;
226  return nullptr;
227  }
228  table->encode_tuples_.push_back(std::move(tuple));
229  table->encode_hash_[table->encode_tuples_.back().get()] =
230  table->encode_tuples_.size();
231  }
232  if (flags & kEncodeHasISymbols) {
233  table->isymbols_.reset(SymbolTable::Read(strm, source));
234  }
235  if (flags & kEncodeHasOSymbols) {
236  table->osymbols_.reset(SymbolTable::Read(strm, source));
237  }
238  return table.release();
239 }
240 
241 } // namespace internal
242 
243 // A mapper to encode/decode weighted transducers. Encoding of an FST is used
244 // for performing classical determinization or minimization on a weighted
245 // transducer viewing it as an unweighted acceptor over encoded labels.
246 //
247 // The mapper stores the encoding in a local hash table (EncodeTable). This
248 // table is shared (and reference-counted) between the encoder and decoder.
249 // A decoder has read-only access to the EncodeTable.
250 //
251 // The EncodeMapper allows on the fly encoding of the machine. As the
252 // EncodeTable is generated the same table may by used to decode the machine
253 // on the fly. For example in the following sequence of operations
254 //
255 // Encode -> Determinize -> Decode
256 //
257 // we will use the encoding table generated during the encode step in the
258 // decode, even though the encoding is not complete.
259 template <class Arc>
261  using Label = typename Arc::Label;
262  using Weight = typename Arc::Weight;
263 
264  public:
266  : flags_(flags),
267  type_(type),
268  table_(std::make_shared<internal::EncodeTable<Arc>>(flags)),
269  error_(false) {}
270 
271  EncodeMapper(const EncodeMapper &mapper)
272  : flags_(mapper.flags_),
273  type_(mapper.type_),
274  table_(mapper.table_),
275  error_(false) {}
276 
277  // Copy constructor but setting the type, typically to DECODE.
278  EncodeMapper(const EncodeMapper &mapper, EncodeType type)
279  : flags_(mapper.flags_),
280  type_(type),
281  table_(mapper.table_),
282  error_(mapper.error_) {}
283 
284  Arc operator()(const Arc &arc);
285 
287  return (type_ == ENCODE && (flags_ & kEncodeWeights))
290  }
291 
293  return MAP_CLEAR_SYMBOLS;
294  }
295 
297  return MAP_CLEAR_SYMBOLS;
298  }
299 
301  uint64 outprops = inprops;
302  if (error_) outprops |= kError;
303  uint64 mask = kFstProperties;
304  if (flags_ & kEncodeLabels) {
306  }
307  if (flags_ & kEncodeWeights) {
309  (type_ == ENCODE ? kAddSuperFinalProperties
311  }
312  return outprops & mask;
313  }
314 
315  uint32 Flags() const { return flags_; }
316 
317  EncodeType Type() const { return type_; }
318 
319  bool Write(std::ostream &strm, const string &source) const {
320  return table_->Write(strm, source);
321  }
322 
323  bool Write(const string &filename) const {
324  std::ofstream strm(filename,
325  std::ios_base::out | std::ios_base::binary);
326  if (!strm) {
327  LOG(ERROR) << "EncodeMap: Can't open file: " << filename;
328  return false;
329  }
330  return Write(strm, filename);
331  }
332 
333  static EncodeMapper<Arc> *Read(std::istream &strm, const string &source,
334  EncodeType type = ENCODE) {
335  auto *table = internal::EncodeTable<Arc>::Read(strm, source);
336  return table ? new EncodeMapper(table->Flags(), type, table) : nullptr;
337  }
338 
339  static EncodeMapper<Arc> *Read(const string &filename,
340  EncodeType type = ENCODE) {
341  std::ifstream strm(filename,
342  std::ios_base::in | std::ios_base::binary);
343  if (!strm) {
344  LOG(ERROR) << "EncodeMap: Can't open file: " << filename;
345  return nullptr;
346  }
347  return Read(strm, filename, type);
348  }
349 
350  const SymbolTable *InputSymbols() const { return table_->InputSymbols(); }
351 
352  const SymbolTable *OutputSymbols() const { return table_->OutputSymbols(); }
353 
354  void SetInputSymbols(const SymbolTable *syms) {
355  table_->SetInputSymbols(syms);
356  }
357 
358  void SetOutputSymbols(const SymbolTable *syms) {
359  table_->SetOutputSymbols(syms);
360  }
361 
362  private:
363  uint32 flags_;
364  EncodeType type_;
365  std::shared_ptr<internal::EncodeTable<Arc>> table_;
366  bool error_;
367 
368  explicit EncodeMapper(uint32 flags, EncodeType type,
370  : flags_(flags), type_(type), table_(table), error_(false) {}
371 
372  EncodeMapper &operator=(const EncodeMapper &) = delete;
373 };
374 
375 template <class Arc>
376 Arc EncodeMapper<Arc>::operator()(const Arc &arc) {
377  if (type_ == ENCODE) {
378  if ((arc.nextstate == kNoStateId && !(flags_ & kEncodeWeights)) ||
379  (arc.nextstate == kNoStateId && (flags_ & kEncodeWeights) &&
380  arc.weight == Weight::Zero())) {
381  return arc;
382  } else {
383  const auto label = table_->Encode(arc);
384  return Arc(label, flags_ & kEncodeLabels ? label : arc.olabel,
385  flags_ & kEncodeWeights ? Weight::One() : arc.weight,
386  arc.nextstate);
387  }
388  } else { // type_ == DECODE
389  if (arc.nextstate == kNoStateId) {
390  return arc;
391  } else {
392  if (arc.ilabel == 0) return arc;
393  if (flags_ & kEncodeLabels && arc.ilabel != arc.olabel) {
394  FSTERROR() << "EncodeMapper: Label-encoded arc has different "
395  "input and output labels";
396  error_ = true;
397  }
398  if (flags_ & kEncodeWeights && arc.weight != Weight::One()) {
399  FSTERROR() << "EncodeMapper: Weight-encoded arc has non-trivial weight";
400  error_ = true;
401  }
402  const auto tuple = table_->Decode(arc.ilabel);
403  if (!tuple) {
404  FSTERROR() << "EncodeMapper: Decode failed";
405  error_ = true;
406  return Arc(kNoLabel, kNoLabel, Weight::NoWeight(), arc.nextstate);
407  } else {
408  return Arc(tuple->ilabel,
409  flags_ & kEncodeLabels ? tuple->olabel : arc.olabel,
410  flags_ & kEncodeWeights ? tuple->weight : arc.weight,
411  arc.nextstate);
412  }
413  }
414  }
415 }
416 
417 // Complexity: O(E + V).
418 template <class Arc>
419 inline void Encode(MutableFst<Arc> *fst, EncodeMapper<Arc> *mapper) {
420  mapper->SetInputSymbols(fst->InputSymbols());
421  mapper->SetOutputSymbols(fst->OutputSymbols());
422  ArcMap(fst, mapper);
423 }
424 
425 template <class Arc>
426 inline void Decode(MutableFst<Arc> *fst, const EncodeMapper<Arc> &mapper) {
427  ArcMap(fst, EncodeMapper<Arc>(mapper, DECODE));
428  RmFinalEpsilon(fst);
429  fst->SetInputSymbols(mapper.InputSymbols());
430  fst->SetOutputSymbols(mapper.OutputSymbols());
431 }
432 
433 // On-the-fly encoding of an input FST.
434 //
435 // Complexity:
436 //
437 // Construction: O(1)
438 // Traversal: O(e + v)
439 //
440 // where e is the number of arcs visited and v is the number of states visited.
441 // Constant time and space to visit an input state or arc is assumed and
442 // exclusive of caching.
443 template <class Arc>
444 class EncodeFst : public ArcMapFst<Arc, Arc, EncodeMapper<Arc>> {
445  public:
448 
449  EncodeFst(const Fst<Arc> &fst, Mapper *encoder)
450  : ArcMapFst<Arc, Arc, Mapper>(fst, encoder, ArcMapFstOptions()) {
451  encoder->SetInputSymbols(fst.InputSymbols());
452  encoder->SetOutputSymbols(fst.OutputSymbols());
453  }
454 
455  EncodeFst(const Fst<Arc> &fst, const Mapper &encoder)
456  : ArcMapFst<Arc, Arc, Mapper>(fst, encoder, ArcMapFstOptions()) {}
457 
458  // See Fst<>::Copy() for doc.
459  EncodeFst(const EncodeFst<Arc> &fst, bool copy = false)
460  : ArcMapFst<Arc, Arc, Mapper>(fst, copy) {}
461 
462  // Makes a copy of this EncodeFst. See Fst<>::Copy() for further doc.
463  EncodeFst<Arc> *Copy(bool safe = false) const override {
464  if (safe) {
465  FSTERROR() << "EncodeFst::Copy(true): Not allowed";
466  GetImpl()->SetProperties(kError, kError);
467  }
468  return new EncodeFst(*this);
469  }
470 
471  private:
474 };
475 
476 // On-the-fly decoding of an input FST.
477 //
478 // Complexity:
479 //
480 // Construction: O(1).
481 // Traversal: O(e + v)
482 //
483 // Constant time and space to visit an input state or arc is assumed and
484 // exclusive of caching.
485 template <class Arc>
486 class DecodeFst : public ArcMapFst<Arc, Arc, EncodeMapper<Arc>> {
487  public:
491 
492  DecodeFst(const Fst<Arc> &fst, const Mapper &encoder)
493  : ArcMapFst<Arc, Arc, Mapper>(fst, Mapper(encoder, DECODE),
494  ArcMapFstOptions()) {
495  GetMutableImpl()->SetInputSymbols(encoder.InputSymbols());
496  GetMutableImpl()->SetOutputSymbols(encoder.OutputSymbols());
497  }
498 
499  // See Fst<>::Copy() for doc.
500  DecodeFst(const DecodeFst<Arc> &fst, bool safe = false)
501  : ArcMapFst<Arc, Arc, Mapper>(fst, safe) {}
502 
503  // Makes a copy of this DecodeFst. See Fst<>::Copy() for further doc.
504  DecodeFst<Arc> *Copy(bool safe = false) const override {
505  return new DecodeFst(*this, safe);
506  }
507 
508  private:
510 };
511 
512 // Specialization for EncodeFst.
513 template <class Arc>
515  : public StateIterator<ArcMapFst<Arc, Arc, EncodeMapper<Arc>>> {
516  public:
519 };
520 
521 // Specialization for EncodeFst.
522 template <class Arc>
524  : public ArcIterator<ArcMapFst<Arc, Arc, EncodeMapper<Arc>>> {
525  public:
526  ArcIterator(const EncodeFst<Arc> &fst, typename Arc::StateId s)
527  : ArcIterator<ArcMapFst<Arc, Arc, EncodeMapper<Arc>>>(fst, s) {}
528 };
529 
530 // Specialization for DecodeFst.
531 template <class Arc>
533  : public StateIterator<ArcMapFst<Arc, Arc, EncodeMapper<Arc>>> {
534  public:
537 };
538 
539 // Specialization for DecodeFst.
540 template <class Arc>
542  : public ArcIterator<ArcMapFst<Arc, Arc, EncodeMapper<Arc>>> {
543  public:
544  ArcIterator(const DecodeFst<Arc> &fst, typename Arc::StateId s)
545  : ArcIterator<ArcMapFst<Arc, Arc, EncodeMapper<Arc>>>(fst, s) {}
546 };
547 
548 // Useful aliases when using StdArc.
549 
551 
553 
554 } // namespace fst
555 
556 #endif // FST_ENCODE_H_
typename Impl::Arc Arc
Definition: fst.h:871
MapSymbolsAction
Definition: arc-map.h:39
void ArcMap(MutableFst< A > *fst, C *mapper)
Definition: arc-map.h:94
constexpr uint64 kAddSuperFinalProperties
Definition: properties.h:266
EncodeType Type() const
Definition: encode.h:317
static EncodeTable< Arc > * Read(std::istream &strm, const string &source)
Definition: encode.h:202
typename ArcMapFst< Arc, Arc, EncodeMapper< Arc > >::Arc Arc
Definition: fst.h:480
constexpr int kNoLabel
Definition: fst.h:179
const SymbolTable * OutputSymbols() const
Definition: encode.h:146
const SymbolTable * OutputSymbols() const
Definition: encode.h:352
uint64_t uint64
Definition: types.h:32
bool Write(std::ostream &strm, const string &source) const
Definition: encode.h:319
ArcIterator(const DecodeFst< Arc > &fst, typename Arc::StateId s)
Definition: encode.h:544
EncodeFst(const Fst< Arc > &fst, Mapper *encoder)
Definition: encode.h:449
virtual SymbolTable * Copy() const
Definition: symbol-table.h:266
size_t Size() const
Definition: encode.h:136
DecodeFst(const Fst< Arc > &fst, const Mapper &encoder)
Definition: encode.h:492
const SymbolTable * InputSymbols() const override=0
void SetInputSymbols(const SymbolTable *syms)
Definition: encode.h:148
EncodeFst(const EncodeFst< Arc > &fst, bool copy=false)
Definition: encode.h:459
virtual void SetInputSymbols(const SymbolTable *isyms)=0
#define LOG(type)
Definition: log.h:48
void RmFinalEpsilon(MutableFst< Arc > *fst)
MapFinalAction FinalAction() const
Definition: encode.h:286
constexpr MapSymbolsAction InputSymbolsAction() const
Definition: encode.h:292
typename ArcMapFst< Arc, Arc, EncodeMapper< Arc > >::Arc Arc
Definition: fst.h:374
const Tuple * Decode(Label key) const
Definition: encode.h:128
void SetOutputSymbols(const SymbolTable *syms)
Definition: encode.h:158
constexpr uint64 kRmSuperFinalProperties
Definition: properties.h:276
EncodeTable(uint32 encode_flags)
Definition: encode.h:102
static EncodeMapper< Arc > * Read(const string &filename, EncodeType type=ENCODE)
Definition: encode.h:339
constexpr uint64 kFstProperties
Definition: properties.h:301
constexpr int kNoStateId
Definition: fst.h:180
EncodeType
Definition: encode.h:25
int64_t int64
Definition: types.h:27
std::ostream & WriteType(std::ostream &strm, const T t)
Definition: util.h:155
#define FSTERROR()
Definition: util.h:35
EncodeFst(const Fst< Arc > &fst, const Mapper &encoder)
Definition: encode.h:455
EncodeMapper(const EncodeMapper &mapper)
Definition: encode.h:271
const SymbolTable * OutputSymbols() const override=0
EncodeMapper(const EncodeMapper &mapper, EncodeType type)
Definition: encode.h:278
MapFinalAction
Definition: arc-map.h:24
bool Write(const string &filename) const
Definition: encode.h:323
DecodeFst< Arc > * Copy(bool safe=false) const override
Definition: encode.h:504
ArcIterator(const EncodeFst< Arc > &fst, typename Arc::StateId s)
Definition: encode.h:526
bool operator()(const Tuple *x, const Tuple *y) const
Definition: encode.h:69
constexpr MapSymbolsAction OutputSymbolsAction() const
Definition: encode.h:296
static SymbolTable * Read(std::istream &strm, const SymbolTableReadOptions &opts)
Definition: symbol-table.h:238
Tuple(Label ilabel_, Label olabel_, Weight weight_)
Definition: encode.h:53
Arc operator()(const Arc &arc)
Definition: encode.h:376
static EncodeMapper< Arc > * Read(std::istream &strm, const string &source, EncodeType type=ENCODE)
Definition: encode.h:333
Tuple(const Tuple &tuple)
Definition: encode.h:56
StateIterator(const DecodeFst< Arc > &fst)
Definition: encode.h:535
TupleKey(uint32 encode_flags)
Definition: encode.h:83
EncodeMapper(uint32 flags, EncodeType type)
Definition: encode.h:265
void SetInputSymbols(const SymbolTable *syms)
Definition: encode.h:354
TupleKey(const TupleKey &key)
Definition: encode.h:81
bool Write(std::ostream &strm, const string &source) const
Definition: encode.h:180
StateIterator(const EncodeFst< Arc > &fst)
Definition: encode.h:517
Label GetLabel(const Arc &arc) const
Definition: encode.h:120
uint32 Flags() const
Definition: encode.h:315
const SymbolTable * InputSymbols() const
Definition: encode.h:350
Label Encode(const Arc &arc)
Definition: encode.h:109
constexpr uint64 kOLabelInvariantProperties
Definition: properties.h:245
uint32_t uint32
Definition: types.h:31
constexpr uint64 kWeightInvariantProperties
Definition: properties.h:255
virtual const SymbolTable * InputSymbols() const =0
uint32 Flags() const
Definition: encode.h:142
int32_t int32
Definition: types.h:26
DecodeFst(const DecodeFst< Arc > &fst, bool safe=false)
Definition: encode.h:500
constexpr uint64 kError
Definition: properties.h:33
const SymbolTable * InputSymbols() const
Definition: encode.h:144
std::istream & ReadType(std::istream &strm, T *t)
Definition: util.h:47
uint64 Properties(uint64 inprops)
Definition: encode.h:300
virtual void SetOutputSymbols(const SymbolTable *osyms)=0
typename Arc::Label Label
Definition: encode.h:46
std::unordered_map< const Tuple *, Label, TupleKey, TupleEqual > EncodeHash
Definition: encode.h:106
typename Arc::Weight Weight
Definition: encode.h:47
EncodeFst< Arc > * Copy(bool safe=false) const override
Definition: encode.h:463
constexpr uint64 kILabelInvariantProperties
Definition: properties.h:236
size_t operator()(const Tuple *x) const
Definition: encode.h:85
void SetOutputSymbols(const SymbolTable *syms)
Definition: encode.h:358
virtual const SymbolTable * OutputSymbols() const =0