FST  openfst-1.8.3
OpenFst Library
encode.h
Go to the documentation of this file.
1 // Copyright 2005-2024 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the 'License');
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an 'AS IS' BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 #ifndef FST_EXTENSIONS_FAR_ENCODE_H_
16 #define FST_EXTENSIONS_FAR_ENCODE_H_
17 
18 #include <memory>
19 
20 #include <fst/extensions/far/far.h>
23 #include <fst/encode.h>
24 #include <fst/fst.h>
25 #include <fst/vector-fst.h>
26 #include <string_view>
27 
28 namespace fst {
29 
30 template <class Arc>
31 void Encode(FarReader<Arc> &reader, FarWriter<Arc> &writer,
32  EncodeMapper<Arc> *mapper) {
33  internal::Map(reader, writer,
34  [mapper](std::string_view key, const Fst<Arc> *ifst) {
35  auto ofst = std::make_unique<VectorFst<Arc>>(*ifst);
36  Encode(ofst.get(), mapper);
37  return ofst;
38  });
39 }
40 
41 template <class Arc>
42 void Decode(FarReader<Arc> &reader, FarWriter<Arc> &writer,
43  const EncodeMapper<Arc> &mapper) {
44  internal::Map(reader, writer,
45  [&mapper](std::string_view key, const Fst<Arc> *ifst) {
46  auto ofst = std::make_unique<VectorFst<Arc>>(*ifst);
47  Decode(ofst.get(), mapper);
48  return ofst;
49  });
50 }
51 
52 } // namespace fst
53 
54 #endif // FST_EXTENSIONS_FAR_ENCODE_H_
void Encode(MutableFst< Arc > *fst, EncodeMapper< Arc > *mapper)
Definition: encode.h:500
void Map(FarReader< Arc > &reader, FarWriter< Arc > &writer, Functor functor)
Definition: map-reduce.h:49
void Decode(MutableFst< Arc > *fst, const EncodeMapper< Arc > &mapper)
Definition: encode.h:507