FST  openfst-1.7.2
OpenFst Library
mpdtscript.cc
Go to the documentation of this file.
1 // See www.openfst.org for extensive documentation on this weighted
2 // finite-state transducer library.
3 //
4 // Definitions of 'scriptable' versions of mpdt operations, that is,
5 // those that can be called with FstClass-type arguments.
6 //
7 // See comments in nlp/fst/script/script-impl.h for how the registration
8 // mechanism allows these to work with various arc types.
9 
10 #include <string>
11 #include <vector>
12 
17 #include <fst/script/script-impl.h>
18 
19 namespace fst {
20 namespace script {
21 
22 void MPdtCompose(const FstClass &ifst1, const FstClass &ifst2,
23  const std::vector<LabelPair> &parens,
24  const std::vector<int64> &assignments, MutableFstClass *ofst,
25  const MPdtComposeOptions &copts, bool left_pdt) {
26  if (!internal::ArcTypesMatch(ifst1, ifst2, "MPdtCompose") ||
27  !internal::ArcTypesMatch(ifst1, *ofst, "MPdtCompose")) return;
28  MPdtComposeArgs args(ifst1, ifst2, parens, assignments, ofst, copts,
29  left_pdt);
30  Apply<Operation<MPdtComposeArgs>>("MPdtCompose", ifst1.ArcType(), &args);
31 }
32 
33 void MPdtExpand(const FstClass &ifst, const std::vector<LabelPair> &parens,
34  const std::vector<int64> &assignments, MutableFstClass *ofst,
35  const MPdtExpandOptions &opts) {
36  MPdtExpandArgs args(ifst, parens, assignments, ofst, opts);
37  Apply<Operation<MPdtExpandArgs>>("MPdtExpand", ifst.ArcType(), &args);
38 }
39 
40 void MPdtExpand(const FstClass &ifst, const std::vector<LabelPair> &parens,
41  const std::vector<int64> &assignments, MutableFstClass *ofst,
42  bool connect) {
43  MPdtExpand(ifst, parens, assignments, ofst, MPdtExpandOptions(connect));
44 }
45 
46 void MPdtReverse(const FstClass &ifst, const std::vector<LabelPair> &parens,
47  std::vector<int64> *assignments, MutableFstClass *ofst) {
48  MPdtReverseArgs args(ifst, parens, assignments, ofst);
49  Apply<Operation<MPdtReverseArgs>>("MPdtReverse", ifst.ArcType(), &args);
50 }
51 
52 void PrintMPdtInfo(const FstClass &ifst, const std::vector<LabelPair> &parens,
53  const std::vector<int64> &assignments) {
54  PrintMPdtInfoArgs args(ifst, parens, assignments);
55  Apply<Operation<PrintMPdtInfoArgs>>("PrintMPdtInfo", ifst.ArcType(), &args);
56 }
57 
58 // Register operations for common arc types.
59 
63 
64 } // namespace script
65 } // namespace fst
std::tuple< const FstClass &, const std::vector< LabelPair > &, std::vector< int64 > *, MutableFstClass * > MPdtReverseArgs
Definition: mpdtscript.h:97
void MPdtCompose(const FstClass &ifst1, const FstClass &ifst2, const std::vector< LabelPair > &parens, const std::vector< int64 > &assignments, MutableFstClass *ofst, const MPdtComposeOptions &copts, bool left_pdt)
Definition: mpdtscript.cc:22
std::tuple< const FstClass &, const std::vector< LabelPair > &, const std::vector< int64 > &, MutableFstClass *, const MPdtExpandOptions & > MPdtExpandArgs
Definition: mpdtscript.h:69
REGISTER_FST_MPDT_OPERATIONS(StdArc)
void MPdtReverse(const FstClass &ifst, const std::vector< LabelPair > &parens, std::vector< int64 > *assignments, MutableFstClass *ofst)
Definition: mpdtscript.cc:46
const string & ArcType() const final
Definition: fst-class.h:290
bool ArcTypesMatch(const M &m, const N &n, const string &op_name)
Definition: script-impl.h:176
void MPdtExpand(const FstClass &ifst, const std::vector< LabelPair > &parens, const std::vector< int64 > &assignments, MutableFstClass *ofst, const MPdtExpandOptions &opts)
Definition: mpdtscript.cc:33
std::tuple< const FstClass &, const FstClass &, const std::vector< LabelPair > &, const std::vector< int64 > &, MutableFstClass *, const MPdtComposeOptions &, bool > MPdtComposeArgs
Definition: mpdtscript.h:37
void PrintMPdtInfo(const FstClass &ifst, const std::vector< LabelPair > &parens, const std::vector< int64 > &assignments)
Definition: mpdtscript.cc:52
std::tuple< const FstClass &, const std::vector< LabelPair > &, const std::vector< int64 > & > PrintMPdtInfoArgs
Definition: mpdtscript.h:125