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 // Definitions of 'scriptable' versions of FAR operations, that is,
18 // those that can be called with FstClass-type arguments.
19
20 #include <fst/extensions/far/farscript.h>
21 #include <fst/script/script-impl.h>
22 #include <fst/extensions/far/far.h>
23
24 namespace fst {
25 namespace script {
26
FarCompileStrings(const 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,bool file_list_input,const string & key_prefix,const string & key_suffix)27 void FarCompileStrings(const vector<string> &in_fnames,
28 const string &out_fname,
29 const string &arc_type,
30 const string &fst_type,
31 const FarType &far_type,
32 int32 generate_keys,
33 FarEntryType fet,
34 FarTokenType tt,
35 const string &symbols_fname,
36 const string &unknown_symbol,
37 bool keep_symbols,
38 bool initial_symbols,
39 bool allow_negative_labels,
40 bool file_list_input,
41 const string &key_prefix,
42 const string &key_suffix) {
43 FarCompileStringsArgs args(in_fnames, out_fname, fst_type, far_type,
44 generate_keys, fet, tt, symbols_fname,
45 unknown_symbol, keep_symbols, initial_symbols,
46 allow_negative_labels, file_list_input,
47 key_prefix, key_suffix);
48
49 Apply<Operation<FarCompileStringsArgs> >("FarCompileStrings", arc_type,
50 &args);
51 }
52
FarCreate(const vector<string> & in_fnames,const string & out_fname,const string & arc_type,const int32 generate_keys,const bool file_list_input,const FarType & far_type,const string & key_prefix,const string & key_suffix)53 void FarCreate(const vector<string> &in_fnames,
54 const string &out_fname,
55 const string &arc_type,
56 const int32 generate_keys,
57 const bool file_list_input,
58 const FarType &far_type,
59 const string &key_prefix,
60 const string &key_suffix) {
61 FarCreateArgs args(in_fnames, out_fname, generate_keys, file_list_input,
62 far_type, key_prefix, key_suffix);
63
64 Apply<Operation<FarCreateArgs> >("FarCreate", arc_type, &args);
65 }
66
FarEqual(const string & filename1,const string & filename2,const string & arc_type,float delta,const string & begin_key,const string & end_key)67 bool FarEqual(const string &filename1, const string &filename2,
68 const string &arc_type, float delta,
69 const string &begin_key, const string &end_key) {
70 FarEqualInnerArgs args(filename1, filename2, delta, begin_key, end_key);
71 FarEqualArgs args_with_retval(args);
72
73 Apply<Operation<FarEqualArgs> >("FarEqual", arc_type, &args_with_retval);
74 return args_with_retval.retval;
75 }
76
FarExtract(const 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)77 void FarExtract(const vector<string> &ifilenames,
78 const string &arc_type,
79 int32 generate_filenames,
80 const string &keys,
81 const string &key_separator,
82 const string &range_delimiter,
83 const string &filename_prefix,
84 const string &filename_suffix) {
85 FarExtractArgs args(ifilenames, generate_filenames, keys,
86 key_separator, range_delimiter,
87 filename_prefix, filename_suffix);
88
89 Apply<Operation<FarExtractArgs> >("FarExtract", arc_type, &args);
90 }
91
FarInfo(const vector<string> & filenames,const string & arc_type,const string & begin_key,const string & end_key,const bool list_fsts)92 void FarInfo(const vector<string> &filenames,
93 const string &arc_type,
94 const string &begin_key,
95 const string &end_key,
96 const bool list_fsts) {
97 FarInfoArgs args(filenames, begin_key, end_key, list_fsts);
98
99 Apply<Operation<FarInfoArgs> >("FarInfo", arc_type, &args);
100 }
101
FarPrintStrings(const 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)102 void FarPrintStrings(const vector<string> &ifilenames,
103 const string &arc_type,
104 const FarEntryType entry_type,
105 const FarTokenType token_type,
106 const string &begin_key,
107 const string &end_key,
108 const bool print_key,
109 const bool print_weight,
110 const string &symbols_fname,
111 const bool initial_symbols,
112 const int32 generate_filenames,
113 const string &filename_prefix,
114 const string &filename_suffix) {
115 FarPrintStringsArgs args(ifilenames, entry_type, token_type,
116 begin_key, end_key, print_key, print_weight,
117 symbols_fname, initial_symbols, generate_filenames,
118 filename_prefix, filename_suffix);
119
120 Apply<Operation<FarPrintStringsArgs> >("FarPrintStrings", arc_type,
121 &args);
122 }
123
124 // Instantiate all templates for common arc types.
125
126 REGISTER_FST_FAR_OPERATIONS(StdArc);
127 REGISTER_FST_FAR_OPERATIONS(LogArc);
128 REGISTER_FST_FAR_OPERATIONS(Log64Arc);
129
130 } // namespace script
131 } // namespace fst
132