farscript.cc revision dfd8b8327b93660601d016cdc6f29f433b45a8d8
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
24namespace fst {
25namespace script {
26
27void 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
53void 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
67bool 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
77void FarExtract(const vector<string> &ifilenames,
78                const string &arc_type,
79                int32 generate_filenames, const string &begin_key,
80                const string &end_key, const string &filename_prefix,
81                const string &filename_suffix) {
82  FarExtractArgs args(ifilenames, generate_filenames, begin_key, end_key,
83                      filename_prefix, filename_suffix);
84
85  Apply<Operation<FarExtractArgs> >("FarExtract", arc_type, &args);
86}
87
88void FarInfo(const vector<string> &filenames,
89             const string &arc_type,
90             const string &begin_key,
91             const string &end_key,
92             const bool list_fsts) {
93  FarInfoArgs args(filenames, begin_key, end_key, list_fsts);
94
95  Apply<Operation<FarInfoArgs> >("FarInfo", arc_type, &args);
96}
97
98void FarPrintStrings(const vector<string> &ifilenames,
99                     const string &arc_type,
100                     const FarEntryType entry_type,
101                     const FarTokenType token_type,
102                     const string &begin_key,
103                     const string &end_key,
104                     const bool print_key,
105                     const bool print_weight,
106                     const string &symbols_fname,
107                     const bool initial_symbols,
108                     const int32 generate_filenames,
109                     const string &filename_prefix,
110                     const string &filename_suffix) {
111  FarPrintStringsArgs args(ifilenames, entry_type, token_type,
112                           begin_key, end_key, print_key, print_weight,
113                           symbols_fname, initial_symbols, generate_filenames,
114                           filename_prefix, filename_suffix);
115
116  Apply<Operation<FarPrintStringsArgs> >("FarPrintStrings", arc_type,
117                                         &args);
118}
119
120// Instantiate all templates for common arc types.
121
122REGISTER_FST_FAR_OPERATIONS(StdArc);
123REGISTER_FST_FAR_OPERATIONS(LogArc);
124REGISTER_FST_FAR_OPERATIONS(Log64Arc);
125
126}  // namespace script
127}  // namespace fst
128