21 #ifndef FST_EXTENSIONS_PDT_PDTSCRIPT_H_ 22 #define FST_EXTENSIONS_PDT_PDTSCRIPT_H_ 47 std::tuple<
const FstClass &,
const FstClass &,
48 const std::vector<std::pair<int64_t, int64_t>> &,
53 const Fst<Arc> &ifst1 = *(std::get<0>(*args).GetFst<Arc>());
54 const Fst<Arc> &ifst2 = *(std::get<1>(*args).GetFst<Arc>());
59 std::vector<std::pair<typename Arc::Label, typename Arc::Label>> typed_parens(
60 std::get<2>(*args).size());
61 std::copy(std::get<2>(*args).begin(), std::get<2>(*args).end(),
62 typed_parens.begin());
63 if (std::get<5>(*args)) {
64 Compose(ifst1, typed_parens, ifst2, ofst, std::get<4>(*args));
66 Compose(ifst1, ifst2, typed_parens, ofst, std::get<4>(*args));
70 void Compose(
const FstClass &ifst1,
const FstClass &ifst2,
71 const std::vector<std::pair<int64_t, int64_t>> &parens,
81 : connect(c), keep_parentheses(k), weight_threshold(w) {}
85 std::tuple<
const FstClass &,
86 const std::vector<std::pair<int64_t, int64_t>> &,
91 const Fst<Arc> &
fst = *(std::get<0>(*args).GetFst<Arc>());
96 std::vector<std::pair<typename Arc::Label, typename Arc::Label>> typed_parens(
97 std::get<1>(*args).size());
98 std::copy(std::get<1>(*args).begin(), std::get<1>(*args).end(),
99 typed_parens.begin());
100 Expand(fst, typed_parens, ofst,
102 std::get<3>(*args).connect, std::get<3>(*args).keep_parentheses,
104 .weight_threshold.GetWeight<
typename Arc::Weight>())));
107 void Expand(
const FstClass &ifst,
108 const std::vector<std::pair<int64_t, int64_t>> &parens,
111 void Expand(
const FstClass &ifst,
112 const std::vector<std::pair<int64_t, int64_t>> &parens,
117 std::tuple<const std::vector<std::pair<int64_t, const FstClass *>> &,
120 const std::string &>;
124 const auto &untyped_pairs = std::get<0>(*args);
125 auto size = untyped_pairs.size();
126 std::vector<std::pair<typename Arc::Label, const Fst<Arc> *>> typed_pairs(
128 for (
size_t i = 0; i < size; ++i) {
129 typed_pairs[i].first = untyped_pairs[i].first;
130 typed_pairs[i].second = untyped_pairs[i].second->GetFst<Arc>();
133 std::vector<std::pair<typename Arc::Label, typename Arc::Label>> typed_parens;
135 std::get<5>(*args), std::get<6>(*args),
137 Replace(typed_pairs, ofst, &typed_parens, opts);
139 std::get<2>(*args)->resize(typed_parens.size());
140 std::copy(typed_parens.begin(), typed_parens.end(),
141 std::get<2>(*args)->begin());
144 void Replace(
const std::vector<std::pair<int64_t, const FstClass *>> &pairs,
145 MutableFstClass *ofst,
146 std::vector<std::pair<int64_t, int64_t>> *parens, int64_t root,
148 int64_t start_paren_labels =
kNoLabel,
149 const std::string &left_paren_prefix =
"(_",
150 const std::string &right_paren_prefix =
"_)");
153 std::tuple<
const FstClass &,
154 const std::vector<std::pair<int64_t, int64_t>> &,
159 const Fst<Arc> &
fst = *(std::get<0>(*args).GetFst<Arc>());
164 std::vector<std::pair<typename Arc::Label, typename Arc::Label>> typed_parens(
165 std::get<1>(*args).size());
166 std::copy(std::get<1>(*args).begin(), std::get<1>(*args).end(),
167 typed_parens.begin());
168 Reverse(fst, typed_parens, ofst);
171 void Reverse(
const FstClass &ifst,
172 const std::vector<std::pair<int64_t, int64_t>> &,
173 MutableFstClass *ofst);
184 : queue_type(qt), keep_parentheses(kp), path_gc(gc) {}
188 std::tuple<
const FstClass &,
189 const std::vector<std::pair<int64_t, int64_t>> &,
194 const Fst<Arc> &
fst = *(std::get<0>(*args).GetFst<Arc>());
196 const PdtShortestPathOptions &opts = std::get<3>(*args);
200 std::vector<std::pair<typename Arc::Label, typename Arc::Label>> typed_parens(
201 std::get<1>(*args).size());
202 std::copy(std::get<1>(*args).begin(), std::get<1>(*args).end(),
203 typed_parens.begin());
204 switch (opts.queue_type) {
206 FSTERROR() <<
"Unknown queue type: " << opts.queue_type;
232 const FstClass &ifst,
233 const std::vector<std::pair<int64_t, int64_t>> &parens,
234 MutableFstClass *ofst,
235 const PdtShortestPathOptions &opts = PdtShortestPathOptions());
240 const std::vector<std::pair<int64_t, int64_t>> &>;
244 const Fst<Arc> &
fst = *(std::get<0>(*args).GetFst<Arc>());
248 std::vector<std::pair<typename Arc::Label, typename Arc::Label>> typed_parens(
249 std::get<1>(*args).size());
250 std::copy(std::get<1>(*args).begin(), std::get<1>(*args).end(),
251 typed_parens.begin());
256 void Info(
const FstClass &ifst,
257 const std::vector<std::pair<int64_t, int64_t>> &parens);
262 #define REGISTER_FST_PDT_OPERATIONS(ArcType) \ 263 REGISTER_FST_OPERATION(PdtCompose, ArcType, PdtComposeArgs); \ 264 REGISTER_FST_OPERATION(PdtExpand, ArcType, PdtExpandArgs); \ 265 REGISTER_FST_OPERATION(PdtReplace, ArcType, PdtReplaceArgs); \ 266 REGISTER_FST_OPERATION(PdtReverse, ArcType, PdtReverseArgs); \ 267 REGISTER_FST_OPERATION(PdtShortestPath, ArcType, PdtShortestPathArgs); \ 268 REGISTER_FST_OPERATION(PrintPdtInfo, ArcType, PrintPdtInfoArgs) 269 #endif // FST_EXTENSIONS_PDT_PDTSCRIPT_H_
PdtShortestPathOptions(QueueType qt=FIFO_QUEUE, bool kp=false, bool gc=true)
MutableFst< Arc > * GetMutableFst()
PdtExpandOptions(bool c, bool k, const WeightClass &w)
void Reverse(const FstClass &ifst, const std::vector< std::pair< int64_t, int64_t >> &parens, std::vector< int64_t > *assignments, MutableFstClass *ofst)
void Replace(const std::vector< std::pair< int64_t, const FstClass * >> &pairs, MutableFstClass *ofst, std::vector< std::pair< int64_t, int64_t >> *parens, int64_t root, PdtParserType parser_type, int64_t start_paren_labels, const std::string &left_paren_prefix, const std::string &right_paren_prefix)
void ShortestPath(const FstClass &ifst, const std::vector< std::pair< int64_t, int64_t >> &parens, MutableFstClass *ofst, const PdtShortestPathOptions &opts)
std::tuple< const std::vector< std::pair< int64_t, const FstClass * >> &, MutableFstClass *, std::vector< std::pair< int64_t, int64_t >> *, int64_t, PdtParserType, int64_t, const std::string &, const std::string & > PdtReplaceArgs
std::tuple< const FstClass &, const std::vector< std::pair< int64_t, int64_t >> &, MutableFstClass * > PdtReverseArgs
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)
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)
std::pair< const FstClass &, const std::vector< std::pair< int64_t, int64_t >> & > PdtInfoArgs
const WeightClass & weight_threshold
std::tuple< const FstClass &, const std::vector< std::pair< int64_t, int64_t >> &, MutableFstClass *, const PdtShortestPathOptions & > PdtShortestPathArgs
std::tuple< const FstClass &, const FstClass &, const std::vector< std::pair< int64_t, int64_t >> &, MutableFstClass *, const PdtComposeOptions &, bool > PdtComposeArgs
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)
std::tuple< const FstClass &, const std::vector< std::pair< int64_t, int64_t >> &, MutableFstClass *, const PdtExpandOptions & > PdtExpandArgs