FST  openfst-1.8.2.post1
OpenFst Library
mpdtscript.cc
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 // Definitions of 'scriptable' versions of mpdt operations, that is,
19 // those that can be called with FstClass-type arguments.
20 //
21 // See comments in nlp/fst/script/script-impl.h for how the registration
22 // mechanism allows these to work with various arc types.
23 
25 
26 #include <cstdint>
27 #include <string>
28 #include <utility>
29 #include <vector>
30 
34 #include <fst/script/script-impl.h>
35 
36 namespace fst {
37 namespace script {
38 
39 void Compose(const FstClass &ifst1, const FstClass &ifst2,
40  const std::vector<std::pair<int64_t, int64_t>> &parens,
41  const std::vector<int64_t> &assignments, MutableFstClass *ofst,
42  const MPdtComposeOptions &copts, bool left_pdt) {
43  if (!internal::ArcTypesMatch(ifst1, ifst2, "Compose") ||
44  !internal::ArcTypesMatch(ifst1, *ofst, "Compose"))
45  return;
46  MPdtComposeArgs args{ifst1, ifst2, parens, assignments,
47  ofst, copts, left_pdt};
48  Apply<Operation<MPdtComposeArgs>>("Compose", ifst1.ArcType(), &args);
49 }
50 
52 
53 void Expand(const FstClass &ifst,
54  const std::vector<std::pair<int64_t, int64_t>> &parens,
55  const std::vector<int64_t> &assignments, MutableFstClass *ofst,
56  const MPdtExpandOptions &opts) {
57  MPdtExpandArgs args{ifst, parens, assignments, ofst, opts};
58  Apply<Operation<MPdtExpandArgs>>("Expand", ifst.ArcType(), &args);
59 }
60 
62 
63 void Expand(const FstClass &ifst,
64  const std::vector<std::pair<int64_t, int64_t>> &parens,
65  const std::vector<int64_t> &assignments, MutableFstClass *ofst,
66  bool connect) {
67  Expand(ifst, parens, assignments, ofst, MPdtExpandOptions(connect));
68 }
69 
70 void Reverse(const FstClass &ifst,
71  const std::vector<std::pair<int64_t, int64_t>> &parens,
72  std::vector<int64_t> *assignments, MutableFstClass *ofst) {
73  MPdtReverseArgs args{ifst, parens, assignments, ofst};
74  Apply<Operation<MPdtReverseArgs>>("Reverse", ifst.ArcType(), &args);
75 }
76 
78 
79 void Info(const FstClass &ifst,
80  const std::vector<std::pair<int64_t, int64_t>> &parens,
81  const std::vector<int64_t> &assignments) {
82  MPdtInfoArgs args{ifst, parens, assignments};
83  Apply<Operation<MPdtInfoArgs>>("Info", ifst.ArcType(), &args);
84 }
85 
87 
88 } // namespace script
89 } // namespace fst
void Reverse(const FstClass &ifst, const std::vector< std::pair< int64_t, int64_t >> &parens, std::vector< int64_t > *assignments, MutableFstClass *ofst)
Definition: mpdtscript.cc:70
REGISTER_FST_OPERATION_3ARCS(Compress, CompressArgs)
const std::string & ArcType() const final
Definition: fst-class.h:323
std::tuple< const FstClass &, const std::vector< std::pair< int64_t, int64_t >> &, const std::vector< int64_t > & > MPdtInfoArgs
Definition: mpdtscript.h:141
std::tuple< const FstClass &, const FstClass &, const std::vector< std::pair< int64_t, int64_t >> &, const std::vector< int64_t > &, MutableFstClass *, const MPdtComposeOptions &, bool > MPdtComposeArgs
Definition: mpdtscript.h:50
bool ArcTypesMatch(const M &m, const N &n, const std::string &op_name)
Definition: script-impl.h:191
void Info(const std::vector< std::string > &sources, const std::string &arc_type, const std::string &begin_key, const std::string &end_key, bool list_fsts)
Definition: farscript.cc:138
std::tuple< const FstClass &, const std::vector< std::pair< int64_t, int64_t >> &, std::vector< int64_t > *, MutableFstClass * > MPdtReverseArgs
Definition: mpdtscript.h:111
void Expand(const FstClass &ifst, const std::vector< std::pair< int64_t, int64_t >> &parens, const std::vector< int64_t > &assignments, MutableFstClass *ofst, const MPdtExpandOptions &opts)
Definition: mpdtscript.cc:53
std::tuple< const FstClass &, const std::vector< std::pair< int64_t, int64_t >> &, const std::vector< int64_t > &, MutableFstClass *, const MPdtExpandOptions & > MPdtExpandArgs
Definition: mpdtscript.h:81
void Compose(const FstClass &ifst1, const FstClass &ifst2, const std::vector< std::pair< int64_t, int64_t >> &parens, const std::vector< int64_t > &assignments, MutableFstClass *ofst, const MPdtComposeOptions &copts, bool left_pdt)
Definition: mpdtscript.cc:39