FST  openfst-1.8.3
OpenFst Library
union.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 // See www.openfst.org for extensive documentation on this weighted
16 // finite-state transducer library.
17 
18 #ifndef FST_SCRIPT_UNION_H_
19 #define FST_SCRIPT_UNION_H_
20 
21 #include <tuple>
22 #include <utility>
23 #include <vector>
24 
25 #include <fst/fst.h>
26 #include <fst/mutable-fst.h>
27 #include <fst/union.h>
28 #include <fst/script/fst-class.h>
29 
30 namespace fst {
31 namespace script {
32 
33 using FstUnionArgs1 = std::pair<MutableFstClass *, const FstClass &>;
34 
35 template <class Arc>
36 void Union(FstUnionArgs1 *args) {
37  MutableFst<Arc> *fst1 = std::get<0>(*args)->GetMutableFst<Arc>();
38  const Fst<Arc> &fst2 = *std::get<1>(*args).GetFst<Arc>();
39  Union(fst1, fst2);
40 }
41 
42 using FstUnionArgs2 =
43  std::tuple<MutableFstClass *, const std::vector<const FstClass *> &>;
44 
45 template <class Arc>
46 void Union(FstUnionArgs2 *args) {
47  MutableFst<Arc> *fst1 = std::get<0>(*args)->GetMutableFst<Arc>();
48  const auto &untyped_fsts2 = std::get<1>(*args);
49  std::vector<const Fst<Arc> *> typed_fsts2;
50  typed_fsts2.reserve(untyped_fsts2.size());
51  for (const auto &untyped_fst2 : untyped_fsts2) {
52  typed_fsts2.emplace_back(untyped_fst2->GetFst<Arc>());
53  }
54  Union(fst1, typed_fsts2);
55 }
56 
57 void Union(MutableFstClass *fst1, const FstClass &fst2);
58 
59 void Union(MutableFstClass *fst1, const std::vector<const FstClass *> &fsts2);
60 
61 } // namespace script
62 } // namespace fst
63 
64 #endif // FST_SCRIPT_UNION_H_
void Union(FstUnionArgs1 *args)
Definition: union.h:36
std::pair< MutableFstClass *, const FstClass & > FstUnionArgs1
Definition: union.h:33
std::tuple< MutableFstClass *, const std::vector< const FstClass * > & > FstUnionArgs2
Definition: union.h:43