The Encode operation allows the representation of a weighted transducer as a
weighted automaton, an unweighted transducer or an unweighted automaton by
considering the pair (input label, output), the pair (input label, weight) or
the triple (input label, output label, weight) as a single label depending on
the value of the encode flags: kEncodeLabels, kEncodeWeights or
kEncodeLabels|kEncodeWeights. The encoding of each pair or triple of labels
and/or weights as a unique key is performed by an EncodeMapper object.
The Decode operation takes as input an encoded FST and the corresponding
EncodeMapper object and reverts the encoding.
static const uint32 kEncodeLabels = 0x0001;
static const uint32 kEncodeWeights = 0x0002;
static const uint32 kEncodeFlags = 0x0003;enum EncodeType { ENCODE = 1, DECODE = 2 };template <class Arc> EncodeMapper<Arc>::
EncodeMapper(uint32 flags, EncodeType type);template <class Arc>
void Encode(MutableFst<Arc> *fst, EncodeMapper<Arc> *encoder);template <class Arc> EncodeFst<Arc>::
EncodeFst<Arc>(const Fst<Arc> &fst, EncodeMapper<Arc> *encoder);template <class Arc>
void Decode(MutableFst<Arc> *fst, const EncodeMapper<Arc> &encoder);template <class Arc> DecodeFst<Arc>::
DecodeFst<Arc>(const Fst<Arc> &fst, EncodeMapper<Arc> *encoder);fstencode [--encode_labels] [--encode_weights] in.fst encoder out.fstfstencode --decode in.fst encoder out.fstencode_flags |
kEncodeLabels |
kEncodeWeights |
|---|---|---|
$flags |
--encode_labels |
--encode_weights |
result |
![]() |
![]() |
encode_flags |
kEncodeLabels | kEncodeWeights |
|---|---|
$flags |
--encode_labels --encode_weights |
result |
![]() |
EncodeMapper<Arc> encoder(encode_flags, ENCODE);
Encode(&A, &encoder);
EncodeFst<Arc>(A, &encoder);
fstencode $flags a.fst encoder b.fstDecode(&A, encoder);
DecodeFst<Arc>(A, encoder);
fstencode --decode a.fst encoder b.fstEncode, Decode:
- Time:
$O(V + E)$ - Space:
$O(1)$
where
EncodeFst, DecodeFst:
- Time:
$O(v + e)$ - Space:
$O(1)$
where



