FST  openfst-1.8.3
OpenFst Library
mpdtscript.cc
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 // 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 <utility>
28 #include <vector>
29 
32 #include <fst/arc.h>
33 #include <fst/cache.h>
34 #include <fst/float-weight.h>
35 #include <fst/script/fst-class.h>
36 #include <fst/script/script-impl.h>
37 
38 namespace fst {
39 namespace script {
40 
41 void Compose(const FstClass &ifst1, const FstClass &ifst2,
42  const std::vector<std::pair<int64_t, int64_t>> &parens,
43  const std::vector<int64_t> &assignments, MutableFstClass *ofst,
44  const MPdtComposeOptions &copts, bool left_pdt) {
45  if (!internal::ArcTypesMatch(ifst1, ifst2, "Compose") ||
46  !internal::ArcTypesMatch(ifst1, *ofst, "Compose"))
47  return;
48  MPdtComposeArgs args{ifst1, ifst2, parens, assignments,
49  ofst, copts, left_pdt};
50  Apply<Operation<MPdtComposeArgs>>("Compose", ifst1.ArcType(), &args);
51 }
52 
54 
55 void Expand(const FstClass &ifst,
56  const std::vector<std::pair<int64_t, int64_t>> &parens,
57  const std::vector<int64_t> &assignments, MutableFstClass *ofst,
58  const MPdtExpandOptions &opts) {
59  MPdtExpandArgs args{ifst, parens, assignments, ofst, opts};
60  Apply<Operation<MPdtExpandArgs>>("Expand", ifst.ArcType(), &args);
61 }
62 
64 
65 void Expand(const FstClass &ifst,
66  const std::vector<std::pair<int64_t, int64_t>> &parens,
67  const std::vector<int64_t> &assignments, MutableFstClass *ofst,
68  bool connect) {
69  Expand(ifst, parens, assignments, ofst, MPdtExpandOptions(connect));
70 }
71 
72 void Reverse(const FstClass &ifst,
73  const std::vector<std::pair<int64_t, int64_t>> &parens,
74  std::vector<int64_t> *assignments, MutableFstClass *ofst) {
75  MPdtReverseArgs args{ifst, parens, assignments, ofst};
76  Apply<Operation<MPdtReverseArgs>>("Reverse", ifst.ArcType(), &args);
77 }
78 
80 
81 void Info(const FstClass &ifst,
82  const std::vector<std::pair<int64_t, int64_t>> &parens,
83  const std::vector<int64_t> &assignments) {
84  MPdtInfoArgs args{ifst, parens, assignments};
85  Apply<Operation<MPdtInfoArgs>>("Info", ifst.ArcType(), &args);
86 }
87 
89 
90 } // namespace script
91 } // 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:72
REGISTER_FST_OPERATION_3ARCS(Compress, CompressArgs)
const std::string & ArcType() const final
Definition: fst-class.h:329
std::tuple< const FstClass &, const std::vector< std::pair< int64_t, int64_t >> &, const std::vector< int64_t > & > MPdtInfoArgs
Definition: mpdtscript.h:144
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:53
bool ArcTypesMatch(const M &m, const N &n, const std::string &op_name)
Definition: script-impl.h:195
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:145
std::tuple< const FstClass &, const std::vector< std::pair< int64_t, int64_t >> &, std::vector< int64_t > *, MutableFstClass * > MPdtReverseArgs
Definition: mpdtscript.h:114
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:55
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:84
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:41