FST  openfst-1.7.1
OpenFst Library
farscript.h
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 // Convenience file for including all of the FAR operations, or registering
5 // them for new arc types.
6 
7 #ifndef FST_EXTENSIONS_FAR_FARSCRIPT_H_
8 #define FST_EXTENSIONS_FAR_FARSCRIPT_H_
9 
10 #include <string>
11 #include <vector>
12 
13 #include <fst/types.h>
18 #include <fst/extensions/far/far.h>
24 #include <fst/script/arg-packs.h>
25 
26 namespace fst {
27 namespace script {
28 
29 // Note: it is safe to pass these strings as references because this struct is
30 // only used to pass them deeper in the call graph. Be sure you understand why
31 // this is so before using this struct for anything else!
33  const std::vector<string> &in_fnames;
34  const string &out_fname;
35  const string &fst_type;
36  const FarType &far_type;
40  const string &symbols_fname;
41  const string &unknown_symbol;
42  const bool keep_symbols;
43  const bool initial_symbols;
45  const string &key_prefix;
46  const string &key_suffix;
47 
48  FarCompileStringsArgs(const std::vector<string> &in_fnames,
49  const string &out_fname, const string &fst_type,
50  const FarType &far_type, int32 generate_keys,
51  FarEntryType fet, FarTokenType tt,
52  const string &symbols_fname,
53  const string &unknown_symbol, bool keep_symbols,
54  bool initial_symbols, bool allow_negative_labels,
55  const string &key_prefix, const string &key_suffix)
56  : in_fnames(in_fnames),
57  out_fname(out_fname),
58  fst_type(fst_type),
59  far_type(far_type),
60  generate_keys(generate_keys),
61  fet(fet),
62  tt(tt),
63  symbols_fname(symbols_fname),
64  unknown_symbol(unknown_symbol),
65  keep_symbols(keep_symbols),
66  initial_symbols(initial_symbols),
67  allow_negative_labels(allow_negative_labels),
68  key_prefix(key_prefix),
69  key_suffix(key_suffix) {}
70 };
71 
72 template <class Arc>
74  FarCompileStrings<Arc>(
75  args->in_fnames, args->out_fname, args->fst_type, args->far_type,
76  args->generate_keys, args->fet, args->tt, args->symbols_fname,
77  args->unknown_symbol, args->keep_symbols, args->initial_symbols,
78  args->allow_negative_labels, args->key_prefix, args->key_suffix);
79 }
80 
81 void FarCompileStrings(const std::vector<string> &in_fnames,
82  const string &out_fname, const string &arc_type,
83  const string &fst_type, const FarType &far_type,
85  const string &symbols_fname,
86  const string &unknown_symbol, bool keep_symbols,
88  const string &key_prefix, const string &key_suffix);
89 
90 // Note: it is safe to pass these strings as references because this struct is
91 // only used to pass them deeper in the call graph. Be sure you understand why
92 // this is so before using this struct for anything else!
93 struct FarCreateArgs {
94  const std::vector<string> &in_fnames;
95  const string &out_fname;
97  const FarType &far_type;
98  const string &key_prefix;
99  const string &key_suffix;
100 
101  FarCreateArgs(const std::vector<string> &in_fnames, const string &out_fname,
102  const int32 generate_keys, const FarType &far_type,
103  const string &key_prefix, const string &key_suffix)
104  : in_fnames(in_fnames),
105  out_fname(out_fname),
106  generate_keys(generate_keys),
107  far_type(far_type),
108  key_prefix(key_prefix),
109  key_suffix(key_suffix) {}
110 };
111 
112 template <class Arc>
114  FarCreate<Arc>(args->in_fnames, args->out_fname, args->generate_keys,
115  args->far_type, args->key_prefix, args->key_suffix);
116 }
117 
118 void FarCreate(const std::vector<string> &in_fnames, const string &out_fname,
119  const string &arc_type, const int32 generate_keys,
120  const FarType &far_type, const string &key_prefix,
121  const string &key_suffix);
122 
123 using FarEqualInnerArgs = std::tuple<const string &, const string &, float,
124  const string &, const string &>;
125 
127 
128 template <class Arc>
129 void FarEqual(FarEqualArgs *args) {
130  args->retval = fst::FarEqual<Arc>(
131  std::get<0>(args->args), std::get<1>(args->args), std::get<2>(args->args),
132  std::get<3>(args->args), std::get<4>(args->args));
133 }
134 
135 bool FarEqual(const string &filename1, const string &filename2,
136  const string &arc_type, float delta = kDelta,
137  const string &begin_key = string(),
138  const string &end_key = string());
139 
140 using FarExtractArgs =
141  std::tuple<const std::vector<string> &, int32, const string &,
142  const string &, const string &, const string &, const string &>;
143 
144 template <class Arc>
146  fst::FarExtract<Arc>(std::get<0>(*args), std::get<1>(*args),
147  std::get<2>(*args), std::get<3>(*args),
148  std::get<4>(*args), std::get<5>(*args),
149  std::get<6>(*args));
150 }
151 
152 void FarExtract(const std::vector<string> &ifilenames, const string &arc_type,
153  int32 generate_filenames, const string &keys,
154  const string &key_separator, const string &range_delimiter,
155  const string &filename_prefix, const string &filename_suffix);
156 
157 using FarInfoArgs = std::tuple<const std::vector<string> &, const string &,
158  const string &, const bool>;
159 
160 template <class Arc>
161 void FarInfo(FarInfoArgs *args) {
162  fst::FarInfo<Arc>(std::get<0>(*args), std::get<1>(*args),
163  std::get<2>(*args), std::get<3>(*args));
164 }
165 
166 void FarInfo(const std::vector<string> &filenames, const string &arc_type,
167  const string &begin_key, const string &end_key,
168  const bool list_fsts);
169 
170 using GetFarInfoArgs = std::tuple<const std::vector<string> &, const string &,
171  const string &, const bool, FarInfoData *>;
172 
173 template <class Arc>
175  fst::GetFarInfo<Arc>(std::get<0>(*args), std::get<1>(*args),
176  std::get<2>(*args), std::get<3>(*args),
177  std::get<4>(*args));
178 }
179 
180 void GetFarInfo(const std::vector<string> &filenames, const string &arc_type,
181  const string &begin_key, const string &end_key,
182  const bool list_fsts, FarInfoData *);
183 
184 using FarIsomorphicInnerArgs = std::tuple<const string &, const string &, float,
185  const string &, const string &>;
186 
188 
189 template <class Arc>
191  args->retval = fst::FarIsomorphic<Arc>(
192  std::get<0>(args->args), std::get<1>(args->args), std::get<2>(args->args),
193  std::get<3>(args->args), std::get<4>(args->args));
194 }
195 
196 bool FarIsomorphic(const string &filename1, const string &filename2,
197  const string &arc_type, float delta = kDelta,
198  const string &begin_key = string(),
199  const string &end_key = string());
200 
202  const std::vector<string> &ifilenames;
205  const string &begin_key;
206  const string &end_key;
207  const bool print_key;
208  const bool print_weight;
209  const string &symbols_fname;
210  const bool initial_symbols;
211  const int32 generate_filenames;
212  const string &filename_prefix;
213  const string &filename_suffix;
214 
215  FarPrintStringsArgs(const std::vector<string> &ifilenames,
216  const FarEntryType entry_type,
217  const FarTokenType token_type, const string &begin_key,
218  const string &end_key, const bool print_key,
219  const bool print_weight, const string &symbols_fname,
220  const bool initial_symbols,
221  const int32 generate_filenames,
222  const string &filename_prefix,
223  const string &filename_suffix)
224  : ifilenames(ifilenames),
225  entry_type(entry_type),
226  token_type(token_type),
227  begin_key(begin_key),
228  end_key(end_key),
229  print_key(print_key),
230  print_weight(print_weight),
231  symbols_fname(symbols_fname),
232  initial_symbols(initial_symbols),
233  generate_filenames(generate_filenames),
234  filename_prefix(filename_prefix),
235  filename_suffix(filename_suffix) {}
236 };
237 
238 template <class Arc>
240  fst::FarPrintStrings<Arc>(
241  args->ifilenames, args->entry_type, args->token_type, args->begin_key,
242  args->end_key, args->print_key, args->print_weight, args->symbols_fname,
244  args->filename_suffix);
245 }
246 
247 void FarPrintStrings(const std::vector<string> &ifilenames,
248  const string &arc_type, const FarEntryType entry_type,
249  const FarTokenType token_type, const string &begin_key,
250  const string &end_key, const bool print_key,
251  const bool print_weight, const string &symbols_fname,
252  const bool initial_symbols, const int32 generate_filenames,
253  const string &filename_prefix,
254  const string &filename_suffix);
255 
256 } // namespace script
257 } // namespace fst
258 
259 #define REGISTER_FST_FAR_OPERATIONS(ArcType) \
260  REGISTER_FST_OPERATION(FarCompileStrings, ArcType, FarCompileStringsArgs); \
261  REGISTER_FST_OPERATION(FarCreate, ArcType, FarCreateArgs); \
262  REGISTER_FST_OPERATION(FarEqual, ArcType, FarEqualArgs); \
263  REGISTER_FST_OPERATION(FarExtract, ArcType, FarExtractArgs); \
264  REGISTER_FST_OPERATION(FarInfo, ArcType, FarInfoArgs); \
265  REGISTER_FST_OPERATION(FarIsomorphic, ArcType, FarIsomorphicArgs); \
266  REGISTER_FST_OPERATION(FarPrintStrings, ArcType, FarPrintStringsArgs); \
267  REGISTER_FST_OPERATION(GetFarInfo, ArcType, GetFarInfoArgs)
268 
269 #endif // FST_EXTENSIONS_FAR_FARSCRIPT_H_
void FarInfo(const std::vector< string > &filenames, const string &arc_type, const string &begin_key, const string &end_key, const bool list_fsts)
Definition: farscript.cc:56
const string & key_suffix
Definition: farscript.h:99
const FarTokenType token_type
Definition: farscript.h:204
void FarPrintStrings(const std::vector< string > &ifilenames, const string &arc_type, const FarEntryType entry_type, const FarTokenType token_type, const string &begin_key, const string &end_key, const bool print_key, const bool print_weight, const string &symbols_fname, const bool initial_symbols, const int32 generate_filenames, const string &filename_prefix, const string &filename_suffix)
Definition: farscript.cc:80
const std::vector< string > & in_fnames
Definition: farscript.h:33
std::tuple< const string &, const string &, float, const string &, const string & > FarIsomorphicInnerArgs
Definition: farscript.h:185
const FarType & far_type
Definition: farscript.h:97
void FarCreate(const std::vector< string > &in_fnames, const string &out_fname, const string &arc_type, const int32 generate_keys, const FarType &far_type, const string &key_prefix, const string &key_suffix)
Definition: farscript.cc:29
const std::vector< string > & in_fnames
Definition: farscript.h:94
std::tuple< const std::vector< string > &, const string &, const string &, const bool, FarInfoData * > GetFarInfoArgs
Definition: farscript.h:171
FarTokenType
Definition: far.h:23
const std::vector< string > & ifilenames
Definition: farscript.h:202
FarCompileStringsArgs(const std::vector< string > &in_fnames, const string &out_fname, const string &fst_type, const FarType &far_type, int32 generate_keys, FarEntryType fet, FarTokenType tt, const string &symbols_fname, const string &unknown_symbol, bool keep_symbols, bool initial_symbols, bool allow_negative_labels, const string &key_prefix, const string &key_suffix)
Definition: farscript.h:48
std::tuple< const string &, const string &, float, const string &, const string & > FarEqualInnerArgs
Definition: farscript.h:124
FarType
Definition: far.h:71
void FarExtract(const std::vector< string > &ifilenames, const string &arc_type, int32 generate_filenames, const string &keys, const string &key_separator, const string &range_delimiter, const string &filename_prefix, const string &filename_suffix)
Definition: farscript.cc:47
bool FarEqual(const string &filename1, const string &filename2, const string &arc_type, float delta, const string &begin_key, const string &end_key)
Definition: farscript.cc:38
const int32 generate_keys
Definition: farscript.h:96
std::tuple< const std::vector< string > &, const string &, const string &, const bool > FarInfoArgs
Definition: farscript.h:158
bool FarIsomorphic(const string &filename1, const string &filename2, const string &arc_type, float delta, const string &begin_key, const string &end_key)
Definition: farscript.cc:70
std::tuple< const std::vector< string > &, int32, const string &, const string &, const string &, const string &, const string & > FarExtractArgs
Definition: farscript.h:142
void GetFarInfo(const std::vector< string > &filenames, const string &arc_type, const string &begin_key, const string &end_key, const bool list_fsts, FarInfoData *data)
Definition: farscript.cc:63
int32_t int32
Definition: types.h:26
const string & key_prefix
Definition: farscript.h:98
void FarCompileStrings(const std::vector< string > &in_fnames, const string &out_fname, const string &arc_type, const string &fst_type, const FarType &far_type, int32 generate_keys, FarEntryType fet, FarTokenType tt, const string &symbols_fname, const string &unknown_symbol, bool keep_symbols, bool initial_symbols, bool allow_negative_labels, const string &key_prefix, const string &key_suffix)
Definition: farscript.cc:14
const FarEntryType entry_type
Definition: farscript.h:203
FarEntryType
Definition: far.h:21
const string & out_fname
Definition: farscript.h:95
FarPrintStringsArgs(const std::vector< string > &ifilenames, const FarEntryType entry_type, const FarTokenType token_type, const string &begin_key, const string &end_key, const bool print_key, const bool print_weight, const string &symbols_fname, const bool initial_symbols, const int32 generate_filenames, const string &filename_prefix, const string &filename_suffix)
Definition: farscript.h:215
constexpr float kDelta
Definition: weight.h:109
FarCreateArgs(const std::vector< string > &in_fnames, const string &out_fname, const int32 generate_keys, const FarType &far_type, const string &key_prefix, const string &key_suffix)
Definition: farscript.h:101