farscript.cc revision f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2
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 allow_negative_labels,
38                       bool file_list_input,
39                       const string &key_prefix,
40                       const string &key_suffix) {
41  FarCompileStringsArgs args(in_fnames, out_fname, fst_type, far_type,
42                             generate_keys, fet, tt, symbols_fname,
43                             unknown_symbol, allow_negative_labels,
44                             file_list_input, key_prefix, key_suffix);
45
46  Apply<Operation<FarCompileStringsArgs> >("FarCompileStrings", arc_type,
47                                           &args);
48}
49
50void FarCreate(const vector<string> &in_fnames,
51               const string &out_fname,
52               const string &arc_type,
53               const int32 generate_keys,
54               const bool file_list_input,
55               const FarType &far_type,
56               const string &key_prefix,
57               const string &key_suffix) {
58  FarCreateArgs args(in_fnames, out_fname, generate_keys, file_list_input,
59                     far_type, key_prefix, key_suffix);
60
61  Apply<Operation<FarCreateArgs> >("FarCreate", arc_type, &args);
62}
63
64void FarExtract(const vector<string> &ifilenames,
65                const string &arc_type,
66                int32 generate_filenames, const string &begin_key,
67                const string &end_key, const string &filename_prefix,
68                const string &filename_suffix) {
69  FarExtractArgs args(ifilenames, generate_filenames, begin_key, end_key,
70                      filename_prefix, filename_suffix);
71
72  Apply<Operation<FarExtractArgs> >("FarExtract", arc_type, &args);
73}
74
75void FarInfo(const vector<string> &filenames,
76             const string &arc_type,
77             const string &begin_key,
78             const string &end_key,
79             const bool list_fsts) {
80  FarInfoArgs args(filenames, begin_key, end_key, list_fsts);
81
82  Apply<Operation<FarInfoArgs> >("FarInfo", arc_type, &args);
83}
84
85void FarPrintStrings(const vector<string> &ifilenames,
86                     const string &arc_type,
87                     const FarEntryType entry_type,
88                     const FarTokenType token_type,
89                     const string &begin_key,
90                     const string &end_key,
91                     const bool print_key,
92                     const string &symbols_fname,
93                     const int32 generate_filenames,
94                     const string &filename_prefix,
95                     const string &filename_suffix) {
96  FarPrintStringsArgs args(ifilenames, entry_type, token_type, begin_key,
97                           end_key, print_key, symbols_fname,
98                           generate_filenames,
99                           filename_prefix,
100                           filename_suffix);
101
102  Apply<Operation<FarPrintStringsArgs> >("FarPrintStrings", arc_type,
103                                         &args);
104}
105
106// Instantiate all templates for common arc types.
107
108REGISTER_FST_FAR_OPERATIONS(StdArc);
109REGISTER_FST_FAR_OPERATIONS(LogArc);
110REGISTER_FST_FAR_OPERATIONS(Log64Arc);
111
112}  // namespace script
113}  // namespace fst
114