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