FST  openfst-1.8.2
OpenFst Library
encode.h
Go to the documentation of this file.
1 // Copyright 2005-2020 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 <fst/extensions/far/far.h>
21 #include <fst/encode.h>
22 #include <fst/vector-fst.h>
23 #include <string_view>
24 
25 namespace fst {
26 
27 template <class Arc>
28 void Encode(FarReader<Arc> &reader, FarWriter<Arc> &writer,
29  EncodeMapper<Arc> *mapper) {
30  internal::Map(reader, writer,
31  [mapper](std::string_view key, const Fst<Arc> *ifst) {
32  auto ofst = std::make_unique<VectorFst<Arc>>(*ifst);
33  Encode(ofst.get(), mapper);
34  return ofst;
35  });
36 }
37 
38 template <class Arc>
39 void Decode(FarReader<Arc> &reader, FarWriter<Arc> &writer,
40  const EncodeMapper<Arc> &mapper) {
41  internal::Map(reader, writer,
42  [&mapper](std::string_view key, const Fst<Arc> *ifst) {
43  auto ofst = std::make_unique<VectorFst<Arc>>(*ifst);
44  Decode(ofst.get(), mapper);
45  return ofst;
46  });
47 }
48 
49 } // namespace fst
50 
51 #endif // FST_EXTENSIONS_FAR_ENCODE_H_
void Encode(MutableFst< Arc > *fst, EncodeMapper< Arc > *mapper)
Definition: encode.h:474
void Map(FarReader< Arc > &reader, FarWriter< Arc > &writer, Functor functor)
Definition: map-reduce.h:46
void Decode(MutableFst< Arc > *fst, const EncodeMapper< Arc > &mapper)
Definition: encode.h:481