• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 // you may not use this file except in compliance with the License.
4 // You may obtain a copy of the License at
5 //
6 //     http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13 //
14 // Copyright 2005-2010 Google, Inc.
15 // Author: jpr@google.com (Jake Ratkiewicz)
16 
17 // Convenience file for including all of the FAR operations,
18 // or registering them for new arc types.
19 
20 #ifndef FST_EXTENSIONS_FAR_FARSCRIPT_H_
21 #define FST_EXTENSIONS_FAR_FARSCRIPT_H_
22 
23 #include <vector>
24 using std::vector;
25 #include <string>
26 
27 #include <fst/script/arg-packs.h>
28 #include <fst/extensions/far/compile-strings.h>
29 #include <fst/extensions/far/create.h>
30 #include <fst/extensions/far/extract.h>
31 #include <fst/extensions/far/info.h>
32 #include <fst/extensions/far/print-strings.h>
33 #include <fst/extensions/far/far.h>
34 
35 #include <fst/types.h>
36 
37 namespace fst {
38 namespace script {
39 
40 // Note: it is safe to pass these strings as references because
41 // this struct is only used to pass them deeper in the call graph.
42 // Be sure you understand why this is so before using this struct
43 // for anything else!
44 struct FarCompileStringsArgs {
45   const vector<string> &in_fnames;
46   const string &out_fname;
47   const string &fst_type;
48   const FarType &far_type;
49   const int32 generate_keys;
50   const FarEntryType fet;
51   const FarTokenType tt;
52   const string &symbols_fname;
53   const string &unknown_symbol;
54   const bool allow_negative_labels;
55   const bool file_list_input;
56   const string &key_prefix;
57   const string &key_suffix;
58 
FarCompileStringsArgsFarCompileStringsArgs59   FarCompileStringsArgs(const vector<string> &in_fnames,
60                         const string &out_fname,
61                         const string &fst_type,
62                         const FarType &far_type,
63                         int32 generate_keys,
64                         FarEntryType fet,
65                         FarTokenType tt,
66                         const string &symbols_fname,
67                         const string &unknown_symbol,
68                         bool allow_negative_labels,
69                         bool file_list_input,
70                         const string &key_prefix,
71                         const string &key_suffix) :
72       in_fnames(in_fnames), out_fname(out_fname), fst_type(fst_type),
73       far_type(far_type), generate_keys(generate_keys), fet(fet),
74       tt(tt), symbols_fname(symbols_fname), unknown_symbol(unknown_symbol),
75       allow_negative_labels(allow_negative_labels),
76       file_list_input(file_list_input), key_prefix(key_prefix),
77       key_suffix(key_suffix) { }
78 };
79 
80 template <class Arc>
FarCompileStrings(FarCompileStringsArgs * args)81 void FarCompileStrings(FarCompileStringsArgs *args) {
82   fst::FarCompileStrings<Arc>(
83       args->in_fnames, args->out_fname, args->fst_type, args->far_type,
84       args->generate_keys, args->fet, args->tt, args->symbols_fname,
85       args->unknown_symbol, args->allow_negative_labels, args->file_list_input,
86       args->key_prefix, args->key_suffix);
87 }
88 
89 void FarCompileStrings(
90     const vector<string> &in_fnames,
91     const string &out_fname,
92     const string &arc_type,
93     const string &fst_type,
94     const FarType &far_type,
95     int32 generate_keys,
96     FarEntryType fet,
97     FarTokenType tt,
98     const string &symbols_fname,
99     const string &unknown_symbol,
100     bool allow_negative_labels,
101     bool file_list_input,
102     const string &key_prefix,
103     const string &key_suffix);
104 
105 
106 // Note: it is safe to pass these strings as references because
107 // this struct is only used to pass them deeper in the call graph.
108 // Be sure you understand why this is so before using this struct
109 // for anything else!
110 struct FarCreateArgs {
111   const vector<string> &in_fnames;
112   const string &out_fname;
113   const int32 generate_keys;
114   const bool file_list_input;
115   const FarType &far_type;
116   const string &key_prefix;
117   const string &key_suffix;
118 
FarCreateArgsFarCreateArgs119   FarCreateArgs(
120       const vector<string> &in_fnames, const string &out_fname,
121       const int32 generate_keys, const bool file_list_input,
122       const FarType &far_type, const string &key_prefix,
123       const string &key_suffix)
124       : in_fnames(in_fnames), out_fname(out_fname),
125         generate_keys(generate_keys), file_list_input(file_list_input),
126         far_type(far_type), key_prefix(key_prefix), key_suffix(key_suffix) { }
127 };
128 
129 template<class Arc>
FarCreate(FarCreateArgs * args)130 void FarCreate(FarCreateArgs *args) {
131   fst::FarCreate<Arc>(args->in_fnames, args->out_fname, args->generate_keys,
132                           args->file_list_input, args->far_type,
133                           args->key_prefix, args->key_suffix);
134 }
135 
136 void FarCreate(const vector<string> &in_fnames,
137                const string &out_fname,
138                const string &arc_type,
139                const int32 generate_keys,
140                const bool file_list_input,
141                const FarType &far_type,
142                const string &key_prefix,
143                const string &key_suffix);
144 
145 
146 typedef args::Package<const vector<string> &, int32,
147                       const string&, const string&, const string&,
148                       const string&> FarExtractArgs;
149 
150 template<class Arc>
FarExtract(FarExtractArgs * args)151 void FarExtract(FarExtractArgs *args) {
152   fst::FarExtract<Arc>(
153       args->arg1, args->arg2, args->arg3, args->arg4, args->arg5, args->arg6);
154 }
155 
156 void FarExtract(const vector<string> &ifilenames,
157                 const string &arc_type,
158                 int32 generate_filenames, const string &begin_key,
159                 const string &end_key, const string &filename_prefix,
160                 const string &filename_suffix);
161 
162 typedef args::Package<const vector<string> &, const string &,
163                       const string &, const bool> FarInfoArgs;
164 
165 template <class Arc>
FarInfo(FarInfoArgs * args)166 void FarInfo(FarInfoArgs *args) {
167   fst::FarInfo<Arc>(args->arg1, args->arg2, args->arg3, args->arg4);
168 }
169 
170 void FarInfo(const vector<string> &filenames,
171              const string &arc_type,
172              const string &begin_key,
173              const string &end_key,
174              const bool list_fsts);
175 
176 struct FarPrintStringsArgs {
177   const vector<string> &ifilenames;
178   const FarEntryType entry_type;
179   const FarTokenType token_type;
180   const string &begin_key;
181   const string &end_key;
182   const bool print_key;
183   const string &symbols_fname;
184   const int32 generate_filenames;
185   const string &filename_prefix;
186   const string &filename_suffix;
187 
FarPrintStringsArgsFarPrintStringsArgs188   FarPrintStringsArgs(
189       const vector<string> &ifilenames, const FarEntryType entry_type,
190       const FarTokenType token_type, const string &begin_key,
191       const string &end_key,  const bool print_key,
192       const string &symbols_fname, const int32 generate_filenames,
193       const string &filename_prefix, const string &filename_suffix) :
194       ifilenames(ifilenames), entry_type(entry_type), token_type(token_type),
195       begin_key(begin_key), end_key(end_key), print_key(print_key),
196       symbols_fname(symbols_fname),
197       generate_filenames(generate_filenames), filename_prefix(filename_prefix),
198       filename_suffix(filename_suffix) { }
199 };
200 
201 template <class Arc>
FarPrintStrings(FarPrintStringsArgs * args)202 void FarPrintStrings(FarPrintStringsArgs *args) {
203   fst::FarPrintStrings<Arc>(
204       args->ifilenames, args->entry_type, args->token_type,
205       args->begin_key, args->end_key, args->print_key,
206       args->symbols_fname, args->generate_filenames, args->filename_prefix,
207       args->filename_suffix);
208 }
209 
210 
211 void FarPrintStrings(const vector<string> &ifilenames,
212                      const string &arc_type,
213                      const FarEntryType entry_type,
214                      const FarTokenType token_type,
215                      const string &begin_key,
216                      const string &end_key,
217                      const bool print_key,
218                      const string &symbols_fname,
219                      const int32 generate_filenames,
220                      const string &filename_prefix,
221                      const string &filename_suffix);
222 
223 }  // namespace script
224 }  // namespace fst
225 
226 
227 #define REGISTER_FST_FAR_OPERATIONS(ArcType)                            \
228   REGISTER_FST_OPERATION(FarCompileStrings, ArcType, FarCompileStringsArgs); \
229   REGISTER_FST_OPERATION(FarCreate, ArcType, FarCreateArgs);            \
230   REGISTER_FST_OPERATION(FarExtract, ArcType, FarExtractArgs);          \
231   REGISTER_FST_OPERATION(FarInfo, ArcType, FarInfoArgs);                \
232   REGISTER_FST_OPERATION(FarPrintStrings, ArcType, FarPrintStringsArgs)
233 
234 #endif  // FST_EXTENSIONS_FAR_FARSCRIPT_H_
235